I am working on a package with a command which creates a new tikzpicture
. I would like to pass a list of tikzpicture
arguments to the command. For example, for my single argument command, I might pass scale=1.5,line width=20pt,ultra thick
to it. Next, there is a replace all regex call. For this MWE, I have simplified is as replacing spaces with a ~
character.
The problem occurs when I try to use the token list which has been regex modified and put it into the optional argument list of the tikzpicture
. For reasons I have yet to understand better, calling \tl_use:N
in this setting creates an error where the entire token list is treated as a single pgf/tikz
key. For example, scale=1.5,line width=20pt,ultra thick
as the argument will generate this error:
! Package pgfkeys Error: I do not know the key
'/tikz/scale=1.5,line~width=20pt,ultra~thick' and I am
going to ignore it. Perhaps you misspelled it.
I am assuming this is a catcode problem? Anyway, I'm fairly new to latex3 and may be missing something or approaching this the wrong way. The following is a MWE showing the issue:
\documentclass{article}
\usepackage{expl3}%
\usepackage{l3regex}%
\usepackage{xstring}%
\usepackage{xparse}%
\usepackage{tikz}%
\DeclareDocumentCommand{\mycommand}{ m }
{%
\tl_new:N \l_tikzvowel_fix_spaces_tl
\tl_set:Nn \l_tikzvowel_fix_spaces_tl {#1}
\regex_replace_all:nnN { \s } { \~ } \l_tikzvowel_fix_spaces_tl
\begin{tikzpicture}[#2]% <--- this compiles fine
%tikz stuff
\end{tikzpicture}
\begin{tikzpicture}[\tl_use:N \l_tikzvowel_fix_spaces_tl]% <--- this causes the error
%tikz stuff
\end{tikzpicture}
}
\begin{document}
\mycommand{scale=1.5,line width=20pt,ultra thick}
\end{document}
Calling \tl_show_analysis:N \l_tikzvowel_fix_spaces_tl
on the token list yields:
The token list \l_tikzvowel_fix_spaces_tl contains the tokens:
> s (the letter s)
> c (the letter c)
> a (the letter a)
> l (the letter l)
> e (the letter e)
> = (the character =)
> 1 (the character 1)
> . (the character .)
> 5 (the character 5)
> , (the character ,)
> l (the letter l)
> i (the letter i)
> n (the letter n)
> e (the letter e)
> (blank space )
> w (the letter w)
> i (the letter i)
> d (the letter d)
> t (the letter t)
> h (the letter h)
> = (the character =)
> 2 (the character 2)
> 0 (the character 0)
> p (the letter p)
> t (the letter t)
> , (the character ,)
> u (the letter u)
> l (the letter l)
> t (the letter t)
> r (the letter r)
> a (the letter a)
> (blank space )
> t (the letter t)
> h (the letter h)
> i (the letter i)
> c (the letter c)
> k (the letter k).
<recently read> }
What am I doing wrong here? And what is the standard latex3 approach to this type of situation? Although this particular situation refers to tikzpicture
environment options, I'm an interested in a solution that could apply to any command or environment's argument(s).
\tl_new:N \l_tikzvowel_fix_spaces_tl
should not be inside the document command definition.