[Tex/LaTex] How to prevent a page break between paragraphs

epigraphsmacrospage-breaking

I would like to typeset something like a "quote plus attribution", e.g. at the beginning of a book chapter. It should look like this:

CHAPTER TITLE

       This  is an  introductory quote.
       It's stylistically questionable,
       but it's a fun LaTeX exercise.

                         -- said by  me

Now starts the main body text, which is not rele-
vant to this question. It just goes on and on and
on and on.
    It just looks like ordinary text.  You do not
have to keep reading.

For this purpose, I have an environment and a command, used like this:

\section{Chapter Title}

\begin{fooquote}
This is an introductory quote % etc. etc.
\quoteattribution{-- said by me}
\end{fooquote}

Question: How can I guarantee that there is no page break between the attribution and the body of the quote? I don't mind if there's a page break within the quote, but there shouldn't be one between the quote and the attribution.

I'm happy to change my entire setup if that's necessary. In my case, it's like this:

\newenvironment{fooquote}%
{ \bgroup
  \let\oldend=\end
  \def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname
                          \csname @afterheading\endcsname}
  \begin{quote}%
  \itshape%
}{%
  \end{quote}
  \egroup
}
\newcommand{\quoteattrib}[1]{\normalfont\flushright#1}

Best Answer

Really it would be a lot easier to answer if there was a supplied example document, fragments are much harder to comment on but

\newenvironment{fooquote}%
{ \bgroup
  \let\oldend=\end
  \def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname
                          \csname @afterheading\endcsname}
  \begin{quote}%
  \itshape%
}{%
  \end{quote}
  \egroup
}
\newcommand{\quoteattrib}[1]{\normalfont\flushright#1}

the \bgroup \egroup are not needed as the fooquote environment is already a group, also { \bgroup introduces a space character.

The \end redefinition (which is rather dangerous really) appears to be too early it will affect the \end of any nested environment and in particular the quote environment. You just want to activate it after fooquote (I assume) so it should be right at the end of the end code of the definition.

flushright is intended to be an environment form, the declaration form being \raggedleft but if it's one line I'd probably just use \hspace{\fill}. \nopagebreak ought to be enough to prevent page breaks at that point as long as there is flexibility elsewhere in the page.

enter image description here

\documentclass{book}

\makeatletter
\newenvironment{fooquote}{%
  \begin{quote}%
  \itshape
}{%
  \end{quote}%
\par
\aftergroup\@afterindentfalse
\aftergroup\@afterheading
\ignorespacesafterend
}
\newcommand{\quoteattrib}[1]{\par\nopagebreak\normalfont\hspace*{\fill}#1\par}

\makeatother

\begin{document}

\chapter{CCC}

\begin{fooquote}
red yellow blue
\quoteattrib{me}
\end{fooquote}

One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.

One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.

\end{document}