Lettrine and section at bottom of page causes bad pagebreak

My custom lettrine and section causes some of my pagebreaks to ruin my layout. Please see the example of the output for the attached code run through XeLaTeX.

Verse 2 on the next page should actually be written next to the bottom part of the 117 lettrine. Or else the whole chapter starting at the 117 lettrine should be moved to the next page. But forcing \nopagebreak before my sections breaks the page before the 118 lettrine as well, which is wrong since chapter 117 is very short and can't be on it's own page for obvious aesthetic reasons.

I have tried using \nopagebreak[n] but that just did not give expected results. Is it possible to customise the priority more specific for when TeX decides to do a page break?

\documentclass[paper=a5,pagesize=pdftex]{scrbook}
\usepackage[top=2cm,bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lettrine}
\usepackage{xltxtra}
\usepackage{etoolbox}
\usepackage{setspace}

\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}

\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Cardo}

% definition of the page style with required headers
\newpagestyle{Biblestyle}{
}

% sets the marks to be used (section and subsection)
\setmarks{section}{subsection}

\newlength\howwide

\newcommand\defhowwide{
\ifnumless{\value{section}}{99}{\ifnumgreater{\value{section}}{8}{\setlength{\howwide}{2.5em}}{\setlength{\howwide}{1em}}}{\ifnumgreater{\value{section}}{98}{\setlength{\howwide}{3.5em}}{\setlength{\howwide}{2.5em}}}
}

