[Tex/LaTex] Overriding the default font size for custom classes

class-optionsdocument-classesfontsize

I'm in the middle of writing a document class (let's call it base.cls) which serves as base class for several other classes I'm writing. The base class itself is based on the article class. By default, the font size is set to 12pt, i.e. I'm calling \LoadClass[12pt]{article} in base.cls. Now, one of the classes derived from base.cls (let's call it derived.cls) should use 11pt rather than 12pt. I therefore added a default option handler to base.cls to pass all options on to article when \LoadClass[11pt]{base} is called in derived.cls.

This is where things break down. It seems that once the 12pt option gets processed, 11pt is ignored and the font size remains 12pt. I tried swapping the font sizes, i.e. set 11pt as default in base.cls, and specify 12pt when loading base.cls in derived.cls. In this case, the result is as expected: the font size is 12pt; if I don't specify 12pt when loading base.cls, the font size is 11pt. Here's a minimal working example.

base.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{base}[2015/09/11 v0.1]

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

\ProcessOptions\relax

\LoadClass[a4paper,12pt]{article}

\endinput

derived.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{derived}[2015/09/11 v0.1]

\LoadClass[11pt]{base}

\endinput

example.tex:

\documentclass{derived}

\usepackage{lipsum}

\begin{document}
\lipsum
\end{document}

Any ideas?

Best Answer

Here is a solution base.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{base}[2015/09/11 v0.1]

\providecommand\mtfntsize{12pt}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

\ProcessOptions\relax

\LoadClass[a4paper,\mtfntsize]{article}

\endinput

derived.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{derived}[2015/09/11 v0.1]

\def\mtfntsize{11pt}

\LoadClass[\mtfntsize]{base}

\endinput

example.tex:

\documentclass{derived}

\usepackage{lipsum}

\begin{document}
\lipsum
\end{document}