2

I would like to pass option conditionally to memoir from my custom class for this I try to do a MWE

myClass.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myClass}

\newif\ifthesis@foo

\DeclareOption{foo}{\thesis@footrue}
\DeclareOption{nofoo}{\thesis@foofalse}

\ExecuteOptions{foo} %default is foo

% Based on the memoir class
\ifthesis@foo
    \DeclareOption*{\PassOptionsToClass{a4paper,12pt,french,twoside,openright,openbib, final}{memoir}}
\else
    \DeclareOption*{\PassOptionsToClass{a5paper,10pt,french,twoside,openright,openbib, final}{memoir}}
\fi

\ProcessOptions\relax
\LoadClass{memoir}

main.tex

\documentclass[foo]{myClass}
\title{MWE}

\begin{document}
    \maketitle
    \frontmatter
    \mainmatter
\end{document}

I would like keep thesis@foo flag to make later conditionally title page.

This MWE produce always a pdf with US Letter as page size (I think it is the default)

Thanks for your help

  • 2
    DeclareOption* is what to do with an unknown option, and your example has no such option, I think you just want \PassOptionsToClass, not \DeclareOption*{\PassOptionsToClass – David Carlisle Jan 13 '17 at 18:48
4

I think, you mixed up your new class. (BTW: you should give it a more descriptive name!)

As David pointed out, you should always define the \DeclareOption* to define, what to do with undeclared options. In your case, it would make sense, to hand the unknown option to class memoir, as it might know, what to do with it.

Next, bear in mind, you really have to declare, what should happen, when you use the option in your class. Your declaration only set the boolean value, but nothing else is happening. By \ExecuteOption you don't get a reasonable result, whatsoever.

Instead, you have to put the \PassOptionsToClass-commands inside the \DeclareOption, to have it executed, when you are actually using that options.

So your class should look like this:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myClass}

%% Actually, you declare this boolean, but you never use it!
\newif\ifthesis@foo

\DeclareOption{foo}{%
  \thesis@footrue
  \typeout{Declare Option Foo!}
  \PassOptionsToClass{a4paper,12pt,french,twoside,openright,openbib,
  final}{memoir}
}

\DeclareOption{nofoo}{%
  \thesis@foofalse
  \typeout{Declare Option NoFoo!}
  \PassOptionsToClass{a5paper,10pt,twoside,openright,openbib,
    final}{memoir}
}

%% What to do, if an unknown option is entered?
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{memoir}}


\ExecuteOptions{foo} %default is foo
\ProcessOptions\relax

% Based on the memoir class
\LoadClass{memoir}
\endinput
|improve this answer|||||
  • 1
    My pleasure, if it helped you. – Jan Jan 13 '17 at 20:48

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.