我在一个模块(在 lyx 中)示例中有一个构建环境theorems-ams-bytype.inc
,我复制了该环境并为名为 的环境创建了一个具有所需更改的副本pitfall
。
Style Pitfall
CopyStyle Definition
LatexName pitfall
LabelString "Pitfall \thepitfall."
Preamble
\theoremstyle{definition}
\newtheorem{pitfall}{\protect\pitfallname}[chapter]
\renewcommand{\thepitfall}{\arabic{pitfall}} % this will number the pitfall number as normal 1,2, etc while if u remove this line then it would be chapterno.pitfall number.
EndPreamble
Requires amsthm
LangPreamble
\providecommand{\pitfallname}{_(Pitfall)}
EndLangPreamble
BabelPreamble
\addto\captions$$lang{\renewcommand{\pitfallname}{_(Pitfall)}}
EndBabelPreamble
LabelCounter pitfall
End
现在我使用 renewenvironment 命令为这个环境添加一些漂亮的装饰。重新定义环境的代码如下。
% for pitfall
\mdfdefinestyle{pitfallstyle}{%
linecolor=gray,middlelinewidth=7pt,%
frametitlerule=false,%
%tikzsetting={shading=axis,top color=gray!10},
% apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
%shade,left color=white, right color=gray!20}}}, frametitlerulecolor=gray!60,
roundcorner=1pt,
splittopskip=1cm,
splitbottomskip=1cm,
bottomline=false,
leftline=false,
rightline=false,
backgroundcolor=gray!10,
frametitlerulewidth=0pt,
innertopmargin=\topskip, }
% changes in pitfall environment
\let\origpitfall\pitfall
\let\endorigpitfall\endpitfall
\renewenvironment{pitfall}{%
% here you can make changes in the original pitfall class
\begin{mdframed}[style=pitfallstyle] \origpitfall }{
\endorigpitfall
\end{mdframed}
}
现在的问题是,如果我不在\begin{pitfall} ... \end{pitfall}
整个文档中使用,则会出现错误。错误如下。
请帮助我理解。
答案1
我认为这是一个时机问题;无论如何,这样做\let\origpitfall=\pitfall
可能会隐藏一个陷阱。
你应该能够通过给出其他名字到内部环境,说
\theoremstyle{definition}
\newtheorem{pitfallx}{\protect\pitfallname}[chapter]
\renewcommand{\thepitfallx}{\arabic{pitfallx}}
\providecommand{\pitfallname}{_(Pitfall)}
pitfall
并根据以下内容定义“真实”环境pitfallx
(您永远不会直接使用):
\mdfdefinestyle{pitfallstyle}{%
linecolor=gray,middlelinewidth=7pt,%
frametitlerule=false,%
%tikzsetting={shading=axis,top color=gray!10},
% apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
%shade,left color=white, right color=gray!20}}}, frametitlerulecolor=gray!60,
roundcorner=1pt,
splittopskip=1cm,
splitbottomskip=1cm,
bottomline=false,
leftline=false,
rightline=false,
backgroundcolor=gray!10,
frametitlerulewidth=0pt,
innertopmargin=\topskip, }
% changes in pitfall environment
\newenvironment{pitfall}
{\begin{mdframed}[style=pitfallstyle]\pitfallx}
{\endpitfallx\end{mdframed}}