# Are mathmode symbols usable within tikz arrays?

I've got a two dimensional array with indices and a one dimensional array with characters. The following code draws the character indicated by the indices, e.g. The char at (0,0) would be "w", the char at (1,0) would be ldots and so on.

\documentclass[pdftex,twoside,a4paper,draft]{book}
% Tikz
\usepackage{tikz}
\usetikzlibrary{positioning, shapes, calc}
%
\begin{document}
\pagestyle{plain}
%
\begin{figure}
\begin{tikzpicture}[scale=1.0]
%character array (this works)
\def\mysymbols{{"w", "\ldots", "v", "w"}}
%
%character array with mathmode symbols in strings (this doesn't work: unknown operator '$') %\def\mysymbols{{"$\approx$", "$\ddot{\ldots}$", "$\Upsilon$", "$\approx$"}} %character array with mathmode symbols (this also doesn't work: unknown operator '7') %\def\mysymbols{{$\approx$,$\ddot{\ldots}$,$\Upsilon$,$\approx$}} % %Array with indices \def\myindices{{{0,1,0},{0,1,0},{2,2,0},{0,2,1}}} % \foreach \x in {0,...,2}{ \foreach \y in {0,...,2}{ %get symbol \pgfmathparse{\mysymbols[\myindices[\y][\x]]} %put a node at x,y with the symbol as the label \node[] at ($(\x,\y)$) {\pgfmathresult}; } } \end{tikzpicture} % \end{figure} % \end{document}  Now, the problem I am having is this: I would like to use mathmode symbols, e.g. greek letters, within the character array. Is there any way to use mathmode symbols in tikz arrays? - pgfmathparse is intended to parse mathematical expressions, and store the result in \pgfmathresult, not to extract symbols. – Peter Grill Jul 16 '12 at 18:30 \mathresult is a typo, I meant \pgfmathresult. I corrected that in the question. You're correct, the output should be w,...,w;w,...,w;v,v,w;w,v,... . I reduced the code I'm working on to a minimal example, so I could have made an error. – sarahm Jul 16 '12 at 18:30 Ok, I tested the code and changing the node definition to \node[] at ($(\x,\y)$) {\pgfmathresult}; gives me the correct result (e.g. the node labels show up as characters). Still, I can't just use any symbol this way. – sarahm Jul 16 '12 at 18:55 ## 1 Answer The problem is not with math. Math is perfectly OK, you can for example replace w by "$w$" (double quotes are mandatory around the dollar signs). The problem is with math accents, as for example \ddot in your sample code. The problem appears because TeX expands \ddot{\ldots} into: "$\mathaccent "707F\relax {\mathinner{\cdotp \cdotp \cdotp }}$"  You can see there the string "707F being " the escape used by TeX to prefix hexadecimal numbers. In this case this " causes trouble to the pgfmath parser, which considers that double quote the end of the string, and thus the following 7 is an unexpected token. The problem can be easily solved by wrapping the whole math expresion into an aditional pair of braces: "{$\ddot{\ldots}$}" as the following MWE shows: \documentclass{article} \usepackage{tikz} \begin{document} % Tikz \usetikzlibrary{positioning, shapes, calc} % \pagestyle{plain} % \begin{figure} \begin{tikzpicture}[scale=1.0] \def\mysymbols{{"$\approx$", "{$\ddot{\cdots}$}", "$\Upsilon$", "$\approx$"}} %Array with indices \def\myindices{{{0,1,0},{0,1,0},{2,2,0},{0,2,1}}} % \foreach \x in {0,...,2}{ \foreach \y in {0,...,2}{ %get symbol \pgfmathparse{\mysymbols[\myindices[\y][\x]]} %put a node at x,y with the symbol as the label \node[] at ($(\x,\y)\$) {\pgfmathresult};
}
}
\end{tikzpicture}
%
\end{figure}
\end{document}

-
This answer solved my problem. Thank you. I must admit, looking at the tex code would have been the last thing to cross my mind. –  sarahm Jul 17 '12 at 0:38