# Force latex to finish compiling regardless of error? (xelatex)

I have a reoccurring problem.

I want to be able to force latex to finish compiling regardless of an error. I know that this error will occur several times in my script and it is a result of the pythontex package.

I use the pythontex package to import data into my report that I've manipulated in python. To use pythontex first you compile the tex document with latex (I use xelatex), then with pythontex, and then once again with latex. So in the command line I run:

xelatex mydoc.tex
pythontex mydoc.tex
xelatex mydoc.tex


The problem is, I want to be able to color code the values returned from python based on whether they are greater than or less than zero. However, the first time I compile my tex file with xelatex (or whatever), because pythontex hasn't been run yet, the \py{2} argument I'm passing my colorme function is empty. This throws an error, and the whole process grinds to a stop.

I will be creating more similar functions such as colorme so I am hoping there is an all encompassing solution that will help keep latex runnign despite the inevitable errors from empty arguments.

Is there anyway to force latex to finish compiling, so that I can at least run pythontex?

\documentclass{article}
\usepackage{pythontex}

%color things red!
\newcommand{\colorme}[1]{

\ifnum\ifnum\numexpr 0 < #1
\textcolor{black}{#1}
\else
\textcolor{red}{#1}
\fi

}

\begin{document}

\colorme{\py{2}}
\colorme{\py{-2}}
\colorme{2}
\colorme{\py{-2}}

\end{document}


xelatex -help


suggests

-interaction=STRING     set interaction mode (STRING=batchmode/nonstopmode/
scrollmode/errorstopmode)


you probably want batchmode but a possibly better alternative would be to fix your macro to accept empty arguments eg

  \ifnum\numexpr 0 < \ifx\valign#1\valign0 \else #1\fi\relax


will make {} be tested as 0 but still print as empty.

You definitely want to change \ifnum\ifnum to \ifnum in any case.

\documentclass{article}
\usepackage{pythontex}

%color things red!
\newcommand{\colorme}[1]{%
\ifnum\numexpr 0 < \ifx\valign#1\valign0 \else#1\fi\relax
\textcolor{black}{#1}%
\else
\textcolor{red}{#1}%
\fi
}

\begin{document}

\colorme{}
\colorme{2}

\end{document}

• Hmmm, your fix to my macro doesn't seem to be working. I'm getting a Incomplete \ifnum error Jun 17 '14 at 15:19
• when I call \colorme{} Jun 17 '14 at 15:27
• @JoeDanger I added the updated code to the answer: you also had omitted % from ends of lines and had spurious blank lines in the definition (which case \par tokens in the definition) Jun 17 '14 at 15:44
• It works great with \colorme{} but with \colorme{\py{2}} its failing with an Missing number treated as zero error. Maybe \py{2} is not treated as empty. Is there a way to figure this out and control for it so that the code compiles? Jun 17 '14 at 17:29
• @JoeDanger I assumed pythontex (which I don't have) defines \py(2) to be something expandable (or your \ifnum test would never have worked?) Jun 17 '14 at 17:37