2

I'm setting some fonts and font-related commands using l3keys, and that works just fine—but it seems there's an issue when setting the same keys via l3keys2e. Is this expected behavior? Is there a way around it?

Here's an MWE:

\documentclass[border=4pt]{standalone}
\usepackage{filecontents}
\begin{filecontents}{keydebug.sty}

\RequirePackage{expl3}

\ProvidesExplPackage
    {keydebug} {2019/00/00}
    {0.0}      {}

\RequirePackage{l3keys2e}

\keys_define:nn { keydebug } {
    myfont      .tl_set:N       = \myfont,
    myfont      .initial:n      = \it,               % 1
}

\ProcessKeysOptions { keydebug }

% \keys_set:nn { keydebug } { myfont = \it }         % 4

\end{filecontents}

\usepackage{keydebug}                                % 1
% \usepackage[myfont=\relax]{keydebug}               % 2
% \usepackage[myfont=\it]{keydebug}                  % 3-4

\begin{document}
{\myfont Hello, world!}
\end{document}

The numbers to the right indicates four scenarios, and which of the given lines should be uncommented/active in each.

Scenario 1

Initializing via the .initial property works just fine, and results in the following:

using .initial

Scenario 2

Here I supply a command via the package options—in this case \relax, but other commands seem generally to work just fine. In this case, the result is the following, as expected:

with \relax

Scenario 3

Now comes the problem. If I try to supply a font command such as \it or \bfseries or the like, I get the following error:

./keydebug.tex:27: Missing control sequence inserted.
<inserted text>
                \inaccessible
l.27

Scenario 4

It's not supplying the command that's the problem—it's using it later. If I ensure that I overwrite it (still in the preamble, here), things are just fine:

overwriting

So … any suggestions for fixes or workarounds?

  • Off topic: please don't use \it, rather use \textit. – Joseph Wright Apr 16 '19 at 14:00
  • In a per-document basis you can load the kvoptions-patch package before loading your keydebug package, which changes LaTeX's package option handling and inhibits the \edef Joseph mentioned. (It seems that in total there are two \edefs in the process, so \usepackage[myfont=\noexpand\noexpand\noexpand\itshape]{keydebug} should work as well). – Phelype Oleinik Apr 16 '19 at 14:02
  • @JosephWright I think you meant \itshape :-) – Phelype Oleinik Apr 16 '19 at 14:02
  • I know :-) This is partly for insertion in places where I can't wrap the argument in braces, which I'm using \itseries and \bfseries etc., there. But where I can, I use \textit (for automatic italics correction), etc. But \textit doesn't fare much better, here. – Magnus Lie Hetland Apr 16 '19 at 14:04
  • Right, though \itshape doesn't fare any better either :-) – Magnus Lie Hetland Apr 16 '19 at 14:05
4

This is out of the control of l3keys2e. The LaTeX2e kernel processes options before they are passed to packages, and the code which does that (written in the early 1990s) carries out \edef expansion. It was written on the basis that options would be simple lists of words, not keyvals and certainly not commands. The LaTeX team are exploring approaches to 'fixing' this, but there are non-trivial issues. At present, you should stick to using a 'setup' approach for any keys that do not strictly expect strings.

| improve this answer | |
  • Right. Yeah, I have a separate setup command too, of course, so I guess I'll just mention this in the docs, then :-) – Magnus Lie Hetland Apr 16 '19 at 14:06
  • Ended up (for now) placing \ProcessKeysOptions between two blocks of \keys_define:nn, with the first defining those keys that may be set in \usepackage. – Magnus Lie Hetland Apr 16 '19 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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