
Моя проблема как в заголовке: я хочу использовать шрифт \ttfamilyсистематически только в примерах, внутри \documentclass{amsbook}. Я делаю это, потому что хочу таким образом отделить примеры от текста вокруг.
Идеальный способ должен быть таким \newtheorem{example}[thm]{Example}[\ttfamily]
(что, к сожалению, не работает).
решение1
Быстрый и простой способ — обойти «официальную» команду для определения нового стиля теоремы (которой является \newtheoremstyle
) и определить стиль с помощью внутренней команды, \th@somestyle
используя только настройку шрифта. Это похоже на то, как, например, встроенный definition
стиль определяется в исходном коде amsthm
.
Телетайп обычно имеет фиксированную ширину символов, поэтому строки обычно неровные. Если вам нужен выровненный текст, вы можете изменить некоторые размеры шрифта, см.http://texblog.net/latex-archive/plaintex/full-justification-with-typewriter-font/.
МВЭ:
\documentclass{amsbook}
\usepackage{amsthm}
\makeatletter
\def\th@example{%
\ttfamily % body font
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
}
\makeatother
\newtheorem{thm}{Theorem}
\theoremstyle{example}
\newtheorem{example}[thm]{Example}
\begin{document}
This is an example:
\begin{example}
An example can be short, or long, such as an entire line this is repeated a few times.
An example can be short, or long, such as an entire line this is repeated a few times.
An example can be short, or long, such as an entire line this is repeated a few times.
\end{example}
This is a theorem:
\begin{thm}
P is either short or long.
A theorem can be long, such as an entire line this is repeated a few times.
A theorem can be long, such as an entire line this is repeated a few times.
A theorem can be long, such as an entire line this is repeated a few times.
\end{thm}
\end{document}
Результат: