用“可重述”定义新环境

用“可重述”定义新环境

我正在为一个会议准备一份手稿,该会议提供了一个类文件和一个宏包。在样式文件中,他们有

\newtheorem{thm}{Theorem}[section]

和类似的行,在宏包中,它们有

\newcommand{\thmvspace}{.4pc plus .2pc minus .1pc}
\newenvironment{theorem}{\vspace{-\lastskip}\par\addvspace{\thmvspace}\begin{thm}}{\end{thm}\par\addvspace{\thmvspace}} 

作者应该theorem在手稿中使用该环境。我猜想包中的宏会调整定理前后的空格,但我不知道它具体是如何工作的。

现在,因为我在附录中有证明,所以我想使用thmtools和在那里重述定理thm-restate。我最终在类文件加载之后才加载这些\newtheorem,这本身就是一个问题。由于会议让作者准备照相排版的 PDF 文件,而不关心 LaTeX 源代码,所以我只需要制作一些非常接近他们意图的东西。所以我想我可以声明一个mythm我自己的定理类型环境并定义一个像会议提供的包中的环境一样的环境。所以我的最小(非)工作示例如下:

\documentclass{article}

\usepackage{thmtools, thm-restate}

\declaretheorem{mythm}
\newcommand{\thmvspace}{.4pc plus .2pc minus .1pc}
\newenvironment{theorem-restatable}[2][]{\vspace{-\lastskip}\par\addvspace{\thmvspace}\begin{restatable}[#1]{mythm}{#2}}{\end{mythm}\par\addvspace{\thmvspace}}

\begin{document}
\begin{theorem-restatable}[Tarski]{tarski}
  Truth is undefinable.
\end{theorem-restatable}
\tarski*
\end{document}

但这会产生错误:

File ended while scanning use of \thmt@collect@body.

这可能与脆弱的宏和缺少有关\protect,但我不知道哪里出了问题。我怎样才能定义一个像宏包中定义的环境,但带有restatable

答案1

存在两个问题:

首先theorem-restatable,你写\begin{restatable}...但是\end{mythm},所以这些不匹配。

导致错误的实际问题是,环境主体的解析与环境开始代码中的restatable写入不兼容。与 类似,您必须使用and而不是and :\begin{restatable}align\restatable\endrestatable\begin{restatable}\end{restatable}

\documentclass{article}

\usepackage{thmtools, thm-restate}

\declaretheorem{mythm}
\newcommand{\thmvspace}{.4pc plus .2pc minus .1pc}
\newenvironment{theorem-restatable}[2][]{\vspace{-\lastskip}\par\addvspace{\thmvspace}\restatable[#1]{mythm}{#2}}{\endrestatable\par\addvspace{\thmvspace}}

\begin{document}
\begin{theorem-restatable}[Tarski]{tarski}
  Truth is undefinable.
\end{theorem-restatable}
\tarski*
\end{document}

相关内容