I lose track of all the different keyval packages. Can we maintain a list here? (Community wiki, one package per answer with a brief description of scope. I've started things off but need help completing it.)
-
1This should be converted to a TUGboat article.– Martin SchröderCommented Aug 28, 2011 at 20:24
-
6@Martin — as soon as we'd do that someone would write another one! :)– Will RobertsonCommented Aug 29, 2011 at 0:26
-
1Why are there (more than) 13 keyval packages anyway?– YouCommented Dec 30, 2011 at 8:43
-
3See also the survey article tug.org/TUGboat/tb30-1/tb94wright-keyval.pdf– Christian FeuersängerCommented Dec 30, 2011 at 11:04
-
1@JairoADelRio Not much point IMO. FWIW you could say this about any active area of LaTeX development. Because LaTeX has a smaller core and a much larger ecosystem, of course there are going to be more solutions to common problems. Also notable that of the 18 packages listed below, 6 are by one author and not much used, and others are more about interfacing keyval into class/package options rather than new keyval approaches per se.– Will RobertsonCommented Jun 25, 2020 at 1:30
23 Answers
pgfkeys.sty, part of PGF/TikZ
Author: Till Tantau
-
I marked this entry up---it also counts for adding the other entries:-)– user10274Commented Dec 30, 2011 at 9:23
l3keys.sty, part of expl3
Author: Joseph Wright (through the LaTeX3 Project)
Inspired by pgfkeys
.
Use l3keys2e
to use it in options of LaTeX2e packages and classes.
keyval.sty
Author: David Carlisle
The original and (probably) most widely used keyval package. Provides \define@key
and \setkeys
but all processing for special key-types must be done manually.
Removes one or two layers of braces around each "val".
Note: this package can have scope problems with nesting \setkeys
. Nowadays I'd recommend a more modern alternative.
-
The keyval package strips off 2 levels of outer brace: one by using the space trimmer \KV@@sp@def and one in internal parsing. Commented Dec 31, 2011 at 1:54
LaTeX kernel
The LaTeX kernel's June 2022 update added key=val functionality (outside of expl3
's l3keys
), that is functionally equivalent to l3keys
.
Defining keys is possible via \DeclareKeys[<module>]{<key-definitions>}
, setting via \SetKeys[<module>]{<key=val-list>}
.
Package and class options are supported via \ProcessKeyOptions[<module>]
.
-
1
-
1@projetmbc documentation is in the making, should be added to
usrguide3
/usrguide
. Currently you can fancy a peek insource2e
in theltkeys
-section. There is also an intention to add documentation toclsguide
.– SkillmonCommented Jun 24, 2022 at 6:52 -
1
-
-
It would be great to have the minimum LaTeX version where this is available. Commented Jan 6, 2023 at 9:54
xkeyval.sty
Author: Hendri Adriaens
Cannot be loaded before \documentclass
.
Note: in the past controversial because it overwrites keyval
's \setkeys
macro and in some cases caused (long-standing) incompatibilities. But I believe any problems resulting from this are now fixed.
-
The xkeyval package strips off precisely 3 levels of outer braces in key values: one by using keyval’s space trimmer \KV@@sp@def and two in internal parsing. The keyreader package addresses this problem. Another problem with the xkeyval package is that its
\setkeys
command doesn't accept unbalanced conditionals. For example,\setkeys[KV]{fam}{key=\iffalse}
fails. The next release of keyreader addresses this problem in its\krdsetkeys
command. The selective sanitization scheme of xkeyval also appears unduly expensive when there are active commas and equals sign in key-vals. Commented Dec 31, 2011 at 2:05 -
Much of the reported incompatibility issue with xkeyval's
\setkeys
seems to have disappeared, even for keys defined by David Carlisle's original\define@key
. kvsetkeys package later replaced its\setkeys
with\kvsetkeys
. Commented Dec 31, 2011 at 2:14 -
Is there any particular reason why it can't be loaded before \documentclass?– kahenCommented Mar 5, 2012 at 17:48
-
Yes, by design. xkeyval needs to know the documentclass options for inheritance purposes. Not sure from a technical standpoint, though, why it can't pick them up along the way; haven't looked into the details recently. Commented Apr 8, 2012 at 2:05
-
xkeyval.sty (not xkeyval.tex) needs the
\@classoptionslist
macro for (1) filtering=<value>
from the class options list and (2) for class and package options processing with\ProcessOptionsX*
. The keyreader packages delays the search for\@classoptionslist
and the actions mentioned at (1) and (2) above until\documentclass
was instantiated later by the document. Commented Nov 8, 2012 at 15:06
scrbase.sty
Author: Markus Kohm
It's part of KOMA-Script and documented in scrguide-en.pdf (English) and scrguide-de.pdf (German). It provides a family hierarchy for key-values and a processing of class and package options. With newer LaTeX kernels it uses the new raw option feature for key-value-options, but still provides a complex (but not easy to understand) feature to report unprocessed values. It also provides several types of values, like integers, length, strings, switches and a mapping from symbolic to numeric values.
I never used it my self so I can’t say more about it …
kvsetkeys.sty
Author: Heiko Oberdiek
-
2kvsetkeys only sets keys; it doesn't define them. It strips one level of outer curly braces in key values. Commented Dec 31, 2011 at 2:20
pgfopts.sty
Author: Joseph Wright
Allows pgfkeys
processing to be performed on class or package options.
-
-
3
keyreader.sty
Author: Ahmed Musa
The package provides a robust interface to controlling keys in xkeyval
, removing some of that package’s restrictions.
-
-
@Ahmed — your comments should be additional answers on this page! Commented Jan 29, 2012 at 21:04
-
Also, this page is supposed to be comprehensive. It makes no sense to remove an entry! I've added
skeyval
below. Commented Jan 29, 2012 at 21:09
yax.tex
Author: Paul Isambert
Part of the author's collection of plain tex/generic packages.
Looks nice, but I've never used the macros. Syntax highly eccentric, as viewed by a latex user...
expkv
-bundle
Author: Jonathan P. Spratte
expkv
is the only fully expandable key=val parser (in addition to the basic \keyval_parse:NNn
of l3keys
which was modelled after expkv
's implementation of \ekvparse
).
The bundle consists of multiple packages:
expkv
The package alone does only provide features comparable with keyval
(the macros are called \ekvdef
, \ekvdefNoVal
, and \ekvset
), but it does only strip one set of braces and only after spaces are stripped, and it does work for active commas and equals signs. As of writing this, it is the fastest key=val parser with robust parsing (in the sense of the aforementioned brace and category code safety).
Additional utility packages by the same author are available to extend expkv
's features:
expkv-def
Provides key-types similar to pgfkeys
or l3keys
, definable in a key=val interface. Many of the key types aren't expandable (because they do assignments).
expkv-cs
Define expandable macros with a key=val argument. The package allows two different syntax variants, one will split the keys into separate arguments (#1
... #9
) the other will provide a list in which values can be accessed by the key names.
expkv-opt
Parse LaTeX class and package options with expkv
.
Except for expkv-opt
all the packages can be used in plainTeX, LaTeX, and ConTeXt.
pgfkeyx.sty
Author: Ahmed Musa
From the package description:
The package extends and improves the robustness of the pgfkeys package. In particular, it can deal with active comma, equality sign, and slash in key parsing. The difficulty with active characters has long been a problem with the pgfkeys package.
With any luck, this facility can be merged into the main code of pdfkeys directly. Unless this robustifying is too resource intensive, I supposed.
Edits by Skillmon:
Up to today (2020-06-23) this package wasn't integrated into pgfkeys
. It fixes two of the bugs pgfkeys
has (I only know of these two bugs), namely it doesn't strip any braces before space stripping, and it works even if commas or equals signs are made active.
Starting with commit 1e520dc7 to pgfkeys
, pgfkeyx
is no longer compatible with it.
The author's statement
pgfkeyx is not any significantly more resource-intensive than the original pgfkeys.
however isn't true. The following shows the results of benchmarking pgfkeys
and pgfkeyx
. The dots are the benchmarking results, the lines are the interpolations on them, linear for pgfkeys
(blue) and quadratic for pgfkeyx
(red).
-
The integration of pgfkeyx with pgfkeys was suggested by the author of pgfkeyx. pgfkeyx is not any significantly more resource-intensive than the original pgfkeys. Commented Nov 8, 2012 at 15:15
-
-
The two packages probably still differ I'd guess. Perhaps @JosephWright knows more? Commented Sep 22, 2017 at 12:58
-
luakeys
Author: Josef Friedrich
A Lua module for parsing key-value options
Pros
- Key-value pairs can be parsed independently of the macro collection (LaTeX or ConTeXt). Even in plain LuaTEX keys can be parsed.
- luakeys can handle nested lists of key-value pairs, i.e. it can handle a recursive data structure of keys.
- Keys do not have to be defined, but can they can be defined.
Cons
- The package works only in combination with LuaTeX.
- You need to know two languages: TeX and Lua.
options
Author: Daan Leijen
Inspired by pgfkeys
and in fact very similar, but faster. It also supports parsing class and package options.
simplekv
Author: Christian Tellechea
Documentation is only available in French. It is pretty fast and unconventional in the way undefined keys are handled (they get stored as new keys and no error is thrown).
-
Much of the functionality of skeycommand has been moved to ltxkeys, as indicated in the sub-title of skeycommand documentation. But my recent experience shows that it's nearly impossible to abandon a package, once it has been released to CTAN. It will resurface somewhere someday. Commented Dec 30, 2011 at 8:31
-
1Shouldn't be used as it loads the problematic
catoptions
package.– SkillmonCommented Jun 30, 2020 at 16:51
ltxkeys.sty
Author: Ahmed Musa
ltxkeys, unlike keyreader, is completely independent of xkeyval and provides many more features. It can be loaded before \documentclass
.
-
2Shouldn't be used as it loads the problematic
catoptions
package.– SkillmonCommented Jun 30, 2020 at 16:51
skeyval.sty
Author: Ahmed Musa
The package (version 1.3) is incompatible with LaTeX 2020/10/01 and newer
The skeyval package provides commands for compactly defining and initializing all types of key (ordinary, command, boolean, style, choice, etc). It attempts to combine the features of ltxkeys package (which has the syntax of the xkeyval package) and pgfkeys package. See Possibility to pass options to packages.
-
1Shouldn't be used as it loads the problematic
catoptions
package.– SkillmonCommented Jun 30, 2020 at 16:51
keyval2e.sty
Author: Ahmed Musa
This was meant to be lightweight, with no facility for options processing.
-
2Shouldn't be used as it loads the problematic
catoptions
package.– SkillmonCommented Jun 30, 2020 at 16:51
rkeyval.sty
Author: Michael Downes
Keyval syntax is restricted in a sense that options must always be surrounded by braces.