1

I'm trying to define a custom class rs-book.cls based on a standard class book.cls and would like to change some of the default options. For instance, by default (with no options given), the command \documentclass{book} produces a 10pt, twoside, onecolumn document. Let's say that in my case, with command \documentclass{rs-book}, I would like to produce a 12pt, oneside, twocolumn document by default, but with the ability overwrite these options (as in \documentclass[10pt]{rs-book} would produce a 10pt font document).

The problem is that I can't recreate this behavior as it gets pretty confusing: in the example below the command \documentclass[10pt,twoside,onecolumn]{rs-book} keeps the default 12pt and twocolumn values, but successfully applies the twoside option.

MWE:

rs-book.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{rs-book}

% Read all options to rs-book class and pass them to book class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
% Execute the code for each option
\ProcessOptions\relax
% Load book class with fixed options
\LoadClass[12pt,oneside,twocolumn]{book}

main.tex

\documentclass[10pt,twoside,onecolumn]{rs-book}

\usepackage{lipsum}

\title{A modification of book.cls}
\author{author}
\date{\today}

\begin{document}
\maketitle

\lipsum
\end{document}

1 Answer 1

2
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{rs-book}

\def\rs@ptsize{12pt} % default value
\DeclareOption{10pt}{\def\rs@ptsize{10pt}}
\DeclareOption{11pt}{\def\rs@ptsize{11pt}}
\DeclareOption{12pt}{\def\rs@ptsize{12pt}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions
\LoadClass[\rs@ptsize,oneside,twocolumn]{book}

\endinput
1
  • 1
    Thanks for the answer. One remark though: your solution manually hardcodes fontsizes (not just the default one) in the custom class. Is there any possibility of some sort of 'option inheritance'? For instance, maybe a 13pt option becomes available in the future for the book class. This means that I would have to edit my custom class and add an additional entry for 13pt option.
    – user244630
    Commented Feb 17, 2022 at 8:03

You must log in to answer this question.