[Tex/LaTex] Calculations and undefined control sequence with TikZ

tikz-pgf

I already produced several figures with TikZ, but I can't see what's wrong with this snippet:

\documentclass[a4paper,10pt,twoside]{scrbook}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \def\groundwidth{8.0cm}
        \def\streetwidth{2.0cm}

        \def\gw{0.5*(\groundwidth-\streetwidth)}

        \fill[color=green!75!black] (0, 0) -- (\gw,0) -- (\gw,\gw) -- (0,\gw) -- cycle;
    \end{tikzpicture}
\end{document}

Compiling it with pdftex, it produces the following error message:

! Package pgf Error: No shape named 0 is known.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.11 ...ll[color=green!75!black] (0, 0) -- (\gw,0)
                                               -- (\gw,\gw) -- (0,\gw) -...

I guess there's something wrong with \gw, but I have no idea how to fix I. Do you have any suggestions or a link to the documentation explaining the problem?

Best Answer

A solution is \def\gw{{0.5*(\groundwidth-\streetwidth)}}

\documentclass[a4paper,10pt,twoside]{scrbook}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\begin{document}
        \def\groundwidth{8.0cm}
        \def\streetwidth{2.0cm}
        \def\gw{{0.5*(\groundwidth-\streetwidth)}}    
    \begin{tikzpicture}
        \fill[color=green!75!black] (0, 0) -- (\gw,0) -- (\gw,\gw) -- (0,\gw) -- cycle;
    \end{tikzpicture}
\end{document} 

you can also use

 \fill[color=green!75!black] (0, 0) -- ({\gw},0) -- ({\gw},{\gw}) -- (0,{\gw}) -- cycle;

instead of

  \def\gw{{0.5*(\groundwidth-\streetwidth)}}