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.

In the script I presented in this question I encountered the following problem. In case of a compilation error, I have to cancel the execution of pdflatex 3 times. This can be very annoying. I would like to add something like

if pdflatex file.tex returned failure break script

However, I could find what values pdflatex returns when it exits. So the question is:

What are the exits/return values/codes of pdflatex?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

The key one for me is that 0 is returned on successful compilation. You don't say what OS you use, so I'll provide a Unix Makefile and a Windows batch file test. On Unix, I use

pdflatex $$NAME
if [ $$? = 0 ] ; then \
  pdflatex $$NAME ; \
  pdflatex $$NAME ; \
else \
 \echo "Compilation failed" ; \
fi

On Windows with a batch file the error level test is slightly different

pdflatex %1
if ERRORLEVEL 1 (
  echo ! Compilation failed
) else (
  pdflatex %1
  pdflatex %1
)

This tests for failure rather than success as the if ERRORLEVEL test works for 'thios number or higher'. You can build quite a lot more complexity on top of this: it depends on your requirements. (For example, my batch file assumes that the name of the file to compile is given as a command-line argument: you might want to use a variable or hard-coded name.)

share|improve this answer
    
Thanks a lot! Worked eventually! Is there some documentation of other return values of pdflatex? This might be helpful... –  Dror Nov 26 '10 at 10:53
    
Pipelines work more cleanly with Unix exit status codes, I think: compare (pdflatex $$NAME && pdflatex $$NAME && pdflatex $$NAME) || echo Compilation failed –  Charles Stewart Nov 26 '10 at 10:54
    
@Charles: I'll take your word for it. (My real Makefile is rather more complex than the example above.) –  Joseph Wright Nov 26 '10 at 11:12
    
@Dror: 0 is a standard value for 'success' from almost all processes. –  Joseph Wright Nov 26 '10 at 11:17
1  
@Dror: (1) the general rule is zero for success, any non-zero for failure. –  Taco Hoekwater Nov 26 '10 at 12:55

Converting Joseph's code into shell syntax, it looks like this:

NAME=$1
pdflatex $NAME
if [ $? = 0 ] ; then
  pdflatex $NAME ;
  pdflatex $NAME ;
else 
  echo "Compilation failed" ;
fi

I am keying this in as an answer on because of formatting, please don't upvote me

share|improve this answer

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.