Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

counters total value

3 views
Skip to first unread message

Par

unread,
Sep 25, 2008, 3:25:21 PM9/25/08
to
I want to create a counter, add to it in various places in the text, and
then be able to at any point i the text refer to the total (i.e. at the
end of document)) value of the counter.

Example:

\newcounter{nog}\setcounter{nog}{0}
...
<value of {nog} at end of file>
...
\stepcounter{nog}
...
\stepcounter{nog}
...
\stepcounter{nog}
...
\stepcounter{nog}
...
\stepcounter{nog}


Is there any way to do this?

/Par

--
Par use...@hunter-gatherer.org
Renting airplanes is like renting sex: It's difficult to arrange on short
notice on Saturday, the fun things always cost more, and someone's always
looking at their watch. -- Paul Tomblin

Lars Madsen

unread,
Sep 25, 2008, 3:46:51 PM9/25/08
to
Par wrote:
> I want to create a counter, add to it in various places in the text, and
> then be able to at any point i the text refer to the total (i.e. at the
> end of document)) value of the counter.
>
> Example:
>
> \newcounter{nog}\setcounter{nog}{0}
> ...
> <value of {nog} at end of file>
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
>
>
> Is there any way to do this?
>
> /Par
>

you need a two step process using the .aux file.

Memoir does this to provide access to the total number of sheets used.

Copying from memoir

\newcounter{lastnog}

\makeatletter
\newcommand{\dol@stnog}{%
\if@filesw
\immediate\write\@auxout%
{\string\setcounter{lastnot}{\the\c@nog}}%
\fi}

\AtBeginDocument{\AtEndDocument{\dol@stnog}}
\makeatother

untested

I'm sure there is a package that can do this as well.


/daleif

Ulrike Fischer

unread,
Sep 25, 2008, 5:24:51 PM9/25/08
to
Am 25 Sep 2008 19:25:21 GMT schrieb Par:

> I want to create a counter, add to it in various places in the text, and
> then be able to at any point i the text refer to the total (i.e. at the
> end of document)) value of the counter.
>
> Example:
>
> \newcounter{nog}\setcounter{nog}{0}
> ...
> <value of {nog} at end of file>
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
> ...
> \stepcounter{nog}
>
>
> Is there any way to do this?
>
> /Par

Use \refstepcounter and a \label after the last one. Then you can use
\ref to reference the counter.


--
Ulrike Fischer

Par

unread,
Sep 26, 2008, 9:39:51 AM9/26/08
to
Lars Madsen <dal...@imf.au.dk>:

> you need a two step process using the .aux file.

Figures.

> Memoir does this to provide access to the total number of sheets used.
>
> Copying from memoir
>
> \newcounter{lastnog}
>
> \makeatletter
> \newcommand{\dol@stnog}{%
> \if@filesw
> \immediate\write\@auxout%
> {\string\setcounter{lastnot}{\the\c@nog}}%
> \fi}
>
> \AtBeginDocument{\AtEndDocument{\dol@stnog}}
> \makeatother
>
> untested

Worked fine one I had done s/lastnot/lastnog/. Thanks!

> I'm sure there is a package that can do this as well.

I looked at styles for exams, but all I could find was multiple choice
style exams. This is for exams, where there is three different types of
questions; pass-level, good-level and excellent-level. This (taken
thrice) allows me to automatically sum up the number of questions of
each type.

/Par

--
Par use...@hunter-gatherer.org
Never attribute to conspiracy what can be fully explained by stupidity.

Heiko Oberdiek

unread,
Oct 1, 2008, 3:10:29 PM10/1/08
to
Lars Madsen <dal...@imf.au.dk> wrote:

> Par wrote:
> > I want to create a counter, add to it in various places in the text, and
> > then be able to at any point i the text refer to the total (i.e. at the
> > end of document)) value of the counter.
> >
> > Example:
> >
> > \newcounter{nog}\setcounter{nog}{0}
> > ...
> > <value of {nog} at end of file>
> > ...
> > \stepcounter{nog}
> > ...
> > \stepcounter{nog}
> > ...
> > \stepcounter{nog}
> > ...
> > \stepcounter{nog}
> > ...
> > \stepcounter{nog}
> >
> >
> > Is there any way to do this?
>

> you need a two step process using the .aux file.
>
> Memoir does this to provide access to the total number of sheets used.
>
> Copying from memoir
>
> \newcounter{lastnog}
>
> \makeatletter
> \newcommand{\dol@stnog}{%
> \if@filesw
> \immediate\write\@auxout%
> {\string\setcounter{lastnot}{\the\c@nog}}%
> \fi}
>
> \AtBeginDocument{\AtEndDocument{\dol@stnog}}
> \makeatother
>
> untested
>
> I'm sure there is a package that can do this as well.

Now I have implemented it in zref (module lastpage) 2008/10/01 v2.3.
Update is on its way to CTAN.

\documentclass{article}

\newcounter{nog}
\renewcommand*{\thenog}{\Alph{nog}}

\usepackage{zref-lastpage,zref-user}[2008/10/01]
\makeatletter
\zref@newprop{thenog}{\thenog}
\zref@newprop{valuenog}{\the\value{nog}}
\zref@addprop{LastPage}{thenog}
\zref@addprop{LastPage}{valuenog}
\makeatother

\begin{document}
At end of the document counter nog is output as
`\zref[thenog]{LastPage}'
with counter value `\zref[valuenog]{LastPage}'.

\newpage
\stepcounter{nog}\thenog,
\stepcounter{nog}\thenog,
\stepcounter{nog}\thenog
\newpage
\stepcounter{nog}\thenog
\newpage
\stepcounter{nog}\thenog,
last page.
\end{document}

Yours sincerely
Heiko <ober...@uni-freiburg.de>

0 new messages