Im setting up a command with some options via l3keys
. One of the options is tikz-options
and it should take a list of TikZ options and pass them to a {tikzpicture}
.
\documentclass{article}
\usepackage{tikz,xparse}
\ExplSyntaxOn
\keys_define:nn { mymodule } {
tikz-options .tl_set:N = \l_mymodule_tikz_options_tl,
tikz-options .initial:n = {},
}
\tikzset{
every~my~image/.style = {
fill = blue,
}
}
\NewDocumentCommand{ \myimage }{ o }{
\IfValueT { #1 } {
\keys_set:nn { mymodule } { #1 }
}
\begin{tikzpicture}[every~my~image, \l_mymodule_tikz_options_tl]
\filldraw (0,0) rectangle (2,2);
\end{tikzpicture}
}
\ExplSyntaxOff
\begin{document}
\myimage
\myimage[tikz-options={fill=red,draw=black}]
\end{document}
The above example gives this error
! Package pgfkeys Error: I do not know the key '/tikz/fill=red,draw=black' and
I am going to ignore it. Perhaps you misspelled it.
I guess there’s a problem with expansion, since TikZ considers the whole content of the token list as one option. How can I manually expand it?
.code=\pgfkeysalsofrom{...}
-- I've done something similar withtcolorbox
(which is tikz) and a\l_tmpa_tl
. Perhaps, I'll find that!\begin{tikzpicture}[every-my-image, #1] ...
. Even aside from the difficulties of combining l3 syntax with TikZ, why would you want to bring in an additional key-value system to no purpose?\l_mymodule_tikz_options_tl
is not a set of options, but it contains a set of options. No key-value based package does expansion when absorbing options.#1
would work buttikz-options
is only one among other l3 options …