Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a custom document class. It's kinda simple, but it will use the geometry package to set page size, orientation and margins. However... Whenever I use that package, the \ExecuteOptions command stops working. Look at this minimalist testcase:

File: myclass.cls

\ProvidesClass{myclass}
\LoadClass{article}

\usepackage[brazilian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[a4paper,
    includehead, includefoot,
    headheight=23mm, headsep=5mm, footskip=1.5em]{geometry}

\DeclareOption{landscape}{\geometry{landscape, top=12mm, bottom=12mm, left=15mm, right=15mm}}
\DeclareOption{portrait}{\geometry{portrait, top=15mm, bottom=15mm, left=12mm, right=12mm}}
\ExecuteOptions{portrait}
\ProcessOptions

File: doc.tex

% This works: \documentclass{myclass}
% This does not work: \documentclass[foobar]{myclass}
% This does not work: \documentclass[landscape]{myclass}
% This does not work: \documentclass[anythingITypeHere]{myclass}
\documentclass[landscape]{myclass}

\title{Simple testcase}

\begin{document}

Simple experiment... I think it should have worked.

\end{document}

Error message:

! Undefined control sequence.
\ExecuteOptions ...eserved@a \CurrentOption \@nil 

l.19 \ExecuteOptions{portrait}

If I don't pass any option to the \documentclass command, then it compiles. However, if I try to pass anything (like in the example above), it fails with that weird message.

If I comment out \usepackage[...]{geometry}, and replace \geometry with something else, then it compiles. So, I'm quite sure this package is messing with \ExecuteOptions command.

If I put both \DeclareOption and \ExecuteOptions before importing the package, I get an error about undefined \geometry (as expected).

If I put \DeclareOption before the \usepackage, and leave \ExecuteOptions after it, then I get an error about importing a package inside the Options section.

So... the question is how to implement document class options while still using geometry package? In other words, how to make the above code work?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
\DeclareOption{landscape}{\PassOptionsToPackage{landscape,top=12mm,bottom=12mm,left=15mm,right=15mm}{geometry}}
\DeclareOption{portrait}{\PassOptionsToPackage{portrait,top=15mm,bottom=15mm,left=12mm,right=12mm}{geometry}}
\ExecuteOptions{portrait}
\ProcessOptions

\RequirePackage{geometry}
\geometry{%
  a4paper,
  includehead, 
  includefoot,
  headheight=23mm,
  headsep=5mm,
  footskip=1.5em
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.