gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.74k stars 126 forks source link

Minted mintinline not reading arg verbatim #327

Closed sra-minshall closed 2 years ago

sra-minshall commented 2 years ago

Macros defined with \newmintinline do not read their args as verbatim. We end up not being able to write something common such as \inlinetext{scratch_test.js} because a "not in math mode" error occurs. Using the underscore package helps but prevents us from writing \jsfile{scratch_test.js} without generating errors.

It'd be great to have both use cases implemented without using the underscore package!

    \documentclass{beamer}

    % \usepackage[strings]{underscore}
    \usepackage{minted}
    \newmintedfile{js}{linenos} % \jsfile{} ...
    \newmintinline[txt]{inlinetext}{} % \txt{foo}

    \begin{document}

    \jsfile{scratch_test.js}     % this errors *with* \usepackage[strings]{underscore}
    \inlinetext{scratch_test.js} % this errors *without* \usepackage[strings]{underscore}

    \end{document}
gpoore commented 2 years ago

I think this will do what you want (there is no Pygments lexer called inlinetext):

\documentclass{beamer}

\usepackage{minted}
\newmintedfile{js}{linenos}
\newmintinline[txt]{text}{}

\begin{document}

\jsfile{scratch_test.js}
\txt{scratch_test.js}

\end{document}

There may be some edge cases where \newmintinline commands don't give exactly the same behavior as \mintinline, but this seems to work fine.

sra-minshall commented 2 years ago

Thanks Geoffrey,

It works, I was mistaken.

Simon

On Apr 12, 2022, at 4:59 PM, Geoffrey Poore @.***> wrote:

I think this will do what you want (there is no Pygments lexer called inlinetext):

\documentclass{beamer}

\usepackage{minted} \newmintedfile{js}{linenos} \newmintinline[txt]{text}{}

\begin{document}

\jsfile{scratch_test.js} \txt{scratch_test.js}

\end{document} There may be some edge cases where \newmintinline commands don't give exactly the same behavior as \mintinline, but this seems to work fine.

— Reply to this email directly, view it on GitHub https://github.com/gpoore/minted/issues/327#issuecomment-1097397429, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV7CXXIJZ4UQFG25TVPZ5LVEYE5DANCNFSM5TIDRWDQ. You are receiving this because you authored the thread.