在下面的代码中,由 定义的计数器mdframed
似乎无法被ntheorem
环境访问,这是有问题的,但ntheorem
可以通过 读取计数器mdframed
。我找不到解决方法,而且似乎没有任何地方提到这个限制。
\documentclass[fleqn,11pt]{book}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}
\usepackage[ntheorem,framemethod=TikZ]{mdframed}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newmdtheoremenv{theorem}{Theorem} % uncomment this line
\newtheorem{theorem}{Theorem}[chapter] % comment this line
\newtheorem{definition}[theorem]{Definition}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
text text text text text text text text text text text text
\begin{definition}[Definition]
text text text text text text text text text text text text
\end{definition}
text text text text text text text text text text text text
\begin{theorem}[Theorem]
text text text text text text text text text text text text
\end{theorem}
text text text text text text text text text text text text
\end{document}
答案1
至少在文档中,这似乎是一个“错误”。只需切换声明即可:
\newtheorem{definition}{Definition}
\newmdtheoremenv{theorem}[definition]{Theorem}
或者声明一个“虚拟”定理环境并根据这个环境定义所有内容:
\newtheorem{dummy}{dummy}[chapter]
\newmdtheoremenv{theorem}[dummy]{Theorem}
\newtheorem{definition}[dummy]{Definition}
(这可能对正确发布声明有用\theoremstyle
)。
\newtheorem{dummy}{dummy}[chapter]
\newmdtheoremenv{theorem}[dummy]{Theorem}
\theoremstyle{definition}
\newtheorem{definition}[dummy]{Definition}
答案2
编辑
处于开发状态的mdframed
bug已经修复:
这是软件包中的解决方案xparse
。目前,该解决方案尚未在当前版本中实现mdframed
。
\documentclass[fleqn,11pt]{book}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}
\usepackage[ntheorem,framemethod=TikZ]{mdframed}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xparse}
\RenewDocumentCommand\newmdtheoremenv{O{} m o m o }{
\ifboolexpr{ test {\IfNoValueTF {#3}} and test {\IfNoValueTF {#5}} }%
{\newtheorem{#2}{#4}}{%
\IfValueTF{#3}{\newtheorem{#2}[#3]{#4}}{}%
\IfValueTF{#5}{\newtheorem{#2}{#4}[#5]}{}%
}%
\BeforeBeginEnvironment{#2}{%
\begin{mdframed}[#1]}%
\AfterEndEnvironment{#2}{%
\end{mdframed}}%
}
\newmdtheoremenv{theorem}{Theorem} % uncomment this line
%\newtheorem{theorem}{Theorem}[chapter] % comment this line
\newtheorem{definition}[theorem]{Definition}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
text text text text text text text text text text text text
\begin{definition}[Definition]
text text text text text text text text text text text text
\end{definition}
text text text text text text text text text text text text
\begin{theorem}[Theorem]
text text text text text text text text text text text text
\end{theorem}
text text text text text text text text text text text text
\end{document}