LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Joel C. Salomon" <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Thu, 27 Jun 2013 12:42:38 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (58 lines)
Building on the TeX.SE posts "Is there a \bool_case:Nnn?"
(http://tex.stackexchange.com/q/121074/2966) and Joseph Wright's
answer to "How do the \xx_case: functions work?"
(http://tex.stackexchange.com/q/121390/2966), here is \bool_case:nn,
proposed for addition:

\documentclass{minimal}
\usepackage{expl3, xparse}

\ExplSyntaxOn

\cs_new:Npn \bool_case:nn #1#2
  {
    \tex_romannumeral:D
      \__bool_case:w #1 \c_true_bool {#2} \q_recursion_stop
  }
\cs_new:Npn \__bool_case:w #1#2
  {
    \bool_if:nTF { #1 }
      { \__bool_case_end:nw {#2} }
      { \__bool_case:w }
  }
\cs_new_eq:NN \__bool_case_end:nw \__prg_case_end:nw

\NewDocumentCommand \testboolcase {}
  {
    \bool_set_false:N \l_tmpa_bool
    \bool_set_true:N \l_tmpb_bool

    \bool_case:nn
      {
        \l_tmpa_bool { false;~ can't~ happen }
        \l_tmpb_bool { true;~ should~ happen }
      }
      { else;~ can't~ happen }
  }

\NewDocumentCommand \testboolcaseelse {}
  {
    \bool_set_false:N \l_tmpa_bool
    \bool_set_true:N \l_tmpb_bool

    \bool_case:nn
      {
        \l_tmpa_bool { false;~ can't~ happen }
        { !\l_tmpb_bool } { false;~ can't~ happen }
      }
      { else;~ should~ happen }
  }

\ExplSyntaxOff

\begin{document}
\testboolcase

\testboolcaseelse
\end{document}

ATOM RSS1 RSS2