7

I am using latexmk for compiling a large number of tex-files to PDF's on a Jenkins server, some of the tex-files are known to have errors in them. I would like to reduce build time as much as possible, to achieve this I have tried not to have latexmk cleanup before running (-gg) option but this gives me erroneous output on a second run.

Consider the following tex-file

\documentclass{article}
\usepackage{graphics}
\begin{document}
Trying to include missing file

\includegraphics{missing_file}
\end{document}

If I run this with

latexmk -latexoption=-interaction=nonstopmode mwe.tex

The first time it returns

<lines deleted...>
latex: Command for 'latex' gave return code 256
Latexmk: Use the -f option to force complete processing,
unless error was exceeding maximum runs of latex/pdflatex

The second time (no errors are reported, the return code is 0)

Latexmk: This is Latexmk, John Collins, 10 Nov 2013, version: 4.39.
**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****
Latexmk: All targets (mwe.dvi) are up-to-date

Is there anyway to avoid this behavior without using the -gg option


Update:

I tried running echo X|latex -interaction=errorstopmode mwe.tex on Ubuntu and Windows and it actually does work, i.e. it does produce any output files.

With the real tex-file though, the dvi-file is produced. I will try to come up with a MWE where this happens.

  • How about latexmk file.tex -interaction=nonstopmode -halt-on-error, that gives me an error every time. – daleif May 23 '14 at 8:03
  • @daleif its the same problem for the real tex-file. I am still trying to come up with a MWE to demonstrate the problem, but haven't had the time (or idea yet). – JoeCed May 23 '14 at 9:32
3

About those files which are "known to contain errors", are they errors you intend to fix, or are they going to be sitting here forever?

Apparently, both nonstopmode and batchmode produce an output file even if there was an error. This tricks latexmk into believing the file is actually up-to-date.

So, as a dirty workaround in the first case (errors you will fix someday), you can compile with either of the following command lines:

echo X | latex -interaction=errorstopmode main.tex
echo X | latex -interaction=scrollmode main.tex

The effect is to issue a X (abort the compilation) the first (and last) time the compiler asks a question, that is if there was an error*. With errorstopmode, it will cancel the compilation at any error, while with scrollmode it will only cancel for serious errors, like a missing file.

To use it with latexmk, you can add to your .latexmkrc the line:

$latex = 'echo X | latex -interaction=errorstopmode %O %S';

The result is that none of the files with errors will produce any output.


If you want an output even if there is an error, or if fixing the errors is not an option, the problem is much harder, as latexmk will have to separate "known" errors from unwanted ones.

You can use the -f command line switch (force processing), to make latexmk ignore errors altogether. I am not sure that it will not make the build time too long again.

Alternatively, you can try to hide the known errors from the compiler. For missing files for example, you can follow the advice given in this question.


*. It won't work if you use interaction for other purposes when creating your document. But then why use latexmk?

| improve this answer | |
  • The errors will hopefully be corrected at one time or another. I tried both with errorstopmode and scrollmode, but the result is the same, running twice will give zero errors on the second run. I think I have come up with a solution that will work for me: If errors are detected, run a cleanup, otherwise do nothing. – JoeCed May 22 '14 at 6:55
  • You have tried with errorstopmode and the echo X pipe? What OS are you using? – T. Verron May 22 '14 at 18:21
  • Your suggestion works! I updated the question, because for the real file output is still produced. – JoeCed May 23 '14 at 6:37

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.