4

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?

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.

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.