Texments/minted 无法正常工作-未定义的控制序列

Texments/minted 无法正常工作-未定义的控制序列

我正在尝试为我的代码添加一些语法高亮,并找到了两个包:texments 和 minted。我尝试使用它们,但在尝试构建时出现错误。我使用以下代码测试这两个包:

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

我得到的只是错误:


**! 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) )

我已经安装了 pygments,版本 1.4。

我怎样才能让一切正常运转?

答案1

我想分享针对同一问题的另一种解决方案,该解决方案无法通过 Frédéric 的答案解决。

在安装 minted(并尝试使其工作)的过程中,我使用了一个 TeX 文件和不同的 python、pdftex 等设置。即使编译 Frédéric 的示例也会导致未定义的控制序列。清理子目录_minted-FILENAME解决了这个问题。

答案2

这是一个很容易纠正的错误。您使用的语法不正确。Pygments 是调用的程序minted。该命令(或环境)用于\minted一段代码:

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

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

对于一行代码,命令是\mint。例如, \mint{python}|print "Hello World"| 注意分隔符 | :该\mint命令的工作方式与\verb命令类似,可以使用任何符号(未出现在您的代码行中)。

还有更多选项可用。例如,有一个listing环境将所有内容放在浮动框中。您还可以显示行号、更改颜色等...

相关内容