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:


\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


%:pass unrecognised options off to \myclasstype
%:process options
%: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.

  • this is so good that I would like to upvote twice! – Alessandro Cuttin Apr 3 '20 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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