Как можно пометить все вхождения ключевого слова, а затем сослаться на все страницы, содержащие этот же тег?

Как можно пометить все вхождения ключевого слова, а затем сослаться на все страницы, содержащие этот же тег?

Я пишу учебную программу с определенными учебными требованиями. Действия помечены этими требованиями, чтобы продемонстрировать соответствие. Я хочу использовать систему маркировки или индексации, чтобы помечать случаи соответствия, а затем ссылаться на все страницы, где встречается случай соответствия.

Существует ли пакет, который будет ссылаться на все страницы, содержащие одну и ту же метку, как в индексе, но позволит мне распечатать страницы для этой метки в произвольной точке документа?

Эта потребность, по-видимому, имеет элементы \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

Я вижу, что Никола только что сделал версию с глоссарием, но вот моя минимальная версия 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.

Связанный контент