# Providing data series for sparkline environment

I would like to have the data series for a sparkline defined in terms of a macro -- or some alternative -- as opposed to have it set explicitly in the sparkline environment itself. My attempts so far have failed. As an MWE, the following would do:

\documentclass[12pt]{memoir}

\usepackage{xcolor,tikz,sparklines}

\begin{document}
\xdef\SparkMacro{0 1 0.5 1.5 1 0.25}
\renewcommand{\sparklineheight}{1.75}
\begin{sparkline}{3}
\sparkrectangle 0 1.75
\spark \SparkMacro\ / % doesn't work
% \spark 0 1 0.5 1.5 1 0.25 /% does work
\end{sparkline}
\end{document}


How could I have those data passed to the environment sparklinewithout having to type (or copy and paste) them explicitly?

-

You need \expandafter to expand the data before \spark sees it. Also you need a real space not \ at the end. The easiest is to make sure your macro ends with space.

\documentclass[12pt]{memoir}

\usepackage{xcolor,tikz,sparklines}

\begin{document}
\xdef\SparkMacro{0 1 0.5 1.5 1 0.25 }
\renewcommand{\sparklineheight}{1.75}
\begin{sparkline}{3}
\sparkrectangle 0 1.75
\expandafter\spark \SparkMacro / % doesn't work
%\spark 0 1 0.5 1.5 1 0.25 /% does work
\end{sparkline}
\end{document}

-
Right. I had it in front of me, but my mind was not clear about the spaces and got into a mess with several \expandafter commands. Thank you so much. –  Marcos Sep 2 '12 at 17:04
Another alternative is to not include the space in SparkMacro but use \SparkMacro{} / –  Aditya Sep 2 '12 at 17:27