9

Consider the minimal example:

\begin{filecontents}{test.cls}
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\RequirePackage{expl3,l3keys2e}
\ProvidesExplClass
{test}
{2013/12/23}
{1.0}
{A test class}

\bool_new:N \g_test_key_bool
\bool_new:N \g_test_key_a_bool
\bool_new:N \g_test_key_b_bool

\keys_define:nn { test } {
  test    .bool_set:N = \g_test_key_bool,
  key     .multichoice:,
  key / a .code:n = \bool_set_true:N \g_test_key_a_bool,
  key / b .code:n = \bool_set_true:N \g_test_key_b_bool,
}

\ProcessKeysOptions{ test }

\LoadClass{article}
\end{filecontents}
\documentclass[test,key={a,b}]{test}

\usepackage{fontspec}

\begin{document}
ducks
\end{document}

When fontspec is loaded (or likely any package that uses class-level options with \ProcessOptions), I get the following error:

………
(/usr/local/texlive/2013/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.271 \ProcessOptions*

! You can't use `macro parameter character #' in horizontal mode.
\@removeelement #1#2#3->\def \reserved@a ##1,#1,##
                                                  2\reserved@a {##1,##2\rese...
l.271 \ProcessOptions*

)
Runaway argument?
{##1,##2\reserved@b }\def \reserved@b ##1,\reserved@b ##2\reserved@b \ETC.
! File ended while scanning use of \reserved@a.
<inserted text> 
                \par 
l.28 ^^M

(./cv.test.aux)

! LaTeX Error: \RequirePackage or \LoadClass in Options Section.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.29 \begin{document}

[1] (./cv.test.aux) )
(\end occurred when \iftrue on line 271 was incomplete)
(\end occurred when \ifx on line 271 was incomplete)
(\end occurred when \ifx on line 271 was incomplete)
(\end occurred when \ifx on line 271 was incomplete)
(\end occurred when \ifx on line 271 was incomplete)
(\end occurred when \ifx on line 271 was incomplete)
(see the transcript file for additional information)
Output written on cv.test.pdf (1 page).
Transcript written on cv.test.log.

LaTeX exited abnormally with code 1 at Sun Jan 19 12:46:17

I suspect this is because the traditional option parsing provided by LaTeX might not be taking brace groups into account. (Is this even possible without messing with catcodes!?) I can see this error coming up if, for example, LaTeX was splitting the options as [test], [key={a], [b}], but I simply don't see how that makes any sense.

Is it possible to enable the use of this key style within class-level options, or should I bop out to a separate setup function (along the lines of \hypersetup{…})?

3
  • 3
    The braces in the class options disturb \ProcessOptions* and they've always done. – egreg Jan 19 '14 at 21:03
  • 1
    @egreg I never had the opportunity to see it first hand until today. From the l3keys2e docs, \l__keys_process_class_bool might have something to do with class-option loading. The documentation is ambiguous: A flag to indicate that class options should be processed for packages. – Sean Allred Jan 19 '14 at 21:12
  • 2
    l3keys2e doesn't take over \ProcessOptions; perhaps it should. – egreg Jan 19 '14 at 22:15
6

As mentioned in a comment, braces in the class option list will in general cause issues or at least be risky. The way that LaTeX2e processes options does not use keyval methods 'natively': all of the packages for allowing package or class keyval options do so by post-processing options passed by the kernel as key=val. The code used to remove 'used' class options from the global list can't cope with the presence of braces, and so will lead to errors if a package recognises a class option which has been given with some braced content. None of this is unique to l3keys2e.

The way that the LaTeX2e option handling system is set up means that it is not possible to safely load a package and have it make changes to the option processing routine: it is 'too late'. There are on CTAN two packages which do redefine the option processing system, but to be used effectively they have to be loaded before the \documentclass line using \RequirePackage. As such, they cannot be regarded as 'general fixes': the set up is non-standard.

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.