5

I need to reproduce the output of a command in a LaTeX document. The command uses ANSI escape codes to produce colored output.

I'd like to use minted, but using \inputminted{shell}{coloredoutput} produces the following error:

! Text line contains an invalid character.
l.2 ^^[
       \PY{o}{[}01\PY{p}{;}31m^^[\PY{o}{[}Kt^^[\PY{o}{[}m^^[\PY{o}{[}K^^[\PY...

To reproduce, create colored output by running

grep --color=always . <(echo test) > coloredoutput

and then compiling the following MWE:

\documentclass{article}
\usepackage{minted}

\begin{document}
\inputminted{shell}{coloredoutput}
\end{document}

You will need -shell-escape.

The error, I imagine, is due to pygments not properly parsing the color codes. How do I force make it parse them properly?

1 Answer 1

4

Unfortunately, this is not possible. Currently, Pygments (which minted uses internally) performs all coloring based on styles, not based on color information passed to it. There has been a feature request for something like this since 2012, but it doesn't appear that any progress has been made.

You have a couple of options. You could look through the existing Pygments styles to see if one of them is close enough to what you need. If not, you could consider creating a custom style. Otherwise, a high-resolution screenshot may be the simplest solution.

1
  • 1
    The feature request URL is broken. Perhaps this alternative might be helpful.
    – Werner
    Mar 29, 2022 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .