8

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?

5
  • 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. Commented Apr 27, 2014 at 1:12
  • How about \DeclareOption{option1}{\LoadClass{class1}} instead? Commented Apr 27, 2014 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. Commented Apr 27, 2014 at 11:23
  • @cfr Maybe you could write an answer? :) Commented Jun 23, 2014 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... Commented Jun 23, 2014 at 21:32

1 Answer 1

8

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
%:load \myclasstype
\LoadClass{\myclasstype}% add options if desired

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.

1
  • this is so good that I would like to upvote twice! Commented Apr 3, 2020 at 9:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.