# use of \noexpand in tikz/math associative arrays

The following does not work in tikz/math :

\documentclass[tikz]{standalone}
\usetikzlibrary{math}
\begin{document}
\tikzmath
{
let \a = my black string ;
let \b = my red string ;
let \c{1} = \a{\noexpand\color{red}\b}\a;
print{\c{1}};
}
\end{document}


even though it will upon replacing all instances of \c{1} by \c.

Some way to still do that for associative arrays ?

Cheers,

• There are several and more robust ways for doing such jobs. I mean, without \tikzmath. Oct 22, 2016 at 8:06

It's a followup question. Apparently \edef is used more often and \noexpand gots consumed, exposing \color again. A better way is therefore to use a robust definition made via e-TeX's \protected\def. Package etoolbox provides an interface via \robustify:

\documentclass[tikz]{standalone}
\usetikzlibrary{math}

\usepackage{etoolbox}
\robustify\color

\begin{document}
\tikzmath
{
let \a = my black string ;
let \b = my red string ;
let \c{1} = \a{\noexpand\color{red}\b}\a;
print{\c{1}};
}
\end{document}