如何积累引言并把它们全部贴在书的末尾?

如何积累引言并把它们全部贴在书的末尾?

我想在我的书中说这样的话:

Text... \quote{Life is great}

Other text \quote{Sky is blue}

我需要所有这些引言都出现仅有的在书的最后,在附录中。我该怎么做?也许有一些软件包可以做到这一点?

答案1

可以使用令牌寄存器保存文本以供日后使用:

\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}

在此处输入图片描述

为了在引文末尾添加“(p. X)”,您可以按照如下方式操作;该\save@this@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}

相关内容