First of all, after
\newcommand{\isempty}{\@empty}
the test
\ifx\isempty\@empty
will return false, because
- both
\isempty
and \@empty
are macros, but
- they differ in their
\long
status.
However, also \newcommand*{\isempty}{\@empty}
would make the test fail, because
- both
\isempty
and \@empty
are macros, with the same \long
status (both aren't \long
), but
- they differ in their first level expansion, which is
\@empty
for \isempty
and nothing for \@empty
.
This assumes, of course, that your code is preceded by \makeatletter
.
Why does \ifthenelse{\equal{\isempty}{\@empty}
follow the true branch? Because the test does full expansion of the arguments of \equal
. In both arguments the full expansion is empty. From the package documentation:
The ⟨string⟩s tested by \equal
may be any sequence of commands that expand to a list of tokens. If these expansions are equal, then the proposition is true.
Basically, \ifx
tests if the two tokens following it would give the same result when \meaning
is applied to them. In the case of
\makeatletter
\newcommand{\isempty}{\@empty}
doing \meaning\isempty
would print
\long macro:->\@empty
while \meaning\@empty
would print
macro:->
so you see they're different as far as \ifx
is concerned.
If you don't have \makeatletter
before your code, the situation is a bit more complicated:
the full expansion of \@empty
, which is six tokens long, is
\spacefactor \@m empty
since \isempty
first expands to \@empty
, the \ifthenelse
test will follow the true branch anyway;
The \ifx
test will compare \isempty
with \@
, which returns false, so empty
will disappear along with the true text and the false branch will be followed.
`
to mark your inline code as I did in my edit.