# Missing \endcsname in tikz draw

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.
\numexpr
;


This is the minimal code:

 \documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{2pt}
\begin{document}
\begin{preview}
\def\step{5}
\begin{tikzpicture}
\def\stepsize{\numexpr180/\step\relax}
\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.

• isn't (\radius:\stepsize)? – touhami Aug 2 '15 at 16:06
• @touhami No, it's (angle:radius). – skevin93 Aug 2 '15 at 16:13
• @fbence The problem in your code is \numexpr. TikZ is able to calculate, so you can simple write \draw(0,0) -- (180/\step:\radius);. – skevin93 Aug 2 '15 at 16:18
• Good to know, although it might not always be convenient (or readable) to do it in each place it occurs. – fbence Aug 2 '15 at 19:09

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}

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.