2

When I use the amsart document class and leave a subsection title empty, then the subsection number is bold. Minimal working example:

\documentclass{amsart}
\begin{document}
\section{Test}
\subsection{} Text
\end{document}

Strangely, when I include the hyperref package, subsection numbers do not get bolded any more. MWE:

\documentclass{amsart}
\usepackage{hyperref}
\begin{document}
\section{Test}
\subsection{} Text
\end{document}

Is there a way I can make subsection numbers appear in bold when using hyperref? I am afraid to break some of the functionality of hyperref if I redefine the \subsection command after loading hyperref.

  • the fact that you get bold numbers with {} is entirely accidental and fragile series of unplanned expansions. – David Carlisle Jan 22 '17 at 22:12
  • @DavidCarlisle Actually it seems to be a wanted behavior: line 1056 of amsart.cls has \ifnum #2=\tw@ \def\@secnumfont{\bfseries}\fi to be executed when #8 (the title) is empty. – egreg Jan 22 '17 at 22:25
  • I assumed it was wanted because subsection numbers don't really stand out if there is no (bold) title next to them. – Johnny Jan 22 '17 at 22:27
  • 1
    Using an inline heading with no actual heading seems to be mis-use of the heading really. Apart from the wrong font you get double space, the space intended before the heading and the space intended after the heading. – David Carlisle Jan 22 '17 at 22:31
  • @DavidCarlisle -- the bolding is intentional, for the reason given: because if there's no heading, the numbers don't stand out. (pretty sure there's a comment on this in amsclass.dtx. but hyperref wasn't a consideration when the change was made; will check into that.) authors use (sub)sectioning with no header text, so it has to be catered for, undesirable though it may be to editors. – barbara beeton Jan 22 '17 at 22:35
1

The amsart class indeed has the feature that if the argument to \subsection is empty, then the number is printed boldface, while normally it is medium series.

I don't like this feature at all, personally. However, what happens is that the code in \@sect that does the job is (line numbers refer to amsart.cls)

