TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

Let's see the following screenshot taken from an answer of Efficient ways to anonymize a document and the given comment.

enter image description here

Is it possible to remove length, counter, dim, etc, that have been declared in a macro, before leaving the macro?

share|improve this question
up vote 10 down vote accepted

No, it's not possible: \newlength allocates a register and this allocation is permanent. If you do the \newlength inside a group, you'll lose the register name at group end, but the register will not be reusable.

Actually it might be possible: define a macro \startlocalallocations that modifies \newlength and \newcounter in such a way that allocations from that point on are stored in a convenient macro, say \allocationsmade, and then define \removelocalallocations that uses \allocationsmade to restore the status as it was before the starting command.

While feasible (at least in principle), this is completely useless. Registers should be allocated outside macro definitions: they can be set and used as many times as one wants. So the correct way to define \blind is


and all will work. There's no need to allocate a temporary variable.

Note: the package etex allows for local allocations. But this is useful in contexts very different from this one: one can think to the allocation of a block of registers for some particular use, when they are not called by name, but by numbers. See the implementation of the float mechanism for a slightly different example in which a block of registers is allocated and they are called \bx@A, \bx@B, ..., \bx@R in order that the next free register can be used by knowing the number of the last one used.

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.