1

I want to say something like this in my book:

Text... \quote{Life is great}

Other text \quote{Sky is blue}

I need all that quotes to show up only at the end of the book, in an Appendix. How can I do that? Maybe there is some package for that?

  • Do you also need a reference to the page? Does tex.stackexchange.com/questions/187478/… help? – egreg Sep 23 '16 at 21:31
  • @egreg no, I don't need a reference to that page. The link you gave looks very close, but the solution it suggests looks over complicated. Maybe you can explain how I can do it using just \def and \expandafter? – yegor256 Sep 23 '16 at 21:58
4

Saving text for later usage can be done with a token register:

\documentclass{article} % for simplicity

\makeatletter
\newtoks\save@quotes
\newcommand{\quoteatend}[1]{%
  \@bsphack % this should be transparent with respect to spaces
  \global\save@quotes=\expandafter{\the\save@quotes#1\par}%
  \@esphack
}
\newcommand{\printquotes}{\par\the\save@quotes}
\makeatother

\begin{document}

\section{Main}

Text here \quoteatend{Life is great}

Other text \quoteatend{Sky is blue}

\appendix

\section{Quotes}

The quotes follow

\medskip

\printquotes

\end{document}

enter image description here

In order to add “(p. X)” at the end of the quote, you can do like as follows; the \save@this@quote macro can be used for further formatting the quote.

\documentclass{article} % for simplicity

\makeatletter
\newtoks\save@quotes
\newcounter{save@quote}
\newcommand{\quoteatend}[1]{%
  \@bsphack % this should be transparent with respect to spaces
  \refstepcounter{save@quote}%
  \label{quote@\romannumeral\value{save@quote}}%
  \protected@edef\save@temp{%
    \the\save@quotes
    \noexpand\save@this@quote{#1}{quote@\romannumeral\value{save@quote}}%
  }
  \global\save@quotes=\expandafter{\save@temp\par}%
  \@esphack
}
\newcommand{\save@this@quote}[2]{#1~(p.~\pageref{#2})}
\newcommand{\printquotes}{\par\the\save@quotes}
\makeatother

\begin{document}

\section{Main}

Text here \quoteatend{Life is great}

Other text \quoteatend{Sky is blue}

\appendix

\section{Quotes}

The quotes follow

\medskip

\printquotes

\end{document}
  • works perfectly! What if I need to say what pages that quotes were seen? Is it possible to adjust your code a bit, or it's a completely different story? – yegor256 Sep 23 '16 at 23:35
  • 1
    @yegor256 Some more work; that's why I asked if you need references. Stay tuned. – egreg Sep 24 '16 at 6:26
  • many thanks, works perfectly! Will be used in this book: yegor256.com/256-bloghacks.html – yegor256 Sep 24 '16 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.