1

I choose the package pygmentex to highlight my source code in LaTeX. I compile the test.texusing the following command:

xelatex -shell-escape test.tex

But it doesn't work, there is no code on the PDF.

\documentclass{article}
\usepackage{pygmentex}
\begin{document}
    Hello World
    \begin{pygmented}[lang=c++]
#include<cstdio>
int main(){
    printf("Hello World");
return 0;
}
    \end{pygmented}
\end{document}

1 Answers1

2

As explained in the package manual, the package generates a .snippets file and you must run the external program pygmentex on this file. The -shell-escape flag is not necessary for the LaTeX runs.

Relevant section of the manual (page 1 at the bottom):

When compiling the document (with pdflatex, for instance), all the source code listings in the document wil be collected and saved in a temporary file with the extension .snippets in its name. Then the auxiliary program pygmentex (a Python application distributed with the PygmenTEX package) should be run taking this file as input. It will produce another temporary file with the extension .pygmented, containing LATEX code for the code listings previously collected. The next time the document is compiled, they are included to produce the final typeset document.

For the example you can therefore use the following compile sequence:

xelatex test.tex
pygmentex test.snippets
xelatex test.tex

Result:

enter image description here

Marijn
  • 37,699