0

To make index I have to write word two times,

\documentclass[12pt,oneside]{book}
\usepackage{makeidx}
\makeindex
\begin{document}
This will not print \index{anything} !!! 
However it will make an entery in Index. 
To print the word in text and index you need to write word \index{word}.
\printindex
\end{document}

To make an index for we need to write word \index{word}. I find it redundant.

Is there any way (package or code) to just write \index{word}?

  • 2
    You can define \newcommand{\iindex}[1]{#1\index{#1}} and then you type \iindex{word} – Sigur Feb 26 '16 at 16:09
  • Getting lot of error "Illegal parameter number in definition of \reserved@a. \newcommand{\iindex}[#1]" . Please post full working example. Thanks – d.putto Feb 26 '16 at 16:19
  • Please, see the edited comment. no # in brackets. – Sigur Feb 26 '16 at 16:23
  • Now it works. Please post it as an answer. – d.putto Feb 26 '16 at 16:26
1

You can define a new command (eg \iindex) with one argument and use this argument to call \index and to print it on the text.

\newcommand{\iindex}[1]{#1\index{#1}} 

and then you simply type \iindex{word}.

\documentclass[12pt,oneside]{book}
\usepackage{makeidx}
\makeindex
\newcommand{\iindex}[1]{#1\index{#1}} %%This is new command
 %%%and then you type \iindex{word}

\begin{document}
This will not print \index{anything} !!! 
However it will make an entry in Index. 
To print the word in text and index you need to write word \index{word}. 
Or \iindex{word} single.
\printindex
\end{document}
  • 1
    if you write "word \index{word}." you will get a space before the period. shouldn't be any space between the term being indexed and the \index{...} entry. (the \iindex definition takes care of that worry.) – barbara beeton Feb 26 '16 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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