How to reliably obtain a control sequence token which is undefined in the current scope?
E.g., is there a sequence of tokens ⟨stuff⟩ with which you can do
\begingroup\expandafter\endgroup\expandafter\dosomething\csname ⟨stuff⟩\endcsname
so that
- TeX won't deliver any error-message while producing the control sequence token from the
\csname..\endcsname
-expression and - the resulting control sequence token behind
\dosomething
in any case is undefined after processing\endgroup
?
I could use this for reliably letting another control sequence token equal to something that is undefined.
By now I do s.th. like \let\token=\UndeFineD
and hope for no piece of third-party-code defining \UndeFineD
before the \let
-assignment is performed.
Another approach could be a loop for constructing names of control sequence tokens until one is found where a test like
\DeclareRobustCommand\CheckWhetherDefined[1]{%
\begingroup
\expandafter\ifx\csname#1\endcsname\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\expandafter\endgroup\expandafter\ifx\csname#1\endcsname\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}{\endgroup\@firstoftwo}%
}%
or like
\DeclareRobustCommand\CheckWhetherDefined[1]{%
\ifcsname#1\endcsname\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}%
does yield \@secondoftwo
.
But I wonder if there is something more clever.
Perhaps an edge case of a \csname..\endcsname
-expression - something of similar "edgeiness" to the scenario of using "frozen-\relax
" in situations where you need a token which definitely is not an explicit character-token and which definitely never is defined in terms of \outer
.
Please notice that the focus of the question is not on methods for testing whether a control sequence token is defined/undefined.
I ask for the best way of obtaining a control sequence token that is undefined in the current scope.
In this context, a test for "definedness/undefinedness" would only be a means to an end, e.g., if one chooses the path of creating tokens until one is created that is not defined.
"Academic question": is there an easily implementable method in TeX to enumerate all possible control sequence names?
\undefined
being undefined? If it isn't, it would break right along your code. More generally, LaTeX heavily relies on conventions anyways, like that\relax
is the TeX primitive and not something else (or undefined). Relying on\undeifned
isn't really different, is it?\@undefined
plays that role, though there's no warranty. (\undefined
is the one used by plaintex, and some packages uses its own ones, for exampleetoolbox
uses\etb@undefined
in\undef
andtikz-pgf
uses\pgfutil@undefined
).\@ifundefined
in recent released which use\ifcsname
\ifx\token\@undefind
\undefined
or\@undefined
. Anybody defining any of those is clearly asking for trouble.