# PassOptionsToClass vs global options

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. Jan 15, 2015 at 13:06
• @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. Jan 15, 2015 at 13:18
• I think i get it, reminds me of A class with default language settings Jan 15, 2015 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. Jan 15, 2015 at 13:39

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, 2015 at 7:03