Script for dualizing diagrams in tikzcd by mirroring
For simple diagrams like this you only need to set the column sep
to a negative value, swap the labels, and revert the arrows. The negative value here was found by looking at the manual. Significantly more complex, where complex means varying column widths, reverted arrows and so on, diagrams may not be dualized that easily. (One can still write styles that revert all relevant original keys to their "dualized" values but the effort for this may not be justified.)
\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{dual/.style={column sep=#1,every label/.append style={swap},
arrows=leftarrow},
dual/.default=-5.5em}
\begin{document}
Original diagram:
\[\begin{tikzcd}
C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] && \vdots \\
&& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] && \vdots
\end{tikzcd}\]
Dual constructed by hand"
\[\begin{tikzcd}
\vdots \arrow[rr] \arrow[ddrr] && C \\
F(x) \arrow[urr, "\phi_x"] \arrow[drr, "\mu_x", swap] \\
\vdots \arrow[uurr]\arrow[rr] && \coprod F \arrow[uu, "\exists ! \Phi", dashed]
\end{tikzcd}\]
Dual constructed by adding the pgf key \texttt{dual} to the original diagram.
\[
\begin{tikzcd}[dual]
C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] && \vdots \\
&& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] && \vdots
\end{tikzcd}\]
\end{document}
How could make this things easier? You could just store the original diagram in a macro (using an appropriate ampersand replacement
) and then dualize it reusing the macro.
\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{dual/.style={column sep=#1,every label/.append style={swap},
arrows=leftarrow},dual/.default=-5.5em,ampersand replacement=\&}
\begin{document}
\def\OriginalDiagram{C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] \&\& \vdots \\
\&\& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] \&\& \vdots
}
Original diagram:
\[\begin{tikzcd}
\OriginalDiagram
\end{tikzcd}\]
Dual constructed by adding the pgf key \texttt{dual} to the original diagram.
\[
\begin{tikzcd}[dual]
\OriginalDiagram
\end{tikzcd}\]
\end{document}
Needless to say that this duality does not turn a \pi
into a \mu
and a \prod
into a \coprod
.