# Revision tracking macro causes widow or orphan

In a previous question "Revision tracking on a per subsection basis" I asked about tracking revisions by section.

The answer that worked well for me was a macro that user Mike wrote.

\documentclass[a4paper]{scrbook}
\usepackage{xcolor}

\makeatletter
\newcommand*{\curr@revision}{}
\newcommand*{\curr@date}{}
\newcommand*{\curr@author}{}

% #1: revison
% #2: date
\newcommand*{\setrevision}[3]{%
\def\curr@revision{#1}%
\def\curr@date{#2}%
\def\curr@author{#3}%
}
\newcommand*{\printrevision}{%
\begingroup
\ifnum\c@section=0\relax
\let\the@sec@number\thechapter
\else
\ifnum\c@subsection=0\relax
\let\the@sec@number\thesection
\else
\let\the@sec@number\thesubsection
\fi
\fi
\parfillskip0pt\color{gray}
revision: \textsf{\hbox to 2em{\hfill \curr@revision}}%
\par\endgroup\noindent
}
\newcommand*{\listofrevisions}{%
\chapter*{Revisions\@mkboth{Revisions}{Revisions}}%
\@starttoc{lor}%
}
\newcommand*{\revisionline}[5]{%
\ifx\\#5\\%
\@revisionline{#1}{#2}{#3}{#4}%
\else
\@revisionline{#1}{#2}{#3}{#4}%
\or % (section) section number
\@revisionline{%
}{#2}{#3}{#4}%
\or % (page) revision number
\@revisionline{#1}{%
}{#3}{#4}%
\else % all
\@revisionline{%
}{%
}{%
}{%
}%
\fi
\fi
}
\newcommand*{\@revisionline}[4]{%
\noindent\parskip\z@\hbox to 3em{#1}\dotfill
}
\makeatother

\begin{document}
\frontmatter
\begin{titlepage}
\centering
{\Huge The big Company Manual}

\vspace{1cm}
{\Large The inner workings of some big company}

\vspace{2cm}
\begin{tabular}{ll}
Authors & Harry Bigboss\\
& Ruth Cando\\
& Amelia Nicecode
\end{tabular}
\end{titlepage}

\tableofcontents

\listofrevisions

\mainmatter
\chapter{Overview}
\section{Status of this Manual}
\subsection{Usage}
\label{sec:usage}
\setrevision{123}{2018-06-10}{Harry Bigboss}
\printrevision
This manual is for internal use only. It must never leave the company.
Those who take it out, will be fired.

\subsection{Completeness}
\setrevision{55}{2018-06-11}{Ruth Cando}
\printrevision
This manual is in a pre-release state. We are still negotiating with Harry about
the contents of \autoref{sec:usage}.

\section{Goals of the Manual}
\subsection{Introduction}
\setrevision{783}{2018-06-10}{Amelia Nicecode}
\printrevision
The manual can be used as an introduction to the procedures used in this company.

\subsection{Reference}
\setrevision{2233}{2018-06-12}{Amelia Nicecode}
\printrevision
The manual is intended to be a reference of the companies internal procedures.

\end{document}


My issue is that when I "\printrevision" after a section heading the \widowpenalty \clubpenalty don't seem to do anything and I get widow headings and orphan paragraphs in my document.

I've tried the \nowidow package and it made no difference. I've spent some time trying to figure this out but have had no luck.

Try this, where the changes are are end of \printrevision. Mainly, avoid doing \par.

\documentclass[a4paper]{scrbook}
\usepackage{xcolor}

\makeatletter
\newcommand*{\curr@revision}{}
\newcommand*{\curr@date}{}
\newcommand*{\curr@author}{}

% #1: revison
% #2: date
\newcommand*{\setrevision}[3]{%
\def\curr@revision{#1}%
\def\curr@date{#2}%
\def\curr@author{#3}%
}
\newcommand*{\printrevision}{%
\begingroup
\ifnum\c@section=0\relax
\let\the@sec@number\thechapter
\else
\ifnum\c@subsection=0\relax
\let\the@sec@number\thesection
\else
\let\the@sec@number\thesubsection
\fi
\endgroup
\noindent\textcolor{gray}{%
revision: \textsf{\hbox to 2em{\hfill \curr@revision}}}%
\linebreak[4]%
}
\newcommand*{\listofrevisions}{%
\chapter*{Revisions\@mkboth{Revisions}{Revisions}}%
\@starttoc{lor}%
}
\newcommand*{\revisionline}[5]{%
\ifx\\#5\\%
\@revisionline{#1}{#2}{#3}{#4}%
\else
\@revisionline{#1}{#2}{#3}{#4}%
\or % (section) section number
\@revisionline{%
}{#2}{#3}{#4}%
\or % (page) revision number
\@revisionline{#1}{%
}{#3}{#4}%
\else % all
\@revisionline{%
}{%
}{%
}{%
}%
\fi
\fi
}
\newcommand*{\@revisionline}[4]{%
\noindent\parskip\z@\hbox to 3em{#1}\dotfill
}
\makeatother

\begin{document}
\frontmatter
\begin{titlepage}
\centering
{\Huge The big Company Manual}

\vspace{1cm}
{\Large The inner workings of some big company}

\vspace{2cm}
\begin{tabular}{ll}
Authors & Harry Bigboss\\
& Ruth Cando\\
& Amelia Nicecode
\end{tabular}
\end{titlepage}

\tableofcontents

\listofrevisions

\mainmatter
\chapter{Overview}
\section{Status of this Manual}
\subsection{Usage}
\label{sec:usage}
\setrevision{123}{2018-06-10}{Harry Bigboss}
\printrevision
This manual is for internal use only. It must never leave the company.
Those who take it out, will be fired.

\subsection{Completeness}
\setrevision{55}{2018-06-11}{Ruth Cando}
\printrevision
This manual is in a pre-release state. We are still negotiating with Harry about
the contents of \autoref{sec:usage}.

\section{Goals of the Manual}
\subsection{Introduction}
\setrevision{783}{2018-06-10}{Amelia Nicecode}
\printrevision
The manual can be used as an introduction to the procedures used in this company.

\vspace{6.51cm}% compare with 6.52cm
\subsection{Reference}
\setrevision{2233}{2018-06-12}{Amelia Nicecode}
\printrevision
The manual is intended to be a reference of the companies internal procedures.

\end{document}


With an additional vertical space of 0.01cm the whole thing shifts to next page.

• For the record your solution solved my problem perfectly in the full version of my document. Thanks! I'll get into reading about \par and the other changes so I can learn a bit more about how this works.
– KJC
Sep 14, 2018 at 15:20
• @KJC Deep inside LaTeX2e code for \section there is a mechanism which prevents an isolated section title at bottom of a page. Via the premature \par this did not extend to include material after section title. Also the \color added possible pagebreak.
– user4686
Sep 14, 2018 at 15:26