josephwright / etoolbox

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

Suggestion: one-armed ifs #40

Closed krono closed 2 years ago

krono commented 3 years ago

I find myself writing a lot of code like:

\ifbool{foo}{}{\knorx}
\notbool{barf}{\zork}{}

with one of the branches empty.

What about one-armed versions?

\newcommand*{\whenbool}[1]{%
  \ifcsundef{if#1}
    {\etb@err@nobool{#1}\@gobble}
    {\csname if#1\endcsname
       \expandafter\@firstofone
     \else
       \expandafter\@gobble
     \fi}}
\newcommand*{\whennotbool}[1]{%
  \ifcsundef{if#1}
    {\etb@err@nobool{#1}\@gobble}
    {\csname if#1\endcsname
       \expandafter\@gobble
     \else
       \expandafter\@firstofone
     \fi}}

Note: i chose whennotbool, because unlessbool was already taken.

josephwright commented 2 years ago

I understand the thinking (it's what expl3 does), but within the classical 2e framework all conditionals have two branches.

krono commented 2 years ago

OK :)