Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Until now, I have been collecting my "frequently used packages", custom macros, and configurations in a personal style file. However, some of those configurations depend on the use of one of the KOMA-Script classes, and therefore (according to my own answer to Classes and packages – what's the difference?) good practice stipulates that I rewrite my personal file into a wrapper class.

According to section A.4.8 of the LaTeX Companion, a wrapper class file myclass.cls that builds on article.cls and passes class options specified by the user to the base class would look like, e.g.,

\ProvidesClass{myclass}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass{article}
\RequirePackage{<package list>}

or, even easier,

\ProvidesClass{myclass}
\LoadClassWithOptions{article}
\RequirePackage{<package list>}

However, my base class may in fact be one of several document classes, namely scrartcl, scrreprt, orscrbook. I want to define some wrapper class options (named, say, article/report/book) that, by specifying one of them, load the corresponding KOMA-Script class. (If I don't specify any of them, scrbook shall be loaded by default.) How do I go on about this?

share|improve this question
add comment

2 Answers

up vote 15 down vote accepted

This scheme seems to work:

\ProvidesClass{lockstep}
\DeclareOption{scrartcl}{\def\lock@class{scrartcl}}
\DeclareOption{scrreprt}{\def\lock@class{scrreprt}}
\DeclareOption{scrbook}{\def\lock@class{scrbook}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\lock@class}}
\ExecuteOptions{scrbook}
\ProcessOptions\relax
\LoadClass{\lock@class}

The default class is scrbook, but the options scrartcl or scrreprt will change it.

In my test I tried with the abstract option:

\documentclass[abstract]{lockstep}

gives Unused global option(s): [abstract], while

\documentclass[scrartcl,abstract]{lockstep}

doesn't show the message.

share|improve this answer
add comment

The following works for me. I like the flexibility given by keys, but you have to \RequirePackage{kvoptions-patch} or to make your own format including it.

\begin{filecontents*}{myclass.cls}
  \ProvidesClass{myclass}
  \RequirePackage{pgfopts}
  \pgfkeys{%
    /MyClassKeys/class/.store in = \MyClass,
    /MyClassKeys/class = scrbook}%
  \ProcessPgfOptions{/MyClassKeys}
  \LoadClassWithOptions{\MyClass}
\end{filecontents*}

\RequirePackage{kvoptions-patch}
\documentclass[class = extarticle,14pt]{myclass}

\begin{document}

This is my class using the \MyClass{} class

\end{document}

Note that is not actually a wrapper but the class itself. If find it easier to maintain (but a .dtx can also be a good solution to maintain different files, including some wrappers).

share|improve this answer
    
I'd rather avoid the need for a \RequirePackage in actual documents, but +1 for a solution using pgfopts. –  lockstep Nov 26 '11 at 23:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.