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.

I would like to have a command which empasizes a term (like a definition in a mathematical text) and produces an item for the index (I use makeindex). Ideally the macro should not be too invasive, such that the index can be turned off it this might be desired.

Can you provide me a solution for this task?

share|improve this question
    
@Martin: I think that it would be more semantic to name the macro something like \keyword for example because what you want to do is to focus one special word. –  projetmbc Apr 4 '12 at 19:11
add comment

2 Answers

up vote 3 down vote accepted

Here is an example: using the macro \myemph{} causes the word to be added to the index and the regular \emph{} macro is still available and does not add the term to the index.

enter image description here

enter image description here

\documentclass{memoir}
\makeindex
\newcommand{\myemph}[1]{\index{#1}\emph{#1}}%

\begin{document}
This is in index: \myemph{foo}

This is not in index: \emph{bar}

\backmatter
\printindex
\end{document}
share|improve this answer
add comment

Or also this, if you prefer:

\let\oldemph\emph
\renewcommand{\emph}[1]{\index{#1}\oldemph{#1}}

Now you can use \emph as you wished.


If you want a starred version, this might help (you need the suffix package):

\documentclass{article}
\usepackage{suffix}

\makeindex

\let\oldemph\emph    % save old \emph
\renewcommand\emph[1]{\oldemph{#1}}    % "new" \emph without star
\WithSuffix\newcommand\emph*[1]{\oldemph{#1}\index{#1}}    % new \emph with a star

\begin{document}   
  \emph{test} \\   % doesn't get indexed
  \emph*{test2}   % gets indexed
\end{document}
share|improve this answer
    
But the OP specifically requested that he want to be able to turn this feature off, so perhaps defining \emph* which added to the index would be an option, and the regular \emph would not add it to the index. –  Peter Grill Apr 4 '12 at 19:22
add comment

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.