Changed minted text color – no language (text option)

minted

I wanted to enclose a bit of text/minimal HTML code in a minted text box. The HTML (a couple <br> and <a href='link'> doesn't matter to me, so I opted to use the text option for language in minted. However, I want to emphasize a few things in red text that are not HTML elements. For example:

Go to this link <a href="domain.com/upload/[UPLOAD_ID]"> to find your upload.

I would like the [UPLOAD_ID] to be in red. Is there any way to do this? Thanks!

Best Answer

The minted documentation has a way to highlight text, as shown here:

enter image description here

As far as I understand, it is achieved by escaping the minted environment and executing the \colorbox command. It is possible to use the \textcolor command, as shown by user187803 instead of \colorbox to make it work with minted.

Example:

\begin{minted}[escapeinside=||]{py}
def f(x):
   y = x|\textcolor{red}{**}|2
   return y
\end{minted}

Result:

enter image description here enter image description here

Applying it to your example, the underscore in [UPLOAD_ID] needs to be escaped with a backslash [UPLOAD\_ID]. This is necessary because the underscore is normally used to index a character. But in this case the underscore should be printed as an underscore and not interpreted to make an index out of ID. If we do not use the backslash here, it will result in an error.

Provided Example:

\begin{minted}[escapeinside=||]{text}
    Go to this link <a href="domain.com/upload/|\textcolor{red}{[UPLOAD\_ID]}|"> to find your upload
\end{minted}

Result: enter image description here