5

Would it be possible to make a wrapper script, or does there exist a sequence of flags -XYZ for latexmk (looking at the manual, it appears not), so that the command behaves in the following way:

~/latexmk -XYZ bla.tex
~/

if there are no errors in the file. (So latexmk gives exactly NO response), and

~/latexmk -XYZ bla.tex
Error on line 54 in file bla.tex
~/

if there are errors.

It would be great to not see output that is useless.

2 Answers 2

5

Reading the documentation leads to some good information. For example, using the standard (pdf|lua)latex options, we immediately come up with the following:

pdflatex -interaction="batchmode" myfile.tex

This produces a very minimal message stating the name of the program, the version, the enablement of restricted \write18, and the fact that it's entering extended mode. It suppresses all other output. The latexmk documentation gives the option -silent, which suppresses a good deal of output, but not all.

None of these options let errors come through, however, and unfortunately TeX was not written for a system which distinguishes between stderr and stdout, so standard output redirection options don't work here. You're probably stuck filtering your output to make this happen. Fortunately, it's not too hard. Assuming you're on some vaguely bash-like shell:

pdflatex -halt-on-error file.tex | grep -A3 '^!'

will do the trick. It's completely silent unless it hits an error (a line that starts with "!"), at which point it dies loudly, spitting out the line declaring the error and the following three lines, as well.

I'm not really familiar with latexmk, and a little fiddling with it revealed that it seems to produce a great deal of output besides the output of the programs it calls. Redirecting latexmk's output catches all the output of latex, including the error messages, so you lose them before you can filter them out with grep. latexmk appears to have options to quiet the programs it calls, such as latex and makeindex, but none for quieting latexmk itself. So you may want to write a script which, in a way not unlike the pdflatex command above, quiets the programs you're actually calling individually. Something like:

#!/bin/bash
pdflatex -halt-on-error file.tex | grep -A3 '^!'
makeindex file.idx &> /dev/null
pdflatex -halt-on-error file.tex | grep -A3 '^!'

(makeindex sends all its messages to stderr, so you need the ampersand (or a "2") for this to work.)

1
  • Did this answer work for you? Did you come up with another solution? Sep 27, 2014 at 22:21
0

Based on @dgoodmaniii's answer, I experimented a bit with latexmk and this latexmkrc file seem to work to quiet the LaTeX output, yet still print any error messages.

$pdflatex = "! xelatex -halt-on-error %O %S | grep -A3 '^!'";
$pdf_mode = 1;
$postscript_mode = 0;
$dvi_mode = 0;

I'm running XeLaTeX but if you change xelatex above to pdflatex and it should work the same, it should work just as well for pdfLaTeX.

The above works by piping the XeLaTeX output to grep (just as dgoodmaniii described it, but inside latexmk) and only extracting lines from the xelatex output that start with ! + 3 lines of context after that.

The added ! at the beginning of the command invert the exit status of command. This is needed because latexmk listens to the return code, and grep will return 0 (=true) if it finds a line beginning with ! and 1 (=false) otherwise. So by inverting the exit status latexmk will see 1 if there is a match because an error was found, and 0 otherwise.

Sidenote: The additional $pdf_mode, $postscript_mode and $dvi_mode are just settings to tell latexmk to only expect PDF output.

Note: I just came up with this, and haven't tested it very much in practice yet. Please poke a hole in it if you can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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