josephwright / etoolbox

Tool-box for LaTeX programmers using e-TeX
LaTeX Project Public License v1.3c
41 stars 7 forks source link

Why \etb@ifdefempty uses \ifstrempty, but not \ifx#1\@empty? #23

Closed muzimuzhi closed 6 years ago

muzimuzhi commented 6 years ago

Currently, \etb@ifdefempty{control sequence} uses \ifstrempty internally (see etoolbox.sty#L275-L280). But in kernel of latex2e, the scheme \ifx{<control sequence>}\@empty ... \else ... \fi is commonly used to test if a control sequence is empty.

Are there any benefits the etoolbox way has?

josephwright commented 6 years ago

The \ifx test has to have exactly equivalent definitions. In particular, if you test with a \long or \protected macro it give the unexpected result:

\def\testa{}
\long\def\testb{}
\protected\def\testc{}
\ifx\testa\empty\TRUE\else\FALSE\fi
\ifx\testb\empty\TRUE\else\FALSE\fi
\ifx\testc\empty\TRUE\else\FALSE\fi

For the purposes of etoolbox, it's the net outcome that's important: the result of using the macro is 'nothing'.

muzimuzhi commented 6 years ago

Thanks for your explanation.