I would like to color numbers red if they are less than zero. In my final report, these number will be generated from a python script. To use the pythontex package, I first run xelatex doc.tex, then pythontex doc.tex, and then xelatex doc.tex one last time for the python script to run and its contents imported into my document.

Unfortunately, during this process, the first xelatex command throws an error because \py{2-4} hasn't been generated yet, so the \colorme command I created is being passed a ? as an argument and not a number.

Is there anyway around this? All I want to do is change the color of the number based on whether its greater than zero or not?



\newcommand{\colorme}[1]{\ifnum #1 > 0


    \colorme{5} %success
    \colorme{-1} %success
    \colorme{\py{2-4}} %fails

  • Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – jub0bs
    Jun 9, 2014 at 18:08
  • Makes sense. I made the appropriate changes Jun 9, 2014 at 18:11

1 Answer 1


Fixed it by adding a default number:

\newcommand{\colorme}[1]{\ifnum 0 < 0#1
        #1 \%
        \textcolor{red}{#1 \%} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .