9

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

7

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}
  • Martin, Thanks, that makes sense, but I doubt I could have figured it out without seeing it somewhere (which I haven't) or having someone tell me. I see that I was unclear about the relation between my options and those from a loaded class, and a few other things. It's interesting that I can have the same option name as a loaded class, but not conflict. – bev Mar 8 '11 at 13:04
  • BTW, I have the \ExecuteOptions statement in the correct place in my real code. I was just moving it around in my code to see whether, if I processed my options after I loaded memoir I could execute 'oneside' and, since memoir was loaded, it would get passed. I forgot to put it back when I pasted the code here. But thanks for your vigilence :-) . – bev Mar 8 '11 at 13:05
0

I realize this is an old question, but I just found something... I ran into an identical problem, just with font size. What I found out is that you can use the command \PassOptionsToClass{<options-list>}{<package-name>} to set your defaults. I'm a beginner, so I don't know if this is actually wrong or is doing something I wouldn't want it to, but so far so good. So I guess your class code would end up being like this (I added Martin Scharrer's corrections):

\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}}
%
\PassOptionsToClass{oneside}{memoir}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{memoir}}
\ExecuteOptions{myopti}
\ProcessOptions*
\LoadClass[12pt,final]{memoir}

 % <remainder of class code>

And then you can either use \documentclass{mythesis} or \documentclass[twoside]{mythesis}. Well, at least the MWE (with more options) I got here is the following:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{memtest}[2018/07/10 v1.0 Testing Memoir class]

% default options
\PassOptionsToClass{
    12pt,
    a4paper,
    openright, % openleft, openright, openany
    oneside, % oneside, twoside
}{memoir}

\DeclareOption*{
    \PassOptionsToClass{\CurrentOption}{memoir}
}

\ProcessOptions\relax

\LoadClass{memoir}

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.