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

newminted escapeinside= #346

Closed Matthew0x closed 1 year ago

Matthew0x commented 1 year ago

I have looked into other issue reports on this minted option and I fail to understand why the following happens:

\begin{minted}[escapeinside=||]{python}
    1 |\textbf{My sample text}| 2
\end{minted}

image

So this is a minted environment inside a tcbox. There is a macro that puts the environment inside my tcbox, right?

\begin{sketch}
    var.<variable-name>.<key-name>
    1 |\textbf{or}| 2
    var.<variable-name>["key-name"]
\end{sketch}

This is a sample environment, which is based off bash, because I couldn't find a "no-code" type of template to base it on.

image

    \newminted[sketch]{bash}{
            texcomments=true,
            escapeinside=||,
            frame=single,
            framesep=2mm,
            baselinestretch=1.2,
            breaklines=true,
            mathescape=true,
            bgcolor=white,
            fontsize=\footnotesize,
            linenos=true,
            rulecolor=kenpozomeBlack}

Am I missing something or is this a bug?... Adding the escapeinside option to the pre-defined environment doesn't compile to me. I guess it's designed to accept that option directly from the template only. I tried it out with texcomments=false to no difference.

Now, look at this. I turned off my macro, so we can talk about the newminted template only, right?

image

gpoore commented 1 year ago

Have you tried the development version on GitHub? (That is, download the latest minted.sty and put that in the same location as your document.) The upcoming release reimplements escapeinside handling and will likely fix whatever issues you are having.

gpoore commented 1 year ago

Also, if you get things working for some languages but not others (maybe Python works but not bash): escapeinside can be fragile in a language-dependent way based on how it is implemented in Pygments, so in some cases some things can only be accomplished by customizing the Python implementation of the Pygments lexer. Here's the bash implementation: https://github.com/pygments/pygments/blob/master/pygments/lexers/shell.py.

Matthew0x commented 1 year ago

Have you tried the development version on GitHub? (That is, download the latest minted.sty and put that in the same location as your document.) The upcoming release reimplements escapeinside handling and will likely fix whatever issues you are having.

That's nice to hear!

I like the library very much and will be happy to try out the newer version. Your second answer actually seems correct! I tried out Bash and Dockerfile prior to posting, but now I have tried the Terraform parser and it seems to bring different results.

Although, pretty ugly, but at least working.

image

\begin{terraform}
    var.<variable-name>.<key-name>
    1 |\textbf{or}| 2
    var.<variable-name>["key-name"]
\end{terraform}

PS: There is a lexer called literally "text", which fits my need and works properly with the escape flag.