Skip to content

Commit

Permalink
Make minted custom lexers work again
Browse files Browse the repository at this point in the history
minted 2.7 changed its behaviour to not allow for custom command
line options, which broke our custom lexer definitions. Here is
a similar bug reported: gpoore/minted#360.

This commit adds a new minted command that allows custom lexers again.
  • Loading branch information
tobiasgrosser committed Apr 22, 2023
1 parent 6fd99c1 commit c8c25dc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
9 changes: 4 additions & 5 deletions paper.tex
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
\usepackage[T1]{fontenc}
\usepackage{microtype}

\usepackage{minted}
\usemintedstyle{colorful}
\newminted[mlir]{tools/MLIRLexer.py:MLIRLexerOnlyOps -x}{mathescape}
\newminted[xdsl]{tools/MLIRLexer.py:MLIRLexer -x}{mathescape, style=murphy}

\usepackage{xargs}
\usepackage{lipsum}
\usepackage{xparse}
Expand All @@ -66,6 +61,10 @@
\input{tex/setup.tex}
\input{tex/acm.tex}

\usemintedstyle{colorful}
\newminted[mlir]{tools/MLIRLexer.py:MLIRLexerOnlyOps}{customlexer, mathescape}
\newminted[xdsl]{tools/MLIRLexer.py:MLIRLexer}{customlexer, mathescape, style=murphy}

% We use the following color scheme
%
% This scheme is both print-friendly and colorblind safe for
Expand Down
40 changes: 40 additions & 0 deletions tex/setup.tex
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,43 @@
\expandafter\newcommand\csname #1\endcsname[2][]{##1}%
}%
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add minted and support costum lexers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{minted}
\makeatletter
\ifwindows
\renewcommand{\minted@optlistcl@quote}[2]{%
\ifstrempty{#2}{\detokenize{#1}}{\detokenize{#1="#2"}}}
\else
\renewcommand{\minted@optlistcl@quote}[2]{%
\ifstrempty{#2}{\detokenize{#1}}{\detokenize{#1='#2'}}}
\fi

% similar to \minted@def@optcl@switch
\newcommand{\minted@def@optcl@novalue}[2]{%
\define@booleankey{minted@opt@g}{#1}%
{\minted@addto@optlistcl{\minted@optlistcl@g}{#2}{}%
\@namedef{minted@opt@g:#1}{true}}
{\@namedef{minted@opt@g:#1}{false}}
\define@booleankey{minted@opt@g@i}{#1}%
{\minted@addto@optlistcl{\minted@optlistcl@g@i}{#2}{}%
\@namedef{minted@opt@g@i:#1}{true}}
{\@namedef{minted@opt@g@i:#1}{false}}
\define@booleankey{minted@opt@lang}{#1}%
{\minted@addto@optlistcl@lang{minted@optlistcl@lang\minted@lang}{#2}{}%
\@namedef{minted@opt@lang\minted@lang:#1}{true}}
{\@namedef{minted@opt@lang\minted@lang:#1}{false}}
\define@booleankey{minted@opt@lang@i}{#1}%
{\minted@addto@optlistcl@lang{minted@optlistcl@lang\minted@lang @i}{#2}{}%
\@namedef{minted@opt@lang\minted@lang @i:#1}{true}}
{\@namedef{minted@opt@lang\minted@lang @i:#1}{false}}
\define@booleankey{minted@opt@cmd}{#1}%
{\minted@addto@optlistcl{\minted@optlistcl@cmd}{#2}{}%
\@namedef{minted@opt@cmd:#1}{true}}
{\@namedef{minted@opt@cmd:#1}{false}}
}

\minted@def@optcl@novalue{customlexer}{-x}
\makeatother

0 comments on commit c8c25dc

Please sign in to comment.