4

I'm trying to add some syntax highlighting to my code and found two packages: texments and minted. I tried to use them, but I'm getting errors while trying to build. I used following code to test both packages:

\pygment{python}{ print "Hello World!"}

All what I get is errors:


**! Undefined control sequence.**

<argument> \PY
{k}{print} \PY {l+s}{"}\PY {l+s}{Hello World!}\PY {l+s}{"}
l.2 ...PY{l+s}{"}\PY{l+s}{Hello World!}\PY{l+s}{"}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

**! Undefined control sequence.**

<argument> \PY {k}{print} \PY
{l+s}{"}\PY {l+s}{Hello World!}\PY {l+s}{"}
l.2 ...PY{l+s}{"}\PY{l+s}{Hello World!}\PY{l+s}{"}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

**! Undefined control sequence.**

<argument> \PY {k}{print} \PY {l+s}{"}\PY
{l+s}{Hello World!}\PY {l+s}{"}
l.2 ...PY{l+s}{"}\PY{l+s}{Hello World!}\PY{l+s}{"}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

**! Undefined control sequence.**

<argument> ... {l+s}{"}\PY {l+s}{Hello World!}\PY
{l+s}{"}
l.2 ...PY{l+s}{"}\PY{l+s}{Hello World!}\PY{l+s}{"}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
) [6]) [7] (./mk_mall.aux) )

I have pygments installed, version 1.4.

How can I get everything to work?

  • Hi, welcome to tex.sx. Please format error messages as code blocks. They are easier to read this way. – Martin Scharrer Feb 25 '11 at 10:14
6

I would like to share another solution for the same issue which couldn't be solved by Frédéric's answer.

In the process of installing minted (and trying to get it to work), I used one TeX file and different settings for python, pdftex and so on. Even compiling Frédéric's example would lead to undefined control sequences. Cleaning up the subdirectory _minted-FILENAME solved this.

  • I actually have the same error, though I cannot find the suddirectory _minted*, any hint? – Auzias Oct 26 '16 at 8:11
  • @Auzias It should be in the same directory as your .tex file. If it isn't there, Pygments isn't working yet. Assuming you use Windows, have you tried all steps mentioned in this question? – Seth Nov 7 '16 at 21:28
  • Thanks for the reply. For the record it was a too old version. I upgraded it to v2.2 with the command: curl -o /usr/share/texlive/texmf-dist/tex/latex/minted/minted.sty https://raw.githubusercontent.com/gpoore/minted/0a8640dddff47ae31a7a0d6e3cf030c82c111907/source/minted.sty. – Auzias Nov 8 '16 at 7:12
2

This is an easy error to correct. You are not using the correct syntax. Pygments is the program that minted calls. The command (or environment) is \minted for a piece of code :

\begin{minted}{python}
def f(x) :
    y = x**2
    return y

for x in range(0,10) :
    print f(x)*" " + "Hello World"
\end{minted} 

For a one-line piece of code, the command is \mint. For example, \mint{python}|print "Hello World"| Note the delimiter | : the \mint command works like the \verb command, any symbol (not appearing in your line of code) may be used.

Many more options are available. For example, there is a listing environment that puts everything in a floating box. You may also show the line numbers, change the colors, etc ...

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.