Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

spacing problem with \index in LaTeX

277 views
Skip to first unread message

John Palmieri

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
Hi,

I'm having a spacing problem with the \index command in my LaTeX
document.

The quick question is: why is \index adding extra space?

The longer version is: I have a document, documentclass amsbook, and
it contains the following:


[blah blah blah]

exactly as stated. As we progress through the chapter, we will make
similar comments, most of which will have a bit more substance.
\end{remark}
\index{qn|)}


\section{The $Q_{n}$-based Adams spectral sequence}\label{sec-mass}

[blah blah blah]

The problem (feature?) is that I get different amounts of vertical
space between the end of the remark and the beginning of the next
section, depending on whether I include the \makeindex command or
not. This is not a big deal, but it does affect some page breaks.

Why does this happen? More generally, how does the \index command
affect spacing?

Where should I put the \index command so that it won't affect the
spacing? In this particular case, I have

\index{qn|(}

at the beginning of one section, and I want to have

\index{qn|)}

as close to the end of that section as possible. Should I put it
before "\end{remark}"? That makes the document harder to read; it's
nice to be able to separate the indexing commands from everything
else, when possible.

--
John H. Palmieri
Dept of Mathematics, Box 354350 palm...@math.washington.edu
University of Washington http://www.math.washington.edu/~palmieri
Seattle, WA 98195-4350

David Carlisle

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to John Palmieri

> The quick question is: why is \index adding extra space?

Wrong question.

The right question is:

Why don't you shower the latex maintainers with praise and money every
time an index command manages to insert itself without messing up the
spacing?

vertical mode is generally a hostile place for \write's \specials \marks
or anything else that you don't want to affect the spacing.

Attaching an \index command hard against a word is always a good idea
so yes place it inside the \end{remark.} This is anyway a good idea if
your remark environment allows a page break after the text as the index
could be a page out if the break happens at the \end{remark} but before
the \index.

Good to see this again


> \section{The $Q_{n}$-based Adams spectral sequence}\label{sec-mass}

it's not often mentioned on c.t.t.

David

James Kilfiger

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
John Palmieri wrote:
>Hi,
>
>I'm having a spacing problem with the \index command in my LaTeX
>document.
>
>The quick question is: why is \index adding extra space?

mis-features in the way tex and latex handle vertical space.
Your problem can be compressed to
\hrule
\addvspace{10pt}
\index{thing}
\addvspace{10pt}
\hrule

The second \addvspace can't `see' the first when there is a `write
whatsit' between them. One solution is to wait for latex 3 (or at least
2e*) in which vertical space handling will be different.

Otherwise consider this macro:
\newlength{\templength}
\newcommmand{\newindex}[1]{%
\ifvmode
\templength=\lastskip\unskip\index{#1}\vskip\templength
\else
\index{#1}}

It should be possible to use such a command in place of \index.
However I feel sure that something else will break.

James

Bernd Schandl

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
John Palmieri wrote:
>
> I'm having a spacing problem with the \index command in my LaTeX
> document.
>
> The quick question is: why is \index adding extra space?
>
> The longer version is: I have a document, documentclass amsbook, and
> it contains the following:
>
> [blah blah blah]
>
> exactly as stated. As we progress through the chapter, we will make
> similar comments, most of which will have a bit more substance.
> \end{remark}
> \index{qn|)}
>
> \section{The $Q_{n}$-based Adams spectral sequence}\label{sec-mass}
>
> [blah blah blah]
>
> [...]

Usually, \index does not add extra space, but this mechanism does not
(always?) work after a line break. So what you should do is
\end{remark}%
\index{qn|)}
Note the percent % sign.
Bernd
--
Bernd Schandl
Tired of spam? Use spamcop.net to complain!

Peter Wilson

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to John Palmieri
John Palmieri wrote:
>
> Hi,

>
> I'm having a spacing problem with the \index command in my LaTeX
> document.
>
> The quick question is: why is \index adding extra space?
>
The quick answer is "read Appendix C.1.5 of Lamport".

Longer answer is that \index is an `invisible' command and does not
normally introduce extra spaces. It may do so when when there is a
linebreak before it, forms a paragraph by itself (blankline \index
blankline) or under some other circumstances. As recommended, always
attach \index to the end of a word to avoid the occasional problem.

Peter W.
peter.r...@boeing.com

John Palmieri

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
David Carlisle <dav...@nag.co.uk> writes:

> > The quick question is: why is \index adding extra space?
>

> Wrong question.
>
> The right question is:
>
> Why don't you shower the latex maintainers with praise and money every
> time an index command manages to insert itself without messing up the
> spacing?

Sorry, I'll try to get it right next time.

> Attaching an \index command hard against a word is always a good idea
> so yes place it inside the \end{remark.} This is anyway a good idea if
> your remark environment allows a page break after the text as the index
> could be a page out if the break happens at the \end{remark} but before
> the \index.

Okay, I've eliminated all whitespace before my \index commands (love
those regular expression searches in Emacs), so that they all follow
either a word or a punctuation mark or a symbol, as in

text\index{blah}

or

text.\index{blah}

or

\[
x^{n} + y^{n} = z^{n}\index{blah}
\]

This makes for an ugly tex file (some really long lines, since I have
some long things as arguments to \index commands, and since I have a
few strings of several \index commands in a row), but anyway...

Should this eliminate any spacing issues with \index?

Removing or inserting \makeindex no longer gives the message "Some
labels may have changed...", but it does produce slightly different
dvi files, and I can't tell if the difference is significant. (It's
more than just the date and time string at the start of the file.)

> Good to see this again

> > \section{The $Q_{n}$-based Adams spectral sequence}\label{sec-mass}

> it's not often mentioned on c.t.t.

Since you liked that one, how about this: does the difference in line
breaks in the following have any effect?

text\index{spectral
sequence!Atiyah-Hirzebruch}

vs.

text\index{spectral sequence!Atiyah-Hirzebruch}

Donald Arseneau

unread,
Nov 20, 1999, 3:00:00 AM11/20/99
to
In article <s5t7lje...@goedel3.math.washington.edu>, John Palmieri <palm...@math.washington.edu> writes...

>\end{remark}
>\index{qn|)}
>\section{The $Q_{n}$-based Adams spectral sequence}\label{sec-mass}
>
>The problem (feature?) is that I get different amounts of vertical
>space between the end of the remark and the beginning of the next
>section, depending on whether I include the \makeindex command or
>not. This is not a big deal, but it does affect some page breaks.

It is a problem, but a well-known difficult one.

Most of the things that add vertical space in LaTeX, such as lists and
section titles, contribute their space via \addvspace (see the manual)
which doesn't necessarily add any space at all! (Poor naming!) What
\addvspace{v} does is conditionally increase the existing space so it
is at least as big as v. To do this, it needs to look for a preceding
space (vertical skip) in the "vertical list".

In the normal case, the \section command sees the space below a list,
and increases that to the space needed before a section, but an \index
command puts something else on the list, and then your \section command
can't see any preceding space, so it adds the entire pre-section space
to give a total space of after_list + before_section.

The same problem happens with \label, \addtocontents, and \color commands.

The only solution I can give is to put your index commands right
in the text, not in "vertical" mode material between other things.

\end{remark}


\section{The $Q_{n}$-based Adams spectral sequence}\label{sec-mass}

Text\index{qn|)} more text...

>as close to the end of that section as possible. Should I put it
>before "\end{remark}"?

Oh, I thought an index entry for qn referred to the $Q_{n}$ section.
If you are referring to something discussed in that "remark" then put
the index entry in the remark.

Donald Arseneau as...@triumf.ca

0 new messages