I have a (multi)line plot generated from a table in pgfplots:
\begin{document}
\begin{tikzpicture}
\begin{axis}
\pgfplotstableread{table.tsv}\loadedtable
\foreach \metavar in {foo,bar} {
\addplot table[x index=1,y=\metavar] from \loadedtable node {\metavar};
}
\end{axis}
\end{tikzpicture}
\end{document}
This works well except for the node I want to place at the end of each line as a kind of inline legend.
Here, LaTeX complains:
! Argument of \T1\metavar has an extra }.
<inserted text>
\par
If I substitute the \metavar node label with some literal text, everything compiles fine, but this of course misses the point of the \foreach. So how do I access a loop variable in a place like this?

\documentclassand all packages that are necessary), and self-sufficient (in this case, that would mean including dummy data). That saves people who try to help the effort of having to complete the code themselves first. – Jake Apr 02 '12 at 17:48