[Tex/LaTex] Missing \endcsname in tikz draw

tikz-pgf

I tried to do some calculations in TeX to help me draw a picture and I can't get over this error:

 ! Missing \endcsname inserted.
<to be read again> 
\numexpr 
l.12 \draw (0,0)--(\stepsize:\radius)
                                   ;

This is the minimal code:

 \documentclass{article} 
    \usepackage{tikz} 
    \usepackage[active,tightpage]{preview}
    \setlength\PreviewBorder{2pt}
    \begin{document} 
    \begin{preview}
    \def\radius{10}
    \def\step{5}
    \begin{tikzpicture}
    \def\stepsize{\numexpr180/\step\relax}
    \draw (0,0)--(\stepsize:\radius);
    \end{tikzpicture}
    \end{preview}
    \end{document}

Looking at random example on the internet it should work, but I'm probably overlooking something very trivial or don't understand something basic.

Best Answer

I had a similar problem, and solved it with the use of \number:

\documentclass{article} 
\usepackage{tikz} 
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{2pt}
\begin{document} 
\begin{preview}
\def\radius{10}
\def\step{5}
\begin{tikzpicture}
\def\stepsize{\number\numexpr180/\step\relax}%% <<<---
\draw (0,0)--(\stepsize:\radius);
\end{tikzpicture}
\end{preview}
\end{document}

With \def\stepsize{\numexpr180/\step\relax} TikZ was seeing the unexpanded macro, not the number itself. \number causes \numexpr to be evaluated and yields the actual number that TikZ needs.