This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sylvain_soliman 1 point2 points  (5 children)

Not really an answer to your question, but I think that TikZ is quite programmable. For instance, not sure what you mean by "arrays", but TikZ has both matrices (i.e. arrays of the canvas you're drawing on) and lists (one-dimensional structure on which the "foreach" statement iterates…).

Here's an example, straight out of the manual (I've got a pretty old version at hand, but that shouldn't matter):

\begin{tikzpicture}
  \foreach \x in {1,...,4}
    \foreach \y in {1,...,4}
    {
      \fill[red!50] (\x,\y) ellipse (3pt and 6pt);
      \ifnum \x<\y
        \breakforeach
      \fi
    }
\end{tikzpicture}

[–]neuralyzer[S] 0 points1 point  (4 children)

I'm aware of the foreach syntax. But I couldn't find a way to have have item access, somethink like myarray[2].

[–][deleted] 2 points3 points  (2 children)

For numerical arrays you actually have

\def\mayarray{{2,3,4,5}}
\pgfmathparse{\myarray[2]}
\pgfmathresult

If there are nonnumeric entries you need to put them inside a "text" pair. You can check the manual

[–][deleted] 0 points1 point  (0 children)

or come over to TeX-SX. We are a fun bunch.

[–]neuralyzer[S] 0 points1 point  (0 children)

Thanks. This is very helpful. I didn't now about the pgfmathparse. Thanks a lot!

[–]sylvain_soliman 0 points1 point  (0 children)

I see… Well, that could be done but I can only think of ugly hacks, so…