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 ^^[

To reproduce, create colored output by running

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

and then compiling the following MWE:



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?


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.