自动切换 newtheorem 正文字体形状

自动切换 newtheorem 正文字体形状

有趣的是,它\emph会根据当前字体是否为斜体自动切换字体的形状,例如,

\emph{This is \emph{non-italic} italic}.

会产生类似这样的结果:

这是非斜体斜体

在某些情况下,我希望对定理主体做同样的事情。据我所知,定理样式定义为

\newtheoremstyle{mythm} % name
{\topsep}               % Space above
{\topsep}               % Space below
{\itshape}              % Body font
{}                      % Indent amount
{\scshape}              % Theorem head font
{.}                     % Punctuation after theorem head
{.5em}                  % Space after theorem head
{}                      % Theorem head spec (can be left empty, meaning ‘normal’)

直接用 替换\itshape(Body 字体选项)\emph不起作用,我相信这是因为\itshape是一个开关 (由 使用{\itshape text}) 而\emph是一个命令 (由 使用\emph{text})。 的定义\emph是 (来自 latex by texdef -t latex -c minimal -F emph):

\emph :
\long macro:#1->\ifmmode \nfss@text {\em #1}\else \hmode@bgroup \text@command {#1}
\em \check@icl #1\check@icr \expandafter \egroup \fi

尽管

\itshape :
\long macro:->\not@math@alphabet \itshape \mathit \fontshape \itdefault \selectfont

任何想法?

女士

\documentclass{amsart}
\newtheoremstyle{mythm} % name
{\topsep}               % Space above
{\topsep}               % Space below
{\itshape}              % Body font
{}                      % Indent amount
{\scshape}              % Theorem head font
{.}                     % Punctuation after theorem head
{.5em}                  % Space after theorem head
{}                      % Theorem head spec (can be left empty, meaning ‘normal’)
\theoremstyle{mythm}
\newtheorem{thm}{Theorem}
\begin{document}
This is a test

\emph{This is \emph{non-italic} italic}.

\begin{thm}
  This is italic
\end{thm}
\itshape
This is a test
\begin{thm}
  This should be non-italic
\end{thm}
\end{document}

答案1

内部amsthm(由 自动加载amsthm)在每个定理构造开始时发出\normalfont,从而对抗外部\itshape

您可以修补\@thm以删除它...:

\usepackage{etoolbox}
\makeatletter
\patchcmd\@thm{\normalfont}{}{}{\NOPE}
\makeatother

\NOPE如果修补失败,此操作将会失败(即运行不存在的)

相关内容