[Tex/LaTex] Where to define new TikZ commands

macrostikz-pgf

I have to start by saying that I am a newbie to LaTeX, let alone TikZ.

In order to solve another problem, I found a solution in another question in a comment by Tom Bombadil. He defines the new command:

    \def\centerarc[#1](#2)(#3:#4:#5)% 
[draw options] (center) (initial angle:final angle:radius) { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); }

This basically draws an arc with a given circle centre, initial and final angle. Now I am not sure about where I should define the command. I tried at the beginning of the Tikz picture, but it does not work.

\begin{tikzpicture}[thick,>=latex]
\def\centerarc[#1](#2)(#3:#4:#5)% 
[draw options] (center) (initial angle:final angle:radius) { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); };
\centerarc[red, thick](0,0)(5:85:1);
\end{tikzpicture}

What am I doing wrong?

Best Answer

Code in comments is badly formatted: the correct input should be

\def\centerarc[#1](#2)(#3:#4:#5)% [draw options] (center) (initial angle:final angle:radius)
  { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); }

because the bits after the % are just comments showing the syntax.

You should have this in the preamble (before \begin{document}) and probably you should also add a \newcommand just to be sure \def doesn't overwrite an existing command.

\newcommand\centerarc{} % just for safety
\def\centerarc[#1](#2)(#3:#4:#5){%
  % Synopsis
  % \centerarc[draw options](center)(initial angle:final angle:radius)
  \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5);
}
Related Question