# Use \index before or after punctuation?

It seems to me that you get different kerning if you use say\index{say}. than if you use say.\index{say} The following silly example is where I can see it:

\documentclass[12pt]{memoir}
\usepackage{microtype}
\begin{document}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say.\index{say} say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
say\index{say}. say.\index{say}
Can you see that there are lots of say\index{say}?
\end{document}


They look different to me:

and so I ask, is the proper method say.\index{say}? Should any command come after punctuation (i.e., \label etc)?

-
\index{say}say –  egreg Mar 23 at 23:32
So if I were doing the shortcut that many recommend, would it be \newcommand{\I}[1]{\index{#1}#1} and would that kern correctly? I tested it with \showoutput and it seems to work. –  bombcar Mar 24 at 0:27

It's easier to see the difference in the log file.

\documentclass[12pt]{memoir}
\usepackage{microtype}
\begin{document}
\showoutput

1say.\index{say}

2say\index{say}.

\end{document}


shows

....\OT1/cmr/m/n/12 1
....\OT1/cmr/m/n/12 s
....\OT1/cmr/m/n/12 a
....\kern-0.32639
....\OT1/cmr/m/n/12 y
....\kern-0.97916
....\OT1/cmr/m/n/12 .
....\penalty 10000

....\OT1/cmr/m/n/12 2
....\OT1/cmr/m/n/12 s
....\OT1/cmr/m/n/12 a
....\kern-0.32639
....\OT1/cmr/m/n/12 y
....\OT1/cmr/m/n/12 .
....\penalty 10000


Which confirms, as you suggest in the question, that you lose the font-specified kern correcting the space before the . in this case -0.97916pt.

As I see egreg just commented it is best to put the \index before the word to avoid these problems.

-
Thanks! I thought I had seen something, and \showoutput may be useful. I wonder why none of the documentation recommend putting \index first. –  bombcar Mar 23 at 23:50
@bombcar -- there are times when you would want to put the \index after, for example if you are indexing a multi-word string, like a name, the string might be split at a page break, and the word that is listed first in the index falls on the second page (Einstein, Albert). then you should indeed put \index after the punctuation. (i'm working on some index documentation, and, thanks to this question, i'll mention the kerning issue.) –  barbara beeton Mar 24 at 1:34