4

at first my MWE:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\def\johnlist{{ala},{bla},{cla}}
% \def\johnlist{2,3,5,7} %This instead of the line above works...

\begin{tikzpicture}
\node[shape=circle,draw=black] at (0,0) {\pgfmathparse{{\johnlist}[1]}\pgfmathresult};
\end{tikzpicture}

\end{document}

I get the following error:

Package PGF Math Error: Unknown function `ala' (in '{{ala},{bla},{cla}}

I've read this and it works, but it's not what I need!

I've read this too and the accepted answer might possibly work, but I can't believe there's no better way! This answer looks promising, but doesn't work either...

Well, I'm searching for hours now and am already proud that I could isolate the error so far, but I'm really getting annoyed now and would greatly appreciate some help!!

4
  • as posted the MWE makes a single circled 3 (for some reason) you don't say what output you want from the commented version. Jun 7, 2015 at 15:04
  • 1
    Yeah, that's what it should do... But I can't use the line that is commented out to define the "johnslist"-array, which is what I really want...
    – caligula
    Jun 7, 2015 at 15:06
  • I changed the MWE, I think it should be easier to understand now!?
    – caligula
    Jun 7, 2015 at 15:09
  • Your commented list has only one pair of braces. You need {{2,3,5,7}}. For otherwise text should be inside double quotes {{"a","b"}} etc
    – percusse
    Jun 7, 2015 at 15:10

1 Answer 1

6

Strings should be quoted, not braced:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\newcommand\johnlist{{"ala","bla","cla"}}

\begin{tikzpicture}
\node[shape=circle,draw=black] at (0,0) {\pgfmathparse{\johnlist[1]}\pgfmathresult};
\end{tikzpicture}

\end{document}

enter image description here

Note the additional braces in the definition of \johnlist and the removal of those around \johnlist in \pgfmathparse, according to the syntax found on page 934 of the manual.

1
  • 1
    Well that works, thanks so far! Unfortunately it seems like I can't get it to work in my real project, so I'll perhaps come up with another question...
    – caligula
    Jun 7, 2015 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .