The example I'm going to post is ridiculous, but serves the purpose.
When I edit my code I usually need to do things like add temporary points and lines and colors and arrows, etc. If I have defined a new command, say, drawarrow:
\newcommand\drawarrow[3]{
\draw[#1] (#2) -- (#3);
}
then I can use it to draw a line with an arrow or not:
With arrow:
\drawarrow{->}{0,0}(1,1};
Without arrow
\drawarrow{}{0,0}{1,1};
Now, for a simple command like this, it's fine. But for a more complicated command I would like to be able to do something like what the regular codes do: \draw[->] or \draw[red] and the like. That way I can just add the new piece or not, as is most convenient.
Just to be clear: If I put in \drawarrow{red,->}{0,0}{1,1}; it will draw a red line with an arrow between the two points. I want to see if I can write the command as \drawarrow{0,0}{1,1}; instead of \drawarrow{}{0,0}{1,1}; while retaining the ability to add the extra {->} to add in if I want it.
This is getting me into library territory, I think? (I'm not sure I want to go that far at this point.)
-Dan
Code: Select all
\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand\drawarrow[3]{
\draw[#1] (#2) -- (#3);
}
\begin{tikzpicture}
\drawarrow{}{0,0}{1,1};
\drawarrow{->}{0,0}{1,-1}
\drawarrow{blue,line width=2pt,dashed}{0,0}{2,0};
\end{tikzpicture}
\end{document}