1

once I asked in Insert key words & key phrases into toc whether it is possible to insert some keywords in the toc that it looks like this:

Contents

1 section .............................1

key word 1 - key phrase 2 - key word 3

    1.1 subsection ...............................5

    key word 1 - key phrase 2 - key word 3 -

    key word 4 - key phrase 5 - key word 6

egreg provided this answer which works perfectly well:

\documentclass[a4paper]{article}
\usepackage{etoolbox}

\makeatletter
\newif\ifsection
\newif\ifsubsection
\newtoks\keywordstoks
\preto\section{\flushkeywords\sectiontrue\subsectionfalse}
\preto\subsection{\flushkeywords\sectionfalse\subsectiontrue}
\preto\enddocument{\flushkeywords}

\newcommand{\flushkeywords}{%
    \ifsection\addtocontents{toc}{\formatkwsection{\protect\@gobble\the\keywordstoks\relax}}\fi
  \ifsubsection\addtocontents{toc}{\formatkwsubsection{\protect\@gobble\the\keywordstoks\relax}}\fi
  \keywordstoks={}}

\newcommand{\keyword}[1]{\@bsphack\keywordstoks=\expandafter{\the\keywordstoks\kwsep#1} \@esphack}
\newrobustcmd{\kwsep}{~-- }
\newrobustcmd{\formatkwsection}[1]{#1\par\medskip}
\newrobustcmd{\formatkwsubsection}[1]{{\leftskip=2.2em\relax#1\par}\smallskip}
\makeatother

\begin{document}

\tableofcontents

\section{Section}

Abc \keyword{key1} def \keyword{key2}

\subsection{Subsection}

Ciao \keyword{key3} ciao \keyword{key4}

\subsection{Another}

x

\end{document}

Now my question: Is it possible to hyperref-ize the keywords?

Philip
  • 3,415
  • It depends on what you want these hyperlinks do. – egreg Jul 27 '11 at 06:38
  • they should behave like the hyperlinked toc. If you press the cursor on the keyword in the toc, the document should "jump" to the corresponding position in the text. – Philip Jul 27 '11 at 07:16

1 Answers1

2

Change the definition of \keyword into

\newcommand{\keyword}[1]{\@bsphack
  \keywordstoks=\expandafter{%
    \the\keywordstoks\kwsep\protect\hyperlink{keyword.#1}{#1}}%
  \hypertarget{keyword.#1}{}%
  \@esphack}
egreg
  • 1,121,712