我有一本书,当我用 pdflatex 编译它时,它在 stdout 上产生了 20,000 行输出。我做了以下事情来减少输出:
\RequirePackage{silence}
\WarningFilter{Fancyhdr}{\headheight is too small}
\WarningFilter{textpos}{environment textblock}
%\pdfsuppresswarningpagegroup=1 % my pdftex isn't new enough
\hfuzz=999pt % reduce overfull hbox errors
\hbadness=10000 % reduce underfull hbox errors
这样就将输出缩减到 500 行。但是,这还是太多了。我想在没有错误的情况下将其缩减到零行,这样每次编译这本书时我都可以实际查看输出。剩余的无用输出似乎主要包括以下类别:
- 说明我已加载的软件包的消息:
(/usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty)
- 通过 包含的每个文件都有一条消息
includegraphics
。 - 针对每种使用的字体都给出一条信息:
<</usr/share/texlive/texmf-dist/fonts/type1/p ublic/amsfonts/cm/cmsy10.pfb>>
- 正在包含的文件。
有些类型的消息似乎是无法阻止的,因为它们被编码到 TeX 本身中。因此,除了对输出进行某种后过滤之外,似乎没有其他选择。我必须编写自己的过滤器吗,还是其他人编写了一些东西来执行此操作?
有关的:
答案1
现有的一些自动构建工具能够进一步减少编译的终端输出。一个相对较新的参与者(我将在这里重点介绍)是ltx2any
。该系统提供以下形式的构建输出:
$> ltx2any bibtex_test.tex [ltx2any] Initialising ... [ltx2any] pdflatex(1) running ... Done [ltx2any] bibtex running ... Error [ltx2any] pdflatex(2) running ... Done [ltx2any] pdflatex(3) running ... Done [ltx2any] pdflatex(4) running ... Done [ltx2any] There were 1 error and 3 warnings. [ltx2any] Output generated at bibtex_test.pdf [ltx2any] Assembling log files ... Done [ltx2any] Log file generated at bibtex_test.log.md
终端上的简短摘要输出会提醒用户在构建过程中遇到的任何错误,并且可以在 Markdown 日志文件(还提供 pdf 日志文件选项)中查看有关任何错误的更多详细信息。 (La)TeX 的完整、纯净的日志文件也可在其通常的位置找到。
虽然这并不严格满足您的零线要求,但此处的输出肯定会适合合理大小的终端窗口而无需滚动,而且我认为微创的视觉反馈很好。
构建系统ltx2any
可高度配置,适用于多种不同的引擎和工作流程。请参阅 GitHub 存储库以了解更多详细信息和功能示例。
答案2
由于似乎没有人知道预先存在的解决方案,因此我编写了以下 ruby 脚本。
#!/usr/bin/ruby
# This program filters TeX's output to get rid of stuff I don't care about.
# It reads stdin, writes stdout.
def do_filtering(t)
path_chars = "[a-zA-Z0-9./\-]" # characters that we expect to see in a path name
extensions = "(sty|aux|fd|cfg|def|ldf|cls|clo)" # tex tells us about these, e.g., (/foo/bar/baz.sty)
path = "\.*\/#{path_chars}+(\n#{path_chars}+)?"
t.gsub!(/\(#{path}\.#{extensions}\)*\s+/,'')
t.gsub!(/\n*pdfTeX warning: pdflatex \(file #{path}\n?\)\n?:\n? \n?[^\n]+(\n[^\n]+)?included in a single page\n*/,'')
# http://tex.stackexchange.com/questions/183149/cant-silence-a-pdftex-pdf-inclusion-multiple-pdfs-with-page-group-error
# messages from includegraphics, e.g., <./ch01/figs/reservoir-tangent-line.pdf>
t.gsub!(/<([^\n]+)\n([^\n]+)>/) {"<"+$1+$2+">"} # remove linebreaks in middle of paths
graphics_extensions = "(jpg|pdf|png)"
graphics_file = "#{path}\.#{graphics_extensions}( \(PNG copy\))?"
t.gsub!(/<(#{graphics_file} )*#{graphics_file}>/,'')
# Underfull \vbox (badness 10000) has occurred while \output is active
# Underfull \hbox (badness 10000) in paragraph at lines 126--126
t.gsub!(/Underfull \\(hbox|vbox) \(badness \d+\) (has occurred while \\output is active|in paragraph at lines \d+--\d+)/,'')
# Overfull \hbox (6.56241pt too wide) detected at line 35
# Overfull \hbox (8.53581pt too wide) in paragraph at lines 824--824
t.gsub!(/Overfull \\(hbox|vbox) \(\d+\.\d+pt too (wide|high)\) in paragraph at (line \d+|lines \d+--\d+)/,'')
# clean up page numbers like [18] [19]
t.gsub!(/\[(\d+) +\]/) {"["+$1+"]"} # remove whitespace inside brackets
1.upto(10) { |i|
t.gsub!(/(\[\d+\])\n ?(\[\d+\])/) {$1+" "+$2} # remove newlines between page numbers
}
t.gsub!(/\[\]/,'') # empty brackets
t.gsub!(/\$\[\]\$/,'') # empty $[]$
t.gsub!(/\$\$/,'') # empty $$
t.gsub!(/^\s*\n/,'') # lines containing only whitespace
# messages from specific packages, etc.
date_version = "<[^>]+>" # e.g., <2008/02/07>, used by packages to announce what version they are
t.sub!(/\AThis is [^\n]+\n/,'')
t.sub!(/^LaTeX2e #{date_version}Babel[^\n]+languages loaded\.\n/,'')
t.sub!(/Package: textpos[^\n]+\n/,'')
# remove lines beginning with specific text
[
"For additional information on amsmath",
"Document Class",
"Style option",
"Grid set ",
"TextBlockOrigin set",
"ABD: EveryShipout initializing macros",
"Output written on",
"Transcript written on",
].each { |x|
t.gsub!(/^#{x}[^\n]*\n/,'')
}
t.gsub!(/^ ?\|?\\OT1[^\n]+(application|derivative|intermediate|acceleration)\|? ?$/,'')
t.gsub!(/^ ?\|?\\OT1[^\n]+/,'') # \OT1/cmr/m/n/10.95 0.110001000000000000000001
# list of fonts, e.g., <</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb>>
t.gsub!(/<\n?<\n?#{path}\n?>\n?>/,'')
t.gsub!(/{\n?#{path}\n?}/,'')
t.gsub!(/\n{2,}/,"\n") # blank lines
return t
end
t = $stdin.gets(nil) # nil means read whole file
if t.nil? then t='' end # gets returns nil at EOF, which means it returns nil if file is empty
do_filtering(t)
print t