I'm currently writing a Python program that can automate detection of whether a certain command is permitted in math mode without using any packages.

For the purpose of testing I add \documentclass{article} \begin{document}$ before a command to be tested and $\end{document} after it. Then I save it to a file using a randomly generated filename and use latex <filename>+'.tex' to TeX the file.

If the command is actually permitted the process ends and I can obtain a return code of 0. On the other hand when TeXing doesn't work instead of returning an error code the process simply doesn't end.

Is there a way to run LaTeX so that the process always return even if there is an error?

  • Nevermind. There is -halt-on-error . Problem solved! – Ying Zhou May 5 '19 at 19:55
  • Not really. There are cases where this does not work for unknown reasons. I really don't want to put some form of timeout there since it will be machine-dependent. – Ying Zhou May 5 '19 at 20:46
  • 1
    most editors will get some error feedback when run using one of the nonstop options run (pdf)latex --help to see most choices especially -interaction=errorstopmode and nonstopmode – user170109 May 5 '19 at 21:03
  • "machine dependent" should be fairly trivial all windows should respond to taskkill should be similar kill for *nix ? the timer is dwn to the app – user170109 May 5 '19 at 22:17
  • 2
    you can quite easily write tex code that runs a long time: tex.stackexchange.com/questions/tagged/compiling. So without some timeout it will not work. – Ulrike Fischer May 5 '19 at 22:29

It's trivial to write a TeX program that results in an infinite loop. As such, one cannot be certain that a job will finish. Typically, automated systems address this by looking for some output over a given time frame, and likely a maximum run time after which a job is killed. Those aspects are of course out-of-scope for this particular site.

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.