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\true
in the main package; in the child files, to be sometimes be compiled alone, I would set on the top:` ` \ifx \nostandalone \undefined \documentclass{paper} \begin{document} \fi .... \ifx \nostandalone \undefined \documentclass{paper} \begin{document} \fi So it should be possible to load e-TeX before\documentclass{paper}
with TeX methods.\@ifdefinable
,\@ifundefined
Why not use them directly as part of your\ifdef
?