2

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?

  • welcome to the forum. although perhaps it's not imperative, or not always done that way, i think it's good to have the possible size options fully defined in the base class; they can always be disabled in a derived class. take a look at how font sizes are defined in amsart.cls to see what i mean. – barbara beeton Sep 11 '15 at 17:30
1

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}
  • That'd work, but I'd prefer derived.cls not to make any assumptions about the internals of base.cls. I've therefore decided to leave the font size unspecified in base.cls, and let each derived class set its desired size manually. – tloeffler Sep 12 '15 at 13:20

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.