可恢复环境中的 tikz-cd 导致编译错误

可恢复环境中的 tikz-cd 导致编译错误

我尝试在可重述定理环境中包含 tikz-cd 图,但这会导致编译错误。有没有办法避免这种情况?

最小工作示例:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz-cd}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{IEEEtrantools}
\declaretheorem{theorem}

\begin{document}

\section{Introduction}

Here's a restatable theorem that compiles:
\begin{restatable}{theorem}{foo}
This is my diagram:
\begin{tikzcd}
A
\end{tikzcd}
\end{restatable}

Here's another restatable theorem that compiles, this time containing an ampersand:
\begin{restatable}{theorem}{bah}
This is my equation:
\begin{IEEEeqnarray*}{RCL}
 a & = & b
 \end{IEEEeqnarray*}
\end{restatable}

Here's a restatable theorem that doesn't compile:
\begin{restatable}{theorem}{baz}
This is my diagram:
\begin{tikzcd}
A & B
\end{tikzcd}
\end{restatable}

\end{document}

产生的错误是:

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options 

l.36 \end{restatable}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options 

l.36 \end{restatable}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Missing character: There is no B in font nullfont!

! Package pgf Error: Single ampersand used with wrong catcode.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.36 \end{restatable}

This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options 

l.36 \end{restatable}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options 

l.36 \end{restatable}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

如果相关的话,我可以提供更多的编译日志。第 36 行是第三个环境的结尾restatable。我最初以为问题是由“&”符号的存在引起的,但第二个定理(环境中有“&”符号IEEEeqnarray*)表明这不是(唯一的)问题。

答案1

ampersand replacement欢迎!如果您想将tikzcd带有 的环境传递&给宏,则需要一个。

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz-cd}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{IEEEtrantools}
\declaretheorem{theorem}

\begin{document}

\section{Introduction}

Here's a restatable theorem that compiles:
\begin{restatable}{theorem}{foo}
This is my diagram:
\begin{tikzcd}
A
\end{tikzcd}
\end{restatable}

Here's another restatable theorem that compiles, this time containing an ampersand:
\begin{restatable}{theorem}{bah}
This is my equation:
\begin{IEEEeqnarray*}{RCL}
 a & = & b
 \end{IEEEeqnarray*}
\end{restatable}

Here's a restatable theorem that also compiles after an \texttt{ampersand
replacement}:
\begin{restatable}{theorem}{baz}
This is my diagram:
\begin{tikzcd}[ampersand replacement=\&]
A \& B
\end{tikzcd}
\end{restatable}

\end{document}

在此处输入图片描述

相关内容