For writing a package it's usually important to be able to define package options. Since the package I'm writing is in expl3 I wondered whether there's a l3ish way of defining key-value-package-options.
I know there's l3keys as part of expl3, but as far as I can tell, it does not evaluate options given to the package directly, but has to be called using a wrapper macro (can that be done automatically?).
Looking at the source code of fontspec it seems to utilize standard LaTeX2e's option processing facilities. Concluding from that I would use kvoptions for key-value-interfaces even for l3, although it creates l2 constructions such as \newifs.
On the other hand there's siunitx which uses the (poorly documented) package l3keys2e (@DavidCarlisle I do not want to reverse engineer) and the l3keys syntax for kv-option-processing. But is that a safe or recommended way? In my package I intend to use l3keys anyway.
To visualize what I want (a prototypical nonsense-MWE):
\documentclass{article}
\usepackage[
quack,% should evaluate to quack=true
font=sffamily,% should set a font token list to sffamily
logo=false,% should set a boolean to false
size=3% should set an integer
]{mypack}
\begin{document}
\quackfig
\end{document}
with mypack.sty:
\RequirePackage{expl3,xparse}
\ProvidesExplPackage{mypack}{2017-05-26}{v1.0}{Quack}
\RequirePackage{graphicx}
\bool_new:N \l__mypack_optkeys_quack_bool
\bool_set_true:N \l__mypack_optkeys_quack_bool
\tl_new:N \l__mypack_optkeys_font_tl
\bool_new:N \l__mypack_optkeys_logo_bool
\int_new:N \l__mypack_optkeys_size_int
\int_set:Nn \l__mypack_optkeys_size_int {10}
% Process options here
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\NewDocumentCommand{\quackfig}{}{
\begin{figure}[htb]
\bool_if:NT \l__mypack_optkeys_quack_bool {
\tl_if_eq:nnT {\l__mypack_optkeys_font} {sffamily} {\sffamily}
Quack!
}
\bool_if:NT \l__mypack_optkeys_logo_bool {
\includegraphics[height=\l__mypack_optkeys_size_int cm]{example-image}
}
\end{figure}
}
QUESTION: What is the recommended way for kv-option-processing with l3 and how would mypack.sty look then?
l3keys2e, perhaps on LaTeX-L or by direct mail? – Joseph Wright May 26 '17 at 07:54\ProcessKeysPackageOptionsand\ProcessKeysOptionsand whether there's a way to hide some options from those commands (only to set with a wrapper). But probably that's another question. – TeXnician May 26 '17 at 07:57\usepackage{myquack}\myquacksetup{...}is much more flexible and avoids option clash errors if the package is loaded more than once. (It also looks odd that you are passing an option to a class, but this perhaps only meant as example). – Ulrike Fischer May 26 '17 at 07:59