我想要一个带有附加必需参数的定理环境:
\begin{mylemma}{text1, text2}
It holds that True.
\end{mylemma}
\begin{mylemma}{text1, text2}[Name]
It holds that True.
\end{mylemma}
输出应如下所示:
引理 1.1[文本1,文本2],则认为正确。
引理 1.2(姓名)[文本1,文本2],则认为正确。
我尝试使用提供的答案这里,这里,这里和这里,但没有一个能工作。我最接近的是以下内容:
\documentclass{book}
\usepackage{amsmath, amsthm}
\usepackage{thmtools}
\declaretheoremstyle[%
within=chapter,%
notefont=\normalfont\itshape,%
notebraces={}{},%
]{mystyle}
\declaretheorem[style=mystyle,name=Lemma]{mydef}
\newenvironment{mylemma}[2]
{\begin{mydef}[{(}#2{)\ [}#1{]}]}
{\end{mydef}}
\begin{document}
\begin{mylemma}{text1, text2}{Name}
It holds that True.
\end{mylemma}
\end{document}
这样我就可以使用了\begin{mylemma}{text1, text2}{Name}\end{mylemma}
,但我希望可选的参数现在是必需的。此外,如果能够编写以下内容而不是如此冗长地定义新环境,那就太好了:
\newtheoremstyle{mystyle}{}...{}
\theoremstyle{mystyle}
\newtheorem{mylemma}[theorem]{Lemma}
\newtheorem{mytheorem}[theorem]{Theorem}
\newtheorem{mycorollary}[theorem]{Corollary}
\newtheorem{myproposition}[theorem]{Proposition}
然后能够使用上面指定的每个环境。我尝试调整提供的答案这里为此,但除了有两个选修的参数,我得到了一个可能与我使用的其他包相关的错误(Package ntheorem Error: Theorem style plain already defined. ...rfont ##1\ ##2\ (##3)\theorem@separator}}
)。编辑:该修改的 MWE:
\documentclass{book}
\usepackage{amsmath, amsthm}
\usepackage{mathtools, xparse}
\usepackage{ntheorem}
\makeatletter
\newtheoremstyle{mystyle}
{\isastyleaux{##1}{##2}}
{\isastyleaux{##1}{##2}[##3]}
\NewDocumentCommand\isastyleaux{mmou\ignorespaces o}
{\item[\theorem@headerfont\hskip\labelsep
#1\ #2%
\IfValueT{#3}{\normalfont\itshape (#3)}%
\IfValueT{#5}{\normalfont\itshape [#5]}%
.\theorem@separator]#4\ignorespaces}
\makeatother
\theoremstyle{mystyle}
\newtheorem{mylemma}{Lemma}
\begin{document}
\begin{mylemma}[text1, text2][Name]
It holds that True.
\end{mylemma}
\end{document}
答案1
定义一个内部定理和一个新的环境。
\documentclass{article}
% define it to your liking
\newtheorem{mylemmainner}{Lemma}[section]
\NewDocumentEnvironment{mylemma}{mo}
{%
\IfNoValueTF{#2}{\mylemmainner\textup{[#1]}}{\mylemmainner[#2]\textup{[#1]}} \ignorespaces
}
{\endmylemmainner}
\begin{document}
\section{Test}
\begin{mylemma}{text1, text2}
This is the text of the statement.
\end{mylemma}
\begin{mylemma}{text1, text2}[Name]
This is the text of the statement.
\end{mylemma}
\end{document}
下面介绍如何将句点移动到方括号部分之后,amsthm
(但不是ntheorem
,您不应该同时加载两者)。
\documentclass{article}
\usepackage{amsthm}
\newtheoremstyle{witharg}
{} % ABOVESPACE
{} % BELOWSPACE
{\itshape} % BODYFONT
{0pt} % INDENT (empty value is the same as 0pt)
{\bfseries} % HEADFONT
{} % HEADPUNCT
{5pt plus 1pt minus 1pt} % HEADSPACE
% CUSTOM-HEAD-SPEC
{\thmname{#1} \thmnumber{#2}\thmnote{ (#3)} \textnormal{[\theoremarg].}}
\newcommand{\theoremarg}{}
\theoremstyle{witharg}
\newtheorem{mylemmainner}{Lemma}[section]
\NewDocumentEnvironment{mylemma}{mo}
{%
\renewcommand{\theoremarg}{#1}%
\IfNoValueTF{#2}{\mylemmainner}{\mylemmainner[#2]}\ignorespaces
}
{\endmylemmainner}
\begin{document}
\section{Test}
\begin{mylemma}{text1, text2}
This is the text of the statement.
\end{mylemma}
\begin{mylemma}{text1, text2}[Name]
This is the text of the statement.
\end{mylemma}
\end{document}