Take the 2-minute tour ×
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.

In other macro systems (notably Lisp's), one often needs to store results into "temporary" variables which shouldn't clash with any variables in the environment where the macro is called. In Lisp, the mechanism for declaring such variables is "gensym"---basically it is a function that returns a fresh variable name that is guaranteed to be unused anywhere else.

It does this essentially by appending an increasing integer onto a variable name prefix. [This is essentially correct, but slightly a lie. Lisp has to do some symbol magic to ensure the variable can't be referred to anywhere else.]

Is there such a capability in Plain TeX?

share|improve this question
    
\begingroup-\endgroup? –  egreg Feb 25 '12 at 16:56
    
that's true. { and } manage scope properly, unlike Lisp. Thanks! –  EfForEffort Feb 25 '12 at 17:01
add comment

1 Answer

up vote 3 down vote accepted

There's nothing of this kind in TeX. However, any macro defined inside a group (which can be initiated in several different ways) will not be accessible outside that group, unless defined with \gdef or \xdef (or if \globaldefs is positive). So

{\def\temp{something}...}

will possibly clobber the meaning of \temp inside the group, but that meaning will be restored at the end of the group or, if \temp was undefined to begin with, it will disappear completely.

share|improve this answer
add comment

Your Answer

 
discard

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.