# Tweaking theorem style last parameter traps?

When I modified the \newtheoremstyle last parameter to get a list for a listoftheorems new command I want to define later, I got some unpleasant side effects I want to get rid of.

First unwanted side effect a blank space between the period and the theorem body or number appears !

Second unwanted side effect the period after the lemma name (which is in normal font when there is one) appears in bold not in normal font when there is an optional name for the lemma. And I want it to be in bold when there is no name.

Third unwanted side effect the name of the theorem is no more in normal font but get the same font than Theorem word (here, in small cap). I do not want this.

What should I do? Below is a 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}%

\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}
\end{thm}
\begin{thm}[Wrong2]
\end{thm}
\begin{lem}[Wrong4]
\end{lem}
\begin{lem}
Good
\end{lem}
\end{document}

• i've added the output of the example code, so that there's something to compare with answers. Jun 26 '15 at 16:30
• (1) the output doesn't exactly match your description. for example, the heading "Theorem" is in caps/small caps (\textsc), not slanted. please clarify. (2) the extra spaces can be got rid of by adding % at the end of all lines in the \newtheoremstyle definition. (i don't think this should be necessary, but haven't yet investigated why it's happening.) (3) i am making a note that there's a request for the possibility of adding a "list of theorems"; providing such a facility could make these gymnastics unnecessary. Jun 26 '15 at 16:38
• @barbarabeeton +1+1 You are right ! I edited my question to correct my mistake and your suggestion of putting % correct all the problem with the blank spaces Jun 26 '15 at 16:44
• so that leaves just the style used for the optional name in theorem 2, and the bold period in lemma 1. will look at those more closely. Jun 26 '15 at 16:48
• @barbarabeeton It does work with the answer of Andrew Swann. i deleted my previous comment. Sorry about that Jun 26 '15 at 16:53

You just have an unprotected end-of-line. The other effects can be cured by adding appropriately \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)}%
}
\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}
\end{thm}
\begin{thm}[Wrong2]
\end{thm}
\begin{lem}[Wrong4]
\end{lem}
\begin{lem}
Good
\end{lem}
\end{document}

I used \@ifempty that amsthm defines for these cases.

However, I would never use boldface for lemmas and small caps for theorems: too much difference.

Note also usage of #2 instead of \thethm: it stands for the current statement number, so it works independently of the counter's name.

Here are the entries in the .aux file:

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

here is a modified example, nearly the same as the original, except with % signs following all the non-final lines of the \newtheoremstyle definitions, and a more comprehensive styling in the last line of the mylemma style; although overkill, it's the easiest way to get around the "bold period" problem.

also shown is the equivalent material in default style for 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}%

\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}
\end{thm}
\begin{thm}[Wrong2]
\end{thm}
\begin{lem}[Wrong4]
\end{lem}
\begin{lem}
Good
\end{lem}

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

\end{document}

• @brunoh -- actually, all those % signs aren't necessary. @egreg found the specific ones causing the problem, namely the unprotected line ends in the last block for mytheorem, which begins with {\thmname.... Jun 26 '15 at 17:10
• I loved all three answers and I had to choose ... egreg gave in his answer the ability for me to get rid of the use of the package etoolsbox and improve my definitions with his last remarks. He also improved my taste ... Jun 26 '15 at 17:11
• @brunoh -- you should (almost) always believe what egreg says. he knows what he is talking about. (i say "almost" because everyone makes silly mistakes from time to time. but with egreg, you have to look really hard.) Jun 26 '15 at 17:18
• Thank you for your last comment. I feel better but a pity we can not choose two answers ... Jun 26 '15 at 17:22

You can move some of the commands in to the then or else parts of the test of the third argument #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}%

\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}

Another version.
\end{thm}

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

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

\end{document}
• good approach, but the heading "Theorem" shouldn't be in bold, i don't think. (see the output example added to the question; but waiting for clarification from op.) Jun 26 '15 at 16:40
• @AndrewSwann With the suggestion of Barbara Beeton and your answer I managed to correct all the bad side effects and to understand better what I was doing. But for the sake of my comprehension, it seems that to tweak with the last parameter overrides all the other choices made in the previous parameters that became useless and better left empty right (and some rules of the original are also like the name being by default in normal font) ? Is it right ? Jun 26 '15 at 17:01