josephwright / etoolbox

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

Bug or feature? \ifdefempty expands to <true> for command with blank replacement text #22

Closed muzimuzhi closed 6 years ago

muzimuzhi commented 6 years ago

Given a parameterless macro whose replacement text is blank but not empty (contains one or more spaces only) as first parameter, \ifdefempty expands to \<true>, which is, in my point of view, inconsistent with the related words in package documentation (see etoolbox.tex@L667-669).

\ifdefempty{\<control sequence>}{\<true>}{\<false>}

Expands to \<true> if the \<control sequence> is defined and is a parameterless macro whose replacement text is empty, and to \<false> otherwise. ...

Example:

\def\test{   }
\ifdefempty{\test}{T}{F} % prints T

Investigating the source code, it shows \ifdefempty uses \etb@ifdefempty after some conditionals, and \etb@ifdefempty uses \ifblank (see etoolbox.sty#L266-280).

If this is more close to a bug, rather than a feature, I think the problem is caused by the usage of \ifblank. Substituting \ifblank to \ifstrempty might fix the problem.