Document ClassesPackage Options

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
Anymouse
Posts: 20
Joined: Mon May 10, 2021 2:50 am

Package Options

Post by Anymouse »

I *think* this is the right forum.

Not a document class per se, but I'm creating a style file with options that defines which fonts to use and also defines some macros I frequently use.

Right now the class has one option and I code it like this:

Code: Select all

% default options
\newcommand{\ampfontcollection}{base35}
\DeclareOption{texgyre}{\renewcommand{\ampfontcollection}{texgyre}}
\DeclareOption*{\PackageWarning{anymouse}{Unknown ‘\CurrentOption’}}
\ProcessOptions\relax
\ifthenelse{\equal{\ampfontcollection}{base35}}{
\IfFileExists{mtpro2.sty}{}{% else
\renewcommand{\ampfontcollection}{texgyre}
}
}{}
Basically I default to using the Adobe Base35 fonts as my primary fonts but if MathTimePro 2 is not available, it switches the option automatically to using the TeX Gyre fonts. However TeX Gyre can be selected even if MathTime Pro 2 is available.

I'd like to add two other package options though, and I'm not sure how to go about doing that, what is the best way.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Anymouse
Posts: 20
Joined: Mon May 10, 2021 2:50 am

Package Options

Post by Anymouse »

Figured it out, LaTeX is smart, comma separated with

Code: Select all

\usepackage[something,else]{whatever}
works just fine when key=value isn't needed - processing is same way.
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Package Options

Post by Ijon Tichy »

You should not use

Code: Select all

\DeclareOption*{\PackageWarning{anymouse}{Unknown ‘\CurrentOption’}}
LaTeX already shows an error message, if you explicitly load a package with an unknown option. Your code reduces the mechanism to only warn. So your package behaves different than all other packages, which is not a good idea.

BTW: There are several packages, that provide key-value options, e.g., kvoptions, scrbase etc. But key-value-options are somehow tricky in case of setting them as global options.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Anymouse
Posts: 20
Joined: Mon May 10, 2021 2:50 am

Package Options

Post by Anymouse »

I understand that perspective but I only want it to warn.

If I publish a second package that takes similar options, some users may want to load them both on same line so that the options they pass to both are always identical, but if one has additional options then the other should only log a warning if they are specified.

And yes, I may publish a second that takes similar or identical options. For example,

Code: Select all

ean13isbn.sty
hard-codes Helvetica from Base35 but if using the Gyre fonts, the Gyre equivalent works just fine reducing the number of fonts that need to be embedded, so passing the font option to both my package and a modified version of that ISBN package would be beneficial, but some of the options for my package make no sense with an ISBN package.

As far as my package behaving differently than all the other packages, well, maybe if I was submitting it to CTAN there would be an argument for conformity but I'm not.
Post Reply