3

Consider

\documentclass{article}
\usepackage{amsthm}
\newtheoremstyle{boldtheorem}
{}
{}
{\itshape}
{}
{}
{\itshape}
{}
{\bfseries}
{.}
{ }
{\thmnumber{#2}\ifx #3\relax\relax\thmname{ #1}\else\thmnote{ #3}\fi}
\theoremstyle{boldtheorem}
\newtheorem{theorem}{Theorem}[section]

\begin{document}
\end{document}

Compiling this with latex gives a Missing \begin{document} error on the line {.}.

Removing the . gives the error

! You can't use `macro parameter character #' in vertical mode.
<argument> ##
         2
l.14 {\thmnumber{#2}
                \ifx #3\relax\relax\thmname{ #1}\else\thmnote{ #3}\fi}

This is extracted from a larger preamble. I have removed all non-printable characters using the vim command :%s/[^[:print]]//g, but the error persists. Removing the .aux file does not seem to have an effect.

Any ideas?

Henricus V.
  • 813
  • 1
  • 6
  • 14

1 Answers1

2

From thmtest.tex (edited)

\newtheoremstyle{<name>}% name
  {<dimen>}%              Space above
  {<dimen>}%              Space below
  {<font>}%               Body font
  {}%                     Indent amount (empty = no indent, \parindent = para indent)
  {<font>}%               Thm head font
  {<punct>}%              Punctuation after thm head
  {<dimen>}%              Space after thm head: " " = normal interword space; \newline = linebreak
  {<spec>}%               Thm head spec (can be left empty, meaning `normal')

If you count the number of arguments, they're exactly nine.

So you probably want

\newtheoremstyle{boldtheorem}
  {\topsep}
  {\topsep}
  {\itshape}
  {}
  {\bfseries}
  {.}
  { }
  {\thmnumber{#2}\ifx\relax#3\relax\thmname{ #1}\else\thmnote{ #3}\fi}

Note that #3 has to be between the two \relax tokens, if you want to test for its emptyness.

\documentclass{article}
\usepackage{amsthm}
\usepackage{lipsum} % just for the example

\newtheoremstyle{boldtheorem}
  {\topsep}
  {\topsep}
  {\itshape}
  {}
  {\bfseries}
  {.}
  { }
  {\thmnumber{#2}\ifx\relax#3\relax\thmname{ #1}\else\thmnote{ #3}\fi}

\theoremstyle{boldtheorem}
\newtheorem{theorem}{Theorem}[section]

\begin{document}

\section{Title}

\lipsum[2]

\begin{theorem}
This is a theorem.
\end{theorem}

\lipsum[3]

\begin{theorem}[Fancy theorem]
This is a fancy theorem.
\end{theorem}

\lipsum[4]

\end{document}

enter image description here

egreg
  • 1,121,712