Bartman wrote:Read section "94.2 Syntax for Mathematical Expressions: Operators" on how to evaluate the array-like structure of your
\entry
command's definition.
Code: Select all
\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\newcommand{\print}[1]{\pgfmathparse{#1}\pgfmathresult}
\newcommand{\entry}{{{"First","Second"},{"Third","Fourth"}}}
\matrix[
matrix of nodes,
execute at begin cell=\print
] {
{\entry[0][0]} & {\entry[0][1]} \\
{\entry[1][0]} & {\entry[1][1]} \\
};
\end{tikzpicture}
\end{document}
Thank you! A bit less obvious than I thought it would be, but obvious enough once I saw what the problem was.
Yes, I finally figured out today that the contents of {..} is considered text, no matter that a variable {\x} might look like a number. I haven't really spent much time with the pgf codes. My loss, apparently.
I have two more questions if you don't mind.
1) I can make this work with \def\entry{{{..}}}. Is there an advantage in using \newcommand?
2) "execute at begin cell" is a neat trick. I'll have to remember that. I would like you to check my understanding of how that works. It tells the matrix operation to run \print on, say, the \entry[0][0] element and returns the number to the 0,0 position in the matrix, inside the { }, where it can be processed properly. This avoids the problem of trying to do something like {\print(\entry[0][0])}, which just repeats my initial mistake and shouldn't work. (I apologize for the likely bad terminology, clearly I'm a noob programmer.)
Thanks for the help!
-Dan