# Tikz macro with calculation error

I'm very new to this so bare with me. To get the hang of macros I wanted to write a simple command to draw a square in tikz. Now I know there are a lot of ways to do this, but I want to be able to write more difficult macros.

My code below:

\documentclass{article}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}

\newcommand{\tikzsquare}[2]{
\fill[blue!40!white, opacity=0.5] (#1, #2) rectangle (#1 + 2, #2 + 2);
}

\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-2,-2) grid (4,4);
\tikzsquare{0,0}
\end{tikzpicture}
\end{center}
\end{document}


What I would have expected was something like this:

...
)
! Argument of \XC@definec@lor has an extra }.
<inserted text>
\par
l.14 \end
{tikzpicture}
?
Runaway argument?
{pgfstrokecolor}{)}\ifx \reserved@a \@currenvir \else \@badend {)}\fi \ETC.
! Paragraph ended before \XC@definec@lor was complete.
\par
l.14 \end
{tikzpicture}
?

! LaTeX Error: \begin{tikzpicture} on input line 11 ended by \end{+}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.14 \end
{tikzpicture}


Any help would be very much appreciated

• Instead of \tikzsquare{0,0} you should use \tikzsquare{0}{0}. Every parameter in its own pair of braces. – Ignasi Mar 16 '16 at 14:33
• Instead of commands I'd suggest using pics for more complex macros. Examples: tex.stackexchange.com/questions/126161/… – Ignasi Mar 16 '16 at 14:35

You have told LaTeX that \tikzsquare has two arguments, but have only given it one (0,0), so \end is being grabbed as #2 and all sorts of weirdness results. You want \tikzsquare{0}{0}.
\def\tikzsquare(#1,#2);{\fill[blue!40!white,opacity=0.5] (#1,#2) rectangle (#1+2,#2+2);}

and then use \tikzsquare(0,0); which has more TikZ-ish syntax.