Discussion:
Adding an option to helvet.sty
(too old to reply)
Peter Flynn
2011-01-21 20:33:42 UTC
Permalink
I have a lot of Type 1 sans-serif fonts installed, and I have added a
[scaled] option to their .sty/.fd files following the pattern of
helvet.sty. This has been working fine.

But I often use several of these packages in sample documents, and I
don't want them all to reset \sfdefault because they would conflict.

So I tried to add an option [default], meaning if I write
\usepackage{helvet} it will load the settings but NOT make it the
\sfdefault unless I write \usepackage[default]{helvet}:

\DeclareOption{default}{\renewcommand{\sfdefault}{phv}}
\ProcessOptions

and commented out \renewcommand{\sfdefault}{phv} at the end of the file.
However, with this MWE

\documentclass{article}
\usepackage[scaled=0.8,default]{helvet}
\begin{document}
CMR and \sffamily Helvetica
\end{document}

I get
! Package keyval Error: default undefined.
See the keyval package documentation for explanation.
Type H <return> for immediate help.
...
l.53 \ProcessOptionsWithKV{Hel}
! LaTeX Error: Unknown option `scaled=0.8' for package `helvet'.
from which I deduce that you can't use both standard options handling
*and* KV in the same file.

OK, I thought, let's see if I can add the [default] option via KV, so I
commented out the \DeclareOptions and \ProcessOptions above, and wrote:

\***@key{Def}{default}[yes]{\renewcommand{\sfdefault}{phv}}

up with scaled, and

\ProcessOptionsWithKV{Def}
! Package keyval Error: default undefined.
See the keyval package documentation for explanation.
Type H <return> for immediate help.
...
l.53 \ProcessOptionsWithKV{Hel}
! Package keyval Error: scaled undefined.
I have clearly misunderstood KV here, but I can't see where.

///Peter
Marc van Dongen
2011-01-22 14:40:37 UTC
Permalink
KV woes
///Peter
Peter,

There's no need for option parsing. The following should do the trick:

\DeclareOption{default}{\renewcommand{\sfdefault}{phv}}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{helvet}}
\ProcessOptions\relax
\RequirePackage{helvet}

Regards,


Marc van Dongen
Peter Flynn
2011-01-22 21:49:23 UTC
Permalink
Post by Marc van Dongen
KV woes
///Peter
Peter,
\DeclareOption{default}{\renewcommand{\sfdefault}{phv}}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{helvet}}
\ProcessOptions\relax
\RequirePackage{helvet}
Thank you...that solves it for helvet, but I have ~20 other font
families installed, and I'd like both the scaled *and* the default
options in their .sty files as well.

///Peter
Will Robertson
2011-01-23 01:47:22 UTC
Permalink
Post by Peter Flynn
Post by Marc van Dongen
KV woes
///Peter
Peter,
\DeclareOption{default}{\renewcommand{\sfdefault}{phv}}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{helvet}}
\ProcessOptions\relax
\RequirePackage{helvet}
Thank you...that solves it for helvet, but I have ~20 other font
families installed, and I'd like both the scaled *and* the default
options in their .sty files as well.
If you're just talking about the method used in helvet.sty, it should
be sufficient to add in there somewhere

\***@key{Hel}{default}[]{%
\renewcommand{\sfdefault}{phv}}

but the code inside helvet.sty pre-dates the various keyval package
option-parsing code around. If you're writing the new packages from
scratch I recommend looking at kvoptions package to do the keyval
parsing for you. In this case you'd write something like (untested)

\RequirePackage{kvoptions}
\DeclareVoidOption{default}{\renewcommand{\sfdefault}{phv}}
\DeclareStringOption{scaled}[0.95]{\def\***@scale{#1}}
\ProcessKeyvalOptions

Hope this helps,
Will
Peter Flynn
2011-01-23 11:29:39 UTC
Permalink
Post by Will Robertson
Post by Peter Flynn
Post by Marc van Dongen
KV woes
///Peter
Peter,
\DeclareOption{default}{\renewcommand{\sfdefault}{phv}}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{helvet}}
\ProcessOptions\relax
\RequirePackage{helvet}
Thank you...that solves it for helvet, but I have ~20 other font
families installed, and I'd like both the scaled *and* the default
options in their .sty files as well.
If you're just talking about the method used in helvet.sty, it should
be sufficient to add in there somewhere
\renewcommand{\sfdefault}{phv}}
But there's already a key called Hel in helvet.sty. Can you have
multiple values for the same key?
Post by Will Robertson
but the code inside helvet.sty pre-dates the various keyval package
option-parsing code around.
I wondered why there was so much code there, but I assumed that it was
doing something special that the keyval package didn't provide. Are you
saying that all that ProcessOptionsWithKV is actually unnecessary now?
Post by Will Robertson
If you're writing the new packages from
scratch I recommend looking at kvoptions package to do the keyval
parsing for you. In this case you'd write something like (untested)
\RequirePackage{kvoptions}
\DeclareVoidOption{default}{\renewcommand{\sfdefault}{phv}}
\ProcessKeyvalOptions
That sounds much more sensible, thanks. Someone should update
helvet.sty...or better, make the scaled option standard on all font
packages...(I can hear the screams of outrage already :-)

