I am looking for a way in TeX to check if a macro was defined.
Currently I use a rather tangled way. I exploit a sort of side effect when comparing two macros via \ifx; this command returns:
- true, if both macros are undefined,
- false, if one macro only is defined.
Therefore, given a surely undefined macro \undefined and the macro \CheckMe, which may or may not be defined, I can use:
\ifx \CheckMe \undefined
CheckMe is NOT defined
\else
CheckMe is defined!
\fi
Is this correct? Can we define a macro ifdef? working like:
\ifdef CheckMe %or \ifdef \CheckMe
CheckMe is defined!
\else
CheckMe is NOT defined
\fi
I tried with something similar:
\def\ifnotdef#1{\ifx \csname#1\endcsname \undefined}
but it doesn't work.
\def\nostandalone\truein the main package; in the child files, to be sometimes be compiled alone, I would set on the top:So it should be possible to load e-TeX before
– antonio Jun 01 '13 at 19:36\documentclass{paper}with TeX methods.\@ifdefinable,\@ifundefinedWhy not use them directly as part of your\ifdef? – Werner Jun 01 '13 at 20:09