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?
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}
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}
\defand\expandafter? – yegor256 Sep 23 '16 at 21:58