在章节内编写附录的 Latex 代码,但在书的末尾排版

在章节内编写附录的 Latex 代码,但在书的末尾排版

是否可以在实际章节中输入附录部分的源代码,但在书的最后一章之后排版?

例如,代码中如下所示的内容:

\chapter{Chapter 1}
\section{Section 1}
This is the first section of the first chapter. For details see Appendix 1.
\begin{appendices}
\section{Appendix for Chapter 1, Section 1}
Here is additional information that is typeset at the end of the book.
\end{appendices}
\chapter{Chapter 2}
\section{A new section}
This is a new section in the second Chapter. Even though I add a new appendix here, it will become consolidated with the first appendix at the end of the book.
\begin{appendices}
\section{Appendix for a new section}
This is the appendix for "A new section" in Chapter 2
\end{appendices}

并产生以下输出:

第1章

1.1 第 1 节

本篇为第一章第一节,具体内容见附录1。

第2章

2.1 新部分

这是第二章的一个新章节。虽然我在这里添加了一个新附录,但它将与书末的第一个附录合并。

附录

A. 第 1 章第 1 节附录

这是排版在书末的附加信息。

B. 新章节的附录

这是第 2 章“新章节”的附录

答案1

这是https://tex.stackexchange.com/a/186907/4427

\documentclass{book}
\usepackage{environ}

\newtoks\mainnotetoks
\newtoks\tempnotetoks
\newtoks\prenotetoks
\newtoks\postnotetoks

\NewEnviron{appendixatend}{%
  \tempnotetoks=\expandafter{\BODY}%
  \edef\notetemp{%
    \the\mainnotetoks % what was already stored
    \the\prenotetoks % text before the new note
    \the\tempnotetoks % the current note
    \the\postnotetoks % text after the new note
  }%
  % update \mainnotetoks
  \global\mainnotetoks=\expandafter{\notetemp}%
}
\newcommand\includeappendices{%
  \appendix
  \chapter*{Appendix}
  \renewcommand{\thesection}{\Alph{section}}
  \the\mainnotetoks}

% set the pre and post note
\prenotetoks={}
\postnotetoks={}

\begin{document}
\mainmatter

\chapter{Chapter 1}
\section{Section 1}
This is the first section of the first chapter. For details see Appendix 1.
\begin{appendixatend}
\section{Appendix for Chapter 1, Section 1}
Here is additional information that is typeset at the end of the book.
\end{appendixatend}
\chapter{Chapter 2}
\section{A new section}
This is a new section in the second Chapter. Even though I add a new appendix here, it will become consolidated with the first appendix at the end of the book.
\begin{appendixatend}
\section{Appendix for a new section}
This is the appendix for "A new section" in Chapter 2
\end{appendixatend}

\includeappendices
\end{document}

在此处输入图片描述

答案2

把内容做成一个宏,然后把这个宏放在书的最后:

\def\LastChapter{.....}

...

\LastChapter

相关内容