TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my package I intend to write in expl3 syntax, how can I get access to the list of options passed to it on the document level via \usepackage[<option list>]{my-l3-pkg}?

I know more or less how to define and set keys using the functions provided by the l3keys package. I don't know yet, which variable holds the contents of <option list> I could pass to \keys_set:...

Is there some replacement for the LaTeX2e functions \DeclareOption and \ProcessOptions?

share|improve this question
Is there a reason while \DeclareOption and \ProcessOptions are not allowed in expl3-style packages? – Martin Scharrer Apr 14 '11 at 9:47
They are allowed but they don't accept key-value options. – AlexG Apr 14 '11 at 10:28
In LaTeX2e, the options list of the package file being read is returned by the internal macro \@ptionlist{\@currname.\@currext}. Is there some public macro available which I don't know yet? – AlexG Apr 14 '11 at 14:55
up vote 9 down vote accepted

First, bear in mind that what we are talking about is LaTeX3 syntax on top of LaTeX2e. That means that LaTeX2e conventions apply to some extent. In particular, LaTeX2e expands options and removes spaces. So you have to be a little wary in what you set up as load-time package options.

Now, as LaTeX2e is still actually doing the processing, the main macros remain: \DeclareOption and \ProcessOptions. However, if you want to create key-value options you are best off loading the support package l3keys2e. This enables you you process LaTeX2e package or class options using the key-value system provided by expl3. What you then need to do is a two-step process:

  1. Declare keys for your package using \keys_define:nn
  2. Process the package options using \ProcessKeysOptions

You might therefore have something like

\ProvidesExplPackage{mypkg}{2011/04/14}{0.0}{A demo}
\keys_define:nn { mypkg }
    option-1 .code:n = some-code-here ,
    option-2 .code:n = some-other-code-here
\ProcessKeysOptions { mypkg }

Any key which is declared before \ProcessKeysOptions is treated as a potential package option (this is true for other key-value approaches to package options).

share|improve this answer
Great! l3keys2e offers exactly what I need. – AlexG Apr 15 '11 at 6:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.