2

The following minimal example demonstrates my situation:

\documentclass{article}
\usepackage{calculator}
\newcommand{\pts}{0}

\begin{document}

\ADD{\pts}{3}{\pts}\pts

\ADD{\pts}{3}{\pts}\pts

\ADD{\pts}{3}{\pts}\pts

\begin{enumerate}
    \item \ADD{\pts}{3}{\pts}\pts
    \item \ADD{\pts}{3}{\pts}\pts
\end{enumerate}

\pts

\end{document}

Ideally I would like to have the counter \pts to increase through and after the application of the enumeration environment (or any environment in fact). The package document does state:

But these commands act as declarations, so that its scope is local in environments and groups.

Is there a way around this? Is there a way to keep a counter running through a document, that one can add (or other arithmetic operations as needs be, which the calculator package does do wonderfully).

2
  • Well, you basically ask for a total sum counter?
    – user31729
    Commented May 27, 2014 at 11:38
  • Yes. I thought that this was a way, but it doesn't work within environments.
    – Geoff
    Commented May 27, 2014 at 11:53

2 Answers 2

2

You need to make \pts global before leave the enumerate environment. To do this, use the \GLOBALCOPY command: \GLOBALCOPY{\pts}{\pts}:

\documentclass{article}
\usepackage{calculator}
\newcommand{\pts}{0}

\begin{document}

\ADD{\pts}{3}{\pts}\pts

\ADD{\pts}{3}{\pts}\pts

\ADD{\pts}{3}{\pts}\pts

\begin{enumerate}
   \item \ADD{\pts}{3}{\pts}\pts
   \item \ADD{\pts}{3}{\pts}\pts
   \GLOBALCOPY{\pts}{\pts}             %%%% Globalize \pts !!!
\end{enumerate}

\pts

\end{document}
1
  • Many thanks for the answer; and for the package!
    – Geoff
    Commented May 28, 2014 at 7:48
3

You can use a counter rather than a command:

\documentclass{article}
\newcounter{pts}

\begin{document}

\addtocounter{pts}{3}\thepts

\addtocounter{pts}{3}\thepts

\addtocounter{pts}{3}\thepts

\begin{enumerate}
    \item \addtocounter{pts}{3}\thepts
    \item \addtocounter{pts}{3}\thepts
\end{enumerate}

\thepts

\end{document}
5
  • This won't work with floating point values, if that should be intented
    – user31729
    Commented May 27, 2014 at 14:36
  • @Christian: Well, that wasn't in the question...!
    – Joce
    Commented May 27, 2014 at 14:37
  • No, it wasn't, just as tiny remark by me
    – user31729
    Commented May 27, 2014 at 14:40
  • @Christian: The word "counter", in my mind, implies an integer.
    – Joce
    Commented May 27, 2014 at 14:43
  • @Joce Many thanks. Christian was correct, I didn't mention since I didn't think about that. I suppose my MWE was too minimal!
    – Geoff
    Commented May 28, 2014 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .