在最近的帖子中
如何定义可以显示/隐藏的证明环境?[结合两个 TeX 解决方案],Werner 帮助我重新定义了一个证明环境,该环境可以通过可选的布尔参数 ( ) 隐藏showProof
。如果没有参数,行/段落的换行就会不正确。如何解决这个问题?
\documentclass{scrartcl}
\usepackage{ifthen}
\usepackage{environ}
\usepackage{amsthm}
\newboolean{showProof}% for showing proofs
\setboolean{showProof}{true}% setting the switch
\newif\ifstarttheorem
% proof environment (with hide feature)
\makeatletter
\providecommand{\env@proof@save@env}{}
\providecommand{\env@proof@process}{}
\RenewEnviron{proof}[2][showProof]{
\gdef\@tmp{#1}%
\ifthenelse{\boolean{#1}}{\par\pushQED{\qed}%
\normalfont\topsep2\p@\@plus2\p@\relax
\trivlist\item[\hskip\labelsep\sffamily\bfseries Proof~#2]\gdef\mycurrenvir{proof}\global\starttheoremtrue\mbox{}\hfill\\*\ignorespaces
\BODY}{\ignorespaces}
}[\ifthenelse{\boolean{\@tmp}}{%
\gdef\mycurrenvir{\relax}
\popQED\endtrivlist\@endpefalse
}{\ignorespacesafterend}]
\makeatother
\begin{document}
Just some text
\begin{proof}
Just some text in a standard proof. As we can see, there is a problem.
\end{proof}
\begin{proof}[false]
Proof with optional argument set to \texttt{false}. This proof correctly does
not appear.
\end{proof}
\begin{proof}[showProof]{(Heading)}
Proof with optional argument (\texttt{true}) and second argument ``(Heading)''
\end{proof}
\end{document}
答案1
我有一个不同的建议;不要让你的生活变得复杂,只需以一种不打印证明proof
的方式重新定义。而不是你可以选择你喜欢的任何(单个)角色。毕竟,这只是一个开关,就这样吧。\begin{proof}*
*
\documentclass{scrartcl}
\usepackage{xparse}
\usepackage{environ}
\usepackage{amsthm}
%% save the original macros
\let\amsthmproof\proof
\let\amsthmendproof\endproof
%% redefine proof
\RenewDocumentEnvironment{proof}{s}
{\IfBooleanTF{#1}
{\ignoreproof}
{\amsthmproof}}
{\IfBooleanTF{#1}
{\endignoreproof}
{\amsthmendproof}}
%% In case you want all proofs to appear, comment the above and
%% uncomment the following; a * following \begin{proof} will be ignored
%\RenewDocumentEnvironment{proof}{s}
% {\amsthmproof}
% {\amsthmendproof}
\NewEnviron{ignoreproof}{}
\begin{document}
Just some text
\begin{proof}
Just some text in a standard proof.
\end{proof}
\begin{proof}*
Proof with the asterisk appended. This proof correctly does not appear.
\end{proof}
\begin{proof}*[Secondary proof]
Proof with the asterisk appended. This proof correctly does not appear.
\end{proof}
\begin{proof}[Proof of the main theorem]
This is the proof of the main theorem.
\end{proof}
\end{document}
如果你想要一个不同的角色,-
第一行应该是
\RenewDocumentEnvironment{proof}{t-}
其余部分将完全相同。
用于忽略所有证明(无论是否加星号)的变体代码;如果您根本不想要证明,只需取消注释标记的行。
\documentclass{scrartcl}
\usepackage{xparse}
\usepackage{environ}
\usepackage{amsthm}
%% save the original macros
\let\amsthmproof\proof
\let\amsthmendproof\endproof
%% a conditional for ignoring all proofs
\newif\ifignoreallproof
%\ignoreallprooftrue % <----- uncomment for ignoring all proofs
%% redefine proof
\ifignoreallproof
\RenewDocumentEnvironment{proof}{s}
{\ignoreproof}
{\endignoreproof}
\else
\RenewDocumentEnvironment{proof}{s}
{\IfBooleanTF{#1}
{\ignoreproof}
{\amsthmproof}}
{\IfBooleanTF{#1}
{\endignoreproof}
{\amsthmendproof}}
\fi
\NewEnviron{ignoreproof}{}
\begin{document}
Just some text
\begin{proof}
Just some text in a standard proof.
\end{proof}
\begin{proof}*
Proof with the asterisk appended. This proof correctly does not appear.
\end{proof}
\begin{proof}*[Secondary proof]
Proof with the asterisk appended. This proof correctly does not appear.
\end{proof}
\begin{proof}[Proof of the main theorem]
This is the proof of the main theorem.
\end{proof}
\end{document}
答案2
重申一下我的评论,你的 MWE 的问题是事实上,正如所写,您的环境有一个可选参数和一个强制参数。您的第一个用例未能提供强制参数(标签)。因此,环境会抓取下一个东西,即您的证明的第一个字母,并将其称为标签。如果您的第一个用例被设置为\begin{proof}{}
,它会给出预期的结果。
既然你回复 Werner 说“是的,它确实像两个可选参数”,我已将此视为明智之举。我认为我已经做到了这一点,即你的proof
环境现在需要两个可选参数和零个强制参数。可选参数括在方[]
括号中,而不是{}
括号中。
但请注意,如果有两个可选参数,则不能在未指定第一个可选参数的情况下指定第二个可选参数。因此,
\begin{proof}[(Heading)]
不是有效的调用。从长远来看,这可能会比您开始时的情况更痛苦。
\documentclass{scrartcl}
\usepackage{ifthen}
\usepackage{environ}
\usepackage{amsthm}
\newboolean{showProof}% for showing proofs
\setboolean{showProof}{true}% setting the switch
\newif\ifstarttheorem
% proof environment (with hide feature)
\makeatletter
\providecommand{\env@proof@save@env}{}
\providecommand{\env@proof@process}{}
\renewenvironment{proof}[1][showProof]{%
\def\proofarg{#1}\proofhelper}{\endproofhelper}
\NewEnviron{proofhelper}[1][]{
\gdef\@tmp{\proofarg}%
\ifthenelse{\boolean{\proofarg}}{\par\pushQED{\qed}%
\normalfont\topsep2\p@\@plus2\p@\relax
\trivlist\item[\hskip\labelsep\sffamily\bfseries Proof~#1]\gdef\mycurrenvir{proof}\global\starttheoremtrue\mbox{}\hfill\\*\ignorespaces
\BODY}{\ignorespaces}
}[\ifthenelse{\boolean{\@tmp}}{%
\gdef\mycurrenvir{\relax}
\popQED\endtrivlist\@endpefalse
}{\ignorespacesafterend}]
\makeatother
\begin{document}
Just some text
\begin{proof}
Just some text in a standard proof. As we can see, there is a problem.
\end{proof}
\begin{proof}[false]
Proof with optional argument set to \texttt{false}. This proof correctly does
not appear.
\end{proof}
\begin{proof}[showProof][(Heading)]
Proof with optional argument (\texttt{true}) and second argument ``(Heading)''
\end{proof}
\end{document}