37

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?

1
  • Welcome for TeX.SX. I included the images for you. Note if you want to edit your question before you got 10rep points you need to change them to links by removing the ! in front of them. Mar 17, 2011 at 22:38

4 Answers 4

51

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

7
  • Thank you! Exactly, what I searched for. Also many thanks for the exact reference in the TeXbook. Mar 18, 2011 at 7:31
  • Why do you need the the \savebox? Is parameter #1 otherwise unavailable in the closing part of the environment? Mar 18, 2011 at 19:22
  • 3
    @Christian Lindig: yes,you are right, when defining a new environment, you cannot specify parameters directly in the closing part of the definition; the standard trick is to store them in boxes in the opening part and use the boxes in the closing part. Mar 18, 2011 at 19:37
  • 1
    ` {\savebox\mybox{(\expandafter\scantokens\expandafter{\detokenize{#1}}\unskip)}\begin{quote}\it} ` allow to use \bibleref inside when : has a 13 catcode. Cf framagit.org/maieul/bibleref/issues/13#note_283589
    – Maïeul
    Jul 28, 2018 at 12:20
  • 1
    @GonzaloMedina : would it be possible to modify this aquote environment to cancel the white space that comes after it (to use it in a footnote, for example)? Thanks.
    – Tobard
    Aug 13, 2018 at 10:26
15

Also for completeness, please refer to the attrib package. You can approximate the effect you want with the following:

\begin{quote}
  We call a disposition the arrangement of that which has parts, in respect 
  either of place or of capacity or of kind; for there must be a certain 
  position, as the word ‘disposition’ shows.

  \attrib{{\em Metaphysics} {\greektext D}.19, 1022b1--3}
\end{quote}
4
  • Welcome to TeX.sx! Mar 11, 2013 at 17:22
  • This doesn't answer the question, though, because it will always put the attribution on a new line, even if there's room on the existing one.
    – cfr
    Jan 9, 2016 at 2:01
  • @cfr If you don't put the blank line between the paragraph and \attrib, the reference will appear in-line. See the examples in the documentation for the LaTeX Frankenstein package. Apr 9, 2017 at 18:32
  • 1
    @phantom-99w Which sort of proves my point.
    – cfr
    Apr 9, 2017 at 20:54
12

I just want to add for completeness that the memoir package provides the

\sourceatright[⟨length⟩]{⟨text⟩}

command, which can be used immediately after a quote or quotation environment and does what the question asks.

8

In my opinion, the simplest variant I found to achieve this

\begin{quote}
  The only way to make the deadline—the only way to go fast—is to keep the code as clean as possible at all times.
  \begin{flushright}
    \tiny{---Robert C. Martin, Clean Code}
  \end{flushright}
\end{quote}

enter image description here

1
  • Like the answer above this doesn't answer the question, because it will always put the author on a new line, even if there's room on the existing one.
    – dexteritas
    Jan 11, 2018 at 9:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .