10

I want to write several classes, most of them will use KOMA classes as base class.

However I stumbled upon the problem that some options (mainly concerned with layout) are not processed if given in the wrapper class:

  \begin{filecontents}{test.cls}
    \ProvidesClass{test}[2015/01/01]
    \DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}
    \ProcessOptions\relax
    \LoadClass[paper=a5]{scrartcl}
  \end{filecontents}

\documentclass{test}

\usepackage{blindtext}

\begin{document}
  \section{Test}
  \blindtext
\end{document}

This results in

LaTeX Warning: Unused global option(s): [paper=a5] If i give the option as \documentclass[paper=a5]{test} it is used correctly, because I pass the options to scrartcl. However I want to change the defaults for the layout.

How can I achieve this?

MaxNoe
  • 6,136
  • All this is passed down to package typearea. I think there was a similar question not long ago. EDIT: http://texwelt.de/wissen/fragen/12417/unerwunschte-ubergabe-von-optionen-an-die-basisdokumentenklasse – Johannes_B May 05 '15 at 11:22
  • Is the option actually not processed or is it just a warning? I have wrapper classes for the standard classes which produce these warnings but the options are, in fact, handled fine. – cfr May 05 '15 at 11:26
  • the resulting pdf document is a4, which is the default for scrartcl – MaxNoe May 05 '15 at 11:27

2 Answers2

10

Using \LoadClass with options is a tricky thing as none of the options are passed to packages, all are meant to be for the class. The paper option is unknown to a KOMA-sclass, as package typearea deals with the layout stuff, hence the warning.

Using documentclass option parsing down to packages is allowed, so this approach works perfectly fine. If you want to set a fixed pagesize, pass options to the package before loading the class, just as the class internally does. This queuing mechanism works well, loading the package with explicit options will fail though.

Of course there is always room for trickery. The KOMA classes know the option a5paper, a4paper and a few more, and will pass the right option to package typearea on their own.

\begin{filecontents}{\jobname.cls}
    \ProvidesClass{\jobname}[2015/01/01]
    \DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}
    \ProcessOptions\relax
    \PassOptionsToPackage{ paper=a5,pagesize }{typearea}
    \LoadClass{scrartcl}
\end{filecontents}

\documentclass{\jobname}

\usepackage{blindtext}

\begin{document}
\section{Test}
\blindtext
\end{document}

You can of course delay the layout stuff to a later point, and can even change it within the document. One thing to remember, tell typearea to do some recalculations. If you can change the paper size, the 8user* can do it too.

\begin{filecontents}{\jobname.cls}
    \ProvidesClass{\jobname}[2015/01/01]
    \DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}
    \ProcessOptions\relax
    \LoadClass{scrartcl}

    \KOMAoptions{paper=a3,pagesize,paper=landscape}
    \recalctypearea
\end{filecontents}

\documentclass[paper=a5]{\jobname}

\usepackage{blindtext}

\begin{document}
\section{Test}
\blindtext
\end{document}

With KOMA version 3.17, the typearea option pagesize became the default. All users still running an older version (TeX Live 2014 is frozen) need to explicitely give that option. I added it to option list passed to typearea to make their life easier. Thanks to @esdd for dropping me a note.

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • According to the KOMA manual all KOMA script classes load typearea, if one uses a KOMA class directly, the options are passed to typearea. Why are they not passed if used in a wrapper class? If I load typearea in the wrapper class I get an option clash for it. – MaxNoe May 06 '15 at 23:38
  • @MaxNoe I made some further explanations. – Johannes_B May 07 '15 at 13:07
0

This answer also solves the problem:

LaTeX warning: Unused global option(s): [DIV].

Which is caused when the option DIV=calc is loaded by LoadClass into a class defined from a class that uses some KOMA class, e.g. I defined a class Style.cls and inside it the code

\LoadClass[DIV=calc]{scrbook}

It causes the warning message displayed above.

Very good answer, after more than six years it is still helpful.

Thank you very much and congratulations to the one who answered and to the one who left the answer active for so long.