Simply put, I have a command defined for an edge when using the tikzpicture
environment.
Command:
\newcommand{\bendangleundiredgenodes}[6]{(#3) edge [-] [bend #2=#1] node [#5] {#6} (#4)}
Usage:
\bendangleundiredgenodes{30}{left}{0}{1}{above}{Test}
This works perfectly fine. However, if I try to make the first argument optional, then I get an error.
Command:
\newcommand{\bendangleundiredgenodes}[6][30]{(#3) edge [-] [bend #2=#1] node [#5] {#6} (#4)}
Usages (both fail):
\bendangleundiredgenodes{left}{0}{1}{above}{Test}
\bendangleundiredgenodes[30]{left}{0}{1}{above}{Test}
Errors (same for both usages):
Package tikz Error: Giving up on this path. Did you forget a semicolon?. \bendangleundiredgenodes
Not defining \perthousand.
Not defining \micro.
Full example usage:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, backgrounds, arrows, automata, positioning, decorations.markings, calc}
\newcommand{\bendangleundiredgenodes}[6]{(#3) edge [-] [bend #2=#1] node [#5] {#6} (#4)}
\newenvironment{discretegraph}[2][\Large]{
\begin{tikzpicture}[
->,
>=stealth',
auto,
node distance=#2cm,
thick,
main node/.style={circle, draw, font=\sffamily#1\bfseries},
nolooparrow/.style={-, every loop/.append style={-}},
double arrows/.style args={##1, ##2, ##3}{
decorate,
decoration={
markings,
mark=at position 0 with {
\coordinate (ta-base-1) at (0,##3pt);
\coordinate (ta-base-2) at (0,-##3pt);
},
mark=at position 1 with {
\draw[##1] (ta-base-1) -- (0,##3pt); \draw[##2] (ta-base-2) -- (0,-##3pt);
}
}
}, every node/.style={font=\sffamily\small}]]
}
{;\end{tikzpicture}}
\begin{document}
\begin{discretegraph}[\normalsize]{3}
\node[main node] (0) [] {};
\node[main node] (1) [right of = 0] {};
\path
\bendangleundiredgenodes{30}{left}{0}{1}{above}{Test}
\end{discretegraph}
\end{document}
\path
performs a single expansion of the token following it and this works with the\newcommand
defined with no optional argument. It can't work with optional arguments.\NewExpandableDocumentCommand
from xparse instead (untested as you didn't provide a complete example).\NewExpandableDocumentCommand
?xparse
documentation.