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
\dosomethingin 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?
\undefinedbeing undefined? If it isn't, it would break right along your code. More generally, LaTeX heavily relies on conventions anyways, like that\relaxis the TeX primitive and not something else (or undefined). Relying on\undeifnedisn't really different, is it? – schtandard Feb 13 '22 at 11:44\@undefinedplays that role, though there's no warranty. (\undefinedis the one used by plaintex, and some packages uses its own ones, for exampleetoolboxuses\etb@undefinedin\undefandtikz-pgfuses\pgfutil@undefined). – muzimuzhi Z Feb 13 '22 at 11:47\@ifundefinedin recent released which use\ifcsname– David Carlisle Feb 13 '22 at 11:49\ifx\token\@undefind– David Carlisle Feb 13 '22 at 12:13\undefinedor\@undefined. Anybody defining any of those is clearly asking for trouble. – Henri Menke Feb 13 '22 at 13:29\ifdefined... :) – Skillmon Feb 13 '22 at 13:32\AwesomePackageByUlrichDiezAssumesThisIsUndefinedis undefined, there is basically no way aside from malice that anything will go wrong. – Misha Lavrov Feb 14 '22 at 01:19