3

Is it possible to have a global counter that can display its value on the first page? From what I can tell, the only way is to display on the last page after compiling.

cohilla
  • 31
  • 2
    See the package totcount, please. It requires two runs of compilations –  Jan 03 '16 at 02:39
  • You can write the value to an external file (e.g. the .aux) and then read the value back on the next run. – cfr Jan 03 '16 at 03:04
  • You can use a regular \label-\ref approach to this. That is, \label the last counter usage (assuming it was \refstepcounter-ed), and place \ref wherever you want. – Werner Jan 03 '16 at 03:13
  • This question and answers provides a nice example of using a counter. http://tex.stackexchange.com/questions/142676/how-can-i-obtain-total-number-of-points/142680#142680 – R. Schumacher Jan 03 '16 at 03:38

1 Answers1

3

While I've pointed to a possible duplicated, it's not necessary to use the answer @egreg supplied. Here's a simple example:

\documentclass{article}
\newcounter{aecounter}
\def\trial{\stepcounter{aecounter}}
\providecommand\aemytotal{ZILCH}

\makeatletter
\AtEndDocument{\write\@auxout{\noexpand\global\noexpand\def\noexpand\aemytotal{\number\value{aecounter}}}}
\makeatother

\begin{document}

Total is \aemytotal

\trial
\trial
\trial
this

\pagebreak

that
\trial
\trial
\trial

\pagebreak

\trial
\trial
\trial

those

\end{document}
A.Ellett
  • 50,533