I am trying to help typeset a book for a friend, and I've converted most to use chapters, sections, subsections and subsubsections. However, some sections are of the form "Digression N: Text". The digression numbering increments independently, and I've managed to define my own style of heading. Here's my LaTeX so far:
\documentclass{article}
\usepackage{hyperref}
\newcounter{dig}
\newcommand{\digname}{digression}
\newcommand{\digautorefname}{Digression} % Found first by hyperref \autoref{...}
\makeatletter
% http://infohost.nmt.edu/tcc/help/pubs/nmtthesis/old/annotated/at.startsection.html
% http://help-csli.stanford.edu/tex/latex-sections.shtml
% http://zoonek.free.fr/LaTeX/LaTeX_samples_section/0.html
\newcommand\dig{\@startsection {dig}{2}{\z@}%
{-3.5ex plus -1ex minus -.2ex}%
{2.3ex plus .2ex}%
{\normalfont\Large\bfseries}}
\makeatother
\newcommand{\digprefix}{\digname\ \thedig :\ }
\newcommand{\digression}[1]{%
\phantomsection%
\refstepcounter{dig}%
\addcontentsline{toc}{dig}{\digprefix #1}%
\dig*{\digprefix #1}
}
\begin{document}
\tableofcontents
\section{You're Number One}
If you're interested, see \autoref{di:putfirst}.
\digression{Putting You First}
\label{di:putfirst}
Yes, but see \autoref{di:look}.
\dig{Strangely Echoed}
\label{di:echo}
This is body text.
\digression{Look Over There!}
\label{di:look}
What is happening in \autoref{di:echo}? The dig counter is currently \thedig . Go back to \autoref{di:putfirst}.
%\section{What's Best}
Choose the good.
\subsection{Huh}
I missed it.
\end{document}
It's a few lines, but there are some problems. I'm processing it with two calls to pdflatex dig.tex. Here's the story:
- If I put a section after the digressions, pdflatex won't process the second run because it snags in the
dig.tocfile. It complains that "Something's wrong--perhaps a missing \item" at...}{\numberline {2}What's Best}{1}{Section.2}. - The call to
\dig{Strangely Echoed}confusingly also puts the digression title after the heading (but integrates nicely with\autoref{...}). - In an attempt to rearrange the digression heading text and remove the duplicate, I defined
\digression, but I can't make it integrate with the\autoreffeature of the hyperref package. In the output PDF,\autorefs that reference a\digressionuse the "section" prefix. - The table of contents doesn't seem to format nicely for
\digbased headings either.
So, please, how can I get a separately numbered sequence of Digression headings of the form "Digression N: Title" that can intersperse between calls to \section and work with \autoref?