3

I am writing a class based on book.cls, to which I want to have an option that is a list, so I can do

\documentclass[languages={french, english}]{testops}

I have define the key using l3key2e. But it seems that the option parser of the class doesn't allow to use =, if all pass the options to book.

If I don't pass the all the options to book, them the document process. But I would like to pass the options not defined by l3keys2e to the class, so I don't have to re-define the usual options of the bookclass (paper size, fontsize, ....).

Is there any way to do this, and at the same time, passing the other options to bookclass?

MWE

\begin{filecontents}{testops.cls}
    \ProvidesClass{\jobname}[2018-11-20 v1.0 SE Test package]
    \RequirePackage{pgfopts}
    \RequirePackage{expl3,l3keys2e,xparse}

    \ExplSyntaxOn
    \keys_define:nn { testops }
    { languages .default:n = {english},
      languages .clist_gset:N = \g_testops_languages_clist,
    }

    \cs_new_protected_nopar:Nn \__printlanguages:
    {
      \clist_use:Nnnn \g_testops_languages_clist { ~and~ } { ,~ } { ~and~ }
    }

    \NewDocumentCommand { \printlanguages} {} {\__printlanguages:}

    \ProcessKeysOptions { testops } % Parses the option list
    \ExplSyntaxOff

    \PassOptionsToClass{\CurrentOption}{book} %%% <-- THIS LINE RISES THE ERROR
    \LoadClass{book}


    \endinput
\end{filecontents}
% ------------------
\documentclass[languages={french,spanish,englis}]{testops}

\begin{document}
\printlanguages
\end{document}
TeXtnik
  • 5,853

1 Answers1

2

Just answering my own question :-)

I learn that we can use the .unknown keyword to process the keys that are not known to the l3keys system. Them we can pass these options to the underlying book class.

\begin{filecontents}{testops.cls}
    \ProvidesClass{testops}[2018-11-20 v1.0 SE Test package]
    \RequirePackage{expl3,l3keys2e,xparse}

    \ExplSyntaxOn
    \keys_define:nn { testops }
    { languages .default:n = {english},
      languages .clist_gset:N = \g_testops_languages_clist,
      unknown .code:n = 
      { \msg_term:n { \l_keys_key_tl\ uknown~option~used }
        \PassOptionsToClass { \CurrentOption } { book }}
      }


    \cs_new_protected_nopar:Nn \__printlanguages:
    {
      \clist_use:Nnnn \g_testops_languages_clist { ~and~ } { ,~ } { ~and~ }
    }

    \NewDocumentCommand { \printlanguages} {}
    {\__printlanguages:
    }

    \ProcessKeysOptions { testops } % Parses the option list
    \ExplSyntaxOff


    \LoadClass{book}
    \RequirePackage{geometry}

    \endinput
\end{filecontents}
% ------------------
\documentclass[a5paper,12pt,languages={french,spanish,englis}]{testops}

\begin{document}
\printlanguages
\end{document}
TeXtnik
  • 5,853