![thmtools -> 在定理头部引用论文](https://linux22.com/image/477555/thmtools%20-%3E%20%E5%9C%A8%E5%AE%9A%E7%90%86%E5%A4%B4%E9%83%A8%E5%BC%95%E7%94%A8%E8%AE%BA%E6%96%87.png)
我想获得以下代码的替代方案,与 thmtools 一起使用:
\begin{theorem}[Theorem X.X of \cite{foo}] bar \end{theorem}
当我执行以下操作时:
\begin{theorem}[name={Theorem X.X of \cite{foo}}] bar \end{theorem}
如果定理是在我的标题中使用创建的环境
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[style=plain, name=Theorem, numberwithin=section]{theorem}
我收到错误信息。我做错什么了吗?
更新
我设法找出了这个问题。它与 ijcai17 包(我不得不使用它)对 cite 命令的一些修改有关。
因此:最小失败示例:
\documentclass{article}
\usepackage{ijcai17}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[style=plain, name=Theorem, numberwithin=section]{theorem}
\begin{document}
\begin{theorem}[name={Theorem X.X of \cite{icdt/Abiteboul88}}]
bar
\end{theorem}
\begin{thebibliography}{}
\bibitem[Abiteboul, 1988]{icdt/Abiteboul88}
Abiteboul, S. (1988).
\newblock Updates, a new frontier.
\newblock pages 1--18.
\end{thebibliography}
\end{document}
答案1
正如 samcarter 所建议的,使用\protect
就可以了。
这是我更新的最小示例,它给了我想要的结果:
\documentclass{article}
\usepackage{ijcai17}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[style=plain, name=Theorem, numberwithin=section]{theorem}
\begin{document}
\begin{theorem}[name={Theorem X.X of \protect\cite{icdt/Abiteboul88}}]
bar
\end{theorem}
\begin{thebibliography}{}
\bibitem[Abiteboul, 1988]{icdt/Abiteboul88}
Abiteboul, S. (1988).
\newblock Updates, a new frontier.
\newblock pages 1--18.
\end{thebibliography}
\end{document}
答案2
您被迫使用的文件包犯了一些基本错误,这些错误可以轻松修复。
\documentclass{article}
\usepackage{ijcai17}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[style=plain, name=Theorem, numberwithin=section]{theorem}
% fix the stupid mistakes in ijcai17
\makeatletter
\DeclareRobustCommand\cite{%
\def\citeauthoryear##1##2{\def\@thisauthor{##1}%
\ifx \@lastauthor \@thisauthor \relax \else##1, \fi ##2}%
\@icite
}
\DeclareRobustCommand\shortcite{\def\citeauthoryear##1##2{##2}\@icite}
\DeclareRobustCommand\citeauthor{\def\citeauthoryear##1##2{##1}\@nbcite}
\DeclareRobustCommand\citeyear{\def\citeauthoryear##1##2{##2}\@nbcite}
\makeatother
\begin{document}
\begin{theorem}[Theorem X.X of \cite{icdt/Abiteboul88}]
bar
\end{theorem}
\begin{thebibliography}{}
\bibitem[Abiteboul, 1988]{icdt/Abiteboul88}
Abiteboul, S. (1988).
\newblock Updates, a new frontier.
\newblock pages 1--18.
\end{thebibliography}
\end{document}
注意
\begin{theorem}[name=Theorem X.X of \cite{icdt/Abiteboul88}]
将以相同的方式工作;我认为没有必要使用该key-value
语法。
原始答案,由于 OP 没有真正展示出问题
恐怕这至少会让人感到困惑。无论如何,您不能name
在可选参数中使用 key theorem
:它只是 key \declaretheorem
。
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[
style=plain,
name=\protect\namedtheoremname,
numberwithin=section
]{namedtheoreminner}
\newcommand{\namedtheoremname}{}
\newenvironment{namedtheorem}[1]
{\renewcommand\namedtheoremname{#1}%
\namedtheoreminner}
{\endnamedtheoreminner}
\begin{document}
\section{A theorem}
\begin{namedtheorem}{Theorem X.X of \cite{foo}}
Some theorem in another paper
\end{namedtheorem}
\begin{thebibliography}{1}
\bibitem{foo} Foo
\end{thebibliography}
\end{document}