Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer

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 ...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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