2

When constructing a superscript box or a subscript box, TeX will automatically append a kern of \scriptspace to the end of that hbox. And if you write a double subscript, say, $A_{i_k}$, then there will be two \scriptspaces, which creates too much white space on the right.

How can you get rid of just one \scriptspace?

\documentclass{article}
\begin{document}
For $i_1$, $i_2$,~$\ldots$, and~$i_k$, we have
\[
P(A_{i_1}\cap A_{i_2}\cap \cdots \cap A_{i_k})
=P(A_{i_1}) P(A_{i_2}) \cdots P(A_{i_k}).
\]
\end{document}
Ruixi Zhang
  • 9,553
  • \newcommand{\dsub}[2]{_{#1_{#2}}\hspace*{-1\scriptspace}} used with A\dsub{i}{1} maybe? (Though that might be annoying.) – frabjous Sep 16 '22 at 02:14
  • @frabjous This surely is one way to go. But the backing up negative space should really go inside one of scripts. The first reason is somewhat obvious: Let’s say you write $A\dsub{i}{1}^c$ for the complement of $A\dsub{i}{1}$. You certainly would want the ^c to attach to the A instead of the negative space, wouldn’t you? The second reason is somewhat philosophical: It’s “logically more natural” to put the negative space inside (see https://tex.stackexchange.com/q/616371). – Ruixi Zhang Sep 16 '22 at 18:33

1 Answers1

2

If you are using LuaTeX then you can set script-space values individually for all math styles using the \Umathspaceafterscript primitive. Note, that the math style of the nucleus is relevant. Example: $a_{b_c}$ adds \Umathspaceafterscript\textstyle after b_c and \Umathspaceafterscript\crampedscriptstyle after c. The resulting space is the sum of these two.

You can try following setting:

\Umathspaceafterscript\displaystyle=.5pt
\Umathspaceafterscript\crampeddisplaystyle=.5pt
\Umathspaceafterscript\textstyle=.5pt
\Umathspaceafterscript\crampedtextstyle=.5pt
\Umathspaceafterscript\scriptstyle=0pt
\Umathspaceafterscript\crampedscriptstyle=0pt
\Umathspaceafterscript\scriptscriptstyle=0pt
\Umathspaceafterscript\crampedscriptscriptstyle=0pt
wipet
  • 74,238
  • Xe(La)TeX users crying internally. More seriously though, this is still not smart enough to understand context (I guess?). Say, we want to write multi-index object, $A_{i_1 j_1 k_1}$ (I know it’d be better to switch to a parenthesized expression, but this is sort of “necessary evil”). Then really the \scriptspaces in i_1 and j_1 should stay. My question would be unchanged though: in this case, there are 4 \scriptspaces, and I still want to get rid of just one, namely, the one from the k_1. – Ruixi Zhang Sep 16 '22 at 18:52