One thing annoying in sparklines is its verbosity and dependence on external arithmetics. For example, to depict a three bar graph of 16%, 53%, 31%, one has to write:
\begin{sparkline}{4}
\sparkspike .166 .302
\sparkspike .500 1
\sparkspike .834 .585
\end{sparkline}
I would prefer:
\threesparkline{0.16}{0.53}{0.31}
So my main question is can I do basic arithmetic in LaTeX, like dividing and multiplying numbers, finding the max among three parameters, etc?
Alternatively, is there a better way of using sparklines that I've missed?
UPDATE:
After the sugestion of using the calc package, I'm stuck with the following attempt which yields an error in \real and \ratio:
\newcommand{\threespike}[3]{
\newcounter{max}\setcounter{max}{\maxof{\maxof{\real{#1}}{\real{#2}}}{\real{#3}}}
\newcounter{a}\setcounter{a}{\ratio{\real{#1}}{max}}
\newcounter{b}\setcounter{b}{\ratio{\real{#2}}{max}}
\newcounter{c}\setcounter{c}{\ratio{\real{#3}}{max}}
\begin{sparkline}{4}
\sparkspike .166 a
\sparkspike .500 b
\sparkspike .834 c
\end{sparkline}
}
UPDATE2:
I eventually got to make \ratio work directly like this:
\newcommand{\ratiofivespark}[7]{
\begin{sparkline}{6}
\sparkspike .1 \ratio{#2}{#1}
\sparkspike .3 \ratio{#3}{#1}
\sparkspike .5 \ratio{#4}{#1}
\sparkspike .7 \ratio{#5}{#1}
\sparkspike .9 \ratio{#6}{#1}
\end{sparkline}
}
Where the first parameter passed establishes the full height of a bar. See the accepted answer for more powerful LaTeX-Fu!
\ratiois expecting the ratio of two integers. You also need something like\arabic{foo}to use that counter, you can't just writefoo. So, what you want requires a bit more work. As for arrays, there's no reason that that couldn't be parsed, but it'd require more work still. – TH. Aug 27 '10 at 5:41sparklines. – Andrew Stacey Aug 27 '10 at 8:24