4
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{funny-class}

%%

% Pass any options to the underlying class.
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article} % (could be another class)
}

% Options for this class.
\DeclareOption{fun}{%
  \def\contentsname{Blarg, blarg, blarg}%
}


% Defaults.
\ExecuteOptions{fun}

% Now execute any options passed in
\ProcessOptions\relax

% Load underlying class.
\LoadClass{article}

LaTeX complains when the article class tries to define \contentsname:

\newcommand\contentsname{Contents}

When I try to load the class before doing my options-processing, LaTeX of course complains.

What's my best way around this? Ideally, I'd like to stick as much to my original idea as possible, because I'm sure there's a much better way to do what I'm trying to do (like figuring out how to harnest Babel, etc.).

Martin Scharrer
  • 262,582
Jérémie
  • 2,991

1 Answers1

7

You shouldn't define macros which the article class later also defines. Either these are overwritten again anyway or an "macro already defined" error is thrown. You need to delay these modifications to after the base class is loaded. In general this is done by only modifying an if-switch in the option code and later execute some code only if this switch is true:

\newif\ifmyclass@myoption% false at first
\DeclareOption{someoption}{\myclass@myoptiontrue}
..
\ProcessOptions\relax

\LoadClass{article}
..
\ifmyclass@myoption
   code active only for this option
\fi

In your specific case I would simply use \AtEndOfClass:

\DeclareOption{fun}{%
  \AtEndOfClass{\def\contentsname{Blarg, blarg, blarg}}%
}
Martin Scharrer
  • 262,582