TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


While attempting to answer Pie chart with values as angles not percent, I stucked on passing a string to a foreach.

The context

To makes things clear, I briefly introduce the context. That question asks for degrees rather than percentages in the chart, so my idea was to convert angles into percentages and call then the usual \pie command from pgf-pie.

The issue

The code:



  \foreach \ang/\lab[count=\xi] in {#1}{
       \xdef\elements{\elements, \perc/\lab}
  %\pie{\elements} % ideally call this
%  \foreach \x/\y in {\elements}
%  \node[draw] at (\x/10,-1) {\y};

\anglepie{10/A, 20/V, 30/C, 40/D}

in principle works because the macro \elements contains a string in the right form to be passed to the foreach (following the same reasoning of Hobby path realization in convex hull approach). This has been verified thanks to \node{\elements};:

enter image description here

However, uncommenting:

\foreach \x/\y in {\elements}
\node[draw] at (\x/10,-1) {\y};

rise as errors:

! Package PGF Math Error: Unknown function `A' (in '2/A').
! Package PGF Math Error: Unknown function `V' (in '5/V').
! Package PGF Math Error: Unknown function `C' (in '8/C').

My feeling is that the string \elements is not interpreted correctly by the foreach, but I have no clues on the motivation behind. What's going on there?

share|improve this question
up vote 4 down vote accepted

enter image description here

You need \expandafter

  \expandafter\pie\expandafter{\elements} % ideally call this
share|improve this answer
I suspected they were necessary somewhere.. Thanks :) – Claudio Fiandrino May 31 '13 at 10:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.