Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In vim I use the following command to compile a tex file:

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

this works in terms of getting the errors into a quick fix window (if you don't use vim, ignore this sentence). The only problem is that I would like to see the latex output coming on the screen while the document is compiling (now grep swallows all the output).

what should I change to make this happen? I already tried piping it all to tail, yet to no avail.

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 should only display:

main.tex l.47 undefined control sequence

Yet I like seeing the output so that I have some feedback about which page is being compiled etc...

share|improve this question

5 Answers 5

up vote 1 down vote accepted

Have you tried using errorformat instead of grep'ing the output? C.f. http://vim.wikia.com/wiki/Errorformats. It is specially useful if you set up the make command ( http://vim.wikia.com/wiki/Make_make_more_helpful ).

Thanks for the updated output, romeovs. It sounds like you wish to have something like:

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

I can't test this, but based on the output, it seems to be what you want.

share|improve this answer
    
I'm actually using the tex_pdf.vim ftplugin. This plugin sets set local makeprg (... see above ...) and setlocal errorformat=%f:%l:\ %m. Yet if I omit the grep part, no error is recognized (I think grep is necessary, although I'm new to all this so correct me if I'm wrong). –  romeovs Oct 3 '11 at 20:11
    
If I omit the grep command, all the output gets shown in the quickfix window... –  romeovs Oct 3 '11 at 20:14
    
I don't know the output of pdflatex (it's been 30+ years since I did any tex work). But based on your grep expression, it looks like you would want to use %f:%l:\ %n, not %m. Could you edit your question to include some example output? –  Arcege Oct 3 '11 at 21:09
    
added sample output for a file setup I use often... –  romeovs Oct 3 '11 at 21:20
    
the error format doesn't work. Vim gives an error about the string being incorrect. –  romeovs Oct 4 '11 at 16:10

You should really have a look at rubber (packaged in many distribs):

Rubber is a program whose purpose is to handle all tasks related to the compilation of LaTeX documents. This includes compiling the document itself, of course, enough times so that all references are defined, and running BibTeX to manage bibliographic references. Automatic execution of dvips to produce PostScript documents is also included, as well as usage of pdfLaTeX to produce PDF documents.

Rubber will hide all the ouput (which is redirected to a .log file) and display only the relevant error messages when invoked.

share|improve this answer
    
yes, this is what my code does now too (I know rubber is better, but I don't need it yet). I rally want to see and not hide the output. –  romeovs Oct 4 '11 at 14:09

It is all about output buffering.

The problem which you are facing lies not in the way grep works, but how pipe does. Or, more precisely, how pdflatex allows the pipe to work. It uses the pipe in the standard way - this means that the output that goes through the pipe is buffered. It is the pdflatex program that decides whether its own output can or cannot be buffered. I'm not sure, but I think that there are no standard options you can use on this program's side to tell it not to buffer its redirected output.

However, you can use the stdbuf program that acts as a kind of wrapper around your command (pdflatex) and adjusts the character of output stream to your needs:

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

or

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

(Stripped escapes and trimmed the commands for readability.) See man stdbuf for details.

Also, you can trick pdflatex (quite harmlessly) not to buffer its output by making it "think" that the output is not redirected. The script program can be used for that:

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

Note that this one needs quotes around the whole pdflatex ... command.

share|improve this answer

It's a standard I/O stream buffering issue as already pointed out by rozcietrzewiacz.

For a quite detailed article on this issue see:

http://www.pixelbeat.org/programming/stdio_buffering/

Here's a small test case filtering pdflatex warnings (instead of errors) for the Vim TeX-PDF ftplugin. I'm using the script command on Mac OS X to make the output of pdflatex line-buffered. Similarly, the output line-buffering mode of grep is turned on as well (though it should not be necessary here).

pdflatex -version    # pdfTeX 3.1415926-1.40.11-2.2 (TeX Live 2010); kpathsea version 6.0.0
mkdir -p ~/.vim/ftplugin/tex
curl -L -o tex_pdf.tar.gz 'http://www.vim.org/scripts/download_script.php?src_id=13845'
tar -xzf tex_pdf.tar.gz 
cp ftplugin/tex/tex_pdf.vim ~/.vim/ftplugin/tex

# on Linux use: script -c 'pdflatex...' /dev/null
cat <<-'EOF' | ed -s ~/.vim/ftplugin/tex/tex_pdf.vim
H
,g/setlocal makeprg=pdflatex/s/\(.*\)/"\1/
.a
            setlocal makeprg=script\ \-q\ /dev/null\ pdflatex\ \-file\-line\-error\ \-interaction=nonstopmode\ $*\\\|\ grep\ \-\-line\-buffered\ \-iP\ 'warning'
.
wq
EOF

curl -L -s 'http://www.maths.manchester.ac.uk/~kd/latextut/beamerex.tex' | 
    LC_ALL=C tr -d '\r' > beamerex.tex

vim --cmd "filetype plugin on" -V9myVimLog beamerex.tex
:set shell=/bin/bash
:BuildTexPdf
:clist
:copen
:cn
:ccl
:qa!

less myVimLog
share|improve this answer

Maybe try teeing stdout to the controlling terminal /dev/tty before stdout goes to the final grep command?

# 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
share|improve this answer
    
Sorry your use of tee makes no sense. It doubles the output displayed on the terminal and does not solve the OP's problem. –  rozcietrzewiacz Oct 4 '11 at 15:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.