我发现 XeLaTeX 的输出过于冗长。我真的只对错误(而不是警告)和有问题的行号感兴趣。我还希望 xelatex 在出现错误时停止(退出)。有没有可以实现这一点的魔法咒语?
答案1
如果你想摆脱所有警告,你可以加载silence
包裹
\usepackage{silence}
然后发出命令
\WarningsOff*
如果需要,请查看其文档以了解选择性警告过滤和错误过滤。
只要记住警告就是它们本来的意义所在:它们会警告你文档中存在错误。
对于您的后一个请求,如果您希望 xelatex 在出现错误时停止(并退出),请添加--halt-on-error
到命令行,否则,如果您希望提示在哪里决定做什么,请添加--interaction=errorstopmode
到命令行。
答案2
TeX Livetexfot
提供了一个由 Karl Berry 编写的 Perl 脚本。
跑步
texfot --ignore '(Warning|Overfull|Underfull)' pdflatex test
test.tex
在以下文件上
\documentclass{article}
\begin{document}
\hbox to 0pt{aaa} % Overfull \hbox
\hbox to 100pt{x} % Underfull \hbox
{\fontsize{125}{0}\selectfont a} % font warning
\foo % undefined control sequence
\end{document}
控制台上的输出是
/Library/TeX/texbin/texfot: invoking: pdflatex test
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
! Undefined control sequence.
l.11 \foo
! Emergency stop.
l.11 \foo
! ==> Fatal error occurred, no output PDF file produced!
如果您发现其他应该忽略的内容,您可以根据自己的意愿自定义正则表达式字符串。
文件.log
仍然完整生成:
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex 2016.12.23) 6 JAN 2017 23:58
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**test
(./test.tex
LaTeX2e <2016/03/31> patch level 3
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
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (./warnerr.aux)
\openout1 = `warnerr.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 T1/cmr/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 OMS/cmsy/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.
Overfull \hbox (15.00005pt too wide) detected at line 5
\OT1/cmr/m/n/10 aaa
[]
Underfull \hbox (badness 10000) detected at line 7
\OT1/cmr/m/n/10 x
[]
LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size <125> not available
(Font) size <24.88> substituted on input line 9.
! Undefined control sequence.
l.11 \foo
% undefined control sequence
?
! Emergency stop.
l.11 \foo
% undefined control sequence
End of file on the terminal!
Here is how much of TeX's memory you used:
200 strings out of 493013
2160 string characters out of 6133342
53632 words of memory out of 5000000
3833 multiletter control sequences out of 15000+600000
3939 words of font info for 15 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
23i,0n,17p,111b,64s stack positions out of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
答案3
尝试了一整天后,我最终使用 pyparsing 编写了我自己的 python 脚本:
#!/usr/local/bin/python
# file: xelatex-clean.py
def spoil(l):
if type(l) == list:
if len(l) == 0:
return ''
elif len(l) == 1:
return spoil(l[0])
return l
def pprint(nested, max_level, level = 0, indent = ' '):
for i,c in enumerate(nested):
nested[i] = spoil(c)
for c in nested:
if type(c) != list:
print (indent*level + c.replace('\n','\n' + indent*level))
elif level < max_level:
pprint (c, max_level, level + 1)
if __name__ == '__main__':
import sys
from pyparsing import nestedExpr, OneOrMore, Word, printables
if len(sys.argv) != 2:
print ("Usage: xelatex document.tex | xelatex-clean.py <nesting-level>")
xelatex_output = sys.stdin.read()
l = nestedExpr('(',')',content=OneOrMore(Word(printables+' \n',excludeChars='()'))).parseString('(%s)'%xelatex_output).asList()[0]
pprint(l,int(sys.argv[1]))
spoil 函数会删除空括号或内联括号,否则这些括号会用空格填充输出。我没有花太多时间去看看是否可以使用标准 pprint 函数代替我自己的函数。希望这对你有帮助。
用法:
<xelatex command> | xelatex-clean.py <nesting-level>
示例 1:
> xelatex document.tex | xelatex-clean.py 0
This is XeTeX, Version 3.1415926-2.5-0.9999.3
TeX Live 2013
restricted \write18 enabled.
entering extended mode
see the transcript file for additional information
Output written on document.pdf
2 pages
.
Transcript written on document.log.
[Finished in 2.4s]
示例 2:
> xelatex document.tex | xelatex-clean.py 1
This is XeTeX, Version 3.1415926-2.5-0.9999.3
TeX Live 2013
restricted \write18 enabled.
entering extended mode
./document.tex
LaTeX2e <2011/06/27>
Babel <3.9g> and hyphenation patterns for 78 languages loaded.
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/themes/font/beamerfontthem
eprofessionalfonts.sty
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/themes/font/beamerfontthem
eserif.sty
/usr/local/texlive/2013/texmf-dist/tex/generic/pgf/frontendlayer/tikz/librarie
s/tikzlibrarypositioning.code.tex
/usr/local/texlive/2013/texmf-dist/tex/latex/silence/silence.sty
./document.aux
/usr/local/texlive/2013/texmf-dist/tex/latex/tipa/t3cmr.fd
*geometry* driver: auto-detecting
*geometry* detected driver: xetex
ABD: EveryShipout initializing macros
./document.out
./document.out
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-basic-dictionary/translator-basic-dictionary-English.dict
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-bibliography-dictionary/translator-bibliography-dictionary-English.dict
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-environment-dictionary/translator-environment-dictionary-English.dict
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-months-dictionary/translator-months-dictionary-English.dict
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-numbers-dictionary/translator-numbers-dictionary-English.dict
/usr/local/texlive/2013/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-theorem-dictionary/translator-theorem-dictionary-English.dict
./document.nav
/usr/local/texlive/2013/texmf-dist/tex/latex/euenc/eu1lmtt.fd
[1]
/usr/local/texlive/2013/texmf-dist/tex/latex/amsfonts/umsa.fd
/usr/local/texlive/2013/texmf-dist/tex/latex/amsfonts/umsb.fd
<use "../figs/figure1.pdf" >
<use "../figs/figure2.pdf" >
<use "../figs/figure3.pdf" >
<use "../figs/figure4.pdf" >
Overfull \hbox
1.99998pt too wide
in paragraph at lines 132--132
[]
Overfull \vbox
16.81339pt too high
detected at line 132
[2]
./document.aux
see the transcript file for additional information
Output written on document.pdf
2 pages
.
Transcript written on document.log.
答案4
(...)
-interaction=STRING set interaction mode (STRING=batchmode/nonstopmode/
scrollmode/errorstopmode)
使用以下方式运行 xelatex-interaction=batchmode -halt-on-error