Minted用于为LaTex中的代码添加美感,例如:
\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
\end{document}
我已安装它,如果我从命令行调用它可以正常工作:
pdflatex -shell-escape minimal.tex
但我正在使用Sublime Text Build System来制作PDF,这里是构建脚本:
{
"cmd": ["/Library/TeX/texbin/pdflatex","-shell-escape","$file"],
"selector": "text.tex.latex"
}
出于某种原因,当我点击Ctrl+B
时,它在终端中不起作用。在输出面板中,我看到:
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
\write18 enabled.
entering extended mode
(/Users/user/Downloads/minted/minimal.tex
LaTeX2e <2016/03/31>
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2016/texmf-dist/tex/latex/minted/minted.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(/usr/local/texlive/2016/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix
<2008/02/07> (tvz))
(/usr/local/texlive/2016/texmf-dist/tex/latex/float/float.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/ifplatform/ifplatform.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/catchfile.sty)
(./minimal.w18))
(/usr/local/texlive/2016/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/xstring/xstring.tex))
(/usr/local/texlive/2016/texmf-dist/tex/latex/lineno/lineno.sty))
(./_minted-minimal/default.pygstyle)system returned with code 256
! Package minted Error: You must have `pygmentize' installed to use this packag
e.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.3 \begin{document}
?
为什么通过Sublime Text找不到pygmentize
?
答案 0 :(得分:2)
尽管我喜欢OS X - 这整个路径的故事只是一种痛苦,至少在我看来它似乎在每个主要版本中都会再次发生变化。现在,在启动Sublime Text时,它继承了$PATH
工具{基本上告诉Sublime Text它应该在哪里寻找pdflatex
或pygmentize
之类的外部程序) - 而不是来自shell。因此,即使一切都在shell中完美运行,它也无法使用Sublime Text(或大多数其他编辑器)。
您可以尝试自行解决此问题,如this question on AskDifferent.SE中所述。这样做的好处是它“修复”了所有应用程序的路径,即使你切换到另一个编辑器。为此,您必须将以下内容添加到launchctl
:
.bash_profile
注意,如果终端中的一切正常,您可能不需要第一行。只需确保在设置所有路径后调用export PATH=some_path:another_path
launchctl setenv PATH $PATH
。
如果您更喜欢Sublime Text方式,另一种可能性是将SublimeFixMacPath plugin用于Sublime Text 2或3,它会将您的shell中的所有路径添加到Sublime Text路径。这样,在shell中工作的任何东西也可以在Sublime Text中使用。