TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering how does TeX manage counters. In particular, assuming I define a new counter in TeX by \newcount\mycounter and at some point I don't need it anymore, can I delete it and free the associated registry?

This may be useful when one needs to use a sequence of counters \c1, \c2, ..., \c<n> where n may become large, and at some point there is no need for some of the counters in the sequence (say, up to some index).

share|improve this question
You can free it without worrying about the name, but the problem is that the standard allocation system (from plain TeX and inherited by LaTeX2e and ConTeXt) is not really designed for this. You could look at the e-TeX mechanism, but that is still more about freeing when TeX groups end. One could write a system to allow freeing, but with e-TeX providing 32k registers, I'm not sure of the need! – Joseph Wright May 17 '12 at 13:42
up vote 11 down vote accepted

If the usage of the n counters is specific for some task you can do the computations in a group and assign them whatever register you want:

<the computations where the total is stored in \mycounta>

The local equivalence of \mycounta to \count11 will be forgotten at the end of the group as will be their values. As long as you don't use any "external" counter in your computation, you'll be sure that no conflict will arise.

Freeing counters would require a rather complex rewriting of the allocation macros; this is not very important with e-TeX that provides 32768 registers of each type.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.