为了陈述一个定理,我们通常会这样做:
\begin{theorem}
... (statement) ...
\end{theorem}
我想更改宏以便能够使用\theorem
如下方法\section
:
\theorem
... (statement) ...
有可能做到吗?我们可以使用定义/引理/命题来代替定理(我使用 amsclass documentclass)。
答案1
用不同的名字定义你的定理:
\newtheorem{theoremx}{Theorem}
然后做
\newcommand{\theorem}[1]{\begin{theoremx}#1\end{theoremx}}
现在比较
\begin{theoremx}
This is the statement.
\end{theoremx}
和
\theorem{This is the statement.}
并决定这是否值得付出努力。
如果你决定采用这种策略(我绝对不推荐),你可以这样做
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\newargumenttheorem}{momo}
{
\NewDocumentCommand{#1}{om}
{
\IfValueTF{##1}
{
\begin{\cs_to_str:N #1-inner}[##1] ##2 \end{\cs_to_str:N #1-inner}
}
{
\begin{\cs_to_str:N #1-inner} ##2 \end{\cs_to_str:N #1-inner}
}
}
\IfValueTF{#2}
{
\newtheorem{\cs_to_str:N #1-inner}[#2-inner]{#3}
}
{
\IfValueTF{#4}
{
\newtheorem{\cs_to_str:N #1-inner}{#3}[#4]
}
{
\newtheorem{\cs_to_str:N #1-inner}{#3}
}
}
}
\ExplSyntaxOff
\newargumenttheorem{\theorem}{Theorem}[section]
\newargumenttheorem{\lemma}[theorem]{Lemma}
\newargumenttheorem{\definition}{Definition}
\begin{document}
\section{Test}
\definition{This is a definition.}
\lemma{This is a lemma.}
\theorem[Important]{\label{important}This is a theorem.}
Theorem \ref{important} is very important.
\end{document}
答案2
该theorem
环境与许多其他 LaTeX 环境一样,已经具有宏\theorem
。
\documentclass{article}
\newtheorem{theorem}{Theorem}
\begin{document}
\section{Introduction}
Theorems can easily be defined
\theorem {
Let $f$ be a function whose derivative exists in every point, then $f$
is a continuous function.
}
\end{document}
编辑:
避免@PhelypeOleinik 指出的问题的另一种选择:
\documentclass{article}
\newtheorem{theorem}{Theorem}
\let\oldtheorem\theorem
\let\endoldtheorem\endtheorem
\renewcommand\theorem[1]{\begin{oldtheorem}#1\end{oldtheorem}}
\begin{document}
\section{Introduction}
Theorems can easily be defined
\theorem {
Let $f$ be a function whose derivative exists in every point, then $f$
is a continuous function.
}
Let $f$ be a function whose derivative exists in every point, then $f$
is a continuous function
\end{document}
答案3
要回答您在评论中提到的版本,您可以简单地这样做:
\newcommand{\mytheorem}[1]{\begin{theorem}#1\end{theorem}}
这样就行了。不过还没有测试过。