Say I have a simple LaTeX file to compile (missingPic.tex) but a picture is missing. The following would be a MWE
\documentclass{article}
\usepackage{graphicx}
\begin{document}
We now include a non existing pic:
\includegraphics[width=\textwidth]{iDontExist.pdf}
\end{document}
If I compile it from cmd (using Win7), I get (removing some lines to make it shorter)
C:\giulio>pdflatex missingPic.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6300 64-bit)
entering extended mode
(missingPic.tex
LaTeX2e <2017-04-15>
Babel <3.9t> and hyphenation patterns for 76 language(s) loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo"))
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\graphicx.sty"
...
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ltxcmds.sty"))))
No file missingPic.aux.
("C:\Program Files\MiKTeX 2.9\tex\context\base\supp-pdf.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
) ("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\pdftexcmds.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ifluatex.sty")
...
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\etexcmds.sty"))))
LaTeX Warning: File `iDontExist.pdf' not found on input line 9.
! Package pdftex.def Error: File `iDontExist.pdf' not found.
See the pdftex.def package documentation for explanation.
Type H <return> for immediate help.
...
l.9 ...egraphics[width=\textwidth]{iDontExist.pdf}
?
So basically it "hangs" and waits for my input from keyboard. I have to do something like ctrl+C to get out.
My question is if there is any way to avoid that and let pdflatex return some kind of error.
My Y is very simply the following: I am actually wrapping this from MATLAB, where I essentially have a line like
[status, result] = system('pdflatex missingPic.tex')
and with this behavior MATLAB really hangs: it keeps saying "busy" without me having access to the variables status and result. So I don't know how to catch this problem (only thing I can think of is something based on elapsed time but it seems quite ugly to me).