[Tex/LaTex] New options and loaded class options bug

documentclass-writing

I found some odd behavior that I can't seem to get around. I'm writing a new version of a class file I did a while ago that is based on the memoir class. Now, the memoir class has two mutually exclusive options: oneside and twoside (twoside is the default). In my class, I want oneside to be the default. So the top of my class file is:

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesClass{mythesis}[01/01/2011, v1.0, my own thesis class]
\RequirePackage{ifthen}
\RequirePackage{calc}
\AtEndOfClass{\RequirePackage{microtype}}
%
\newboolean{@myopti}
\setboolean{@myopti}{false}
\newboolean{@myoptii}
\setboolean{@myoptii}{false}
%
\DeclareOption{myopti}{\setboolean{@myopti}{true}}
\DeclareOption{myoptii}{\setboolean{@myoptii}{true}}
%
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{memoir}}
\LoadClass[12pt,final]{memoir}
\ExecuteOptions{myopti,oneside}

 % <remainder of class code>

Which fails to make oneside the default. If, I change it to:

\LoadClass[12pt,final,oneside]{memoir}
\ExecuteOptions{myopti}

then if, in the main file I do:

\documentclass[twoside]{mythesis}

it remains in oneside mode. The only way I can get it to work is to put

\LoadClass[12pt,final]{memoir}
\ExecuteOptions{myopti}

in the class file and then specify oneside if I want that (twoside is the default, remember, since I'm loading memoir).

But I don't want to have the user need to specify oneside since I want:

\documentclass{mythesis}

to be oneside.

I don't think this is a memoir problem, it's either a LaTeX2e problem, or an I-just-don't-know-the-right-way-to-do-it problem.

Gracias

Best Answer

In order to do this correctly you should create an if-switch or boolean which is modified by the oneside and twoside options of your package, which then pass the final option to memoir. Note that you should process or execute your options before loading another class or package.

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesClass{mythesis}[01/01/2011, v1.0, my own thesis class]
\RequirePackage{ifthen}
\RequirePackage{calc}
\AtEndOfClass{\RequirePackage{microtype}}
%
\newboolean{@myopti}
\setboolean{@myopti}{false}
\newboolean{@myoptii}
\setboolean{@myoptii}{false}
\newboolean{@myopt@oneside}
\setboolean{@myopt@oneside}{true}
%
\DeclareOption{myopti}{\setboolean{@myopti}{true}}
\DeclareOption{myoptii}{\setboolean{@myoptii}{true}}

\DeclareOption{oneside}{\setboolean{@myopt@oneside}{true}}
\DeclareOption{twoside}{\setboolean{@myopt@oneside}{false}}
%
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{memoir}}
\ExecuteOptions{myopti}
\ProcessOptions*
\ifthenelse{\boolean{@myopt@oneside}}
    {\PassOptionsToClass{oneside}{memoir}}
    {\PassOptionsToClass{twoside}{memoir}}
\LoadClass[12pt,final]{memoir}