# Dual commutative diagrams

I use tikz-cd to draw my commutative diagrams, like the following:

\documentclass{scrartcl}
\usepackage{tikz-cd}
\begin{document}
\begin{equation}
\begin{tikzcd}[row sep=scriptsize]
0 \rar & X \dar["\tilde p", hook, dashed] \rar["x", hook]\ar["\scriptscriptstyle(*)", phantom, dr] & Y \dar["p", two heads]\rar["y", two heads] & Z \dar[equal]\rar & 0\\
0 \rar & U \rar["u"', hook] & V \rar["v"', two heads] & W \rar & 0
\end{tikzcd}
\end{equation}
\end{document} I want to draw the picture for the dual diagram, which is obtained by the following transformations:

• hooks and double headed tips are exchanged.
• labels of dashed arrows obtain a prime, unless:
• they have a bar or a tilde. In this case, bars and tildes are exchanged.
• $x$- and $y$-coordinates are inverted.

Is it possible to just write down the primal diagram and let TikZ build the dual one automatically?

• Maybe it's possible, but you employ (waste?) more time in trying to do it than to retype the diagram. Side note: I believe that \arrow[r,<other options>] is clearer than \rar \dar and similar. Mar 29, 2020 at 9:07
• @egreg That's probably true; I just have to wonder how to best write the diagrams in such a way that if I change one, it's easy to find the necessary elements to change in the other. Mar 29, 2020 at 9:09
• Can you please enhance the example so that's is compilable? Starting with \documentclass... and ending with \end{document}. That well make it easier to experiment with your code, without having to guess the packages loaded and so on... Thanks! Mar 29, 2020 at 9:46
• @Rmano Sorry; changed. Mar 29, 2020 at 11:55
• Maybe you can start from here.
– user194703
Mar 29, 2020 at 12:18