0

I'm working on refactoring the building of the open-source book at https://github.com/hmemcpy/milewski-ctfp-pdf. Basically, it was using very old dependencies and I'm refreshing everything.

After upgrading the LaTeX version and python version, I notice that I'm unable to build the document. I'm now stuck because \inputminted is not working as I would expect. Obviously, I might be wrong, but it seems that it doesn't use the value of a variable, but the variable itself. I spent the whole day yesterday trying to figure out what I was doing wrong, without luck.

I tried to reproduce a minimal working environment, here it is:

\documentclass{book}

\usepackage[cache=false,kpsewhich]{minted}

\def\OPTCustomLanguage{ocaml} \def\OPTCustomLanguageExt{ml}

\NewDocumentCommand{\src}{m}{ \srcsnippet{code/haskell/#1.hs}{haskell} \srcsnippet{code/\OPTCustomLanguage/#1.\OPTCustomLanguageExt}{\OPTCustomLanguage} } \NewDocumentCommand{\srcsnippet}{mm}{ \inputminted{#2}{#1} } \begin{document}

\src{snippet01}

\end{document}

Create the src files:

touch code/haskell/snippet01.hs
touch code/ocaml/snippet01.ml

Then compile the document... and the error is:

(/nix/store/nr191iv6nas2ayhwg86v6rdnrymn5lmn-texlive-combined-2022/share/texmf/
tex/latex/l3backend/l3backend-xetex.def) (build/ctfp-ocaml.aux)
(/nix/store/nr191iv6nas2ayhwg86v6rdnrymn5lmn-texlive-combined-2022/share/texmf/
tex/latex/base/ts1cmr.fd) (./ctfp-ocaml.out.pyg) (./ctfp-ocaml.out.pyg)Error: no lexer for alias '\\OPTCustomLanguage ' found
system returned with code 256

Can you tell me if I'm doing something wrong here?

PS: after a bit of search on stackexchange, I found these related issues:

1 Answers1

1

Straight from the author of minted package (see more on the Github issue at https://github.com/gpoore/minted/issues/353):

An expansion issue. Fully expanding args of \inputminted before it absorbs them does the trick.

The fixed code:

\documentclass{book}

\usepackage[cache=false,kpsewhich]{minted}

\def\OPTCustomLanguage{ocaml} \def\OPTCustomLanguageExt{ml}

\NewDocumentCommand{\src}{m}{% \srcsnippet{code/haskell/#1.hs}{haskell}% \srcsnippet{code/\OPTCustomLanguage/#1.\OPTCustomLanguageExt}{\OPTCustomLanguage}% } \NewDocumentCommand{\srcsnippet}{mm}{% \ExpandArgs{ee}% \inputminted{#2}{#1}% }

\begin{document}

\src{snippet01}

\end{document}