[texhax] Retrieving the value of a counter from previous run

Philip G. Ratcliffe philip.ratcliffe at fastwebnet.it
Sat Apr 14 21:10:43 CEST 2007


> This must be easy, but I can't find out how.
> 
> I have a counter I use to count names in an included file:
> 
> master.tex has:
> 
> \newcounter{nnames}
> \newcommand\nextname[1]{#1\addtocounter{nnames}{1}}
> 
> ...
> 
> \include{names}
> 
> ...
> 
> 
> names.tex has:
> 
> The following \arabic{nnames}\ all agree with me:
> 
> %\setcounter{nnames}{0}  %this is what I had in mind to restart
> 
> \nextname{Joe Bloggs}
> \nextname{Fred Smith}
> 
> ...
> 
> So the idea is to count the names on the first pass through the file,
> and then pick up that value on subsequent passes. The problem seems to
> be (a) the \newcounter command resets the counter to zero (as 
> one might
> expect and normally want) and (b) the value from the previous 
> run (which
> I can see in the \@setckpt in names.aux) is then inside the scope of
> that checkpoint.
> 
> Changing \include to \input needs something else to get a line:
> 
> \setcounter{nnames}{xx}
> 
> into the main aux file I guess.

Yep, just take a look at how the \label and \ref commands work, for example.

Cheers,  Phil



More information about the texhax mailing list