我正在尝试在新电脑上使用该minted
软件包。我的 tex 代码如下,我在 Windows 10 中使用 MikTeX + TexMaker:
\documentclass{article}
\usepackage[cache=false]{minted}
\begin{document}
First Line
\begin{minted}{python}
import numpy as np
\end{minted}
Second Line
\end{document}
在XeLaTeX中,编译命令行为"xelatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex"
,输出结果并没有显示预期的高亮Python代码:
而在PdfLaTeX中,编译命令行带有"pdflatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex"
输出结果:
我想使用 XeLaTeX,但不知道如何使用。有什么建议或提示吗?
PS日志文件的完整内容:
This is XeTeX, Version 3.141592653-2.6-0.999995 (MiKTeX 24.1) (preloaded format=xelatex 2024.3.23) 28 MAR 2024 15:33
entering extended mode
\write18 enabled.
%&-line parsing enabled.
**./test.tex
(test.tex
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-01-04>
(D:\OfficeSoftware\MikTex\tex/latex/base\article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(D:\OfficeSoftware\MikTex\tex/latex/base\size10.clo
File: size10.clo 2023/05/17 v1.4n Standard LaTeX file (size option)
)
\c@part=\count183
\c@section=\count184
\c@subsection=\count185
\c@subsubsection=\count186
\c@paragraph=\count187
\c@subparagraph=\count188
\c@figure=\count189
\c@table=\count190
\abovecaptionskip=\skip48
\belowcaptionskip=\skip49
\bibindent=\dimen140
)
(D:\OfficeSoftware\MikTex\tex/latex/minted\minted.sty
Package: minted 2023/12/18 v2.9 Yet another Pygments shim for LaTeX
(D:\OfficeSoftware\MikTex\tex/latex/graphics\keyval.sty
Package: keyval 2022/05/29 v1.15 key=value parser (DPC)
\KV@toks@=\toks17
)
(D:\OfficeSoftware\MikTex\tex/latex/kvoptions\kvoptions.sty
Package: kvoptions 2022-06-15 v3.15 Key value format for package options (HO)
(D:\OfficeSoftware\MikTex\tex/generic/ltxcmds\ltxcmds.sty
Package: ltxcmds 2023-12-04 v1.26 LaTeX kernel commands for general use (HO)
)
(D:\OfficeSoftware\MikTex\tex/latex/kvsetkeys\kvsetkeys.sty
Package: kvsetkeys 2022-10-05 v1.19 Key value parser (HO)
))
(D:\OfficeSoftware\MikTex\tex/latex/fvextra\fvextra.sty
Package: fvextra 2023/11/28 v1.6.1 fvextra - extensions and patches for fancyvr
b
(D:\OfficeSoftware\MikTex\tex/latex/etoolbox\etoolbox.sty
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
\etb@tempcnta=\count191
)
(D:\OfficeSoftware\MikTex\tex/latex/fancyvrb\fancyvrb.sty
Package: fancyvrb 2024/01/20 4.5c verbatim text (tvz,hv)
\FV@CodeLineNo=\count192
\FV@InFile=\read2
\FV@TabBox=\box51
\c@FancyVerbLine=\count193
\FV@StepNumber=\count194
\FV@OutFile=\write3
)
(D:\OfficeSoftware\MikTex\tex/latex/upquote\upquote.sty
Package: upquote 2012/04/19 v1.3 upright-quote and grave-accent glyphs in verba
tim
(D:\OfficeSoftware\MikTex\tex/latex/base\textcomp.sty
Package: textcomp 2020/02/02 v2.0n Standard LaTeX package
))
(D:\OfficeSoftware\MikTex\tex/latex/lineno\lineno.sty
Package: lineno 2023/05/20 line numbers on paragraphs v5.3
Invalid UTF-8 byte or sequence at line 292 replaced by U+FFFD.
\linenopenalty=\count195
\output=\toks18
\linenoprevgraf=\count196
\linenumbersep=\dimen141
\linenumberwidth=\dimen142
\c@linenumber=\count197
\c@pagewiselinenumber=\count198
\c@LN@truepage=\count199
\c@internallinenumber=\count266
\c@internallinenumbers=\count267
\quotelinenumbersep=\dimen143
\bframerule=\dimen144
\bframesep=\dimen145
\bframebox=\box52
LaTeX Info: Redefining \\ on input line 3180.
)
\c@FancyVerbWriteLine=\count268
\c@FancyVerbBufferIndex=\count269
\c@FancyVerbBufferLength=\count270
\c@FancyVerbBufferLine=\count271
\c@FV@oldbufferlength=\count272
\c@FV@TrueTabGroupLevel=\count273
\c@FV@TrueTabCounter=\count274
\FV@TabBox@Group=\box53
\FV@TmpLength=\skip50
\c@FV@HighlightLinesStart=\count275
\c@FV@HighlightLinesStop=\count276
\FV@LoopCount=\count277
\FV@NCharsBox=\box54
\FV@BreakIndent=\dimen146
\FV@BreakIndentNChars=\count278
\FV@BreakSymbolSepLeft=\dimen147
\FV@BreakSymbolSepLeftNChars=\count279
\FV@BreakSymbolSepRight=\dimen148
\FV@BreakSymbolSepRightNChars=\count280
\FV@BreakSymbolIndentLeft=\dimen149
\FV@BreakSymbolIndentLeftNChars=\count281
\FV@BreakSymbolIndentRight=\dimen150
\FV@BreakSymbolIndentRightNChars=\count282
\c@FancyVerbLineBreakLast=\count283
\FV@LineBox=\box55
\FV@LineIndentBox=\box56
\c@FV@BreakBufferDepth=\count284
\FV@LineWidth=\dimen151
)
(D:\OfficeSoftware\MikTex\tex/latex/base\ifthen.sty
Package: ifthen 2022/04/13 v1.1d Standard LaTeX ifthen package (DPC)
)
(D:\OfficeSoftware\MikTex\tex/latex/tools\shellesc.sty
Package: shellesc 2023/07/08 v1.0d unified shell escape interface for LaTeX
Package shellesc Info: Unrestricted shell escape enabled on input line 75.
)
(D:\OfficeSoftware\MikTex\tex/latex/ifplatform\ifplatform.sty
Package: ifplatform 2017/10/13 v0.4a Testing for the operating system
(D:\OfficeSoftware\MikTex\tex/generic/pdftexcmds\pdftexcmds.sty
Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO
)
(D:\OfficeSoftware\MikTex\tex/generic/infwarerr\infwarerr.sty
Package: infwarerr 2019/12/03 v1.5 Providing info/warning/error messages (HO)
)
(D:\OfficeSoftware\MikTex\tex/generic/iftex\iftex.sty
Package: iftex 2022/02/03 v1.0f TeX engine tests
)
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode not found.
)
(D:\OfficeSoftware\MikTex\tex/generic/catchfile\catchfile.sty
Package: catchfile 2019/12/09 v1.8 Catch the contents of a file (HO)
(D:\OfficeSoftware\MikTex\tex/generic/etexcmds\etexcmds.sty
Package: etexcmds 2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO)
))
(D:\OfficeSoftware\MikTex\tex/generic/iftex\ifluatex.sty
Package: ifluatex 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.
))
(D:\OfficeSoftware\MikTex\tex/latex/xstring\xstring.sty
(D:\OfficeSoftware\MikTex\tex/generic/xstring\xstring.tex
\xs_counta=\count285
\xs_countb=\count286
)
Package: xstring 2023/08/22 v1.86 String manipulations (CT)
)
(D:\OfficeSoftware\MikTex\tex/latex/framed\framed.sty
Package: framed 2011/10/22 v 0.96: framed or shaded text with page breaks
\OuterFrameSep=\skip51
\fb@frw=\dimen152
\fb@frh=\dimen153
\FrameRule=\dimen154
\FrameSep=\dimen155
)
(D:\OfficeSoftware\MikTex\tex/latex/float\float.sty
Package: float 2001/11/08 v1.3d Float enhancements (AL)
\c@float@type=\count287
\float@exts=\toks19
\float@box=\box57
\@float@everytoks=\toks20
\@floatcapt=\box58
)
\minted@appexistsfile=\read3
\minted@bgbox=\box59
\minted@code=\write4
\c@minted@FancyVerbLineTemp=\count288
\c@minted@pygmentizecounter=\count289
\@float@every@listing=\toks21
\c@listing=\count290
)
(D:\OfficeSoftware\MikTex\tex/latex/xcolor\xcolor.sty
Package: xcolor 2023/11/15 v3.01 LaTeX color extensions (UK)
(D:\OfficeSoftware\MikTex\tex/latex/graphics-cfg\color.cfg
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
Package xcolor Info: Driver file: xetex.def on input line 274.
(D:\OfficeSoftware\MikTex\tex/latex/graphics-def\xetex.def
File: xetex.def 2022/09/22 v5.0n Graphics/color driver for xetex
)
(D:\OfficeSoftware\MikTex\tex/latex/graphics\mathcolor.ltx)
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1350.
Package xcolor Info: Model `RGB' extended on input line 1366.
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1368.
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1369.
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1370.
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1371.
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1372.
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1373.
)
runsystem(for ^%i in (pygmentize.exe pygmentize.bat pygmentize.cmd) do set > te
st.aex <nul: /p x=^%~$PATH:i>> test.aex)...executed.
runsystem(del test.aex)...executed.
(D:\OfficeSoftware\MikTex\tex/latex/l3backend\l3backend-xetex.def
File: l3backend-xetex.def 2024-01-04 L3 backend support: XeTeX
\g__graphics_track_int=\count291
\l__pdf_internal_box=\box60
\g__pdf_backend_object_int=\count292
\g__pdf_backend_annotation_int=\count293
\g__pdf_backend_link_int=\count294
)
No file test.aux.
\openout1 = `test.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 3.
LaTeX Font Info: Trying to load font information for TS1+cmr on input line 3
.
(D:\OfficeSoftware\MikTex\tex/latex/base\ts1cmr.fd
File: ts1cmr.fd 2023/04/13 v2.5m Standard LaTeX font definitions
)
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for TU/lmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
\openout3 = `test.pyg'.
runsystem(pygmentize -S default -f latex -P commandprefix=PYG > test.out.pyg)..
.executed.
(test.out.pyg)
runsystem(pygmentize -l "python" -f latex -P commandprefix=PYG -F tokenmerge -P
stripnl="False" -o test.out.pyg test.pyg)...executed.
(test.out.pyg) [1
] (test.aux)
***********
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-01-04>
***********
runsystem(del test.pyg)...executed.
runsystem(del test.out.pyg)...executed.
)
Here is how much of TeX's memory you used:
5028 strings out of 409616
96945 string characters out of 5778052
1918191 words of memory out of 5000000
27102 multiletter control sequences out of 15000+600000
558077 words of font info for 37 fonts, out of 8000000 for 9000
1348 hyphenation exceptions out of 8191
74i,5n,81p,268b,207s stack positions out of 10000i,1000n,20000p,200000b,200000s
Output written on test.pdf (1 page).
我比较了XeLaTeX和PdfLaTeX的日志文件,主要区别是:
(D:\OfficeSoftware\MikTex\tex/latex/l3backend\l3backend-pdftex.def
File: l3backend-pdftex.def 2024-01-04 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count295
\l__pdf_internal_box=\box60
) (test.aux)
\openout1 = `test.aux'.
还有 XeLaTex 的
(D:\OfficeSoftware\MikTex\tex/latex/l3backend\l3backend-xetex.def
File: l3backend-xetex.def 2024-01-04 L3 backend support: XeTeX
\g__graphics_track_int=\count291
\l__pdf_internal_box=\box60
\g__pdf_backend_object_int=\count292
\g__pdf_backend_annotation_int=\count293
\g__pdf_backend_link_int=\count294
)
No file test.aux.
\openout1 = `test.aux'.
命令行"xelatex -synctex=1 -interaction=nonstopmode -shell-escape test.tex"
执行后显示的完整内容:
I:\test>xelatex -synctex=1 -interaction=nonstopmode --shell-escape test.tex
xelatex: security risk: running with elevated privileges
This is XeTeX, Version 3.141592653-2.6-0.999995 (MiKTeX 24.1) (preloaded format=xelatex.fmt)
\write18 enabled.
entering extended mode
(test.tex
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-01-04>
(D:\OfficeSoftware\MikTex\tex/latex/base\article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(D:\OfficeSoftware\MikTex\tex/latex/base\size10.clo))
(D:\OfficeSoftware\MikTex\tex/latex/minted\minted.sty
(D:\OfficeSoftware\MikTex\tex/latex/graphics\keyval.sty)
(D:\OfficeSoftware\MikTex\tex/latex/kvoptions\kvoptions.sty
(D:\OfficeSoftware\MikTex\tex/generic/ltxcmds\ltxcmds.sty)
(D:\OfficeSoftware\MikTex\tex/latex/kvsetkeys\kvsetkeys.sty))
(D:\OfficeSoftware\MikTex\tex/latex/fvextra\fvextra.sty
(D:\OfficeSoftware\MikTex\tex/latex/etoolbox\etoolbox.sty)
(D:\OfficeSoftware\MikTex\tex/latex/fancyvrb\fancyvrb.sty)
(D:\OfficeSoftware\MikTex\tex/latex/upquote\upquote.sty
(D:\OfficeSoftware\MikTex\tex/latex/base\textcomp.sty))
(D:\OfficeSoftware\MikTex\tex/latex/lineno\lineno.sty))
(D:\OfficeSoftware\MikTex\tex/latex/base\ifthen.sty)
(D:\OfficeSoftware\MikTex\tex/latex/tools\shellesc.sty)
(D:\OfficeSoftware\MikTex\tex/latex/ifplatform\ifplatform.sty
(D:\OfficeSoftware\MikTex\tex/generic/pdftexcmds\pdftexcmds.sty
(D:\OfficeSoftware\MikTex\tex/generic/infwarerr\infwarerr.sty)
(D:\OfficeSoftware\MikTex\tex/generic/iftex\iftex.sty))
(D:\OfficeSoftware\MikTex\tex/generic/catchfile\catchfile.sty
(D:\OfficeSoftware\MikTex\tex/generic/etexcmds\etexcmds.sty))
(D:\OfficeSoftware\MikTex\tex/generic/iftex\ifluatex.sty))
(D:\OfficeSoftware\MikTex\tex/latex/xstring\xstring.sty
(D:\OfficeSoftware\MikTex\tex/generic/xstring\xstring.tex))
(D:\OfficeSoftware\MikTex\tex/latex/framed\framed.sty)
(D:\OfficeSoftware\MikTex\tex/latex/float\float.sty))
(D:\OfficeSoftware\MikTex\tex/latex/xcolor\xcolor.sty
(D:\OfficeSoftware\MikTex\tex/latex/graphics-cfg\color.cfg)
(D:\OfficeSoftware\MikTex\tex/latex/graphics-def\xetex.def)
(D:\OfficeSoftware\MikTex\tex/latex/graphics\mathcolor.ltx))
I:\test>set /p x=C:\Program Files\Python312\Scripts\pygmentize.exe 0<nul: 1>>test.aex
I:\test>set /p x= 0<nul: 1>>test.aex
I:\test>set /p x= 0<nul: 1>>test.aex
1 file(s) copied.
(D:\OfficeSoftware\MikTex\tex/latex/l3backend\l3backend-xetex.def) (test.aux)
(D:\OfficeSoftware\MikTex\tex/latex/base\ts1cmr.fd) (test.out.pyg)Error: Invalid value 'False -o test.out.pyg test.pyg' for option stripnl; use 1/0, yes/no, true/false, on/off
(test.out.pyg) [1] (test.aux)miktex-dvipdfmx: security risk: running with elevated privileges
1 file(s) copied.
1 file(s) copied.
)
(see the transcript file for additional information)
Output written on test.pdf (1 page).
SyncTeX written on test.synctex.gz.
Transcript written on test.log.
I:\test>
对于错误信息"Error: Invalid value 'False -o test.out.pyg test.pyg' for option stripnl; use 1/0, yes/no, true/false, on/off"
,是否是因为 Pygments 选项"stripnl=False"
没有正确分离"-o test.out.pyg test.pyg"
?
\setminted{stripnl=false}
然后,我注释掉了中的行minted.sty
,PdfLaTeX 仍然可以工作,但 XeLaTeX 提示了一个新的错误,内容是Error: no lexer for alias 'python -f latex -P commandprefix=PYG -F tokenmerge -o test.out.pyg test.pyg' found
。现在更加困惑了!
【解决方案】我刚刚更新了整个MikTeX,现在可以正常工作了。似乎上一个MikTeX版本有一些错误,但我找不到它。如果有人遇到类似的问题,你应该尝试更新MikTeX。