I have this piece of code:
\documentclass{scrartcl}
\usepackage{pbox,calc}
\makeatletter
\newcommand*{\strippt}[1]{\strip@pt#1}
\makeatother
\newlength{\pointsExo}
\setlength{\pointsExo}{4pt}
\newlength{\pointsSousTotal}
\setlength{\pointsSousTotal}{0pt}
\newlength{\souspointsExo}
\newcommand{\sousPoints}[1]{
\setlength{\souspointsExo}{#1pt}
\setlength{\pointsSousTotal}{\pointsSousTotal + #1pt}
{\scriptsize{(#1~\ifdim#1pt=1pt point\else points\fi/\strippt\pointsExo)}}
}
\newcommand{\subexo}[2]{
\textsf{ %%If I comment these two lines, the sub-total is correct
#1\hfill\sousPoints{#2}% Points
} %%If I comment these two lines, the sub-total is correct
\medskip
}
\newcommand{\exercice}[2]{
\setlength{\pointsExo}{#2pt}
\setlength{\pointsSousTotal}{0pt}
\medskip
#1\hfill#2 Points% Points
\medskip
}
\begin{document}
\exercice{A first one}{2.5}
\subexo{Anything}{2}
\subexo{Something}{0.5}
Sub-Total: \strippt\pointsSousTotal %should display 2.5
\exercice{A title}{4}
\subexo{another thing}{2.5}
\subexo{and a thing}{1.5}
Sub-Total: \strippt\pointsSousTotal %should display 4
\end{document}
The problem with this is that it should display something like this:
A first one 2.5 Points
Anything (2 points/2.5)
Something (0.5 points/2.5)
Sub-Total: 2.5
A title
another thing (2.5 points/4)
and a thing (1.5 points/4)
Sub-Total: 4
But, unless I comment the two indicated lines (currently, an enclosing \textsf{...}, but the problem is the same as soon as I enclose the \sousPoints{#2} between two curly braces), I get this:
A first one 2.5 Points
Anything (2 points/2.5)
Something (0.5 points/2.5)
Sub-Total: 0
A title
another thing (2.5 points/4)
and a thing (1.5 points/4)
Sub-Total: 0
What is wrong with using length inside an enclosing brace {...} ? Is it a bug ? A bad understanding of how commands work ?
\setlength
are local settings so the values are restored at the end of a group. (Also you are missing%
from the ends of lots of lines.)%
see tex.stackexchange.com/questions/7453/…