% sections and subsections formatting
\titleformat{\section}{}{\lettrine{\thesection}}{0em}{}[\vskip-1\baselineskip]
\titleformat{\subsection}[runin]{\small\bfseries}{\thesubsection}{1em}{}
\titlespacing{\section}{\howwide}{-1pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{1em}

\setlength{\parindent}{0pt}

\newlength\NumLen
\newlength\LinLen
% indents one line of text. Indentation= width of section number + 1em
\newcommand\IndOne{%
\setlength\NumLen{\howwide}
\setlength\LinLen{\dimexpr\textwidth-\NumLen}%\the\NumLen\the\LinLen
\parshape 2 \NumLen \LinLen 0pt \textwidth}
% indents two lines of text. Indentation= width of section number + 1em
\newcommand\IndTwo{%
\setlength\NumLen{\howwide}
\setlength\LinLen{\dimexpr\textwidth-\NumLen}%\the\NumLen\the\LinLen
\parshape 3 \NumLen \LinLen \NumLen \LinLen 0pt \textwidth}

\usepackage[none]{hyphenat}
\sloppy

\begin{document}
\frontmatter

\mainmatter
\pagestyle{Biblestyle}
\newlength{\myIndent}
\begin{center}
THE BOOK OF\\
\vspace{0.15cm}\textbf{\Huge{PSALMS}}\vspace{0.00cm}\\
\end{center}

\renewcommand{\chaptertitle}{Psalms}
\setcounter{section}{115}

%\pdfbookmark[1]{116}{19O116}
\defhowwide
\section{}
\settowidth{\myIndent}
{\IndOne I love the \textsc{Lord}, because he hath heard my voice and my supplications.}
\ifdimless{\the\myIndent}
{\textwidth-\howwide}
{\IndOne I love the \textsc{Lord}, because he hath heard my voice and my supplications. \stepcounter{subsection}
\subsection{} \IndOne Because he hath inclined his ear unto me, therefore will I call upon him as long as I live.}
{\IndTwo I love the \textsc{Lord}, because he hath heard my voice and my supplications. \stepcounter{subsection} \subsection{} Because he hath inclined his ear unto me, therefore will I call upon him as long as I live.}
\subsection{} The sorrows of death compassed me, and the pains of hell gat hold upon me: I found trouble and sorrow.
\subsection{} Then called I upon the name of the \textsc{Lord}; O \textsc{Lord}, I beseech thee, deliver my soul.
\subsection{} Gracious is the \textsc{Lord}, and righteous; yea, our God is merciful.
\subsection{} The \textsc{Lord} preserveth the simple: I was brought low, and he helped me.
\subsection{} Return unto thy rest, O my soul; for the \textsc{Lord} hath dealt bountifully with thee.
\subsection{} For thou hast delivered my soul from death, mine eyes from tears, and my feet from falling.
\subsection{} I will walk before the \textsc{Lord} in the land of the living.
\subsection{} I believed, therefore have I spoken: I was greatly afflicted:
\subsection{} I said in my haste, All men are liars.
\subsection{} What shall I render unto the \textsc{Lord} for all his benefits toward me?
\subsection{} I will take the cup of salvation, and call upon the name of the \textsc{Lord}.
\subsection{} I will pay my vows unto the \textsc{Lord} now in the presence of all his people.
\subsection{} Precious in the sight of the \textsc{Lord} is the death of his saints.
\subsection{} O \textsc{Lord}, truly I am thy servant; I am thy servant, and the son of thine handmaid: thou hast loosed my bonds.
\subsection{} I will offer to thee the sacrifice of thanksgiving, and will call upon the name of the \textsc{Lord}.
\subsection{} I will pay my vows unto the \textsc{Lord} now in the presence of all his people,
\subsection{} In the courts of the \textsc{Lord}'s house, in the midst of thee, O Jerusalem. Praise ye the \textsc{Lord}.

%\pdfbookmark[1]{117}{19O117}
\defhowwide
\section{}
\settowidth{\myIndent}
{\IndOne O praise the \textsc{Lord}, all ye nations: praise him, all ye people.}
\ifdimless{\the\myIndent}
{\textwidth-\howwide}
{\IndOne O praise the \textsc{Lord}, all ye nations: praise him, all ye people. \stepcounter{subsection}
\subsection{} \IndOne For his merciful kindness is great toward us: and the truth of the \textsc{Lord} endureth for ever. Praise ye the \textsc{Lord}.}
{\IndTwo O praise the \textsc{Lord}, all ye nations: praise him, all ye people. \stepcounter{subsection} \subsection{} For his merciful kindness is great toward us: and the truth of the \textsc{Lord} endureth for ever. Praise ye the \textsc{Lord}.}

%\pdfbookmark[1]{118}{19O118}
\defhowwide
\section{}
\settowidth{\myIndent}
{\IndOne O give thanks unto the \textsc{Lord}; for he is good: because his mercy endureth for ever.}
\ifdimless{\the\myIndent}
{\textwidth-\howwide}
{\IndOne O give thanks unto the \textsc{Lord}; for he is good: because his mercy endureth for ever. \stepcounter{subsection}
\subsection{} \IndOne Let Israel now say, that his mercy endureth for ever.}
{\IndTwo O give thanks unto the \textsc{Lord}; for he is good: because his mercy endureth for ever. \stepcounter{subsection} \subsection{} Let Israel now say, that his mercy endureth for ever.}
\end{document}

-

Observe that it is possible insert the code snippet \needspace{3\baselineskip} into the middle argument of the \titleformat command, as in

\titleformat{\section}{\needspace{3\baselineskip}}{\lettrine{\thesection}}{0em}
{}[\vskip-1\baselineskip]


This must be preferable to inserting the instruction just in front of each \section command. (Note that the \Needspace macro is less precise than \needspace in determining how much space there's left on the page.)

On a different subject, I've noticed that you have a lot of instances of \textsc{Lord}; you may want to consider loading the xspace package, defining a macro such as

\newcommand{\Lord}{\textsc{Lord}\xspace}


and then doing a global change from \textsc{Lord} to \Lord in the body of the document. I'm surmising that this would make the code quite a bit more readable. Plus, if you ever want to change the "style" of the Lord's appellation (e.g., add a color), you'll only need to do so in one instance, i.e., in your document's preamble.

Addendum: I can't help make but make two more quick observations related to the formatting/appearance of the document. First, verse 116:6 has a single, very short word ("me") on the second line; if you insert a tie (tilde) between the words "helped" and "me", you'll force the whole verse to occupy only one line. (A side benefit is that the entire 117th Psalm will now fit on the page as well.) Second, despite the fact that their size is \small, the numerals at the start of each verse are quite obtrusive in appearance (in part because they're in boldface). Have you considered assigning them the size \footnotesize instead of \small?

-
Very nice idea :-) –  ℝaphink Sep 7 '11 at 15:39
Note titlesec has the functionality provided by needspace built in (in fact, iir, the latter is based on titlesec). On the other hand, I wonder if the wrap' shape would be better than lettrine. –  Javier Bezos Sep 7 '11 at 16:51

I have found this previous answer to another question which seems to work when I use it modified as \Needspace*{3\baselineskip}

pagebreak if only 1/4th of the page left?

-
Very nice! You can probably add this in the \LettrineFontHook`. –  ℝaphink Sep 6 '11 at 10:12