[Tex/LaTex] Quote environment with reference at the end right

environmentsline-breakingquoting

I want to define a quote environment such that after the quote on the right occurs the author with page number. My solution is yet the redefinition of the quote environment

\usepackage{amsthm} % pushQED, popQED
\newenvironment{aquote}[1]{%
  \pushQED{#1}%
  \begin{quote}
}{%
  \par\nointerlineskip\noindent\hfill(\popQED)%
  \end{quote}%
}

with the following result:

The drawback is the parskip in front of the author, which wastes some space in the first quote, but is right in the second one. If I change my command to:

\newenvironment{aquote}[1]{%
  \pushQED{#1}%
  \begin{quote}
}{%
  \noindent\hfill(\popQED)%
  \end{quote}%
}

I get the following result:

Now the placement of the author's name in the first quote is perfect, but in the second quote I want a parskip in front, like in my first example.

How can I find out, whether the line has enough space to put the author without a parskip behind or if there is not enough space to introduce a parskip to put the author on the next line?

Best Answer

There's a nice \signed macro that serves this purpose on page 106 of the TeXbook; here's a little variation used to build the aquote environment which behaves as expected;

\documentclass{book}

\def\signed #1{{\leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
  \hbox{}\nobreak\hfil(#1)%
  \parfillskip=0pt \finalhyphendemerits=0 \endgraf}}

\newsavebox\mybox
\newenvironment{aquote}[1]
  {\savebox\mybox{#1}\begin{quote}}
  {\signed{\usebox\mybox}\end{quote}}

\begin{document}

\begin{aquote}{Bourbaki}
This is a case where the name fits in nicely with the quote so the name will appear in the same line.
\end{aquote}

\begin{aquote}{Nicolas Bourbaki}
This is a case where the name won't fit in nicely with the quote, and in this case the name will be moved to the next line.
\end{aquote}

\end{document}

Here's the result:

enter image description here

Related Question