# How to evaluate tikz expression before printing as text?

Edit: In response to the comments, the question has been edited to include the MWE. The accepted answer (by Gonzalo) is still valid.

Here's my code:

\documentclass{article}

% *** MISC UTILITY PACKAGES ***
\usepackage{graphicx}
\usepackage[caption=false]{subfig}%The caption option has been disabled
%to avoid conflict with the IEEEtran class file.
\usepackage{tikz}

% *** MATH PACKAGES ***
\usepackage[cmex10]{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{figure}[!t]
\centering
\begin{tikzpicture}
\node[anchor=south west, inner sep = 0] (image) at (0,0)
{\includegraphics[width=8cm]{Tulips.jpg}};
\begin {scope}[x={(image.south east)},y={(image.north west)}]
\fill [white] (0,0) rectangle (1,1);
\foreach \y in {0,1,...,8} { \node [anchor=east] at (0.09,0.07+0.88*\y/8) {\small {-5+5*\y}}; }
\end {scope}
\end{tikzpicture}
\caption{Nothing}
\label{nothing}
\end{figure}
\end{document}


Here's the result:

I wanted the series to appear as {-5,0,5,...35}. What's being shown is {-5+5*0,-5+5*1,-5+5*2,...-5+5*8}.

How to evaluate the series before it gets printed as text?

-
Really sorry about that. I will post MWE soon. –  Shashank Sawant Sep 27 '12 at 18:23
@Jake: That's an excellent way to put it. –  Andrew Stacey Sep 27 '12 at 18:26
I guess you did not use standalone class for each diagram you want to draw. –  Stiff Jokes Sep 27 '12 at 18:33
@ShashankSawant: I have resorted to using \pgfmathsetmacro{\<name>}{<expression>} to compute expression and has found that quite useful. The evaluate= is clearly better for this case, but you should keep \pgfmathsetmacro in mind. –  Peter Grill Sep 27 '12 at 20:45

You can use the evaluate=<variable> as <macro> using <formula> syntax:

\documentclass{scrartcl}
\usepackage{tikz,pgf}
\usepackage{graphicx}

\begin{document}

\begin{tikzpicture}
\node[anchor=south west, inner sep = 0] (image) at (0,0)
{\includegraphics[width=8cm]{cat}};
\begin {scope}[x={(image.south east)},y={(image.north west)}]
\draw [help lines,lime,xstep=.01,ystep=.01] (0,0) grid (1,1);
\draw [help lines,orange,xstep=.05,ystep=.05] (0,0) grid (1,1);
\draw [help lines,red,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }

\fill [white] (0,0) rectangle (1,1);
\foreach \y [evaluate=\y as \yeval using -5+5*\y] in {0,...,8} { \node [anchor=east,font=\tiny] at (0.09,0.07+0.88*\y/8) {\pgfmathtruncatemacro{\yet}{\yeval}\yet}; }
\end {scope}
\end{tikzpicture}

\end{document}


-

\documentclass{article}

% *** MISC UTILITY PACKAGES ***
\usepackage{graphicx}
\usepackage[caption=false]{subfig}%The caption option has been disabled
%to avoid conflict with the IEEEtran class file.
\usepackage{tikz}

% *** MATH PACKAGES ***
\usepackage[cmex10]{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{figure}[!t]
\centering
\begin{tikzpicture}
\node[anchor=south west, inner sep = 0] (image) at (0,0)
{\includegraphics[width=8cm]{Tulips.jpg}};
\begin {scope}[x={(image.south east)},y={(image.north west)}]
\fill [white] (0,0) rectangle (1,1);
%   \foreach \y in {0,1,...,8} { \node [anchor=east] at (0.09,0.07+0.88*\y/8) {\small {-5+5*\y}}; }
\foreach \y [evaluate=\y as \yeval using -5+5*\y] in {0,...,8} { \node [anchor=east,font=\small] at (0.09,0.07+0.88*\y/8) {\yeval}; }
\end {scope}
\end{tikzpicture}
\caption{Nothing}
\label{nothing}
\end{figure}
\end{document}


The output looks like this:

-