A previous question What is the difference between \def and \newcommand? has discussed the difference between \def and \newcommand at some length. However, I cannot find in that discussion an explanation of the following phenomenon.
This code prints Empty:
\documentclass{article}
\begin{document}
\def\foo{}
\ifx\foo\empty Empty\else Not empty\fi
\end{document}
This code prints Not empty:
\documentclass{article}
\begin{document}
\newcommand\foo{}
\ifx\foo\empty Empty\else Not empty\fi
\end{document}
The only difference is that one has \def and the other has \newcommand. What's going on?
\emptyand\fooare different.\foois defined as\long\def\foo{}which is different than\def\empty{}. Try\newcommand*\foo{}instead. – Qrrbrbirlbel May 24 '13 at 12:27\newcommand*\foo{}gives the same result as\def. should be obvious, but ... – barbara beeton May 24 '13 at 12:43