Expanding macro defined by \csdef to define a style via \tikzset
You can use expanded
instead of expand once
in your MWE:
\tikzset{Node Options/.style/.expanded=\csuse{My Node Option}}%% ????
\csuse{...}
is not quite the same as \csname...\endcsname
:
% etoolbox.sty, line 883:
\newcommand*{\csuse}[1]{%
\ifcsname#1\endcsname
\csname#1\expandafter\endcsname
\fi}
If you expand once in your context you get
\ifcsname My Node Option\endcsname\csname My Node Option\endcsname\fi
A further expansion step will remove the conditional, leaving
\csname My Node Option\endcsname\fi
which requires two expansion steps in order to deliver
draw=red, thick, fill=yellow\fi
but then the \fi
kicks in, because it is shuffled around at the wrong place.
You can do
\tikzset{Node Options/.style/.expand twice=\csname My Node Option\endcsname}
that avoids the problem of the dangling \if
.
However, the best strategy, in my opinion, is to use styles all around:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{My Node Option/.style={draw=red, thick, fill=yellow}}
\begin{tikzpicture}
\tikzset{Node Options/.style=My Node Option}
\node [Node Options] at (0,0) {Node Text};
\end{tikzpicture}
\end{document}
You can use the \begingroup\edef\x{\endgroup <stuff to expand>}\x
expansion trick:
\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\begin{document}
\csdef{My Node Option}{draw=red, thick, fill=yellow}
\noindent
\begin{tikzpicture}
\begingroup\edef\x{\endgroup
\noexpand\tikzset{Node Options/.style={\csuse{My Node Option}}}}%
\x
\node [Node Options] at (0,0) {Node Text};
\end{tikzpicture}%
\end{document}
Note the additional braces around the \csuse
.