使用 grep 时将输出显示到控制台

使用 grep 时将输出显示到控制台

在 vim 中我使用以下命令来编译 tex 文件:

pdflatex\ \-file\-line\-error\ \-shell\-escape\ \-interaction=nonstopmode\ $*\\\|\ grep\ \-P\ ':\\d{1,5}:\ '

这可以将错误放入快速修复窗口中(如果您不使用 vim,请忽略这句话)。唯一的问题是我希望在文档编译时看到屏幕上出现乳胶输出(现在 grep 吞掉了所有输出)。

我应该改变什么才能实现这一点?我已经尝试将其全部通过管道传输tail,但无济于事。

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011) (format=preamble 2011.10.2)  3 OCT 2011 23:16
entering extended mode
 \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**main.tex
(./main.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2011-07-01, ngerman-x-2011-07-01, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, galician, german, ngerman, swissgerman, monogreek, greek, hungarian,
 icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, marathi, or
iya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, kurmanji,
 lao, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, pol
ish, portuguese, romanian, russian, sanskrit, serbian, serbianc, slovak, sloven
ian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, welsh, loaded
.
PRECOMILED PREAMBLE LOADED

LaTeX Warning: Overwriting file `./main.bib'.

\openout15 = `main.bib'.


\openout4 = `main.auxlock'.

Package biblatex Info: Trying to load language 'english'...
Package biblatex Info: ... file 'english.lbx' found.
(/usr/local/texlive/2011/texmf-dist/tex/latex/biblatex/lbx/english.lbx
File: english.lbx 2011/07/29 v1.6 biblatex localization
)

Package biblatex Warning: 'babel' detected but 'csquotes' missing.
(biblatex)                Loading 'csquotes' recommended.

\@quotelevel=\count451
\@quotereset=\count452
(./main.aux)
\openout1 = `main.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 42.
LaTeX Font Info:    ... okay on input line 42.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 42.
LaTeX Font Info:    ... okay on input line 42.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 42.
LaTeX Font Info:    ... okay on input line 42.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 42.
LaTeX Font Info:    ... okay on input line 42.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 42.
LaTeX Font Info:    ... okay on input line 42.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 42.
LaTeX Font Info:    ... okay on input line 42.
LaTeX Font Info:    Checking defaults for PD1/pdf/m/n on input line 42.
LaTeX Font Info:    ... okay on input line 42.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 42.
LaTeX Font Info:    Try loading font information for TS1+cmr on input line 42.
 (/usr/local/texlive/2011/texmf-dist/tex/latex/base/ts1cmr.fd
File: ts1cmr.fd 1999/05/25 v2.5h Standard LaTeX font definitions
)
LaTeX Font Info:    ... okay on input line 42.
Package caption Info: Begin \AtBeginDocument code.
Package caption Info: subfig package 1.2 or 1.3 is loaded.
Package caption Info: float package is loaded.
Package caption Info: hyperref package is loaded.
Package caption Info: wrapfig package is loaded.
Package caption Info: End \AtBeginDocument code.

(/usr/local/texlive/2011/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count453
\scratchdimen=\dimen319
\scratchbox=\box86
\nofMPsegments=\count454
\nofMParguments=\count455
\everyMPshowfont=\toks48
\MPscratchCnt=\count456
\MPscratchDim=\dimen320
\MPnumerator=\count457
\makeMPintoPDFobject=\count458
\everyMPtoPDFconversion=\toks49
) (/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
Package: epstopdf-base 2010/02/09 v2.5 Base part for package epstopdf

(/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/grfext.sty
Package: grfext 2010/08/19 v1.1 Managing graphics extensions (HO)
)
Package grfext Info: Graphics extension search list:
(grfext)             [.png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 452.

(/usr/local/texlive/2011/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
e
))
Package biblatex Info: No input encoding detected.
(biblatex)             Assuming 'ascii'.
Package biblatex Info: Automatic encoding selection.
(biblatex)             Assuming data encoding 'ascii'.
\openout3 = `preamble-blx.bib'.

Package biblatex Info: Trying to load bibliographic data...
Package biblatex Info: ... file 'main.bbl' not found.

No file main.bbl.
Package biblatex Info: Reference section=0 on input line 42.
Package biblatex Info: Reference segment=0 on input line 42.
ABD: EveryShipout initializing macros
\AtBeginShipoutBox=\box87
Package hyperref Info: Link coloring ON on input line 42.

(/usr/local/texlive/2011/texmf-dist/tex/latex/hyperref/nameref.sty
Package: nameref 2010/04/30 v2.40 Cross-referencing by name of section

(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/gettitlestring.sty
Package: gettitlestring 2010/12/03 v1.4 Cleanup title references (HO)
)
\c@section@level=\count459
)
LaTeX Info: Redefining \ref on input line 42.
LaTeX Info: Redefining \pageref on input line 42.
LaTeX Info: Redefining \nameref on input line 42.

(./main.out) (./main.out)
\@outlinefile=\write8
\openout8 = `main.out'.


(/usr/local/texlive/2011/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-basic-dictionary/translator-basic-dictionary-English.dict
Dictionary: translator-basic-dictionary, Language: English 
)
(/usr/local/texlive/2011/texmf-dist/tex/latex/siunitx/config/siunitx-abbreviati
ons.cfg
File: siunitx-abbreviations.cfg 2011/09/13 v2.3f siunitx: Abbreviated units
)
(/usr/local/texlive/2011/texmf-dist/tex/latex/siunitx/config/siunitx-binary.cfg
File: siunitx-binary.cfg 2011/09/13 v2.3f siunitx: Binary units
)
LaTeX Info: Redefining \microtypecontext on input line 42.
Package microtype Info: Generating PDF output.
Package microtype Info: Character protrusion enabled (level 2).
Package microtype Info: Using default protrusion set `alltext'.
Package microtype Info: Automatic font expansion enabled (level 2),
(microtype)             stretch: 20, shrink: 20, step: 1, non-selected.
Package microtype Info: Using default expansion set `basictext'.
Package microtype Info: No tracking.
Package microtype Info: No adjustment of interword spacing.
Package microtype Info: No adjustment of character kerning.
Package microtype Info: Redefining babel's language switching commands.
 (/usr/local/texlive/2011/texmf-dist/tex/latex/microtype/mt-cmr.cfg
File: mt-cmr.cfg 2009/11/09 v2.0 microtype config. file: Computer Modern Roman 
(RS)
)
\c_siunitx_mathsf_int=\count460
LaTeX Font Info:    Try loading font information for U+msa on input line 42.

(/usr/local/texlive/2011/texmf-dist/tex/latex/amsfonts/umsa.fd
File: umsa.fd 2009/06/22 v3.00 AMS symbols A
)
(/usr/local/texlive/2011/texmf-dist/tex/latex/microtype/mt-msa.cfg
File: mt-msa.cfg 2006/02/04 v1.1 microtype config. file: AMS symbols (a) (RS)
)
LaTeX Font Info:    Try loading font information for U+msb on input line 42.

(/usr/local/texlive/2011/texmf-dist/tex/latex/amsfonts/umsb.fd
File: umsb.fd 2009/06/22 v3.00 AMS symbols B
)
(/usr/local/texlive/2011/texmf-dist/tex/latex/microtype/mt-msb.cfg
File: mt-msb.cfg 2005/06/01 v1.0 microtype config. file: AMS symbols (b) (RS)
)
LaTeX Font Info:    Try loading font information for U+esint on input line 42.

(/usr/local/texlive/2011/texmf-dist/tex/latex/esint/uesint.fd
File: uesint.fd 
)
LaTeX Font Info:    Try loading font information for U+rsfs on input line 42.

(/usr/local/texlive/2011/texmf-dist/tex/latex/jknapltx/ursfs.fd
File: ursfs.fd 1998/03/24 rsfs font definition file (jk)
)
\c_siunitx_mathtt_int=\count461

./main.tex:47: Undefined control sequence.
l.47 \akaka

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Package atveryend Info: Empty hook `BeforeClearDocument' on input line 51.
[1{/usr/local/texlive/2011/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
Package atveryend Info: Empty hook `AfterLastShipout' on input line 51.

(./main.aux)
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 51.
Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 51.
Package rerunfilecheck Info: File `main.out' has not changed.
(rerunfilecheck)             Checksum: D41D8CD98F00B204E9800998ECF8427E;0.
Package logreq Info: Writing requests to 'main.run.xml'.
\openout1 = `main.run.xml'.

 ) 
Here is how much of TeX's memory you used:
 2167 strings out of 455899
 40306 string characters out of 2353312
 1131909 words of memory out of 3000000
 42382 multiletter control sequences out of 15000+200000
 26633 words of font info for 111 fonts, out of 3000000 for 9000
 831 hyphenation exceptions out of 8191
 36i,6n,45p,773b,1377s stack positions out of 5000i,500n,10000p,200000b,50000s
{/usr/local/texlive/2011/texmf-dist/fonts/enc/dvips/cm-super/cm-super-t1.enc}
</usr/local/texlive/2011/texmf-dist/fonts/type1/public/cm-super/sfrm1000.pfb></
usr/local/texlive/2011/texmf-dist/fonts/type1/public/cm-super/sfrm1200.pfb></us
r/local/texlive/2011/texmf-dist/fonts/type1/public/cm-super/sfrm1728.pfb>
Output written on main.pdf (1 page, 19387 bytes).
PDF statistics:
 29 PDF objects out of 1000 (max. 8388607)
 22 compressed objects within 1 object stream
 2 named destinations out of 1000 (max. 500000)
 23053 words of extra memory for PDF output out of 24883 (max. 10000000)

Vim 应该只显示:

main.tex l.47 undefined control sequence

然而我喜欢看到输出,这样我就可以得到一些关于正在编译哪个页面等的反馈......

答案1

您是否尝试过使用errorformat而不是 grep 输出? CFhttp://vim.wikia.com/wiki/Errorformats。如果您设置命令makehttp://vim.wikia.com/wiki/Make_make_more_helpful)。

感谢您更新的输出,romovs。听起来您希望拥有类似的东西:

set errorformat=%E%f:%l:\ %m%C1.%l\ %Z

我无法对此进行测试,但根据输出,它似乎就是您想要的。

答案2

你真的应该看看橡皮(打包在许多发行版中):

Rubber 是一个程序,其目的是处理与 LaTeX 文档编译相关的所有任务。当然,这包括编译文档本身,足够的时间以便定义所有参考文献,以及运行 BibTeX 来管理书目参考文献。还包括自动执行 dvips 来生成 PostScript 文档,以及使用 pdfLaTeX 来生成 PDF 文档。

橡胶会隐藏所有输出(重定向到 .log 文件)和只显示相关的错误信息当被调用时。

答案3

这都是关于输出缓冲的。

你面临的问题不在于如何grep运作,而在于如何运作管道做。或者,更准确地说,如何pdflatex 允许管道工作。它以标准方式使用管道 - 这意味着通过管道的输出是缓冲的。程序pdflatex决定其自身的输出是否可以被缓冲。我不确定,但我认为在这个程序方面没有可以使用的标准选项来告诉它不要缓冲重定向的输出。

但是,您可以使用该stdbuf程序作为命令 ( ) 的一种包装器pdflatex,并根据您的需要调整输出流的字符:

stdbuf -oL pdflatex -file-line-error ... | grep ...

或者

stdbuf -o0 pdflatex -file-line-error ... | grep ...

(为了可读性,删除了转义符并修剪了命令。)请参阅man stdbuf参考资料 了解详细信息。

另外,您还可以诡计 pdflatex(相当无害)不通过使其“认为”输出未重定向来缓冲其输出。该script程序可用于:

script -c 'pdflatex -file-line-error ... ' | grep ...

请注意,整个pdflatex ...命令需要用引号引起来。

答案4

也许在执行最终命令之前尝试tee访问stdout控制终端?/dev/ttystdoutgrep

# example using ls instead of pdflatex in Bash

# all of stdout goes to the controlling terminal before grep
ls -ld / errorfile 2>&1 | tee /dev/tty | grep error

# only grep-filterd stdout goes to the controlling terminal before the final grep
ls -ld / errorfile 2>&1 | tee >(grep --line-buffered error > /dev/tty) | 
    grep error

相关内容