# Why are there two identical headwords in an index where there should only be one?

In an index generated by Latex there are the two headwords: abhainn, 52 and abhainn, 53. But there should only be one, abhainn 52, 53.

Both of the instances of abhainn are marked identically in the original file as \emph{abhainn}\index{abhainn@\textbf{abhainn}}, so they shouldn't be treated as different in the indexing of them.

But in the .idx and .idn files they are different: they are as follows: in .idn, \item \textbf {abhainn}, 52 (with the gap as indicated between \textbf and {abhainn}) but \item \textbf{abhainn}, 53 (without this spacing).

The irregular spacing occurs also in the .idx entry \indexentry {abhainn@\textbf {abhainn}}{52}, but not in .idx entry \indexentry{abhainn@\textbf{abhainn}}{53}.

Why is there a difference of spacing in these entries, even though they are marked identically as \emph{abhainn}\index{abhainn@\textbf{abhainn}} in the original file? This spacing seems to be introduced as a result of the creation of the .idx and .idn files, as it is not in the original file, but is it the reason why there are two identical headwords in the index where there should only be one?

This happens if you "hide" one of the index commands inside some other command:

\documentclass{article}
\usepackage{imakeidx}
\makeindex

\begin{document}
blub \index{abhainn@\textbf{abhainn}}
\newcommand\mytext{\index{abhainn@\textbf{abhainn}}}\mytext

\printindex
\end{document}