I want to elaborate a command that would print differently simple differential dx
and multidimensional differential d^3x
. For this purpose I invented the command \dif
with one optional argument. It is defined as follows:
\newcommand{\dif}[1][]{%
\def\@tmp@a{#1}%
\ifx\@tmp@a\@empty
[b1]\mathrm{d}
\else
[b2]\mathrm{d}^{#1}{} \!
\fi
}
Here [b1] and [b2] are added for debugging. Branch [b1] is intended for the case when the command is called without any argument, e.g. \dif{x}
. Second branch [b2] should be taken in case where, e.g., the command \dif[3]{x}
is used to print d^3x
. The definition, shown above, seems to work fine. However, if \@empty
is substituted with \empty
first branch is always ignored.
The command \empty
is explained in The TeXBook, so that initially I tried it for this code and only occasionally reverted to \@empty
having remembered a post at this site where it was said that the \end
command of Plain TeX is redefined to \@@end
in LaTeX.
Can somebody explain what is the difference between
\empty
and
\@empty
in LaTeX and, perhaps, suggest a better solution for my
problem?
Best Answer
The
\@empty
and\empty
macros are defined in the source file for the LaTeX formatlatex.ltx
on line 122 and 441, respectively:So both are actually identical. I as well wondered about having two names for the same thing around. I guess the LaTeX developers wanted a macro which is safer for being redefined by the user or other packages.
You code actually should work with both
\@empty
and\empty
. Put a\show\@empty
and\show\empty
before your\ifx
to debug the issue. Maybe one gets redefined somewhere. In that case you could place a\tracingall\tracingassigns=1\relax \tracingonline=0\relax
very early of your document preamble and then search for the redefinition in the log file.