Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am generating a latex file with many \includegraphics commands from a program. The image files change from run to run. The latex file might, for example, look like the one in this question. Occasionally an image file that I receive is corrupted. I can eliminate nearly all such situations by checking the size of the image file and emitting some vertical space instead of the \includegraphics command should the the image file be too small to reasonably be the sort of image I am expecting; however, a very small number of corrupted image files are larger. In that case pdflatex stops with an error message. All my image files are .jpg files. I believe that jpegtran on UNIX will fix most of these and I could pass every jpeg through that but I am concerned about the impact on runtime if I do that and also there could still be a very few that that does not address. Is there a way to handle this? Basically I need something like: "include a jpg file using includegraphics without generating an error and if that fails then emit some vertical space otherwise the includegraphics can stand".

share|improve this question
    
Are your images all in the same folder? I would run some external script that can pick up the corrupted images and replace them with some standard faulty image (like mwe's example-image-a). –  Werner Sep 21 '12 at 21:56
    
I could run jpegtran on them all in advance but its not really that convenient and also I am not sure that that would necessarily catch them all although it probably would catch most. I would prefer if all this were self contained in the report so I don't have to start messing with external processes. –  user1189687 Sep 21 '12 at 22:00
    
TeX can't even adequately handle bounding box issues, so I don't think it would be able to detect corrupted JPGs internally/at compile time (let alone efficiently). –  Werner Sep 21 '12 at 22:07
1  
So there is no try...catch processing possible in tex? Seems like a serious omission. –  user1189687 Sep 21 '12 at 22:55
    
Perhaps related: Trapping LaTeX error/warning –  Werner Sep 21 '12 at 22:58
show 8 more comments

1 Answer

up vote 6 down vote accepted

The error you get:

Error: pdflatex (file corrupt.jpg): reading JPEG image failed 
==> Fatal error occurred, the output PDF file is not finished!

Even with nonstopmode active indicates to me that this is a pdfTeX specific issue which occurs in the special PDF-related code of the binary which is responsible for reading JPEG files and not a real TeX error.

Therefore there seems to be nothing you can do in (La)TeX itself. If you can't manually sort out the corrupted files then I would try to write a script which compiles a small test document for each image and checks if the compilation was successful.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.