![可恢复环境中的 tikz-cd 导致编译错误](https://linux22.com/image/415300/%E5%8F%AF%E6%81%A2%E5%A4%8D%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84%20tikz-cd%20%E5%AF%BC%E8%87%B4%E7%BC%96%E8%AF%91%E9%94%99%E8%AF%AF.png)
我尝试在可重述定理环境中包含 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}