2

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}
  • Yes, it is possible (although currently somewhat limited). See here, for instance. I suggest you show us a MWE that demonstrates why the options aren't working. – Phelype Oleinik Nov 29 '18 at 10:23
  • @PhelypeOleinik: Thank for the link. I provide now a MEW. – TeXtnik Dec 1 '18 at 7:29
1

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}

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.