是否可以使用单个命令从编译中排除某一类型的所有定理?

是否可以使用单个命令从编译中排除某一类型的所有定理?

我有一个名为的定理类型application。它用于列出书中讨论的概念的应用。我想将它们从汇编中排除,以便生成一本将与一些学生一起测试的初步书籍。这些应用程序和其他定理环境被保存为秘密,以供将来出版整本书时使用。

最小工作示例:

\documentclass[a4paper,10pt]{book}

\usepackage{amsmath}
\usepackage{mdframed}

\mdfdefinestyle{applicationSty}{linewidth=1pt, innermargin =1cm, outermargin =1cm}
\newcounter{applicationCounter}[chapter]
\numberwithin{applicationCounter}{chapter}
\newmdtheoremenv[style=applicationSty]{application}[applicationCounter]{Aplication}

\begin{document}

This is some text.

\begin{application}
    This is an application.
\end{application}

This is more text.

\begin{application}
    This is another application.
\end{application}

This is more text.

\end{document}

答案1

mdframed提供手段环绕其他环境。为了高效地实现这一点,它利用了通常用于表示环境的\begin和宏。形式为和的钩子被插入到环境的开始/结束处,有效地使包装的环境从\end\@beforebegin@<env>@hook\@afterend@<env>@hook<env>mdframedmyenv

\begin{myenv}
  % environment contents
\end{myenv}

在你的代码中

\begin{mdframed}[<options>]
\begin{myenv}
  % environment contents
\end{myenv}
\end{mdframed}

因此,仅仅利用和改变myenv是不够的。还必须删除mdframed插入的环境包装。以下以类似切换的方式实现了这一点:

enter image description here

\documentclass{book}

\usepackage{amsmath,mdframed,environ}

\mdfdefinestyle{applicationSty}{linewidth=1pt, innermargin =1cm, outermargin =1cm}
\newcounter{applicationCounter}[chapter]
\numberwithin{applicationCounter}{chapter}

\makeatletter
\let\old@beforebegin@application@hook\@beforebegin@application@hook
\let\old@afterend@application@hook\@afterend@application@hook
\newcommand{\MakeApplicationsTopSecret}{%
  % Make application environment gobbles its contents
  \RenewEnviron{application}{}%
  % Remove mdframed hooks inserted at \begin and \end environment
  \renewcommand{\@beforebegin@application@hook}{}%
  \renewcommand{\@afterend@application@hook}{}%
}
\newcommand{\MakeApplicationsPublic}{%
  \let\application\relax% Clear application macro/environment
  \let\endapplication\relax
  \newmdtheoremenv[style=applicationSty]{application}[applicationCounter]{Application}%
}
\makeatother

\MakeApplicationsPublic% applications are visible/public by default

\begin{document}

This is some text at the start.

\begin{application}
  This is an application.
\end{application}

This is more text in the middle top.

\MakeApplicationsTopSecret
\begin{application}
  This is another application.% This application is removed
\end{application}

This is more text in the middle bottom.

\MakeApplicationsPublic
\begin{application}
  This is another application.
\end{application}

This is more text at the end.

\end{document}

\MakeApplicationsTopSecret删除与环境相关的钩子application,并吞噬整个环境内容,这要归功于environ. 相反,恢复application环境的功能是通过 来实现的\MakeApplicationsPublic

答案2

这是一个丑陋的解决方案 -comment包无法识别application要排除的环境,而且我似乎无法打开和关闭application包装器内部,因此您必须application手动包装每个包装器。如果您刚刚开始,这可能没问题。如果您已经有一个大文档,那就麻烦了。

也许有人会编辑它并改进它。

\documentclass[a4paper,10pt]{book}

\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{comment}

\mdfdefinestyle{applicationSty}{linewidth=1pt, innermargin =1cm, outermargin =1cm}
\newcounter{applicationCounter}[chapter]
\numberwithin{applicationCounter}{chapter}
\newmdtheoremenv[style=applicationSty]{application}[applicationCounter]{Aplication}

\newenvironment{applicationwrapper}
{}{}
%{\begin{application}}  % this fails - too bad
%{\end{application}}

\excludecomment{applicationwrapper}

\begin{document}

This is some text.

\begin{applicationwrapper}
\begin{application}
    This is an application.
\end{application}
\end{applicationwrapper}

This is more text.

\begin{application}
    This is another application.
\end{application}

This is more text.

\end{document}

相关内容