6

The MWE below points out that expl3 booleans value are printed as Γ and ∆ (or, if \usepackage[T1]{fontenc} is used, as back and forward quotes ` and ́) depending whether they are false or true:

\documentclass{article}
\usepackage{xparse}
\usepackage[T1]{fontenc}
\ExplSyntaxOn
\bool_new:N \falsebool
\bool_new:N \truebool
\bool_set_true:N \truebool
\cs_new_protected:Nn \_boolean_value:n
{
  A~\bool_if:NTF {#1}{true~($=1$)}{false~($=0$)}~ boolean~ is~ printed~ as:~#1
}
\NewDocumentCommand { \displaybooleans } { m }
{
  \_boolean_value:n{#1}
}
\ExplSyntaxOff
\begin{document}
\begin{itemize}
\item \displaybooleans{\falsebool}
\item \displaybooleans{\truebool}
\end{itemize}
\end{document}

Do you know why? Why, outside tests, aren't their values printed as e.g. 0 and 1?

Edit

Here is the background, the real use case: in a package of mine, which is coded thanks to expl3, I provide some (in fact many) options that let the user fix floating points variables, token list variables, boolean variables, etc. And I consider to provide a macro that displays all the options (default ones and user defined ones) in use. The floating points variables and token list variables can be printed in a rather direct way:

  • The nice floating point variable is set to: \fp_use:N\g_a_nice_floating_point_variable_fp (though one could expect in a typesetting context, by opposite to a computing context, The nice floating point variable is set to: \g_a_nice_floating_point_variable_fp to be enough, i.e. \fp_use:N to be superfluous),
  • The nice token list variable is set to: \g_a_nice_token_list_variable_tl.

And my question is: in order to print the current value of a boolean variable, is it necessary to go through a \bool_if:NTF \g_a_nice_boolean_variable_bool { ... } { ... } test to print its current value or is there a more direct way to do?

  • Why would you want to "print" a boolean? That thing or action does not exist. You can print whatever you want depending on the boolean, but not "print the boolean". – Manuel Nov 21 '16 at 20:46
  • @Manuel I meant "print the value" of a boolean (I'll edit my question in this respect), in a more direct way than with a test as the one in my \_boolean_value:n control sequence. – Denis Bitouzé Nov 21 '16 at 20:49
  • There's no function to "print the value of the boolean", and I don't know what would you expect; although there are funcionts that let you print whatever you want depending on the boolean \bool_if:NTF \l_db_bool { 1 } { 0 }. In any case, you are now expecing 1 and 0, but may be in other contexts other may expect true and false for instance. – Manuel Nov 21 '16 at 20:50
  • @Manuel Ill edit the question in order to explain the background (too long for a comment). – Denis Bitouzé Nov 21 '16 at 20:57
  • 2
    \cs_new:Npn \db_bool_use:N #1 { \bool_if:NTF #1 { 1 } { 0 } } and there you go, \tl_use:N \l_tmpa_tl, \fp_use:N \l_tmpa_fp and \db_bool_use:N \l_tmpa_bool. But again, it's logic what a \tl_use:N and \fp_use:N should do, but \bool_use:N has no obvious standard definition (I have yet to find a moment in the last few years in which I needed a default function that converted a true bool to a 1 token and a false bool to a 0 token). – Manuel Nov 21 '16 at 21:39
9

This brings up a very old question: “What is truth?” (John, 18:38).

Unfortunately, there is no answer to this question: truth (at least in mathematics) is whatever, so long as it is different from falsehood. Truth has only meaning relative to a model.

LaTeX3 thinks to truth and falsehood in the same way as Perl: 0 is false and 1 is true. Or the other way around. However, one shouldn't rely on the particular implementation, just remain assured that false will always be the same, and truth won't change.

A false conditional is implemented as returning the constant 0 and, similarly, a true conditional returns the constant 1, but this is just implementation. A conditional such as your \falsebool should only be used in the context of a boolean expression and never on its own.

As is usual in TeX, a constant is defined through \chardef, so when it is found in a typesetting context, \falsebool will typeset the character in slot 0 and \truebool the character in slot 1.

In a OT1 encoded font, these are Gamma and Delta respectively. In a T1 encoded font they're the grave and acute accent. More generally, they'll print the characters in slots 0 and 1 of the current font.

If you try \show\falsebool, you'll get

> \falsebool=\char"0.

on the terminal.

  • 1
    Indeed: over my time on the team we've had two or three implementations of the values! – Joseph Wright Nov 21 '16 at 21:07
  • @JosephWright I should add that in the quoted book, the question receives no answer. – egreg Nov 21 '16 at 21:09
  • @JosephWright Interesting! Do you remember what were the different implementations? – Denis Bitouzé Nov 21 '16 at 21:19
  • 1
    @DenisBitouzé One was using two numbers, so 00 and 01. Not sure what else we've used: these are implementation details and should not be relied on (outside of low-level work by the team ourselves). – Joseph Wright Nov 21 '16 at 21:23
  • Older code didn't pass the true/false values around often. Then there was 00 and 01 to be used with an \if test but it was sort of strange to have 00 meaning 'true' and 01 meaning 'false'. So in 2009 the current concept was introduced which allowed 0/1 to mean what they usually mean and to then have the primitive \ifodd become \if_bool:N for a natural selector. – Morten Høgholm Nov 22 '16 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.