1

I am trying to learn how to use Tikz and its library Tikzmath to make graphics. I am trying to practice by drawing a series of circles along a line.

My code is as follows:

\documentclass[tikz]{standalone}
\usetikzlibrary{math}

\tikzmath
{
    function num(\n)
    {
         int \i;
         \i=0;
         for \i in {\i,1,...,\n}
         {
            \draw[red] circle[radius=0.5] (\i, 0);
         };
    };
}

\begin{document}
    \begin{tikzpicture}
        \draw[help lines,step=2mm] (-1,-1) grid (4,1);
        \tikzmath{num(2);}
    \end{tikzpicture}
\end{document}

However I keep getting an error message that states:

.Math.tex.swp:20: Argument of \tikz@@math has an extra }.

            \par 

l.20 \tikzmath{num(2);}

I cannot find any extra braces in my code that might be causing this error. I have been trying for the past 40 minutes!

1028
  • 647
  • 5
  • 16
  • 1
    Use the math commands enclosed in brackets. i.e. \tikzmath{{num(2)};} which is found in http://tex.stackexchange.com/questions/41828/using-math-in-tikz. So, you have two issues. First, your installation of tikz is out of date; so, it is time for a complete update of your LaTeX system. Second, this is probably a duplicate question. – R. Schumacher Jul 27 '15 at 03:28
  • @R.Schumacher tikzmath is not calc. – Kpym Jul 31 '15 at 07:18

1 Answers1

2

I have no acces to comuter right now, so my answer will be short and non verifyed. I see three errors:

  1. In the for loop you can't let a space between } and { in the current version of tikzmath.
  2. Your draw command must be enclosed in { };
  3. The coordinates in your draw command must be before the circle.

You can check the following code:

\documentclass[tikz]{standalone}
\usetikzlibrary{math}

\tikzmath
{
    function num(\n)
    {
         for \i in {0,...,\n}{
            {\draw[red] (\i, 0) circle[radius=0.5];};
         };
    };
}

\begin{document}
    \begin{tikzpicture}
        \draw[help lines,step=2mm] (-1,-1) grid (4,1);
        \tikzmath{num(2);}
    \end{tikzpicture}
\end{document}
Kpym
  • 23,002