# How can I stop the “setspace” package from processing a “doublespacing” documentclass option?

LaTeX does not behave as I expected with the following files.

First file:

\documentclass[doublespacing]{article}
\usepackage{lipsum} % for dummy text only
\begin{document}
\lipsum
\end{document}


Second file:

\documentclass[doublespacing]{article}
\usepackage{setspace}
\usepackage{lipsum} % for dummy text only
\begin{document}
\lipsum
\end{document}


For the first file, LaTeX gives this warning as expected:

LaTeX Warning: Unused global option(s):
[doublespacing].


However, the second file compiles without any warnings and uses double-spacing to typeset the text.

Why does the second file work? It seems like the option given to the article documentclass should be parsed and give a warning before the \usepackage{setspace} is encountered.

And a little bit of context: I'm trying to extend a document class to include a doublespacing (by using \DeclareOption{doublespacing}, etc.), but I can't configure the behavior properly because the setspace package picks it up as if I had done \usepackage{doublespacing}. Is there a way to keep setspace from seeing the doublespacing documentclass option?

-
As a follow-on: why doesn't \RequirePackage[singlespacing]{setspace} override the value given in the documentclass option? –  amcnabb Jan 29 '13 at 22:28

Every option given in the \documentclass line is called global and is passed to all packages subsequently loaded. If the package doesn't know the option, it does nothing, otherwise it applies the option. (See clsguide.pdf on your TeX system or here for details.)

Thus it's expected behavior: saying

\documentclass[doublespacing]{article}
\usepackage{setspace}


is equivalent to saying

\documentclass{article}
\usepackage[doublespacing]{setspace}


(as the article class doesn't know the option).

If you write a class that has a doublespacing option, the result is that this option, when specified, is passed to all packages loaded afterwards.

However, in this particular case, you can revert the setting by setspace by issuing an instruction

\AtBeginDocument{\setstretch{<factor>}}


where <factor> is how much you like.

-
Unfortunately, the \AtBeginDocument trick didn't work because the class creates some new lengths that were based on parameters that the setspace package sets at load time. However, I was able to add \singlespacing immediately after the \RequirePackage{setspace} line. –  amcnabb Jan 29 '13 at 22:32
@amcnabb Please, don't use doublespacing in your class. ;-) –  egreg Jan 29 '13 at 22:50
egreg, I would hope it's clear from the fact that I'm writing/editing a document class that I'm not a fan of double-spacing. But I'm not a university bureaucrat, so what do I know about typesetting? :) –  amcnabb Jan 29 '13 at 22:59
@amcnabb So true. :( –  egreg Jan 29 '13 at 23:06

Document options (by package or by document class) are assembled and processed as needed (if one is using the \DeclareOption method). Only at the start of the document - at \begin{document}, there is a check to see whether all options have been processed or not. From latex.ltx, the following is processed at \begin{document}:

\def\document{\endgroup
\ifx\@unusedoptionlist\@empty\else
\@latex@warning@no@line{Unused global option(s):^^J%
\@spaces[\@unusedoptionlist]}%
%...


Unknown options are kept in \@unusedoptionlist. So, even though doublespacing is passed to the document class, it is processed when setspace is loaded. From setspace.sty:

\DeclareOption{singlespacing}{\AtEndOfPackage{\singlespacing}}
\DeclareOption{onehalfspacing}{\AtEndOfPackage{\onehalfspacing}}
\DeclareOption{doublespacing}{\AtEndOfPackage{\doublespacing}}

\ProcessOptions

-