I'm looking for a LaTeX way to control macro expansion, contingent on some macro being defined or not. I'm looking for something like this (but then actually working):
\newcommand[1]{\checkfor}{
\if\isdef\csname{#1}
... expand this if command exists ...
\else
... expand this if command does not exist ...
\fi
}
which can then be called using
\checkfor{CommandName}
(this example is, of course, useless. The actual code I want to use this kind of expansion in is a package that dynamically creates a large number of macros from an even larger set of possible macros, with default behaviour for "all macros". Since not "all" macros may exist, I need some way to test whether a macro was declared, before I can expand based on its value).
\nameref
(like\newcommand{\refn[1]{\nameref{#1}}
vs.\newcommand{\refn}[1]{[#1]}
). I tried any of the answers, but wasn't successful.