minted 软件包在 Windows 7 上无法运行

minted 软件包在 Windows 7 上无法运行

在安装了 MikTeX-21.6 的 Windows 7 笔记本电脑上,我需要使用minted利用 PythonPygments模块的包,因此我安装了Pygments-2.9.0(最新版本),并且它运行完美(我用 pygmented 了一个基本C文件,pygmentize -l c -f latex -P commandprefix=PYG -F tokenmerge main.c它的输出与参考示例相同)的路径pygmentize.exe在 Windows 路径中设置正确。

当我尝试编译以下.tex 文件时:

xelatex.exe -shell-escape pygment_SAMPLE.tex

\documentclass{article}
\RequirePackage[cache=false]{minted}
\usepackage[cache=false]{minted}
\begin{document}
\begin{minted}[fontsize=\small]{c}
int main() {
  printf("hello, world");
}  
\end{minted}
\end{document}

它提示:\minted@apppathifexists=

我输入t后它停止了:

! Package minted Error: Missing Pygments output; \inputminted was
probably given a file that does not exist--otherwise, you may need
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.

问题似乎围绕着这些方面:

for ^%i in (pygmentize.exe pygmentize.bat pygmentize.cmd) do set > pygment_SAMPLE.aex <nul: /p x=^%~$PATH:i>> pygment_SAMPLE.aex

Windows 7 无法正确处理此行或 Windows 7 处理上下文中的路径或文件权限的方式minted

为了调试这个问题,我尝试取消注释第 775 行minted.sty

               % For debugging, uncomment: %%%%
this line -->  % \immediate\typeout{\minted@cmd}%
               % %%%%

但它没有效果。我猜minted.sty必须重建/重新安装,而且我不知道该.tex语言的内部原理。

我已将此问题发布在 github 问题页面上Win 10 - Texlive 无法找到已安装的 pygmentize #280他们建议我将这个问题发布到 StackOverflow 上,因此您可以在这里找到:如何minted在 Windows 7 上正确运行?请注意,此问题也会影响 Windows 10。

更新额外信息:

将这些添加到c:/Program Files/miktex-21.6/texmfs/config/miktex/config/miktex.ini

ShellCommandMode = Restricted
AllowedShellCommands[] = miktex-bibtex
AllowedShellCommands[] = miktex-bibtex8
AllowedShellCommands[] = miktex-epstopdf
AllowedShellCommands[] = miktex-gregorio
AllowedShellCommands[] = miktex-kpsewhich
AllowedShellCommands[] = miktex-makeindex
AllowedShellCommands[] = bibtex
AllowedShellCommands[] = bibtex8
AllowedShellCommands[] = extractbb
AllowedShellCommands[] = findtexmf
AllowedShellCommands[] = gregorio
AllowedShellCommands[] = kpsewhich
AllowedShellCommands[] = makeindex
AllowedShellCommands[] = texosquery-jre8
AllowedShellCommands[] = pygmentize

$ xelatex --restrict-write18 pygments_SAMPLE.tex -shell-escape

出现相同的提示:

C:\Users\Lars
>set  /p x=C:\Program Files\python-3.5.0\Scripts\pygmentize.exe 0<nul: 1>>pygments.aex

C:\Users\Lars
>set  /p x= 0<nul: 1>>pygments.aex

C:\Users\Lars
>set  /p x= 0<nul: 1>>pygments.aex

\minted@apppathifexists=

无论我输入什么,\minted@apppathifexists=它都会显示相同的错误消息。

答案1

首先,确保pygmentize可执行文件的目录位于您的 PATH 中(您可以在系统属性 > 高级中的“环境变量”下编辑它)。您还需要使用选项运行 TeX 程序,--shell-restricted并编辑您的texmf.cnf以允许此特定程序运行,否则请抛开一切顾虑并使用 运行--shell-escape

texmf.cnfTeX Live 2021 中的默认设置是,由于担心其过滤功能的安全性,默认情况下pygmentize不会在中声明。如果您确实想更改此设置,您可以添加shell_escape_commands

shell_escape_commands = \
bibtex,bibtex8,\
extractbb,\
gregorio,\
kpsewhich,\
makeindex,\
repstopdf,\
r-mpost,\
texosquery-jre8,\
pygmentize,\
%

texmf.cnf按照的习俗texlive/YYYY/,而不用 的习俗texlive/YYYY/texmf-dist/web2c/

在 MikTeX 上,你可能想运行 TeX wirh--restrict-write18并运行initexmf来修改miktex.ini。您可能想要添加一个新AllowedShellCommands[] = pygmentize行。

相关内容