# How can I set up my custom class to load a different class depending on the class option(s) passed?

I have written class files in the past. One of them is even up on CTAN. But that was ages ago, and I am rusty today.

I am trying to roll a new class file for my University. I am being a little ambitious, and want to use the same class file for University letters, forms, reports, etc (and use class options to select each type). The reason is that this is a LaTeX-resistant place and being able to provide just one file would help in selling the power of LaTeX to them. Plus, there is a coolness factor involved which I wish to explore.

Logically, each of those documents would correspond to inheriting from standard LaTeX classes and then adding local customizations.

Is it possible to have an option-dependent inheritance (\LoadClass) for a new class file? Or is that a fundamental impossibility?

• Sure. Just define a macro to hold the selection and then pass the macro to LoadClass. e.g. \PassOptionsToClass{\CurrentOption}{\myclasstype}}\LoadClass{\myclasstype} where you have defined \myclasstype to hold the selection. – cfr Apr 27 '14 at 1:12
• How about \DeclareOption{option1}{\LoadClass{class1}} instead? – user2751530 Apr 27 '14 at 5:46
• That will work provided you don't want to pass any other options to the class. When I do this, I have a whole bunch of options and the class is only one of them. If your situation is simpler, you can do it more straightforwardly. – cfr Apr 27 '14 at 11:23
• @cfr Maybe you could write an answer? :) – Mario S. E. Jun 23 '14 at 9:28
• @MarioS.E. Sure. For what it is worth. It really depends on how the OP is handling options. But my answer should give the basic idea... – cfr Jun 23 '14 at 21:32

I use something like this:

\ProvidesClass{superclass}

\RequirePackage{xkeyval}% better option processing - there are many other possibilities as you probably know so just adapt as needed

\def\myclasstype{article}% make sure a default is defined

\DeclareOptionX{article}{%
\gdef\myclasstype{article}}
\DeclareOptionX{report}{%
\gdef\myclasstype{report}}
\DeclareOptionX{book}{%
\gdef\myclasstype{book}}

%:pass unrecognised options off to \myclasstype
\DeclareOptionX*{%
\PassOptionsToClass{\CurrentOption}{\myclasstype}}
%:process options
\ProcessOptionsX

There are other ways to do this and I would not necessarily do it this way if starting from scratch as I think I could neaten things up using the facilities of xkeyval. However, it should be enough to give you the basic idea which you can adapt and streamline for whichever method of option handling you decide to use.