
私はします
\begin{center}
\begin{tikzcd}
...some commutative diagram...
\end{tikzcd}
\end{center}
一日に何十回も。例えば、ショートカットを作る方法はありますか?
\diagram{
...some commutative diagram...
}
?
答え1
まったく複雑ではありません。しかし、\&
列区切り記号として使用する必要があることに気付いた瞬間に、これを実行したことを後悔することになります (おそらく大した問題ではありません)。また、標準的な方法で図に番号を付ける可能性も失われます。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usepackage{lipsum}% just for the example
\newcommand{\diagram}[2][]{%
\begin{equation*}% better than center
\begin{tikzcd}[ampersand replacement=\&,#1]
#2
\end{tikzcd}
\end{equation*}
}
\begin{document}
\lipsum*[2]
\diagram{
A \arrow[r,"f"] \arrow[d,"\alpha"] \& B \arrow[d,"\beta"] \\
C \arrow[r,"g"] \& D
}
\lipsum*[3]
\begin{equation}
\begin{tikzcd}
A \arrow[r,"f"] \arrow[d,"\alpha"] & B \arrow[d,"\beta"] \\
C \arrow[r,"g"] & D
\end{tikzcd}
\end{equation}
\lipsum[4]
\end{document}
後者に比べて前者の入力に実際の改善が見られますか?
次のようにダイアグラムにオプションを渡すことができる
\diagram[column sep=4em]{
...
}