Discussion:
Moving to key=value options
Add Reply
Peter Flynn
2018-11-01 20:35:54 UTC
Reply
Permalink
I have an old thesis package which uses lots of \DeclareOption commands
to preset the names and bibliographic style parameters for each of
several dozen departments/disciplines and names of degrees. This allows (eg)

\documentclass[stats,phd]{thesis}

I am looking into changing this to something like

\documentclass[dept=stats,degree=phd]{thesis}

but I am unclear amid the complexity of the keyval, xkeyval, clefval,
simplekv, conv-xkv, keycommand, and keyval2e packages which one is most
suited to the task.

Or should I just leave it as it is?

///Peter
Ulrike Fischer
2018-11-02 10:09:17 UTC
Reply
Permalink
Post by Peter Flynn
I have an old thesis package which uses lots of \DeclareOption commands
to preset the names and bibliographic style parameters for each of
several dozen departments/disciplines and names of degrees. This allows (eg)
\documentclass[stats,phd]{thesis}
I am looking into changing this to something like
\documentclass[dept=stats,degree=phd]{thesis}
but I am unclear amid the complexity of the keyval, xkeyval, clefval,
simplekv, conv-xkv, keycommand, and keyval2e packages which one is most
suited to the task.
Or should I just leave it as it is?
I personally don't like it to overload the optional argument both of
\documentclass and \usepackage with to many options.

I would always try to setup the class/package so that most settings
can be done after the loading with e.g.

\documentclass{thesis}
\thesissetup{dept=stats}

This gives imho more flexibility to set options in meaningful
blocks.

Beside this:
keyval settings in the class options are bit picky regarding spaces
and braces due to the internal code processing the options so don't
do to complicated stuff. (With the next latex release the situation
for packages will hopefully improve (see
https://github.com/latex3/latex2e/issues/85)).

And I would use expl3/l3keys, but this is a personal preference.
--
Ulrike Fischer
http://www.troubleshooting-tex.de/
Peter Flynn
2018-11-02 21:42:25 UTC
Reply
Permalink
Post by Ulrike Fischer
Post by Peter Flynn
I have an old thesis package which uses lots of \DeclareOption commands
to preset the names and bibliographic style parameters for each of
several dozen departments/disciplines and names of degrees. This allows (eg)
\documentclass[stats,phd]{thesis}
I am looking into changing this to something like
\documentclass[dept=stats,degree=phd]{thesis}
but I am unclear amid the complexity of the keyval, xkeyval, clefval,
simplekv, conv-xkv, keycommand, and keyval2e packages which one is most
suited to the task.
Or should I just leave it as it is?
I personally don't like it to overload the optional argument both of
\documentclass and \usepackage with too many options.
Good point. In the current class, only two options are needed (as top
example above) but the list to choose from is very long.
Post by Ulrike Fischer
I would always try to setup the class/package so that most settings
can be done after the loading with e.g.
\documentclass{thesis}
\thesissetup{dept=stats}
This gives imho more flexibility to set options in meaningful
blocks.
In the case of only two parameters needed, it would be even easier to say

\department{stats}
\degree{phd}

The more I look at this, the less convinced I am that it needs any kind
of keyval.
Post by Ulrike Fischer
keyval settings in the class options are bit picky regarding spaces
and braces due to the internal code processing the options so don't
do to complicated stuff.
I am more inclined now to go for plain 1-argument setup commands and put
all the settings in separate .clo files which can then be \input. This
has the advantage that the settings for each dept can be updated
independently of the whole package, and a user could even just delete
all the .clo files except the two needed.

///Peter
GL
2018-11-05 12:03:32 UTC
Reply
Permalink
Post by Peter Flynn
I have an old thesis package which uses lots of \DeclareOption commands
to preset the names and bibliographic style parameters for each of
several dozen departments/disciplines and names of degrees. This allows (eg)
\documentclass[stats,phd]{thesis}
I am looking into changing this to something like
\documentclass[dept=stats,degree=phd]{thesis}
but I am unclear amid the complexity of the keyval, xkeyval, clefval,
simplekv, conv-xkv, keycommand, and keyval2e packages which one is most
suited to the task.
Or should I just leave it as it is?
///Peter
You can look to Oberdiek's 'kvoptions' package, whose documentation
explains how to use key=value syntax in package/class options.

Regards.
jfbu
2018-11-05 12:51:24 UTC
Reply
Permalink
Post by GL
Post by Peter Flynn
I have an old thesis package which uses lots of \DeclareOption commands
to preset the names and bibliographic style parameters for each of
several dozen departments/disciplines and names of degrees. This allows (eg)
    \documentclass[stats,phd]{thesis}
I am looking into changing this to something like
    \documentclass[dept=stats,degree=phd]{thesis}
but I am unclear amid the complexity of the keyval, xkeyval, clefval,
simplekv, conv-xkv, keycommand, and keyval2e packages which one is most
suited to the task.
Or should I just leave it as it is?
///Peter
You can look to Oberdiek's 'kvoptions' package, whose documentation
explains how to use key=value syntax in package/class options.
Regards.
+1 for kvoptions.

I once looked at a trace and saw therein thousands of lines, in relation to xkeyval package, for some (a priori) very simple option parsing. And what's worse, these thousands of lines were from option processing for some package which never had loaded xkeyval in the first place.

J.-F.

Loading...