Consider the code:
\documentclass[openany]{book}
\usepackage{imakeidx}
\makeindex
\usepackage{idxlayout}
\begin{document}
\thispagestyle{empty}
\Large
This is a sentence. This is another \textbf{sentence}. \textbf{This} is too a sentence.
\vspace*{15pt}
This is a sentence. This is another \textbf{sentence}. \index{HEADING@\textbf{HEADING}! An index entry with a lot of words.} \index{HEADING@\textbf{HEADING}! A different index entry with some more words.} \textbf{This} is too a sentence. This is another sentence. This is a sentence.
\idxlayout{columns=1}
\printindex
\end{document}
with the first page of output:
Notice the (expected) proper horizontal spacing between the sentences in the first paragraph, even though in the code I had inserted extra spaces between the second and third sentences.
Remark: If I had inserted in the code, say, ten extra spaces between the said sentences, I would expect the same output.
Now, look at the output of the second paragraph---and in particular---the extra horizontal space that has been inserted between the second and third spaces. The difference in the code is---that I have inserted a couple of index commands, which, many times, appears to have no affect on the horizontal spacing between two consecutive sentences at all.
But here, it does.
QUESTION: Can anyone tell me what might be causing this unwanted phenomenon and is there a remedy for it? Perhaps, more importantly, is there a proper way to insert indexing code? Is it O.K. to leave a space between two consecutive index commands or should they be inserted consecutively without interruption as in one long command?
Note: I have added the bold for visual emphasis. The described phenomenon occurs whether or not bold is used. I compile the code with lualatex.
Thank you.




\indexshould normally be placed attached to the word you want to index, for a couple of reasons; one is to avoid unwanted spaces. – egreg Mar 03 '22 at 20:59\index{}and\index{}be coded\index{}\index{}or\index{}\index{}? Or does it not matter? – DDS Mar 03 '22 at 21:09