自动排序附录

自动排序附录

我想知道是否可以自动排序附录(就像使用 bibtex 排序参考文献一样),这样如果文本中的参考文献发生变化,我就不必一直更改它。例如:

\documentclass[10pt]{article}

\usepackage{appendix}

\begin{document}

Hi, this is a document to ask a question about appendix references and auto updating them.

For example, first I referred to appendix "\,Example 1"\, here, by using \ref{appendix:1} 
and after that, I used the reference for appendix \ref{appendix:2}.


\newpage
\begin{appendices}

\section{Example 1}
\label{appendix:1}
\newpage

\section{Example 2}
\label{appendix:2}

\end{appendices}

\end{document}

这是我当前的代码,但是我希望能够引用附录而不需要更改它,就像我使用 Bibtex 作为参考一样。因此,当我将其更改为:

\documentclass[10pt]{article}

\usepackage{appendix}

\begin{document}

Hi, this is a document to ask a question about appendix references and auto updating them.

Now I refer to to appendix "\,Example 2"\, first, by using \ref{appendix:2} 
and after that, I used the reference for appendix \ref{appendix:1}.


\newpage
\begin{appendices}

\section{Example 1}
\label{appendix:1}
\newpage

\section{Example 2}
\label{appendix:2}

\end{appendices}

\end{document}

但是,这不会自动将附录 B 更新为附录 A,反之亦然。有人知道我可以使用的方法吗,也许是类似于 Bibtex 的方法,但适用于附录?我希望问题清楚,如果我忘记了什么,请随时询问。

答案1

此解决方案使用 endfloat 将示例从正文移至附录。优点是它将文本保存到另一个文件 (.eee),而不是占用 RAM。主要缺点是示例只能占一页。

\documentclass[10pt]{article}
\usepackage{appendix}
\usepackage[nolists,nomarkers,nofigures,notables]{endfloat}

\newenvironment{example}[1]% #1 = label
{\minipage[t][0.5\textheight][t]{\textwidth}%
  \section{Example \arabic{section}}\label{#1}}
{\endminipage}%\oldendexample}

\DeclareDelayedFloat{example}[eee]{List of Examples}

\begin{document}

Hi, this is a document to ask a question about appendix references and auto updating them.

For example, first I referred to appendix "\,Example 1"\, here, by using \ref{appendix:1} 
\begin{example}{appendix:1}
  First example
\end{example}
and after that, I used the reference for appendix \ref{appendix:2}.
\begin{example}{appendix:2}
  Second example
\end{example}


\newpage
\begin{appendices}
\processdelayedfloats
\end{appendices}

\end{document}

此解决方案将示例保存为宏。它的优点是比 endfloat 更具适应性。它的主要缺点是必须立即扩展内容。

\documentclass[10pt]{article}
\usepackage{appendix}
\usepackage{environ}

\newcounter{example}
\NewEnviron{example}[1]% #1 = label
{\stepcounter{example}%
  \expandafter\xdef\csname examplelabel.\arabic{example}\endcsname{#1}%
  \expandafter\xdef\csname example.\arabic{example}\endcsname{\BODY}%
}

\newcommand{\ProcessExamples}{\bgroup
  \count1=0
  \loop\ifnum\count1 < \value{example}\relax
    \advance\count1 by 1
    \section{Example \number\count1}%
    \label{\csname examplelabel.\number\count1\endcsname}%
    \csname example.\number\count1\endcsname
    \newpage
  \repeat
\egroup}


\begin{document}

Hi, this is a document to ask a question about appendix references and auto updating them.

For example, first I referred to appendix "\,Example 1"\, here, by using \ref{appendix:1} 
\begin{example}{appendix:1}
  First example
\end{example}
and after that, I used the reference for appendix \ref{appendix:2}.
\begin{example}{appendix:2}
  Second example
\end{example}

\newpage
\begin{appendices}
\ProcessExamples
\end{appendices}

\end{document}

相关内容