Closed muzimuzhi closed 3 weeks ago
The \detokenize
allows \minted@opt@quote
to be used with things like escapeinside
, which may involve punctuation/symbol characters that cannot be expanded (unless they are redefined to literal versions of themselves). Probably what is needed is putting the language inside a temp macro with \edef
to expand.
The
\detokenize
allows\minted@opt@quote
to be used with things likeescapeinside
, which may involve punctuation/symbol characters that cannot be expanded (unless they are redefined to literal versions of themselves).
Yes and no. \minted@opt@quote
is only used in one place, in \minted@pygmentize
to quote the language name. Things like escapeinside
use another quoting macro, \minted@optlistcl@quote
.
But yes \minted@opt@quote
as is is rather good.
Probably what is needed is putting the language inside a temp macro with
\edef
to expand.
I agree with you that the language can be \edef
ed hence stored in a macro and I already find such one---\minted@lang
, which is only set by \minted@configlang
.
A new proposal:
\minted@configlang
, \edef
the \minted@lang
;\minted@pygmentize
, use \minted@lang
to replace its #2
, and expand \minted@lang
one-step before passing it to \minted@opt@quote
;\minted@pygmentize
uses constant. For example, make them always be called with \minted@lang
, not the value of \minted@lang
. (Mostly because in \minted@pygmentize[#3]{\minted@lang}
it's hard to pass the value of \minted@lang
without either using newly added primitive \expanded
(generally available in popular since texlive 2019) or adding an \edef
.)\minted@pygmentize
doesn't make use of its #2
anymore. Simplification chance.Dear all,
I tried the proposed workaround:
\ifwindows
\def\minted@opt@quote#1{\detokenize\expandafter{\expandafter"\expanded{#1}"}}
\else
\def\minted@opt@quote#1{\detokenize\expandafter{\expandafter'\expanded{#1}'}}
\fi
When enabled, the original issue I had doesn't seems to show up, however another one related is coming (I don't know if it comes before the original issue).
ctfp-ocaml> Chapter 1.
ctfp-ocaml> (./content/1.1/category-the-essence-of-composition.tex [2]
ctfp-ocaml> ./content/1.1/category-the-essence-of-composition.tex:36: Use of \minted doesn'
ctfp-ocaml> t match its definition.
ctfp-ocaml> \\snip ...alse } \begin {mdframed}\begin {minted}[
ctfp-ocaml> #1]{#2}
ctfp-ocaml> l.36 \begin{snip}{text}
ctfp-ocaml> Output written on ctfp.xdv (13 pages, 140388 bytes).
ctfp-ocaml> Transcript written on ctfp.log.
I have a hunch that this is because of the snip
environment which is defined as such:
\newenvironment{snip}[2][]
{\VerbatimEnvironment
\mdfsetup{
linecolor=gray!20,
linewidth=2pt,
topline=false,
bottomline=false,
rightline=false
}
\begin{mdframed}\begin{minted}[#1]{#2}}
{\end{minted}\end{mdframed}
\vspace{-1ex}}
This environment has always been working before, maybe this is another issue?
Anyway, let me know if you need more information.
@drupol Those five lines need to be surrounded by \makeatletter ... \makeatother
(for more explanation see https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do):
\makeatletter
\ifwindows
\def\minted@opt@quote#1{\detokenize\expandafter{\expandafter"\expanded{#1}"}}
\else
\def\minted@opt@quote#1{\detokenize\expandafter{\expandafter'\expanded{#1}'}}
\fi
\makeatother
It works indeed!
This is fixed in the minted
v3.0 beta. \minted@opt@quote
no longer exists. Settings are now expanded (\edef
) before being passed to the Python side; there are no arbitrary invocations of \detokenize
to interfere.
Description and example
Before v2.7, the example below compiles without errors
Since v2.7, it fails with pygments error
because
\minted@opt@quote{\mylang}
prevents expansion of\mylang
. See a report in #353.Analysis The problem is introduced in https://github.com/gpoore/minted/commit/25e1f300159c3e7848026688415141508248d113. It changed
with
\minted@opt@quote
defined by https://github.com/gpoore/minted/blob/9ac85a3a1ae09936d80daf46927f55c51449555b/source/minted.dtx#L3003-L3007Suggestion