///Peter
Will Robertson
2011-01-23 13:34:13 UTC
Permalink
Post by Peter Flynn
Post by Will Robertson
If you're just talking about the method used in helvet.sty, it should
be sufficient to add in there somewhere
       \renewcommand{\sfdefault}{phv}}
But there's already a key called Hel in helvet.sty. Can you have
multiple values for the same key?
The "Hel" is simply a prefix to make the "default" key unique among
different packages.
Post by Peter Flynn
Post by Will Robertson
but the code inside helvet.sty pre-dates the various keyval package
option-parsing code around.
I wondered why there was so much code there, but I assumed that it was
doing something special that the keyval package didn't provide. Are you
saying that all that ProcessOptionsWithKV is actually unnecessary now?
Only if you use kvoptions.sty.
Post by Peter Flynn
Post by Will Robertson
\RequirePackage{kvoptions}
\DeclareVoidOption{default}{\renewcommand{\sfdefault}{phv}}
\ProcessKeyvalOptions
That sounds much more sensible, thanks. Someone should update
helvet.sty...or better, make the scaled option standard on all font
packages...
I completely agree about the font scaling options, which is why all
fonts loaded through fontspec can be scaled arbitrarily when they're
defined. Making font scaling easier is perhaps the one thing I'd
change in the NFSS.

Cheers,
Will
Peter Flynn
2011-01-23 21:03:22 UTC
Permalink
Post by Will Robertson
Post by Peter Flynn
Post by Marc van Dongen
KV woes
///Peter
Peter,
\DeclareOption{default}{\renewcommand{\sfdefault}{phv}}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{helvet}}
\ProcessOptions\relax
\RequirePackage{helvet}
Thank you...that solves it for helvet, but I have ~20 other font
families installed, and I'd like both the scaled *and* the default
options in their .sty files as well.
If you're just talking about the method used in helvet.sty, it should
be sufficient to add in there somewhere
\renewcommand{\sfdefault}{phv}}
but the code inside helvet.sty pre-dates the various keyval package
option-parsing code around. If you're writing the new packages from
scratch I recommend looking at kvoptions package to do the keyval
parsing for you. In this case you'd write something like (untested)
\RequirePackage{kvoptions}
\DeclareVoidOption{default}{\renewcommand{\sfdefault}{phv}}
\ProcessKeyvalOptions
Hope this helps,
That doesn't seem to be the right syntax somewhere. I adapted this to my
otherwise unadorned olive.sty:

\ProvidesPackage{olive}[0.1 bitstrea olive PSNFSS2e package]
\RequirePackage[T1]{fontenc}
\RequirePackage{kvoptions}
\DeclareVoidOption{default}{\renewcommand{\sfdefault}{bao}}
\DeclareStringOption{scaled}[0.95]
\ProcessKeyvalOptions
\endinput

And t1bao.fd now uses \***@scaled and \olive@@scale, because the
kvoptions doc says that declarations create a macro
<packagename>@<optionname> by default (eg \***@scaled). I changed the
last Declare to match the spec in the docs,

\DeclareStringOption{scaled}

which is supposed to create \***@scaled equal to whataver value I supply.

But running this against the MWE

\documentclass{article}
\usepackage[default]{olive}
\begin{document}
Default Serif Face \sffamily Default Sans-Serif Face
\end{document}

just gives me the error message:

! Package keyval Error: default undefined.

The documentation for kvoptions is deeply confusing...are these
\Declare...Option commands supposed to be *in addition* to some
(unspecified) \***@key (keyval) or \DeclareOption (kernel) commands,
or are they supposed to function independently? It appears that
kvoptions calls keyval, but it clearly doesn't work as I have it, which
is according to the documentation. There is obviously some key piece of
information I am missing, but I can't see what it is? Has anyone ever
implemented kvoptions for something this simple?

///Peter

///Peter
Heiko Oberdiek
2011-01-23 21:56:57 UTC
Permalink
Post by Will Robertson
\RequirePackage{kvoptions}
\DeclareVoidOption{default}{\renewcommand{\sfdefault}{phv}}
\ProcessKeyvalOptions
The star is missing (see documentation):
\ProcessKeyvalOptions*
--
Heiko Oberdiek
Loading...