Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
It depends on what you want these hyperlinks do. –  egreg Jul 27 '11 at 6: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 7:16

1 Answer 1

up vote 1 down vote accepted

Change the definition of \keyword into

\newcommand{\keyword}[1]{\@bsphack
  \keywordstoks=\expandafter{%
    \the\keywordstoks\kwsep\protect\hyperlink{keyword.#1}{#1}}%
  \hypertarget{keyword.#1}{}%
  \@esphack}
share|improve this answer
    
Thank you! Once again you helped me very much! –  Philip Jul 27 '11 at 13:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.