8

The xparse documentation says,

enter image description here

But that's not what I get when I test s.

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\myfunc}{s}{#1}

\begin{document}
\myfunc    % should return \BooleanFalse; actually returns \Gamma
\myfunc*   % should return \BooleanTrue; actually returns \Delta
\end{document}

Edit: Also, \IfValueTF doesn't return 0 when * is absent.

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\myfuncB}{s}{
    \IfValueTF{#1}{1}{0}
}

\begin{document}
\myfuncB    % should return 0; actually returns 1
\myfuncB*   % should return 1; actually returns 1
\end{document}
6
  • 3
    \BooleanTrue and \BooleanFalse cannot be typeset: they are boolean variables and don't make sense outside of a \IfBooleanTF{#1} test. Try \IfBooleanTF{#1}{True}{False} Apr 9, 2021 at 14:44
  • @PhelypeOleinik But is it a happy coincidence that Gamma is \char"00 and Delta is \char"01?
    – campa
    Apr 9, 2021 at 14:46
  • @PhelypeOleinik Fair enough, but see edit to OP for more.
    – mjc
    Apr 9, 2021 at 14:47
  • @campa No, expl3 booleans are \char"0 and \char"1, and that's why OP gets that output. Regardless it doesn't make much sense to use them for typesetting Apr 9, 2021 at 14:47
  • 2
    Careful: \IfBooleanTF, not \IfValueTF. The latter tests for the special marker -NoValue-
    – campa
    Apr 9, 2021 at 14:48

1 Answer 1

10

\BooleanFalse and \BooleanTrue are boolean variables not meant for typesetting. You can only use them in a \IfBooleanTF test:

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\myfuncB}{s}{%
    \IfBooleanTF{#1}{1}{0}%
}

\begin{document}
\myfuncB    % returns 0
\myfuncB*   % returns 1
\end{document}

\IfValueTF can't be used either because it checks if the argument is -NoValue-, and neither \BooleanTrue nor \BooleanFalse are -NoValue-, so the test returns true always. \IfValueTF is supposed to be used with optional arguments like o and d.


Under the hood, \BooleanFalse is \char"0 and \BooleanTrue is \char"1 so they take the zeroth and first character of the current font, whatever that happens to be. In the OT1 encoding, \char"0 and \char"1 are the glyphs Γ and ∆:

\documentclass{article}
\usepackage{fonttable}
\begin{document}
\fonttable{cmr10}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .