0

I want to process options passed to the base class in my derived class. Specifically, I'd like to enforce margin sizes for the article class with geometry package.

Moreover, I would like to forbid certain layout options e.g. twosided, limit paper sizes and specify defaults. The latter I was able to find here, but I was missing information about how to process the options in the derived class.

This is my MWE:

\begin{filecontents}{myarticle.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mymarticle}[2022/12/10 My white paper class]

\DeclareOption{a5paper}{\OptionNotUsed} \DeclareOption{b5paper}{\OptionNotUsed} \DeclareOption{legalpaper}{\OptionNotUsed} \DeclareOption{landscape}{\OptionNotUsed} \DeclareOption{twosided}{\OptionNotUsed}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} \ProcessOptions\relax \LoadClass[oneside]{article}

\PassOptionsToPackage{left=10bp, right=10bp, top=10bp}{geometry} @ifclasswith{article}{a4paper}{ \PassOptionsToPackage{bottom=20bp}{geometry} } { \PassOptionsToPackage{bottom=40bp}{geometry} } \RequirePackage{geometry}

\end{filecontents} \documentclass{myarticle}

\usepackage{lipsum}

\begin{document}

\lipsum[1-20]

\end{document}

This does what I want, but I don't think is the best way of achieving what I want. In particular, ifclasswith would require substantial nesting if I wanted to support 3 options or combining with twocolumns.

  • You could just \DeclareOption{a4paper}{<your code>\PassOptionsToClass{a4paper}{article}}. For instance you could add your own conditional this way. \newif\ifmyarticle@aIVpaper\DeclareOption{a4paper}{\myarticle@aIVpapertrue\PassOptionsToClass{a4paper}{article}} and then instead of \@ifclasswith you could use \ifmyarticle@aIVpaper. But I guess avoiding some nesting of conditionals is impossible (slightly depends on how the rest of your behaviour should be defined). – Skillmon Dec 14 '22 at 05:46
  • Of course you could also just pass your options to geometry with something like \DeclareOption{a4paper}{\PassOptionsToPackage{bottom=10bp,a4paper}{geometry}\PassOptionsToClass{a4paper}{article}}. Also, if your class got the option a4paper that'll be in the global options list that geometry will pick up, you don't need to explicitly forward that to geometry. – Skillmon Dec 14 '22 at 05:48
  • Thanks @Skillmon. That helps. I like the idea of using PassOptionsToPackage, as I can avoid code duplication. I am going to change the MWE slightly and refine my question. What I am still worried about is that there is no explicitly defined defaults just the if/else alternative. I am not expressing myself very well, sorry. – Robert Manson-Sawko Dec 14 '22 at 10:22

0 Answers0