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 3a6b988
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/build_paper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
container:
# Most recent version of texlive image has broken minted/pygments
image: ghcr.io/xu-cheng/texlive-full:20221101

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Compile draft
run: |
latexmk -shell-escape -pdf draft
uses: xu-cheng/latex-action@master
with:
root_file: draft.tex

- name: Compile paper
run: |
latexmk -shell-escape -pdf paper
uses: xu-cheng/latex-action@master
with:
root_file: paper.tex

- name: Format Python files with yapf
id: autoyapf
Expand Down
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
4 changes: 3 additions & 1 deletion tools/create-video.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def createImage(data):

shutil.copyfile("Makefile", dirname + "/Makefile")
shutil.copyfile(".latexmkrc", dirname + "/.latexmkrc")
run(['make', '-C', dirname, f"{base_filename}.pdf"], stdout=DEVNULL, stderr=STDOUT)
cmd = ['make', '-C', dirname, f"{base_filename}.pdf"]
print(" ".join(cmd))
#run(['make', '-C', dirname, f"{base_filename}.pdf"], stdout=STDOUT, stderr=STDOUT)
createImageOfPaper(dirname + f"/{base_filename}.pdf")
plotStatistics(commit, dirname + "/statistics.png", branch, count)
run(['convert', dirname + f"/{base_filename}.pdf-full.png", '-resize', '3840x2160',
Expand Down

0 comments on commit 3a6b988

Please sign in to comment.