Note that this blog post has been archived. Information may be out of date or incorrect.

LaTeX- Checking if a macro is (un-)defined

When I started coding some LaTeX templates for myself, I had a very hard time figuring out how to check if some macro is defined or not. I tried lots of different solutions, and none of them seemed to do what I want (or anything, for that matter). I ended up using ifundef from the etoolbox package.


\ifundef{\somemacro}{ \newcommand{\somemacro}{default value} }{ \relax } % else: do nothing

Hope this saves you some time ;)