# Behavior of \global when used with xifthen package [duplicate]

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}
{
\getlength{\mylength}
}
\getlength{\mylength}
{
\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?

## marked as duplicate by David Carlisle, Red, Mensch, Werner, karlkoellerSep 24 '13 at 16:54

• \global\addtolength is wrong anyway. The problem is that xifthen loads calc that redefines \addtolength so that \global has no effect (but it has effect without calc just by chance). See tex.stackexchange.com/a/119738/4427 – egreg Sep 24 '13 at 14:59