7

I want to define a key, which, if set, sets a boolean variable to false.

The documentation is not clear on that point. It states (source3.pdf, sect. 87, p. 134):

Defines <key> to set <bool> to <value> (which must be either true or false).

However, I cannot see where to put the false value in the key definition. <value> is not present in the synopsis. It seems that the default behaviour is to set <bool> to true.

7

The .bool_set:N key property is intended to work as

\keys_define:nn { module }
  {
    key-name .bool_set:N = \l_my_bool
  }

which will be used as key-name = true or key-name = false. If you want to have the key name alone to be equivalent to setting false, you need a default:

\keys_define:nn { module }
  {
    key-name .bool_set:N = \l_my_bool ,
    key-name .default:n  = false
  }

However, I'd probably use a raw .code:n approach, as this seems to be 'backward' compared to what I'd expect

\bool_new:N \l_my_bool
\keys_define:nn { module } 
  {
    key-name .code:n = { \bool_set_false:N \l_my_bool } 
  }
  • Thanks. So, if I understand correctly, a key-name defined as .bool_set:N always requires a value and key-name alone raises an error? Is there no implicit .default:n = true? – AlexG Apr 15 '11 at 15:30
  • @Alexander: It should set the default as true. – Joseph Wright Apr 15 '11 at 19:52

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.