# How to not repeat word in \index

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}?

• 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

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}

• 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