5

In the interface3 documentation it can be read (what follows is not a literal quotation) that the variable \l_keys_choice_int is available to be used as an index register for a multiple-choices key with its values starting up from 0. Nonetheless, according to my experience with the code below, it is as though the starting value is actually 1.

This is my class, in a file insightfully called myclass.cls:

\RequirePackage{l3keys2e,xparse}
\ProvidesExplClass
    {myclass}
    {2013/08/25}
    {1.0}
    {myclass}

\bool_new:N  \g_myclass_enum_bool
\bool_new:N  \g_myclass_enumalt_bool

\NewDocumentCommand \SetTBool { m }
 {
    \bool_gset_true:c
     { g_myclass_\tl_trim_spaces:n {#1} _bool}
 }

\NewDocumentCommand \TypeBool { m }
 { \bool_if:cTF { g_myclass_#1_bool } { T } { F } }

\keys_define:nn { myclass }
 {
   alter .choice_code:n =
    {   
       \AtBeginDocument{Option ~ Index: ~ \int_use:N \l_keys_choice_int\par}    
       \int_compare:nNnTF { \l_keys_choice_int } =  { 1 }
        { \SetTBool { enum } }
        { \SetTBool { enumalt } }
    },
   alter .generate_choices:n = { enum, enumalt }
 }

\ProcessKeysOptions { myclass }

\LoadClass{memoir}

Then I have a document file by the original name mydoc.tex reading thus:

\documentclass[alter = enum]{myclass}

\begin{document}
\TypeBool{enum}\par
\TypeBool{enumalt}
\end{document}

What I get in my typeset document is 1 T F, whereas according to the documentation I should get 0 T F. Moreover, if I set the class option alter = enumalt, I get 2 F T. Am I getting something wrong?

5

I suspect you have on older copy of interface3: we changed generally from index-from-zero to index-from-one a little while ago now. Thus your observation is correct: the index for \l_keys_choice_int begins at one.

  • Oh, ok, the documentation I'm using is dated December 2012. – Marcos Aug 26 '13 at 19:41
  • Btw, before posting another question that can be solved trivially... I'm having trouble with an expl3-coded class of my own which is based on the memoir class when I try to load the xcolor package before memoir. I don't run into trouble if I load xcolor after memoir, though. Do you know something about this? – Marcos Aug 26 '13 at 19:45
  • @Marcos I'd need to see an example, I'm afraid – Joseph Wright Aug 26 '13 at 19:46
  • Well, it's as simple as adding \RequirePackage{xcolor} after the class header in the code in this post. I get the message Command \@namelet already defined. Maybe it is that xcolor defines a macro by that name, and memoir defines another macro by the same name. – Marcos Aug 26 '13 at 19:47
  • 1
    @Marcos \let\@namelet\relax or \let\@namelet\undefined prior to loading the offending package/code and the test whether it's already defined shouldn't throw an error. – Skillmon Dec 15 '18 at 22:44

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.