
假設我有一個大文檔,在整個文檔中使用了多個宏,例如\AAA
、等。\BBB
有沒有辦法在最終的 pdf 中列出所有這些巨集?例如,我想\AAA
在開頭重複所有調用,以便在編寫文件時快速瀏覽它們。
一項可選功能將使用 hyperref 單擊\AAA
列表之一直接進入實際使用巨集的 pdf 頁面。
答案1
\hypertarget
您可以在 的每次呼叫中放入\AAA
,其中名稱使用計數器。之後您可以透過 來引用它\hyperlink
。
在範例中\AAA No. 1
, 等是可點擊的連結。
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{pgffor,hyperref}
\newcount\countAAA
\countAAA=0
\newcommand*\AAA{%
\advance\countAAA by 1%
\hypertarget{AAA\the\countAAA}{}%
AAA% your replacement text goes here
}
\newcommand\blindtext{\par\noindent Lorem ipsum dolor sit amet \par\noindent}
\begin{document}
\section{Some text with \texttt{\string\AAA} macros}
\blindtext
\AAA
\blindtext
\AAA
\blindtext
\AAA
\blindtext
\AAA
\section{List of \texttt{\string\AAA} calls}
There are \the\countAAA\ calls of \texttt{\string\AAA} throughout the document.
\foreach \i in {1,...,\the\countAAA} {
\hyperlink{AAA\i}{\texttt{\string\AAA} No.\ \i}
}
\end{document}