# Line break without page break using poetry package

The poetry package overrides \\*, which means that I can't use that to prevent page breaks in the middle of a stanza. Is there another way to create a line break while forbidding a page break at the same location? Preferably a setting, rather than adding something to the end of every line - but whatever works, works.

Example:

\documentclass[a4paper]{article}
\usepackage{poetry}

\begin{document}

Some text.
\vspace{15cm} % Force poem down page

\poem
Some poetry\\
A metaphor here,\\
A metaphor there.\\!

Here begins another stanza\\
More words.\\!

The final stanza\\
A final metaphor\\
The end\\-

\end{document}


I'd like to prevent page breaks in mid-stanza (in the final stanza in the compiled example).

• Do you need a fully automatic solution where you don't know what your input will be, or is it sufficient to correct the occasional bad page break manually? – Marijn Feb 6 '19 at 15:09
• Please provide an MWE to show the issue. – Steven B. Segletes Feb 6 '19 at 18:19
• @Marijn I don't mind having to correct by hand, but the more automatic, the better. – Watercleave Feb 6 '19 at 18:20
• @StevenB.Segletes Gladly! What's an MWE? – Watercleave Feb 6 '19 at 18:20
• MWE = Minimum Working Example. Code beginning with \documentclass and ending with \end{document}, boiled down to as small a size as possible to demonstrate the actual issue at hand. – Steven B. Segletes Feb 6 '19 at 18:22

Not sure if this is sufficient, but it allows the avoidance of 1-line widows by growing the page by \baselineskip. It is invoked with \\*

The "fix" accomplishes this by redefining \poem@endpart, which is what gets invoked via \\*. The original \poem@endpart is saved in \poemendpart

The following MWE demonstrates the use of \\* on page 1, but not on page 2 (which wraps to page 3).

\documentclass[a4paper]{article}
\usepackage{poetry}

\makeatletter
\let\poemendpart\poem@endpart
\def\poem@endpart{\enlargethispage{\baselineskip}\poem@endline}
\makeatother
\begin{document}

Some text.
\vspace{16.2cm} % Force poem down page

\poem
Some poetry\\
A metaphor here,\\
A metaphor there.\\!

Here begins another stanza\\
More words.\\!

The final stanza\\
A final metaphor\\*
The end\\-
\clearpage
Some text.
\vspace{16.2cm} % Force poem down page

\poem
Some poetry\\
A metaphor here,\\
A metaphor there.\\!

Here begins another stanza\\
More words.\\!

The final stanza\\
A final metaphor\\
The end\\-

\end{document}


An alternative in the other direction, that is, forcing an early break, is to issue a \clearpage immediately prior to a \\, as in

\documentclass[a4paper]{article}
\usepackage{poetry}

\begin{document}

Some text.
\vspace{16.2cm} % Force poem down page

\poem
Some poetry\\
A metaphor here,\\
A metaphor there.\\!

Here begins another stanza\\
More words.\clearpage\\!

The final stanza\\
A final metaphor\\
The end\\-
\clearpage
Some text.
\vspace{16.2cm} % Force poem down page

\poem
Some poetry\\
A metaphor here,\\
A metaphor there.\\!

Here begins another stanza\\
More words.\\!

The final stanza\\
A final metaphor\\
The end\\-

\end{document}


SUPPLEMENT

This attempt tries to modify the use of \\ so that page breaks are prevented altogether. Thus, a normal verse will never break across a page boundary midway through. Seems to work for this use case.

I edited \poem@endline to begin with a \nopagebreak, so that a break did not occur at such a line. However, additional instances of \nopagebreak needed to be added in the macro \placelineno, after instances of \hskip, to prevent pagebreaks following the line number (but before the verse line). I don't think I got them all, but enough to demonstrate the effect in the OP's MWE.

\documentclass[a4paper]{article}
\usepackage{poetry}

\makeatletter

\def\poem@endline{\nopagebreak%
\par%
\poem@defaultpars%
\leftskip=\poem@defleftskip%
\placelineno%
}%

\def\placelineno{%
\setcounter{verseline}{\the\vslineno}%
\setcounter{poemline}{\the\poemlineno}%
\poem@linenumsevery=\value{poemlinenumsevery}%
\poem@linenumboxgap=\the\poemlinenumboxgap%
\poem@linenumboxwd=\the\poemlinenumboxwd%
\modulo{\the\poemlineno}{\the\poem@linenumsevery}%
\ifpoemlinenums%
\ifnum\poem@tmpa=0%
\ifpoemlinenumright%
\hskip0pt\nopagebreak\tlap{%
\rlap{%
\hskip\poem@maxlinewd%
\hskip\poem@linenumboxgap%
\hbox to\poem@linenumboxwd{%
\hfil%
\poemlinenumstyle\thepoemline%
}%
}%
}%
\else%
\hskip-\poem@linenumboxgap\nopagebreak%
\llap{%
\tlap{%
\hbox to\poem@linenumboxwd{%
\poemlinenumstyle\thepoemline%
\hfil%
}\penalty10000%
}%
}\penalty10000%
\fi%
\else
\hskip-\poem@linenumboxgap\nopagebreak%
\llap{\tlap{\hbox to\poem@linenumboxwd{\hfil}}}%
\penalty10000%
\fi%
\else
\hskip-\poem@linenumboxgap\nopagebreak%
\llap{\tlap{\hbox to\poem@linenumboxwd{\hfil}}}%
\penalty10000%
\fi%
\par\vskip-\baselineskip%
\poem@indentevery=\value{poemindentevery}%
\ifnum\poem@indentevery=0%
\else%
\modulo{\the\poemlineno}{\the\poem@indentevery}%
\ifnum\poem@tmpa=0%
\hin%
\fi%
\fi%
\expandafter\poem@expandvsloop\expandafter{\poemvsindentlines}%
\def\@currentlabel{\thepoemline}%
\phantomsection%
}%

\let\poemendpart\poem@endpart
\def\poem@endpart{\enlargethispage{\baselineskip}\poem@endline}
\makeatother
\begin{document}

Some text.
\vspace{16.2cm} % Force poem down page

\poem
Some poetry\\
A metaphor here,\\
A metaphor there.\\!

Here begins another stanza\\
More words.\\!

The final stanza\\
A final metaphor\\*
The end\\-
\clearpage
Some text.
\vspace{16.2cm} % Force poem down page

\poem
Some poetry\\
A metaphor here,\\
A metaphor there.\\!

Here begins another stanza\\
More words.\\!

The final stanza\\
A final metaphor\\
The end\\-

\end{document}

• Thanks! Is it possible to redefine \ to \nopagebreak followed by the existing \ command? Would that work? – Watercleave Feb 8 '19 at 12:30
• @Watercleave Do you really mean \`? That is a macro that places a grave accent over a letter. – Steven B. Segletes Feb 8 '19 at 13:50
• @Watercleave See SUPPLEMENT to my answer. – Steven B. Segletes Feb 8 '19 at 15:15
• Ah, markup error. I meant \\ (double backslash), the short line break command. – Watercleave Feb 9 '19 at 17:22