I plan to put some common commutative diagrams and short exact sequences as new commands in my *.sty file. However, putting this code in my *.sty file
\ProvidesPackage{myLayout}
\usepackage{ifthen,amsopn}
\newcommand{\SES}[3]{
\begin{center}
\begin{tikzpicture}[every node/.style={midway}]
\matrix[column sep={2em},
row sep={0em}] at (0,0)
{ \node(A) {$0$} ;
& \node(B) {#1} ;
& \node(C) {#2} ;
& \node(D) {#3} ;
& \node(E) {$0$} ; \\};
\draw[->] (A) -- (B) node[anchor=south] {};
\draw[->] (B) -- (C) node[anchor=south] {};
\draw[->] (C) -- (D) node[anchor=south] {};
\draw[->] (D) -- (E) node[anchor=south] {};
\end{tikzpicture}
\end{center}
}
Copy-pasting this whole thing to my *.tex document (except the \newcommand part) and replacing #1, #2, #3 with $A$, $B$ and $C$ gives me a wonderful exact sequence diagram.
I want to know what's going wrong when I paste the same exact code in \newcommand. Moreover, I'd like to know if there is a more efficient way to "save layouts" of tikzpicture so that I don't have to copy paste the same codes every time (especially if I'm just making minor adjustments).
The ultimate goal would be to just write one line like this
\SES{A}{B}{C}
for a short exact sequence.
A general and efficient solution would be a very nice plus.
Any help would be very much appreciated.
Best Answer
You can use
ampersand replacement
; however, I'd not use thecenter
environment, for better flexibility (and use\[...\]
instead, around the command). You can also simplify the code usingmatrix of math nodes
.However, I'd recommend using
tikz-cd
.With the simplified syntax of
tikz-cd
you'll probably give up to defining several types of commutative diagrams with macros.