I'm trying to calculate the sum of some numbers in my document. I want to allow non-integer values, so I'm using lengths, which works just fine.
In my document it's often necessary to specify the values for adding to the sum from inside an environment. I learned that the \global command does the trick.
However, I encountered the problem that the \global command seems to not work properly when the xifthen package is loaded, either directly or by another package.
Here's an example:
\documentclass{article}
\usepackage{xifthen}
\makeatletter
\newcommand*{\getlength}[1]{\strip@pt#1}
\makeatother
\begin{document}
\newlength{\mylength}
\setlength{\mylength}{0pt}
\getlength{\mylength}
{
\addtolength{\mylength}{0.5pt}
\getlength{\mylength}
}
\getlength{\mylength}
{
\global\addtolength{\mylength}{0.5pt}
\getlength{\mylength}
}
\getlength{\mylength}
\end{document}
The output is:
0 0.5 0 0.5 0
Removing the xifthen package produces the expected output:
0 0.5 0 0.5 0.5
Is there any workaround to produce the second output, without having to ensure that no package which uses xifthen is loaded?
\global\addtolengthis wrong anyway. The problem is thatxifthenloadscalcthat redefines\addtolengthso that\globalhas no effect (but it has effect withoutcalcjust by chance). See http://tex.stackexchange.com/a/119738/4427 – egreg Sep 24 '13 at 14:59