I'm having a problem with the \index command causing unwanted whitespace:
\documentclass[a4paper,11pt,oneside]{book}
\usepackage{makeidx}
\makeindex
\def \nothing #1{}
\begin{document}
\noindent The Principle of Availability\\\index{principle of availability}
What is said must be intuitively accessible to the conversational participants,
unless something goes wrong and they cannot be counted as `normal interpreters'.
\end{document}
If this is compiled, the line starting with "What is said" has a slight indent. This indent is gone if I add a \relax, or a % after the index{...} command, I guess since that gobbles up the newline following it. If there is no index command at all (i.e. the line ends after the \\), or if I replace it by \nothing{...} the spurious whitespace is also gone.
If I change \index to \nothing and have \nothing insert an empty hbox by defining it \def \nothing #1{\hbox{}}, the problem is back again. So I guess \index inserts something that makes LaTeX no longer ignore the newline character.
Is there a way to prevent \index from causing whitespace?
Note that the above is actually the result of some macro expansions, so "just move the \index to the next line" isn't going to help me. Also, I tried wrapping \index in my own macro that inserts a \relax after it, but that didn't work either.
\newcommand*{\myindex}[1]{\index{#1}\ignorespaces}and using\myindexin the document? – lockstep Aug 25 '11 at 09:48\indexis after\\, you start a paragraph with it. I can't recall exactly, but\indexdoes some funny things with surrounding spaces (seesource2e.pdf), and probably this might not work in vertical mode. You might thus try\\\leavevmode\index{...}(or\newcommand\myindex[1]{\leavevmode\index{#1}}or something similar). – mbork Aug 25 '11 at 13:22\\we are still in same paragraph. – Sep 18 '17 at 18:06\\you are still in the same paragraph, but in vertical mode... – mbork Sep 18 '17 at 19:19\\you still are in horizontal modefoo\\\relax\ifhmode OK\fi bar– Sep 18 '17 at 20:36