LaTeX forum ⇒ Document ClassesPackage Options Topic is solved

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

Package Options

Postby Anymouse » Sat May 29, 2021 8:07 am

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:
% 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.

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

Postby Anymouse » Sat May 29, 2021 9:10 am

Figured it out, LaTeX is smart, comma separated with
\usepackage[something,else]{whatever}
works just fine when key=value isn't needed - processing is same way.

User avatar
Ijon Tichy
Posts: 526
Joined: Mon Dec 24, 2018 10:12 am

Postby Ijon Tichy » Sun May 30, 2021 8:51 am

You should not use
\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.

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

Postby Anymouse » Sun May 30, 2021 11:03 am

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,
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.


Return to “Document Classes”

Who is online

Users browsing this forum: No registered users and 6 guests