3

I am exploring the use of class options, I was under the impression that optional arguments presented at the point of class declaration, were subsequently presented to all packages used thereafter.

Can someone explain to me why the following doesn't produce the output I would expect, which is to pass the geometry arguments (left, right, top, bottom) through to the geometry package.

\documentclass[left=0cm,right=0cm,top=0cm,bottom=0cm]{article}

\usepackage{geometry}
\usepackage{lipsum}

\begin{document}
    \lipsum[1-10]

\end{document} 
10
  • Why would it? \documentclass does not have parameters like that. Or does it? That would be a useful feature in some cases, but with multiple packages using intersecting parameter lists... – masu Oct 17 '13 at 1:12
  • 1
    This only seem to effect those options (and probably others, too), but, for example, using \documentclass[showframe]{article} \usepackage{geometry} works just fine. – Qrrbrbirlbel Oct 17 '13 at 1:30
  • 1
    @Qrrbrbirlbel Altough it works it still doesn't seem like a good thing to do for me because it can be really ambiguous. Is there a use-case when it should be considered to use or this is just a syntactic sweetener? – masu Oct 17 '13 at 1:47
  • I have a custom class, and I need to pass some options thought, it seems like this problem effects a number of packages, for instance, biblatex. This question here is a MWE, clearly it is a trivial case, but it demonstrates the issue that I am having. For the moment, I have been using \PassOptionsToPackage{...} prior to the class declaration, however, I would prefer to put the options in the class declaration itself. – Nicholas Hamilton Oct 17 '13 at 1:48
  • 1
    This may be specific to geometry since it sets package options using a different approach than using \ProcessOptions. – Werner Oct 17 '13 at 5:49
2

While geometry is meant to adjust paper and text block layouts, it also does us a favour and overwrites things that may be defined at the document class level. For example,

\documentclass[landscape]{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-10]
\end{lipsum}

works without error as the article class has a defined way of handling the landscape option:

\DeclareOption{landscape}
   {\setlength\@tempdima   {\paperheight}%
    \setlength\paperheight {\paperwidth}%
    \setlength\paperwidth  {\@tempdima}}

However, geometry's use of this is far superior, making

\documentclass[landscape]{article}
\usepackage{geometry,lipsum}
\begin{document}
\lipsum[1-10]
\end{lipsum}

work just as expected, where geometry actually re-applied its own document layouts based on the landscape document class option.

This is what makes geometry special: it re-checks all the document class-level options (not just unused ones) to see whether it should override them or not. However, it does so in a very crude way. In fact, key-only options are properly evaluated (like landscape, or showframe), while key-value options are not (like left=1cm or headheight=10pt).

The only way to get around this is to supply the options verbatim to geometry

\documentclass{article}
\usepackage[margin=0pt]{geometry}
%...

or

\documentclass{article}
\usepackage{geometry}
\geometry{margin=0pt}
%...

or pass options using the traditional way via \PassOptionsToPackage[<options>]{<package>}:

\documentclass{article}
\PassOptionsToPackage{margin=0pt}{geometry}
\usepackage{geometry}
%...
0

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.