定义交换图并重复使用它

定义交换图并重复使用它

在我正在写的一篇论文中,我需要绘制双复数,这是一个相当复杂的交换图。我使用 tikzcd 编写了它,代码如下

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz-cd}
\newcommand{\s}[1]{\mathscr{#1}}
\begin{document}    
\begin{tikzcd}
    & 0 \arrow{r} 
        & O_X \arrow{r}{\partial}\arrow{d}{i} 
        & \Omega^1_X \arrow{r}{\partial}\arrow{d}{i} 
        & \dots\arrow{r}{\partial}\arrow{d}{i} 
        & \Omega^n_X\arrow{r}\arrow{d}{i} 
    & 0 \\
    & 0 \arrow{r} 
        & \s{A}\arrow{r}{\partial}\arrow{d}{\bar{\partial}}    
        & \s{A}^{1,0}\arrow{r}{\partial}\arrow{d}{\bar{\partial}}    
        & \dots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}    
        & \s{A}^{n,0}\arrow{r}\arrow{d}{\bar{\partial}} 
    & 0 \\
    & 0 \arrow{r} 
        & \s{A}^{0,1} \arrow{r}{\partial}\arrow{d}{\bar{\partial}} 
        & \s{A}^{1,1}\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        & \dots \arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        & \s{A}^{n,1}\arrow{r}\arrow{d}{\bar{\partial}}
    & 0 \\
    &
        & \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        & \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        & \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        & \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
    & \\
    & 0 \arrow{r}
        & \s{A}^{0,n}\arrow{r}{\partial}
        & \s{A}^{1,n}\arrow{r}{\partial}
        & \dots\arrow{r}{\partial}
        & \s{A}^{n,n}\arrow{r}{\partial}
    & 0\\
    \end{tikzcd}
\end{document}

由于我需要多次绘制相同的图表,所以我想我可以定义一个控制序列

\def\DoubleComplex{
"All the code you saw above"
}

当我尝试使用编译它时

\[
     \DoubleComplex
\]

我不断收到以下错误信息:

! Missing $ inserted.
<inserted text> 
            $
l.234     \DoubleComplex

我想知道发生了什么?重用交换图的好方法是什么?

答案1

Tikz 会创建&一个活动角色,这在某些情况下可能会导致问题。将其添加[ampersand replacement=\&]到环境中并在图表中tikzcd使用,而不是。\&&

我发现您的代码还有另一个问题:第四行中第七个单元格是空的,这会导致 tikcd 错误 ( ),因为第六个单元格的箭头的目的地缺失。似乎将其添加为空单元格的内容No shape named tikz@f@1-4-7 is known就足够了。{}

在此处输入图片描述

\documentclass{article}
\usepackage{tikz-cd}
\newcommand\s[1]{\mathsf{#1}}
\makeatletter
\DeclareRobustCommand{\tvdots}{%
  \vbox{\baselineskip4\p@\lineskiplimit\z@\kern0\p@\hbox{.}\hbox{.}\hbox{.}}}
\makeatother
\newcommand\DoubleComplex
  {\begin{tikzcd}[ampersand replacement=\&]
    \& 0 \arrow{r} 
        \& O_X \arrow{r}{\partial}\arrow{d}{i} 
        \& \Omega^1_X \arrow{r}{\partial}\arrow{d}{i} 
        \& \dots\arrow{r}{\partial}\arrow{d}{i} 
        \& \Omega^n_X\arrow{r}\arrow{d}{i} 
    \& 0 \\
    \& 0 \arrow{r} 
        \& \s{A}\arrow{r}{\partial}\arrow{d}{\bar{\partial}}    
        \& \s{A}^{1,0}\arrow{r}{\partial}\arrow{d}{\bar{\partial}}    
        \& \dots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}    
        \& \s{A}^{n,0}\arrow{r}\arrow{d}{\bar{\partial}} 
    \& 0 \\
    \& 0 \arrow{r} 
        \& \s{A}^{0,1} \arrow{r}{\partial}\arrow{d}{\bar{\partial}} 
        \& \s{A}^{1,1}\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        \& \dots \arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        \& \s{A}^{n,1}\arrow{r}\arrow{d}{\bar{\partial}}
    \& 0 \\
    \&
        \& \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        \& \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        \& \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
        \& \tvdots\arrow{r}{\partial}\arrow{d}{\bar{\partial}}
    \& {}\\
    \& 0 \arrow{r}
        \& \s{A}^{0,n}\arrow{r}{\partial}
        \& \s{A}^{1,n}\arrow{r}{\partial}
        \& \dots\arrow{r}{\partial}
        \& \s{A}^{n,n}\arrow{r}{\partial}
    \& 0\\
    \end{tikzcd}%
  }
\begin{document}
First occurrence:
\[ \DoubleComplex \]
Second occurrence:
\[ \DoubleComplex \]
\end{document}

相关内容