This simple code produces
"Missing number, treated as zero"
\documentclass{article}
\newcounter{test}
\newcounter{testtwo}
\usepackage{calc}
\usepackage{amsmath}
\begin{document}
\addtocounter{test}{\value{testtwo}*\value{testtwo}}
\end{document}
In the following situations compiles good:
- Without
amsmath
- When
calc
is loaded afteramsmath
- using
\setcounter
instead of\addtocounter
What is happening here?
If a class loads calc
and we need amsmath
, what can we do? I know that a solution in this case would be loading amsmath
before the class with \RequirePackage
. It is possible another workaround between both \usepackage
?
Best Answer
A quicker workaround, regardless which package is loaded first, is to use
\numexpr
frome-tex
extensions (which should be available for basically any TeX distribution nowadays).It expands the values of the calculation before it's advance by
\addtocounter
In the following MWE the result is, as expected,
100