minted icon indicating copy to clipboard operation
minted copied to clipboard

escapeinside argument is expanded

Open thisirs opened this issue 4 years ago • 3 comments

I tried to set backquotes as escape characters but failed to get it working. For example, the following is not working:

\begin{minted}[escapeinside=``]{python}
  1 `\textcolor{red}{!=}` 2
\end{minted}

It appears that the backquotes are expanded because the option escapeinside is put in double-quote when passed to the shell (line 612) of minted.sty).

A simple fix is to use quotes instead of double-quotes. So use

\minted@def@optcl@e{escapeinside}{-P 'escapeinside}{#1'}

instead of

\minted@def@optcl@e{escapeinside}{-P "escapeinside}{#1"}

I don't know but it could introduce some regressions.

Regards,

thisirs avatar Dec 18 '19 14:12 thisirs

The following minimal example cannot reproduce your problem.

% minted-escape.tex
\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}[escapeinside=``]{python}
  1 `\textcolor{red}{!=}` 2
\end{minted}
\end{document}
$ pdflatex -shell-escape minted-escape.tex

Maybe your problem came from other settings of your document. For example, symbol ' is set to be active character by \MakeShortVerb{\'}.

muzimuzhi avatar Dec 19 '19 02:12 muzimuzhi

I still have the problem with the MWE. This is really an escaping problem when calling the shell, backquotes are interpreted by the shell (bash for me). This might not be the case for all shells.

When escaping characters from inside the LaTeX source (not ideal), things are working.

\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}[escapeinside=\\`\\`]{python}
  1 `\textcolor{red}{!=}` 2
\end{minted}
\end{document}

thisirs avatar Dec 20 '19 10:12 thisirs

This is really an escaping problem when calling the shell, backquotes are interpreted by the shell (bash for me). This might not be the case for all shells.

Oh, I missed this.

muzimuzhi avatar Dec 21 '19 09:12 muzimuzhi

This should be fixed as of minted v2.7 (2022/12/12). The upcoming minted v3.0 will completely eliminate the entire class of bugs related to shell quoting.

gpoore avatar Sep 12 '23 17:09 gpoore