我无法在 Windows 10 上使用 TeXworks 运行 minted,我不知道为什么......
这是我的 .tex 文件:
\documentclass{article}
\usepackage{graphicx}
\usepackage{minted}
\begin{document}
\begin{listing}[h!]
\begin{minted}{Python}
def hello_world():
print("Hello floating world!")
\end{minted}
\inputminted{pascal}{screentime/screentime.pas}
\caption{Floating listing.}
\label{lst:hello}
\end{listing}
\end{document}
编译错误:
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (MiKTeX 21.8)
entering extended mode
(C:/Users/schodmi/Desktop/A01/Lesson-1.tex
LaTeX2e <2021-06-01> patch level 1
L3 programming layer <2021-08-27>
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/base\article.cls
Document Class: article 2021/02/12 v1.4n Standard LaTeX document class
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/base\size10.clo))
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/graphics\graphicx.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/graphics\keyval.sty)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/graphics\graphics.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/graphics\trig.sty)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/graphics-cfg\graphics
.cfg)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/graphics-def\pdftex.d
ef)))
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/minted\minted.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/kvoptions\kvoptions.s
ty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/ltxcmds\ltxcmds.sty
)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/kvsetkeys\kvsetkeys
.sty))
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/fvextra\fvextra.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/base\ifthen.sty)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/etoolbox\etoolbox.sty
)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/fancyvrb\fancyvrb.sty
) (C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/upquote\upquote.sty
) (C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/lineno\lineno.sty))
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/tools\calc.sty)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/tools\shellesc.sty)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/ifplatform\ifplatform
.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/pdftexcmds\pdftexcm
ds.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/infwarerr\infwarerr
.sty)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/iftex\iftex.sty))
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/catchfile\catchfile
.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/etexcmds\etexcmds.s
ty))
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/iftex\ifluatex.sty)
) (C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/xstring\xstring.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/generic/xstring\xstring.tex
)) (C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/framed\framed.sty)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/float\float.sty))
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/xcolor\xcolor.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/graphics-cfg\color.cf
g))
C:\Users\schodmi\AppData\Local\Temp\1\mik79764\_src>set /p x=C:\Users\schodmi\Miniconda3\Scripts\pygmentize.exe 0<nul: 1>>Lesson-1.aex
C:\Users\schodmi\AppData\Local\Temp\1\mik79764\_src>set /p x= 0<nul: 1>>Lesson-1.aex
C:\Users\schodmi\AppData\Local\Temp\1\mik79764\_src>set /p x= 0<nul: 1>>Lesson-1.aex
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/l3backend\l3backend-p
dftex.def)
No file Lesson-1.aux.
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/context/base/mkii\supp-pdf.
mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/epstopdf-pkg\epstopdf
-base.sty
(C:\Users\schodmi\AppData\Local\Programs\MiKTeX\tex/latex/00miktex\epstopdf-sys
.cfg)) [1{C:/Users/schodmi/AppData/Local/MiKTeX/pdftex/config/pdftex.map}]
(_minted-Lesson-1/default-pyg-prefix.pygstyle)
(_minted-Lesson-1/default.pygstyle)
(_minted-Lesson-1/30A1976BD221E0E570D0694297709B14BEF32A50D0526707C76F4235AAD6E
FD1.pygtex)Error: cannot read infile: [Errno 2] No such file or directory: 'screentime/screentime.pas'
! 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.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.34 ...tminted{pascal}{screentime/screentime.pas}
?
我安装了 python 3.9.5(Miniconda),我在“C:\Users\schodmi\Miniconda3\Scripts”中安装了 pygmentize,并将其添加到我的环境变量中。
.pyg 文件似乎存储在 %AppData%/../Temp 中,TeXworks 无法找到它,但我没有找到有关此问题的任何帮助。
答案1
嗨,你不想尝试一下这个吗?
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\begin{document}
\lstinputlisting[language=Python,caption={My listing},label={lst:1}]{4.py}
\end{document}
答案2
问题是 TeXworks 不会查看您自己的环境变量。当 TeX 由 TeXworks 启动时,它只知道一组有限的位置来搜索 shell 命令。特别是,TeX 不知道在哪里寻找 pygment。
一个问题已经就该事项进行了填补。
同时,OS X 上的解决方案是从终端而不是桌面启动 TeXworks。Windows 上肯定有类似的解决方案。