5

When running pdflatex -interaction=nonstopmode I am looking for:

  1. Ways to detect whether there were errors solely based on the log files (assume we don't have access to the process exit code).

  2. Extract a user-friendly error message from the log file.

Error messages seem to always start with a ! so this really boils down to:

  1. Is it safe to assume that there was an error if any line in the log starts with !?

  2. How can I determine how many additional lines after the one starting with ! are part of the error message?


Here's an example. Suppose the error is triggered by $x^{$. The in the log I get (with context):

...
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 3.

! Missing } inserted.
<inserted text> 
                }
l.3 $x^{$

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

[1

{/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./ts.aux) ) 
...

Given that pdflatex is run non-interactively, in this specific case the most user-friendly error message to extract is simply:

! Missing } inserted.
<inserted text> 
                }
l.3 $x^{$

The following lines ("I've inserted something...") are also clearly part of the error message, aimed at the user to read. But in this specific case it's they are more confusing than helpful because there's no way to type `2' now.

To sum up, I'm looking for a way to extract enough of the error messages to make them the most useful and the least confusing for a user to read. I am finding this difficult because I do not see a general pattern in the error format and I don't know what special edge cases to anticipate. Note: Line numbers are irrelevant for my use case.

  • Please re-tag the question if necessary, I couldn't find many relevant already existing tags. – Szabolcs Apr 3 '15 at 17:08
  • 2
    You can read lines from the ! as far as the ? – David Carlisle Apr 3 '15 at 18:21
  • @David There's no ? because of -interaction=nonstopmode. Is it possible to put in a marker where the ? would be or preserve the ? while making sure that TeX will never try to read any input? – Szabolcs Apr 3 '15 at 19:05
  • If you have unix tools available to you, you can use the yes program for standard in. – Sean Allred Apr 3 '15 at 19:06
  • 1
    You should look at the texfot script (included in TeX Live) – egreg Apr 3 '15 at 19:37
4

To quote errors.ini from from winedt:

// Before you conclude that this error detection is a pretty complicated business
// take a good look at the log file produced by TeX or its accessories. It lacks
// structure and it does not follow any clear conventions that would make it easy
// to locate Errors and Warnings in your source files. Even locating the source
// file in a multi file document based on the info in TeX's log file is far from
// trivial. In other words: TeX's log files are a genuine mess! 

Imho the simplest way to see errors is to use an editor with good log-parsing build in. Most TeX-editors nowadays do a quite good job. So I wouldn't try to reinvent the wheel.

|improve this answer|||||
  • In my application, one-line math-mode snippers are being auto-converted to vector graphics and then used in another software (similar to LaTeXiT). Given the application and workflow, showing the full log file, with all the irrelevant part (most of it) is counterproductive (although I understand that it's hard to see why this is the case without having used the application). So I still need to extract the errors, or perhaps only the very first error. Currently I am only extracting a single line (with the !), which is still better than the full log. But I'm hoping to do a little better. – Szabolcs Apr 3 '15 at 17:53
  • Do you have any comments on question 1., i.e. is the ! a reliable indicator that something went wrong? I'm going to try reading from the ! line up to the next empty line as an imperfect but useful solution, with some limitation on the number of lines just in case that empty line is missing. – Szabolcs Apr 3 '15 at 17:56
  • 1
    If you're using grep or similar, you can supply -C which should give you context. Best to just use a good editor though (emacs/AUCTeX is solid). – Sean Allred Apr 3 '15 at 18:48
  • @SeanAllred Neither grep, not an editor is involved. Think of something similar to LaTeXiT, which makes it necessary to report readable errors to the user. – Szabolcs Apr 3 '15 at 18:59
  • 2
    And we're trying to tell you that this isn't an easy problem -- certainly not in the scope of a TeX.SX question. Your need is hardly unique to you -- many have tried (and a few have succeeded, but only with great effort). Regarding editors, if you're changing something -- like a preview -- you're editing it. – Sean Allred Apr 3 '15 at 19:05

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.