0

This question "has been asked before" Trapping LaTeX error/warning but I would like to be more specific. I use only lualatex on Linux.

In my usage, a properly-compiled lualatex document has a proprietary "seal of approval" added at its end, using immediate\write. That speeds the workflow when the PDF is sent out. The "seal of approval" does not mean that the file looks pretty or has meaningful content. It only means that the PDF was processed according to certain standards, which are outside the scope of TeX.

If compilation throws a ClassError or PackageError, I can trap them (I believe) by using the etoolbox macro \pretocmd. My prepended code sets a binary flag to true. The flag means that an error was thrown. When processing gets to the point where it will write the "seal of approval" it will not do that, if the flag was set. Might still get a PDF, but no seal.

But I see that there are also some errors that do not originate from packages that I can easily identify. I suppose they come from the bare-metal binaries. Is there a way to deal with that? This is my question.

Note: I could launch lualatex as a subprocess of a BASH script, and deal with it that way. That would allow me to put options on the lualatex command line, inspect the log file after completing, and deleted the PDF if erroneous. Seems bit brutal. But I cannot use --shell-escape within the document.

I do not care about fatal errors. They would not reach the "seal of approval" stage.

Also note that I am not the only user. Although I know that I should halt on any error, other users may simply hit return and continue.

rallg
  • 2,379
  • 1
    well if the seal is created with some lua code, you could disable this code in the show_error_hook callback. – Ulrike Fischer Feb 18 '23 at 21:43
  • @UlrikeFischer The seal is created with ordinary LaTeX code, but no problem. The solution below, which does uses show_error_hook, works. I use the good/bad to set a boolean false when bad. – rallg Feb 19 '23 at 19:42

1 Answers1

1

You can use the show_error_hook to track if errors are issued:

\documentclass{article}
\directlua{
  local error_seen = false

local true_cmd = token.create'use_i:nn' local false_cmd = token.create'use_ii:nn' local id = luatexbase.new_luafunction'iferrorsissued' token.set_lua('iferrorsissued', id)

lua.get_functions_table()[id] = function() token.put_next(error_seen and true_cmd or false_cmd) end

luatexbase.add_to_callback('show_error_hook', function() error_seen = true texio.write('.') tex.show_context() end, 'track_errors') } \begin{document} Before

\iferrorsissued{Something bad happened}{All fine so far}

Some_error

\iferrorsissued{Something bad happened}{All fine so far} \end{document}

  • That looks like what I am after. Cannot test it today. Will reply/approve after testing. – rallg Feb 18 '23 at 23:35
  • Yay! Works great. It is particularly useful for trapping something such as \setlength\somelength{3furlongs}. When 3furlongs is read, LaTeX offers to use 0pt if the user continues. Then the document often compiles from there. But it is incorrect. Now I can trap that error, even if the 0pt is substituted, and decline to insert the "seal of approval" (which uses ordinary LaTeX code). Thanks! – rallg Feb 19 '23 at 19:41