我对 Tex 还很陌生,最近意识到我需要大量使用 TikZCD。我开始画很多图,意识到如果有一种快速的方法对图进行对偶化会非常方便(也许这意味着将所有内容旋转 π,然后翻转所有箭头)。举一个简单的例子
\begin{tikzcd}
T
\arrow[drr, bend left,]
\arrow[ddr, bend right,]
\arrow[dr, dashed] & & \\
& R/IJ \arrow[r] \arrow[d]
& R/I \arrow[d, "f"] \\
& R/J \arrow[r, "g"]
& R/(I+J)
\end{tikzcd}
是回拉图的一个例子,它的对偶是推出图:
\begin{tikzcd}
Z \ar[d,"f",swap] \ar[r,"g"] & Y \ar[d,"g'"] \ar[ddr,bend left,swap,"k"]\\
X \ar[r,"f'",swap] \ar[drr,bend right,"j"] & W \ar[dr,dashed]\\
& & V
\end{tikzcd}
我想要一个脚本,它可以获取第一个图表并返回类似于第二个图表的内容。如果有人知道一个脚本或可以执行此类操作的东西,那就太好了。谢谢!
答案1
下面是一些反转箭头并将所有内容旋转 180 度的基本代码:
\documentclass{article}
\usepackage{tikz-cd}
\usepackage{etoolbox}
\usepackage{rotating}
\makeatletter
\pgfkeysgetvalue{/tikz/commutative diagrams/.unknown/.@cmd}{\dualizetikzcdunknownkeyhandler}
\patchcmd\dualizetikzcdunknownkeyhandler{\tikzcd@ar@target}{\tikzcd@ar@start}{}{\error}
\newenvironment{dualtikzcd}{
\begin{turn}{180}
\pgfkeyssetvalue{/tikz/commutative diagrams/.unknown/.@cmd}{\dualizetikzcdunknownkeyhandler}
\tikzcdset{
bend left/.code = {\tikzset{bend right=##1}},
bend right/.code = {\tikzset{bend left=##1}},
every label/.append style=swap,
to/.code={\tikzcd@setarrowend\tikzcd@ar@start{##1}},
from/.code={\tikzcd@setarrowend\tikzcd@ar@target{##1}},
/tikz/every node/.style={rotate=180,}
}
\begin{tikzcd}
}{\end{tikzcd}\end{turn}}
\makeatother
\begin{document}
\begin{tikzcd}
T
\arrow[drr, bend left,]
\arrow[ddr, bend right,]
\arrow[dr, dashed] & & \\
& R/IJ \arrow[r] \arrow[d]
& R/I \arrow[d, "f"] \\
& R/J \arrow[r, "g"]
& R/(I+J)
\end{tikzcd}
\begin{dualtikzcd}
T
\arrow[drr, bend left]
\arrow[ddr, bend right,]
\arrow[dr, dashed] & & \\
& R/IJ \arrow[r] \arrow[d]
& R/I \arrow[d, "f"] \\
& R/J \arrow[r, "g"]
& R/(I+J)
\end{dualtikzcd}
\end{document}
输出结果如下: