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öder Aug 28 '11 at 20:24
-
6@Martin — as soon as we'd do that someone would write another one! :) – Will Robertson Aug 29 '11 at 00:26
-
i'd second what @will says: i constructed a list, but in two months, two more (getoptk -- a slightly weird thing, and ltxkeys) have appeared. – wasteofspace Aug 30 '11 at 21:14
-
1Why are there (more than) 13 keyval packages anyway? – You Dec 30 '11 at 08:43
-
3See also the survey article http://www.tug.org/TUGboat/tb30-1/tb94wright-keyval.pdf – Christian Feuersänger Dec 30 '11 at 11:04
-
@You - Some of the packages emerged from a desire to address a shortcoming identified with an existing package, to add features to an existing package, to attend to a personal need (or even desire) of the author or of a requestor, or simply to experiment with coding. – Ahmed Musa Dec 31 '11 at 06:41
-
Wow. I've just seen this. Another reason to prefer ConTeXt unified treatment of key-value pairs. Btw, do ConTeXt modules count as answers? – Jun 23 '20 at 18:52
-
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 Robertson Jun 25 '20 at 01:30
-
The following topic “Key-Val: packages with key-value argument systems” on CTAN also gives a good overview of the available keyval packages. – JosefFriedrich Dec 30 '22 at 15:28
23 Answers
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.
- 73,872
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.
- 73,872
-
The keyval package strips off 2 levels of outer brace: one by using the space trimmer \KV@@sp@def and one in internal parsing. – Ahmed Musa Dec 31 '11 at 01: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>].
- 60,462
-
1
-
1@projetmbc documentation is in the making, should be added to
usrguide3/usrguide. Currently you can fancy a peek insource2ein theltkeys-section. There is also an intention to add documentation toclsguide. – Skillmon Jun 24 '22 at 06:52 -
1@projetmbc usage example on this site is available here. The
<module>argument defaults to the current file name. – Skillmon Jun 24 '22 at 06:53 -
-
It would be great to have the minimum LaTeX version where this is available. – Jérôme LAURENS Jan 06 '23 at 09: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.
- 73,872
-
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
\setkeyscommand doesn't accept unbalanced conditionals. For example,\setkeys[KV]{fam}{key=\iffalse}fails. The next release of keyreader addresses this problem in its\krdsetkeyscommand. The selective sanitization scheme of xkeyval also appears unduly expensive when there are active commas and equals sign in key-vals. – Ahmed Musa Dec 31 '11 at 02:05 -
Much of the reported incompatibility issue with xkeyval's
\setkeysseems to have disappeared, even for keys defined by David Carlisle's original\define@key. kvsetkeys package later replaced its\setkeyswith\kvsetkeys. – Ahmed Musa Dec 31 '11 at 02:14 -
Is there any particular reason why it can't be loaded before \documentclass? – kahen Mar 05 '12 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. – Will Robertson Apr 08 '12 at 02:05
-
xkeyval.sty (not xkeyval.tex) needs the
\@classoptionslistmacro 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\@classoptionslistand the actions mentioned at (1) and (2) above until\documentclasswas instantiated later by the document. – Ahmed Musa Nov 08 '12 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
- 505,128
-
2kvsetkeys only sets keys; it doesn't define them. It strips one level of outer curly braces in key values. – Ahmed Musa Dec 31 '11 at 02:20
keyreader.sty
Author: Ahmed Musa
The package provides a robust interface to controlling keys in xkeyval, removing some of that package’s restrictions.
- 505,128
-
-
@Ahmed — your comments should be additional answers on this page! – Will Robertson Jan 29 '12 at 21:04
-
Also, this page is supposed to be comprehensive. It makes no sense to remove an entry! I've added
skeyvalbelow. – Will Robertson Jan 29 '12 at 21:09
pgfopts.sty
Author: Joseph Wright
Allows pgfkeys processing to be performed on class or package options.
- 73,872
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...
- 5,352
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.
- 60,462
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).
- 60,462
- 73,872
-
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. – Ahmed Musa Nov 08 '12 at 15:15
-
-
The two packages probably still differ I'd guess. Perhaps @JosephWright knows more? – Will Robertson Sep 22 '17 at 12:58
-
keyval2e.sty
Author: Ahmed Musa
This was meant to be lightweight, with no facility for options processing.
- 73,872
ltxkeys.sty
Author: Ahmed Musa
ltxkeys, unlike keyreader, is completely independent of xkeyval and provides many more features. It can be loaded before \documentclass.
- 73,872
- 505,128
-
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. – Ahmed Musa Dec 30 '11 at 08:31
-
1
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.
- 73,872
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.
rkeyval.sty
Author: Michael Downes
Keyval syntax is restricted in a sense that options must always be surrounded by braces.
- 73,872
