[Tex/LaTex] TikZ: \newcommand with optional TikZ options

macrosoptional argumentstikz-pgf

I want to create a new command with some default TikZ options that you can override using an optional argument. If working as intended the code below would generate a red line between A and B, and a translucent green line with arrows between A and C. How can I accomplish this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\newcommand{\relation}[3][]
{
  % this needed to be modified somehow...
  \path [draw, red] (#2) -- (#3);
}

\begin{tikzpicture}
  \node [draw] (A) at (0, 0) {A};
  \node [draw] (B) at (3, 0) {B};
  \node [draw] (C) at (3, 3) {C};
  \relation{A}{B}
  \relation[<->, color=green!10]{A}{C}
\end{tikzpicture}

\end{document}

Best Answer

As @TomBombadil answered in this question a way to do that is

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\CloudRed}[2][180]% [angle], content
{   \begin{tikzpicture}[overlay]
    \node[align=center, draw,  fill=red, text=white, cloud callout, cloud puffs=17, cloud puff arc=140, callout pointer segments=3, anchor=pointer, callout relative pointer={(#1:2 cm )}, aspect=4,scale=0.5] at (-3ex,0.5ex) {#2};
\end{tikzpicture}
}

\begin{document}

  \begin{itemize}
        \item XY Resistive MM\Cloud{Thank you Rui}
    \item Manufactured by Rui de Oliveira\Cloud[160]{Thanks again}
    \item bla bla bla\Cloud[120]{Thanks yet another time}
    \end{itemize}
\end{document}

The result looks like

enter image description here

As @percusse suggested just a little modification is needed to your code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\newcommand{\relation}[3][]
{
  % this needed to be modified somehow...
  \path [draw=red,#1] (#2) -- (#3);
}

\begin{tikzpicture}
  \node [draw] (A) at (0, 0) {A};
  \node [draw] (B) at (3, 0) {B};
  \node [draw] (C) at (3, 3) {C};
  \relation{A}{B}
  \relation[<->, color=green!40!black!100]{A}{C}
\end{tikzpicture}

\end{document}

The result is

enter image description here