1055     \@ifempty{#8}{%
1056       \ifnum #2=\tw@ \def\@secnumfont{\bfseries}\fi}{}%

but when hyperref is loaded, the argument #8 is

\Sectionformat{<title>}{2}

so it is not empty as far as \@ifempty is concerned.

Here's a patch for it.

\documentclass{amsart}

\usepackage{xpatch}
\usepackage{hyperref}

\makeatletter
% we need to patch the saved version of \@sect
\providecommand{\H@old@sect}{} % so this doesn't choke if hyperref is removed
\xpatchcmd{\H@old@sect}
  {\@ifnotempty{#8}}
  {\checkempty@title{#8}{}}
  {}{}
\xpatchcmd{\H@old@sect}
  {\@ifempty{#8}}
  {\checkempty@title{#8}}
  {}{}
\xpatchcmd{\H@old@sect}
  {\@ifempty{#8}}
  {\checkempty@title{#8}}
  {}{}
\def\checkempty@title#1{\checkempty@title@aux#1}
\def\checkempty@title@aux#1#2#3{\@ifempty{#2}}
\makeatother

\begin{document}
\section{Test}
\subsection{} Text
\end{document}

enter image description here

Actually, there is a bug in amsart: if you have one subsection with empty title, all subsequent section numbers are typeset boldface.

In order to cure this bug another couple of patches are needed:

\documentclass{amsart}

\usepackage{xpatch}
\usepackage{hyperref}

\makeatletter
% we need to patch the saved version of \@sect
\providecommand{\H@old@sect}{} % so this doesn't choke if hyperref is removed
\xpatchcmd{\H@old@sect}
  {\@ifnotempty{#8}}
  {\checkempty@title{#8}{}}
  {}{}
\xpatchcmd{\H@old@sect}
  {\@ifempty{#8}}
  {\checkempty@title{#8}}
  {}{}
\xpatchcmd{\H@old@sect}
  {\@ifempty{#8}}
  {\checkempty@title{#8}}
  {}{}
\xpatchcmd{\H@old@sect}
  {\def\@secnumfont}
  {\gdef\@secnumfont}
  {}{}
\def\checkempty@title#1{\checkempty@title@aux#1}
\def\checkempty@title@aux#1#2#3{\@ifempty{#2}}
% patch the bug of amsart
\xapptocmd{\@seccntformat}
  {\noexpand\reset@secnumfont}
  {}{}
\AtBeginDocument{%
  \edef\reset@secnumfont{%
    \gdef\noexpand\@secnumfont{\expandafter\noexpand\@secnumfont}%
  }%
}
\makeatother

\begin{document}

\section{Test}
\subsection{} Text

\section{Test}

\end{document}

enter image description here

|improve this answer|||||
0

You can specify the section numbers are bold:

\documentclass{amsart}
\usepackage{hyperref}
\makeatletter
\def\@secnumfont{\bfseries}
\makeatletter

\begin{document}
\section{Test}

\subsection{} Text
\end{document}

If you specify an empty heading then the font that is specified for the heading text is unfortunately applied to the number, however you should not rely on that mis-feature as it could be fixed.


an enpty heading does not just make the one heading have bold numbers it affects all headings at all levels from the point on, consider

\documentclass{amsart}
%\usepackage{hyperref}

\begin{document}
\section{Test}

\subsection{x} Text

\subsection{} Text

\subsection{} Text


\subsection{x} Text

\section{test2}

\end{document}

which makes

enter image description here


this fixes the bug with an empty heading changing the font of all following headings, and gets the right fonts in hyperref, it still has extra horizontal space in the hyperref case

\documentclass{amsart}
\usepackage{hyperref}

\makeatletter
%\def\@secnumfont{\bfseries}

\def\@sect#1#2#3#4#5#6[#7]#8{%
  \edef\@toclevel{\ifnum#2=\@m 0\else\number#2\fi}%
  \ifnum #2>\c@secnumdepth \let\@secnumber\@empty
  \else \@xp\let\@xp\@secnumber\csname the#1\endcsname\fi
  \@tempskipa #5\relax
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \edef\@secnumpunct{%
      \ifdim\@tempskipa>\z@ % not a run-in section heading
        \@ifnotempty{#8}{.\@nx\enspace}%
      \else
        \@ifempty{#8}{.}{.\@nx\enspace}%
      \fi
    }%
%%%%
    \def\zz{#8}%
    \def\tmp{\Sectionformat{}{2}}%
    \ifx\zz\tmp\def\zz{}\fi
    \let\zzz\@secnumfont
%%%%
    \expandafter\@ifempty\expandafter{\zz}{%
      \ifnum #2=\tw@ \def\@secnumfont{\bfseries}\fi}{}%
    \protected@edef\@svsec{%
      \ifnum#2<\@m
        \@ifundefined{#1name}{}{%
          \ignorespaces\csname #1name\endcsname\space
        }%
      \fi
      \@seccntformat{#1}%
    }%
     \let\@secnumfont\zzz
  \fi
  \ifdim \@tempskipa>\z@ % then this is not a run-in section heading
    \begingroup #6\relax
    \@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty\@M #8\par}%
    \endgroup
    \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
  \else
  \def\@svsechd{#6\hskip #3\@svsec
    \expandafter\@ifnotempty\expandafter{\zz}{\ignorespaces#8\unskip
       \@addpunct.}%
    \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
  }%
  \fi
  \global\@nobreaktrue
  \@xsect{#5}%
}

\def\@seccntformat#1{%
  \protect\textup{\@secnumfont
    \csname the#1\endcsname
    \protect\@secnumpunct
  }%
}

\makeatletter


\begin{document}
\section{Test}

\subsection{x} Text

\subsection{} Text

\subsection{} Text


\subsection{x} Text

\section{test2}

\end{document}

enter image description here

|improve this answer|||||
  • Thank you! Doesn't this solution also make section numbers bold? How would you arrange for only the subsection numbers (and possibly subsubsection numbers) to be bold? – Johnny Jan 22 '17 at 22:25
  • @Johnny it is a feature of the ams design that the same number font is used at all levels, you could change it of course but, there are limits to which it makes sense to change the style of a publisher class rather than use a generic class that is designed to be customised. – David Carlisle Jan 22 '17 at 22:27
  • I see your point; on the other hand, making section numbers bold looks somewhat strange because the section titles themselves are not bold. Ultimately, I just want the style intended by the publisher, which gets somehow broken by hyperref. – Johnny Jan 22 '17 at 22:34
  • @Johnny but since egreg points out it's a feature I suppose I should show how to make the feature work with hyperref, i'll updat eanswer in a bit – David Carlisle Jan 22 '17 at 22:34
  • @Johnny but note your empty heading also makes all headings at all levels bold! see my update... (fix will need to be more extensive than I thought....) – David Carlisle Jan 22 '17 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.