# Creation of macros for a part of commutative diagram

I am using tikz-cd for drawing commutative diagrams. Most of them are just exact triangles which are written as a sequence like a -> b -> c -> a[1] or two or three of them as rows, connected with 4 separate named arrows. I think that if it is possible to write them like

\start{something}
\ExactTriangle{a, b, c} \\
\ExactTriangle{a, b, c} \\
\ExactTriangle{a, b, c} \\
\Morphism{1, 2}{x, y, z}
\Morphism{2, 3}{x', y', z'}
\end{something}


$\begin{tikzcd} a \arrow[r] \arrow[d, "x"] & b \arrow[r] \arrow[d, "y"] & c \arrow[r] \arrow[d, "z"] & a[1] \arrow[d, "x{[1]}"] \\ a \arrow[r] \arrow[d, "x'"] & b \arrow[r] \arrow[d, "y'"] & c \arrow[r] \arrow[d, "z'"] & a[1] \arrow[d, "x'{[1]}"] \\ a \arrow[r] & b \arrow[r] & c \arrow[r] & a[1] \\ \end{tikzcd}$


and get result like: It would increase both their readability and speed of creation/fixing compared to reading and writing down all these \arrows. But most similar questions which i read are answered with advice to use tikz-cd environment wrapped into some command, and I got vague impression that inside tikz environment there is no way to define custom commands like this. So the question is: Is it possible to do such thing with tikz-cd, is there some other package that allows doing things like this or is there a way that could be compared with readability and flexibility to this potential one.

• Could you please show exactly to what this should be translated? Dec 28, 2021 at 11:09
• Can you show some tikz-cd code that does what you need but is in your opinion "long" and "inelegant"? Jan 5, 2022 at 13:32

I think that using TikZ and \pics you can achieve a close enough code as the one in your example.

Like this:

\documentclass[tikz,border=2mm]{standalone}

\tikzset
{%
pics/ExactTriangle/.style n args={3}{
code={%
\node[inner sep=1pt] (-4) at (4.5,0) {\strut$a[1]$};
\foreach[count=\ii]\i in {#1,#2,#3}
\node[inner sep=1pt] (-\ii) at (1.5*\ii-1.5,0) {\strut$\i$};
\foreach\i in {1,2,3}
{
\pgfmathtruncatemacro\j{\i+1}
\draw[-latex] (-\i.east) -- (-\j.west);
}
}},
pics/Morphism/.style n args={5}{
code={%
\foreach[count=\ii]\i in {#3,#4,#5}
\draw[-latex] (#1-\ii) -- (#2-\ii) node[midway,right] {\strut$\i$};
\draw  [-latex] (#1-4)   -- (#2-4)   node[midway,right] {\strut$#3[1]$};
}},
}

\begin{document}
\begin{tikzpicture}[y=-1cm]
\pic (1) at (0,0)   {ExactTriangle={a}{b}{c}};
\pic (2) at (0,1.5) {ExactTriangle={a}{b}{c}};
\pic (3) at (0,3)   {ExactTriangle={a}{b}{c}};
\pic {Morphism={1}{2}{x}{y}{z}};
\pic {Morphism={2}{3}{x'}{y'}{z'}};
\end{tikzpicture}
\end{document}