7

I'm currently using \PassOptionsToClass, as suggested in Conditional Compiling and \documentclass to compile a document in several languages. However, if I use language-options in \PassOptionsToClass, they will not be passed to babel.

MWEs:

\documentclass[english]{article}

\usepackage{babel}

\begin{document}
\end{document}

compiles (without complaints) an empty document. But

\PassOptionsToClass{english}{article}
\documentclass{article}

\usepackage{babel}

\begin{document}
\end{document}

yields

! Package babel Error: You haven't specified a language option.

since babel does not get the english option.

So here is my actual question: Is there any (simple) possibility to add a global option (which is passed to subsequent packages) before the actual \documentclass?

  • What do you mean by »add a global option«? I am not sure i understand the question. – Johannes_B Jan 15 '15 at 13:06
  • 1
    @Johannes_B with \documentclass[<opt>]{article} the option <opt> is also passed to all subsequently-loaded packages. Apparently this doesn't happen when using \PassOptionsToClass{<opt>}{article} as shown in the example. – Paul Gessler Jan 15 '15 at 13:18
  • 1
    I think i get it, reminds me of A class with default language settings – Johannes_B Jan 15 '15 at 13:33
  • @Johannes_B Exactly. The thing is that the system isn't really set up for that, and 'hidden' language options in classes or similar are usually a tricky idea to get right. – Joseph Wright Jan 15 '15 at 13:39
11

The mechanism used by \PassOptionsToClass (or indeed \PassOptionsToPackage) targets just that file: it's therefore equivalent to

\LoadClass[<options>]{<name>}

and very similar to

\RequirePackage[<options>]{<name>}
\usepackage[<options>]{<name>}

In contrast, the options given as part of the \documentclass line are globally available to all packages and classes loaded (yes, you can have only one class using \documentclass but that can load a series of ones to build on). As such, the global options are stored in another place. There's no pre-defined mechanism to access this 'publicly' other than via the optional argument to \documentclass. Of course, one can access it using the internal name

\makeatletter
\def\@classoptionslist{english}
\makeatother
\documentclass{article}

\usepackage{babel}

\begin{document}
\end{document}

I'm not really sure why you would choose to do this: a class shouldn't really be messing about with this type of thing.

  • Thank you for your answer. In my understanding, we have three types of options: package options, class options and global options (passed to all classes and packages). In the standard way (\documentclass[<options>]) one can set global options and with \PassOptionsToClass we can set class options. In a standard document however, one does not distinguish between class and global options. – gerw Jan 16 '15 at 7:03

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.