The title already states the whole question. It has been answered by Joseph Wright at http://www.texdev.net/2009/11/17/tex-counts-and-latex-counters/, but I have not seen the according answer here at tex.stackexchange.com yet.
|
At the LaTeX level, a counter is created using
This creates a counter initialised at zero which can then be set using
or manipulated using
There are then some methods to get the counter value back out. LaTeX creates a
LaTeX's counters are set globally. That makes them good for tracking something that covers the entire document, but not as good for localised calculations. A TeX count is created using
where the name is a name including a backslash. Setting a count is done very simply: there is no set function
Notice the
A similar termination is brought about by having a space after the number
The value of a count register can be recovered using
The big difference is that TeX sets count registers locally. So to do a global assignment you have to do it deliberately
As LaTeX is built on TeX, you might guess that LaTeX's counters are an interface to TeX’s count registers, but it's not immediately obvious how this is done. The way it works is that LaTeX prefixes all of the counter names with
LaTeX would issue an error message: the counter is already defined. The other LaTeX functions then build on this, so that they manipulate the internal counters. This is all done globally and with some error checking. For example, the definition of
This checks the counter exists, and if it does globally advances it. |
|||||
|

@usersyntax only works for users which already posted a comment to the same post. Joseph won't get notified about your comment above because of this. Spaces are also not allowed, so you should use@JosephWright. – Martin Scharrer♦ Nov 16 '11 at 19:07