在文档末尾附加附录

在文档末尾附加附录

我正在寻找一种方法来在我的 TeX 文本流中写入附录,并在渲染期间将它们在文档末尾拒绝。

主要动机是,我不断地将内容移入和移出附录,例如,为了对主文档实施一些大小限制。因此,我不想物理地移动文本。在环境中包装它会更方便。

例如,我会写类似这样的内容:

\section{The Premisses}

Bananas are yellow. More info can be found in the appendices.

\begin{appendix}
    \section{On The Colour Of Bananas}
    The assumption that bananas are yellow was derived
    from a rigorous field study. The following table
    gathers collected data.
    ....
    ....
\end{appendix}


\section{The Shocking Truth}

Not only are bananas yellow, but pineapples, too.
Refer to appendices for a visual proof sketch.

\begin{appendix}
    \section{On The Yellow-Tooness of Pineapples}
    Here is a picture that evidences that pineapples
    are yellow.
           .    .
          / \  / \
          \_/__\_/
         /\/\/\/\/\
        /\/\/\/\/\/\
        \/\/\/\/\/\/
         \/\/\/\/\/
          \/\/\/\/
\end{appendix}


\section{The Conclusion}

It appears that most fruits are yellow.

我会得到类似这样的信息:

1. The premisses
...
2. The Shocking Truth
...
3. The Conclusion
...
Appendix A. On The Colour Of Bananas
...
Appendix B. On The Yellow‐Tooness of Pineapples
...

有没有专门的方法来实现这一点?否则,有什么更简洁的解决方法吗?

如果重要的话,我正在使用文档类acmart,并且我的文档的各个部分位于单独的文件中找到\input

答案1

我不知道有哪个包可以做到这一点,但是使用LaTeX3做到这一点相当容易。首先,请注意,已经有一个\appendix命令,因此您无法调用您的环境appendix(因为\begin{XXX}...会进行一些初始化,然后插入\XXX到输入流中...)。

下面的代码定义了一个名为的新环境Appendix。此环境使用环境将环境中的内容放入一个包中LaTeX3\AtEndDocument“序列”。在文档的末尾,使用电子工具箱包。最终结果是您的 MWE 生成:

在此处输入图片描述

完整代码如下:

\documentclass{acmart}
\usepackage{expl3}
\usepackage{environ}
\ExplSyntaxOn
\seq_new:N \g_appendices_seq% define a sequence for holding the appendices
\NewEnviron{Appendix}{\seq_gput_right:No \g_appendices_seq \BODY}
\newcommand\AddAppendices{% regurgitate the appendices
  \appendix% turn all subsequent sections into appendices
  \seq_map_inline:Nn \g_appendices_seq {##1}
}
\ExplSyntaxOff

% automatically print the appendices at the end of the document
\usepackage{etoolbox}
\AtEndDocument{\AddAppendices}

\begin{document}

\section{The Premisses}

Bananas are yellow. More info can be found in the appendices.

\begin{Appendix}
    \section{On The Colour Of Bananas}
    The assumption that bananas are yellow was derived
    from a rigorous field study. The following table
    gathers collected data.
    ....
    ....
\end{Appendix}

\section{The Shocking Truth}

Not only are bananas yellow, but pineapples, too.
Refer to appendices for a visual proof sketch.

\begin{Appendix}
    \section{On The Yellow-Tooness of Pineapples}
    Here is a picture that evidences that pineapples
    are yellow.
\end{Appendix}

\section{The Conclusion}

It appears that most fruits are yellow.

\end{document}

相关内容