7

Is there any way to show all colored words at the end of a document?

Say I'm marking definitions as red and theorems as blue.

Is it possible to make a list of "keywords" where all red words is listed, and another list with all blue words.

Something like this

\documentclass[12pt,a4paper]{article}
\usepackage{color}

    \newcommand{\RC}{\textcolor{red}}
    \newcommand{\BC}{\textcolor{blue}}

\begin{document}
\RC{red1} test

\BC{blue1} test

\BC{blue2} test

\RC{red2} test

    \vfill

\RC{Definitions:}
\begin{itemize}
\item red1
\item red2
\end{itemize}

    \bigskip

\BC{Theorems:}
\begin{itemize}
\item blue1
\item blue2
\end{itemize}
\end{document}
Labbiqa
  • 317
  • 2
  • 9

1 Answers1

9

You can use, for example, this definition of \RC, \BC:

\documentclass[12pt,a4paper]{article}
\usepackage{color}

\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\RC#1{\addto\RClist{\item#1}\textcolor{red}{#1}}
\def\BC#1{\addto\BClist{\item#1}\textcolor{blue}{#1}}
\def\RClist{}
\def\BClist{}

\begin{document}
\RC{red1} test

\BC{blue1} test

\BC{blue2} test

\RC{red2} test

    \vfill

\textcolor{red}{Definitions:}
\begin{itemize}
\RClist
\end{itemize}

    \bigskip

\textcolor{blue}{Theorems:}
\begin{itemize}
\BClist
\end{itemize}
\end{document}
wipet
  • 74,238
  • Thanks! Is there any way to make links in \RClist so that when I click on red1 in the list, it will refer to '\RC{red1} test' in the main text? – Labbiqa Feb 25 '16 at 14:17
  • I think you might want to use \gdef in the definition of \addto in case these commands are called from within some kind of scoped group. – A.Ellett Feb 25 '16 at 15:29