Sign up ×
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.

The following code (minimal example taken from here)


% Both of these are require to duplicate the problem


produces the following error in imakeidx.sty (only in texlive 2012, not in 2011)

! Missing number, treated as zero.
<to be read again> 
l.48   \ifnum\luatexversion<

Any idea why this happens or can be solved is welcome.

share|improve this question
If I change the order of the packages, it compiles with both LuaLaTeX and PDFLaTeX. – percusse Oct 2 '12 at 20:48
Unfortunately, a new version of imakeidx has reintroduced a malfunction caused by pgfplots. – egreg Oct 2 '12 at 20:53
As of today, version 1.2d of imakeidx is on the TeX Live servers; it should have corrected this issue and others due to bugs introduced in version 1.2 for which I apologize again. – egreg Oct 10 '12 at 15:45

2 Answers 2

up vote 10 down vote accepted

Package imakeidx tests for \directlua before using \luatexversion:


However after package pgfplots is loaded the command \directlua is defined with meaning \relax. The problem is in the file TDS:tex/generic/pgfplots/util/pgfplotsutil.code.tex and also TDS:tex/generic/pgfplots/util/pgfplotsbinary.code.tex, TDS:tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-pdftex.def are candidates, they contain:


The macro \pgfutil@ifundefined is defined in TDS:tex/generic/pgf/pgfutil-common.tex:


\csname has the side effect that it defines undefined commands with the meaning of \relax. If \pgfutil@ifundefined (also the same with LaTeX's \@ifundefined) is called, \directlua gets defined with meaning \relax. In pgfplotsutil.code.tex this happens outside of groups.

Package imakeidx tests for \directlua and finds it defined, because it uses eTeX's \ifdefined.

In my opinion pgfplots shouldn't use \pgfutil@ifundefined for macros that should remain undefined. A better variant is (name with camel case):


Then \csname and the test is called inside group and the meaning of the tested command remains unchanged after the group. The disadvantage is that \pgfutil@IfUndefined is not expandable. But this does not matter in the use case here and many other uses cases in the package. Other macros are also affected (\@ifpackageloaded, \if@filesw, …). See also package ltxcmds that defines \ltx@ifundefined and ltx@IfUndefined that support e-TeX if available.

Package imakeidx could do a more conservative testing to additionally check the command to be tested for the meaning \relax.

Workaround to fix the issue for the OP:


Defining \luatexversion has the severe risk, that other packages might be confused.

Further remark to \pgfutil@ifundefined: \par tokens break \csname, therefore \long does not make any sense here. A better location for \long would be \pgfutil@firstoftwo and \pgfutil@secondoftwo, then their arguments might contain \par tokens (depending on the semantics of these two macros).

share|improve this answer
So I can either load imakeidx after pgfplots or wait for imakeidx to be fixed ? – Matthias Pospiech Oct 2 '12 at 21:27
This problem for imakeidx had been corrected in May; unfortunately the new version was prepared based on version 1.1 instead of 1.1a; I apologize. The real bug, however, is in pgfplots. – egreg Oct 2 '12 at 21:30
The workaround works. – Matthias Pospiech Oct 2 '12 at 21:45
@Heiko thanks for the detailed analysis. I have fixed it in pgfplots using your IfUndefined macro; will become part of the next stable. – Christian Feuersänger Oct 3 '12 at 10:00

works if you are using pdflatex. However you should file a bug report to the author of imakeidx

share|improve this answer

Your Answer


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.