I am currently typesetting a document which requires many commutative diagrams of the same shape and construction, but with different labels at the vertices and edges. For example, I want a commutative diagram which describes the associative structure of an algebra. This I can do with:
\begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\matrix(m)[matrix of math nodes,
row sep=2.6em, column sep=2.8em,
text height=2ex, text depth=0.5ex]
{(A\otimes A)\otimes A& & A\otimes (A\otimes A)\\
A\otimes A& &A\otimes A\\
&A& \\};
\path[->,font=\normalsize,>=angle 90]
(m-1-1) edge node[auto] {$\mu\otimes Id$} (m-2-1)
(m-2-1) edge node[auto] {$\mu$} (m-3-2)
(m-1-3) edge node[auto] {$ Id\otimes\mu$} (m-2-3)
(m-2-3) edge node[auto] {$ \mu$} (m-3-2);
\path[<->, font=\normalsize,>=angle 90]
(m-1-1) edge node[auto] {$\alpha$} (m-1-3);
\end{tikzpicture}
\end{equation}
In the same section, I also want to use a commutative diagram to express the monoidal structure of a group. In my document as it stands, this is exactly the same code, but with different labels. As I go forward, I know that this is a diagram which I will likely use very often, and would like to not have to copy and paste this exact code into each new document.
I naively tried using \newcommand{\monoid}[8]{...}
to wrap the whole thing, however this did not work. Is there a way to define a macro around this environment so that I can specify only the arguments I need and not be cluttered by having to copy and paste the whole block every time?
\newcommand
is pretty much what you should use, so please give us your faulty code.