调整定理样式的最后一个参数陷阱?

调整定理样式的最后一个参数陷阱?

当我修改\newtheoremstyle最后一个参数以获取我想稍后定义的新命令 listoftheorems 的列表时,我遇到了一些我想摆脱的不愉快的副作用。

第一个不良副作用句号和定理主体或数字之间出现空格!

第二个不良副作用词条名称后面的句点(如果有句点,则使用正常字体)在词条有可选名称时以粗体显示,而不是正常字体。我希望在没有名称时将其显示为粗体。

第三个不良副作用定理的名称不再采用正常字体,而是采用与定理单词相同的字体(此处采用小写)。我不想要这个。

我该怎么办?以下是 MWE

\documentclass{amsbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}

\newtheoremstyle{mytheorem}
{6pt plus 0pt minus 2pt}
{0pt plus 0pt minus 2pt}
{\slshape}
{}{\scshape}
{.}
{5pt plus 1pt minus 1pt}
{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}
     \ifstrempty{#3}%
      {\addcontentsline{def}{subsection}{#1~\thethm}}%
      {\addcontentsline{def}{subsection}{#1~\thethm~(#3)}}}

\newtheoremstyle{mylemma}
{6pt plus 0pt minus 2pt}
{0pt plus 0pt minus 2pt}
{\slshape}
{}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{}

\theoremstyle{mytheorem}
\newtheorem{thm}{Theorem}
\theoremstyle{mylemma}
\newtheorem{lem}{Lemma}

\begin{document}
\begin{thm}
Bad effect
\end{thm}
\begin{thm}[Wrong2]
Double Bad effect
\end{thm}
\begin{lem}[Wrong4]
Bad effect
\end{lem}
\begin{lem}
Good
\end{lem}
\end{document}

示例代码的输出

答案1

您只是有一个不受保护的行尾。其他影响可以通过适当添加来解决\normalfont

\documentclass{amsbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\makeatletter
\newtheoremstyle{mytheorem}
{6pt plus 0pt minus 2pt}
{0pt plus 0pt minus 2pt}
{\slshape}
{}{\scshape}
{.}
{5pt plus 1pt minus 1pt}
{\thmname{#1}\thmnumber{ #2}\thmnote{\normalfont\ (#3)}%
 \addcontentsline{def}{subsection}{#1\string~#2\@ifempty{#3}{}{\string~(#3)}}%
}
\makeatother


\newtheoremstyle{mylemma}
{6pt plus 0pt minus 2pt}
{0pt plus 0pt minus 2pt}
{\slshape}
{}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{\thmname{#1}\thmnumber{ #2}\thmnote{\normalfont\ (#3)}}

\theoremstyle{mytheorem}
\newtheorem{thm}{Theorem}
\theoremstyle{mylemma}
\newtheorem{lem}{Lemma}

\begin{document}
\begin{thm}
Bad effect
\end{thm}
\begin{thm}[Wrong2]
Double Bad effect
\end{thm}
\begin{lem}[Wrong4]
Bad effect
\end{lem}
\begin{lem}
Good
\end{lem}
\end{document}

我使用\@ifempty这些amsthm定义来描述这些情况。

在此处输入图片描述

但是,我永远不会对引理使用粗体,对定理使用小写字母:差别太大。

还要注意使用#2而不是\thethm:它代表当前语句编号,因此它独立于计数器的名称。

以下是文件中的条目.aux

\@writefile{def}{\contentsline {subsection}{Theorem~1}{1}}
\@writefile{def}{\contentsline {subsection}{Theorem~2~(Wrong2)}{1}}

答案2

这是一个修改后的例子,几乎与原始示例相同,只是 %在定义的所有非最终行之后都有符号\newtheoremstyle ,并且在样式的最后一行有更全面的样式 mylemma;虽然有些过度,但这是解决“粗体句号”问题的最简单方法。

还显示了 的默认样式中的等效材料amsbook

\documentclass{amsbook}
\usepackage{etoolbox}

\newtheoremstyle{mytheorem}%
{6pt plus 0pt minus 2pt}%
{0pt plus 0pt minus 2pt}%
{\slshape}%
{}{\scshape}%
{.}%
{5pt plus 1pt minus 1pt}%
{\thmname{#1}\thmnumber{ #2}\thmnote{ \normalfont (#3)}%
     \ifstrempty{#3}%
      {\addcontentsline{def}{subsection}{#1~\thethm}}%
      {\addcontentsline{def}{subsection}{#1~\thethm~(#3)}}}

\newtheoremstyle{mylemma}%
{6pt plus 0pt minus 2pt}%
{0pt plus 0pt minus 2pt}%
{\slshape}%
{}%
{\bfseries}%
{.}%
{5pt plus 1pt minus 1pt}%
{\thmname{#1}\thmnumber{ #2}\thmnote{ \normalfont (#3)}}

\theoremstyle{mytheorem}
\newtheorem{thm}{Theorem}
\theoremstyle{mylemma}
\newtheorem{lem}{Lemma}

\theoremstyle{plain}
\newtheorem{pthm}{Theorem}
\newtheorem{plem}{Lemma}

\begin{document}
\begin{thm}
Bad effect
\end{thm}
\begin{thm}[Wrong2]
Double Bad effect
\end{thm}
\begin{lem}[Wrong4]
Bad effect
\end{lem}
\begin{lem}
Good
\end{lem}

\begin{pthm}
Bad effect
\end{pthm}
\begin{pthm}[Wrong2]
Double Bad effect
\end{pthm}
\begin{plem}[Wrong4]
Bad effect
\end{plem}
\begin{plem}
Good
\end{plem}

\end{document}

示例代码的输出

答案3

您可以将某些命令移到第三个参数测试的 then 或 else 部分#3

示例图像

\documentclass{amsbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}

\newtheoremstyle{mytheorem}
{6pt plus 0pt minus 2pt}
{0pt plus 0pt minus 2pt}
{\slshape}
{}{\scshape}
{.}
{5pt plus 1pt minus 1pt}
{\textnormal{\bfseries \thmname{#1}\thmnumber{ #2}}%
     \ifstrempty{#3}%
      {\addcontentsline{def}{subsection}{#1~\thethm}}%
      {\thmnote{ (#3)}\addcontentsline{def}{subsection}{#1~\thethm~(#3)}}}

\newtheoremstyle{mylemma}
{6pt plus 0pt minus 2pt}
{0pt plus 0pt minus 2pt}
{\slshape}
{}
{\bfseries}
{}
{5pt plus 1pt minus 1pt}
{\thmname{#1}\thmnumber{ #2}%
  \ifstrempty{#3}{.}{\textnormal{\thmnote{ (#3).}}}}

\theoremstyle{mytheorem}
\newtheorem{thm}{Theorem}
\theoremstyle{mylemma}
\newtheorem{lem}{Lemma}

\begin{document}

\begin{thm}
First version.
\end{thm}

\begin{thm}[Attribution]
Another version.
\end{thm}

\begin{lem}[Atrribution]
Example.
\end{lem}

\begin{lem}
Good.
\end{lem}

\end{document}

相关内容