如何標記出現的所有關鍵字,然後引用包含相同標記的所有頁面?

如何標記出現的所有關鍵字,然後引用包含相同標記的所有頁面?

我正在編寫具有特定課程要求的教學大綱。活動都標有這些要求以證明一致性。我想使用標籤或索引系統來標記對齊實例,然後引用發生對齊實例的所有頁面。

是否有一個套件可以引用包含相同標籤的所有頁面(如索引中所示),但允許我在文件中的任意位置列印該標籤的頁面?

這種需求似乎有 \label - \ref 和 \index 的元素。

我沒有最小的工作範例,但我想要的看起來像這樣。

\documentclass{article}
\begin{document}
\begin{description}
\item[CR1] This is a description of a requirement. \\ See page <LIST OF PAGES LABELED WITH CR1>
\item[CR2] This is a description of another requirement. \\ See page <LIST OF PAGES LABELED WITH CR2>
\end{description}

\section{Section 1}
This is an activity aligned with CR1. (\label{CR1} or \index{CR1})

This is an activity aligned with CR2. (\label{CR2} or \index{CR2})
\section{Section 2}
This is another activity aligned with CR1. (\label{CR1} or \index{CR1})

\end{document}

答案1

我看到 Nicola 剛剛做了一個詞彙表版本,但這是我的準系統 makeindex 版本。

在此輸入影像描述

您只需要一種索引樣式,將每個頁面清單保存在定義中而不是排版中,例如foo.ist

preamble
"\n\\makeatletter{"
postamble
"}\n\\makeatother\n"

item_0 "}\n\\@namedef{"
delim_0 "}{"

然後

pdflatex file
makeindex -s foo.ist file
pdflatex file

應該從類似的文檔中產生上述輸出

\documentclass{article}
\usepackage{makeidx}
\makeindex
\def\listfor#1{\csname #1\endcsname}
\begin{document}

\printindex

\begin{description}
\item[CR1] This is a description of a requirement. \\ See pages \listfor{CR1}
\item[CR2] This is a description of another requirement. \\ See pages \listfor{CR2}
\end{description}

\section{Section 1}
This is an activity aligned with CR1\index{CR1}.

aa
\clearpage

This is an activity aligned with CR2\index{CR2}.
\section{Section 2}
This is another activity aligned with CR1\index{CR1}.

\section{Section 3}
This is an activity aligned with CR1\index{CR1}.


aa
\clearpage

This is an activity aligned with CR2\index{CR2}.
\section{Section 4}
This is another activity aligned with CR1\index{CR1}.


aa
\clearpage

aa
\clearpage

This is an activity aligned with CR2\index{CR2}.
\section{Section 4}
This is another activity aligned with CR1\index{CR1}.

\end{document}

答案2

這是一個使用的範例glossaries:

\documentclass{article}

\usepackage[colorlinks]{hyperref}% optional but if needed must come 
                                 % before glossaries.sty
\usepackage[nopostdot]{glossaries}

\makeglossaries

% syntax: \newglossaryentry{label}{options}
\newglossaryentry{CR1}{name={CR1},
 description={This is a description of a requirement.}}

% Or
% syntax: \longnewglossaryentry{label}{options}{description}

\longnewglossaryentry{CR2}{name={CR2}}%
{This is a description of another requirement.

With a paragraph break.
}

\begin{document}
\printglossary[title={Requirements}]

\section{Section 1}
This is an activity aligned with CR1.\glsadd{CR1}% index only

This is an activity aligned with \gls{CR2}.% index and show name

\section{Section 2}

This is an activity aligned with \gls{CR1}.% index and show name

\end{document}

建置過程(假設檔案名稱myDoc.tex):

pdflatex myDoc
makeglossaries myDoc
pdflatex myDoc

makeglossaries是一個 Perl 腳本,它調用makeindex所有必要的開關集。

或者,如果您沒有安裝 Perl,可以使用一個輕量級 Lua 腳本:

pdflatex myDoc
makeglossaries-lite myDoc
pdflatex myDoc

任一建置過程都會產生:

文件影像

紅色文字表示超連結。描述後面1是引用該條目的頁碼。

附有擴充包glossaries-extra您可以使用該選項單獨抑制自動索引noindex

\documentclass{article}

\usepackage[colorlinks]{hyperref}% optional but if needed must come 
                                 % before glossaries.sty
\usepackage{glossaries-extra}

\makeglossaries

% syntax: \newglossaryentry{label}{options}
\newglossaryentry{CR1}{name={CR1},
 description={This is a description of a requirement.}}

% Or
% syntax: \longnewglossaryentry{label}{options}{description}

\longnewglossaryentry{CR2}{name={CR2}}%
{This is a description of another requirement.

With a paragraph break.
}

\begin{document}
\printglossary[title={Requirements}]

\section{Section 1}
This is an activity aligned with CR1.\glsadd{CR1}% index only

This is an activity aligned with \gls{CR2}.% index and show name

\newpage

\section{Section 2}

This is an activity aligned with \gls{CR1}.% index and show name

Some minor reference to \gls[noindex]{CR2} that doesn't need
indexing.

\end{document}

建置過程是相同的。

您可以變更樣式。例如:

\printglossary[title={Requirements},style=index]

有大量預定義樣式可供選擇

為了供日後參考,很快就會有另一種方法使用bib2gls代替makeglossaries/ makeglossaries-lite。我已將其添加到此處,以防以後有人發現此問題。

建立一個.bib名為的文件,例如requirements.bib

@entry{CR1,
  name={CR1},
  description={This is a description of a requirement.}
}

@entry{CR2,
  name={CR2},
  description={This is a description of another requirement.

  With a paragraph break.}
}

該文件myDoc.tex現在是:

\documentclass{article}

\usepackage[colorlinks]{hyperref}% optional but if needed must come 
                                 % before glossaries.sty
\usepackage[record]{glossaries-extra}

\GlsXtrLoadResources[src={requirements}]% data in requirements.bib

\begin{document}
\printunsrtglossary[title={Requirements}]

\section{Section 1}
This is an activity aligned with CR1.\glsadd{CR1}% index only

This is an activity aligned with \gls{CR2}.% index and show name

\newpage

\section{Section 2}

This is an activity aligned with \gls{CR1}.% index and show name

Some minor reference to \gls[noindex]{CR2} that doesn't need
indexing.

\end{document}

建置過程是:

pdflatex myDoc
bib2gls myDoc
pdflatex myDoc

沒有呼叫makeindex同時bib2gls從文件中取得和排序條目.bib並收集文件中的位置.aux

這裡的區別在於record選項 和 的使用\GlsXtrLoadResources。該命令\makeglossaries不是必需的,並且現在打印詞彙表\printunsrtglossary而不是\printglossary

相關內容