27

When a tex file is compiled, everytime an error is detected, compilation stops and user action (usually hitting return key) is expected through console by user. I would like to ask, how is it possible to avoid this. I would like it not to stop on detected errors and finish with compilation of the tex file. Thanks in advance.

1
  • 2
    Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Oct 27 '13 at 4:55
36

What I would advise you is to use this;

latex -interaction nonstopmode -halt-on-error -file-line-error filename.tex

Specifying -interaction nonstopmode is equivalent to using \nonstopmode in your document.

The -halt-on-error option instructs the program to return a non-zero error code when an error is found. This is useful when you are e.g. calling latex from a script or from the make utility. Using make or an equivalent program like e.g. scons is highly recommended for larger documents that have an index or use citations. Because in those cases you will not only have to call LaTeX but also the programs to generate an index and bibliography.

The -file-line-error option is makes it easier to locate errors in your source files, especially when you use \include to e.g. split up a long document into parts (like splitting a book into chapters and putting each chapter in a separate TeX file.

Here is a Makefile fragment that I use for big LaTeX documents;

$(DOCPDF): $(SUBDIR) $(TEXSRC) lbref.bib .git/index
        sh tools/vc -m
        python tools/mkhistory.py hist.tex
        pdflatex --interaction nonstopmode -halt-on-error -file-line-error $*.tex # >/dev/null
        makeindex -c -s myindex.ist $*.idx #2>/dev/null
        bibtex $* #>/dev/null
        pdflatex --interaction nonstopmode -halt-on-error -file-line-error $*.tex #>/dev/null
        makeindex -c -s myindex.ist $*.idx #2>/dev/null
        pdflatex  --interaction nonstopmode -halt-on-error -file-line-error $*.tex #>/dev/null
        rm -f $*.lo* *.aux $*.ilg $*.ind $*.toc $*.bbl $*.blg $*.out *.asc

The first line specifies that the commands have to be carried out when either the tex source document (the TEXSRC variable), the bibliography database (lbref.bib) or the revision control status (.git/index) has changed. The first two commands add the revision number to the document and add a list of changes. After that it calls pdflatex a couple of times interspersed with calls to makeindex and bibtex. Several calls to LaTeX are generally necessary to resolve and stabilize all references when using makeindex.

Edit: I've switched to using latexmk because it will automatically take care of resolving cross-references, bibliographies and such.

So I've modified my Makefile:

SUBDIR= figuren lam calc grafieken
OUTDIR= uitvoer
DOCPDF = $(DOCSRC:.tex=.pdf)

# This is the first target in the Makefile.
all:  $(DOCPDF)

PDFLATEX= xelatex -interaction nonstopmode -halt-on-error -file-line-error
$(DOCPDF): $(SUBDIR) $(TEXSRC) lbref.bib .git/index
        -latexmk -bibtex -recorder -outdir=$(OUTDIR) -auxdir=$(OUTDIR) -pdflatex="$(PDFLATEX)" -pdf $(DOCSRC) 2>&1|grep -C12 '^l\.'
        mv  $(OUTDIR)/$(DOCPDF) .

${SUBDIR}::
        cd ${.TARGET}; make ${.TARGETS}

I've switched to xelatex for its simpler font handling. All the output files are now put in a subfirectory as to not clutter the main directory and for easier cleaning. Only the resulting PDF file is moved to the main directory after it has been created.

2
  • Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Oct 27 '13 at 4:58
  • Ronald, thank you very much for the detailed answer.
    – YiannaCo
    Oct 28 '13 at 7:14
14

Try

latex -interaction=nonstopmode foo.tex
0

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.