I’m trying to use a command defined using \NewDocumentCommand in a tikzpicture environment and cannot resolve an error. Here’s a minimal example of what I’m trying to do:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\ExplSyntaxOn
\NewDocumentCommand { \test } { m }
{
\tl_set:Nn \l_tmpa_tl { #1 }
\int_eval:n { \l_tmpa_tl }
}
\ExplSyntaxOff
\begin{tikzpicture}
\draw (\test{0}, 0) -- (1, 1);
\end{tikzpicture}
\end{document}
Attempting to compile this (with LuaLaTeX) results in:
! Missing \endcsname inserted.
<to be read again>
\__kernel_tl_set:Nx
l.16 \draw (\test{0}, 0)
-- (1, 1);
A different error results if the token list is removed. Changing the code to—
\documentclass{article}
\usepackage{tikz}
\begin{document}
\ExplSyntaxOn
\NewDocumentCommand { \test } { m }
{
% \tl_set:Nn \l_tmpa_tl { #1 }
\int_eval:n { #1 } % <-- This line is different.
}
\ExplSyntaxOff
\begin{tikzpicture}
\draw (\test{0}, 0) -- (1, 1);
\end{tikzpicture}
\end{document}
—results in:
! Missing number, treated as zero.
<to be read again>
\relax
l.16 \draw (\test{0}, 0)
-- (1, 1);
I’m hoping I’m missing something simple that can make TikZ work with commands from \NewDocumentCommand.
\node (a)you can not do assignments like\node (\def\foo{a}\foo)it has to be\def\foo{a} \node(\foo)\nodeis followed by a name, not a point on a path. I’ve updated the post for this, but I suspect it’s a similar issue (assignments can’t occur during path construction).\pgfresultmacro to use later rather than returning a result "inline" as you typically need something that expands to a value.pgfmathevaluation in the specification of a coordinate by using braces. So you could use that here rather than\int_eval:n.pgfmathis slow, but maybe not slower than the shenanigans necessary to offload the calculation to TeX.