17

I need to increase the space globally between operators in subscripts/superscripts.

Example: \sum_{x=4}

I need a little more space before and after the = symbol in the subscript. It is required globally in every operator in subscripts/superscripts.

2
  • Welcome to TeX.SX! You may have a look on our starter guide. Commented May 10, 2013 at 5:30
  • You could probably renew the sum command with some trick to add spaces to equals signs in the subscripts. Commented Jan 22, 2018 at 10:41

8 Answers 8

14

TeX does not put any space around operators in that position, so there is no parameter that you can set to control that space. This is different from the space in text or display style which you can control by setting the em width. See this answer on font dimens

So you can either set the subscript in text style (which might already be enough space) and then increase em or \thickmuskip or you need to use an explicit space such as \,.

enter image description here

\documentclass{article}

\begin{document}

\[\sum_{x=3}x=3\]

\[\sum_{\displaystyle x=4}x=4\]

\[\sum_{x\,=\,5}x=5\]

{\thickmuskip=22mu
\[\sum_{\displaystyle x=6}x=6\]
}

\fontdimen6\scriptfont2=1in
\fontdimen6\textfont2=1in

\[\sum_{x=7}x=7\]


\[\sum_{\textstyle x=8}x=8\]


\end{document}
8

You could make = active in math mode and add a thin space in \scriptstyle and \scriptscriptstyle using \mathchoice.

Adapting this nice @egreg's answer, use something like

\cs_new_protected:Nn \virgo_mathchardef:Nn
 {
  \tex_mathchardef:D #1 = #2 \scan_stop:
 }
\cs_generate_variant:Nn \virgo_mathchardef:Nn { c }

\NewDocumentCommand{\FixOperatorInScripts} { m }
  {
    \virgo_mathchardef:cn { __virgo_letter_#1: } { \char_value_mathcode:n { `#1 } }
    \cs_new:cn { __virgo_active_#1: }
      {
        \mathchoice
          {  \use:c {  __virgo_letter_#1: } }       % \displaystyle
          {  \use:c {  __virgo_letter_#1: } }       % \textystyle
          {  \, \use:c {  __virgo_letter_#1: } \, } % \scriptstyle
          {  \, \use:c {  __virgo_letter_#1: } \, } % \scriptscriptstyle
      }
    \char_set_active_eq:nc { `#1 } { __virgo_active_#1: }
    \AtBeginDocument
      {
        \char_set_mathcode:nn { `#1 } { "8000 }
      }
 }

Example:

\documentclass{article}

\usepackage{amsmath}

\ExplSyntaxOn

\cs_new_protected:Nn \virgo_mathchardef:Nn
 {
  \tex_mathchardef:D #1 = #2 \scan_stop:
 }
\cs_generate_variant:Nn \virgo_mathchardef:Nn { c }

\NewDocumentCommand{\FixOperatorInScripts} { m }
  {
    \virgo_mathchardef:cn { __virgo_letter_#1: } { \char_value_mathcode:n { `#1 } }
    \cs_new:cn { __virgo_active_#1: }
      {
        \mathchoice
          {  \use:c {  __virgo_letter_#1: } }       % \displaystyle
          {  \use:c {  __virgo_letter_#1: } }       % \textystyle
          {  \, \use:c {  __virgo_letter_#1: } \, } % \scriptstyle
          {  \, \use:c {  __virgo_letter_#1: } \, } % \scriptscriptstyle
      }
    \char_set_active_eq:nc { `#1 } { __virgo_active_#1: }
    \AtBeginDocument
      {
        \char_set_mathcode:nn { `#1 } { "8000 }
      }
 }

\ExplSyntaxOff

\begin{document}

\[ \sum_{x=3}x=3 \]

\FixOperatorInScripts{=}

\[ \sum_{x=3}x=3 \]

\end{document}

Example

7

I don't think it's a good idea. Anyway…

\documentclass{article}
\usepackage{amsmath}
\usepackage{xpatch}

\makeatletter
\AtBeginDocument{%
  \NewCommandCopy{\slimits@ams}{\slimits@}%
  \RenewCommandCopy{\slimits@}{\slimits@mihir}%
  \NewCommandCopy{\ilimits@ams}{\ilimits@}%
  \RenewCommandCopy{\ilimits@}{\ilimits@mihir}%
}
\NewDocumentCommand{\ilimits@mihir}{}{%
  \ilimits@ams
  \generic@limits
}
\NewDocumentCommand{\slimits@mihir}{}{%
  \slimits@ams
  \generic@limits
}
\NewDocumentCommand{\generic@limits}{e{_^}}{%
  \IfValueT{#1}{_{\text{$\m@th#1$}}}%
  \IfValueT{#2}{^{\text{$\m@th#2$}}}%
}
\ExplSyntaxOn
\tl_map_inline:nn{\det\gcd\inf\injlim\lim\liminf\limsup\max\min\Pr\projlim\sup}
 {
  \xapptocmd{#1}{\generic@limits}{}{}
 }
\ExplSyntaxOff
\makeatother

\begin{document}
\[
\lim_{x\to 0}\frac{\sin x}{x}=1 \qquad \int_{x=1}^{x=3} x\,dx
\]
\[
\sum_{n=1}^{\infty} \prod_{k=1}^{n-k}\max_{1\le i\le n-k}
\]
\begin{center}
$\sum_{n=1}^{\infty} \prod_{k=1}^{n-k}$
\end{center}

\end{document}

output

1
  • Underrated hack. Commented Jun 14, 2025 at 2:28
5
+100

@egreg's answer is the best, but below, I show a method to reduce the spacing a bit.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xpatch}

\makeatletter
\AtBeginDocument{%
  \NewCommandCopy{\slimits@ams}{\slimits@}%
  \RenewCommandCopy{\slimits@}{\slimits@mihir}%
  \NewCommandCopy{\ilimits@ams}{\ilimits@}%
  \RenewCommandCopy{\ilimits@}{\ilimits@mihir}%
}
\NewDocumentCommand{\ilimits@mihir}{}{%
  \ilimits@ams
  \generic@limits
}
\NewDocumentCommand{\slimits@mihir}{}{%
  \slimits@ams
  \generic@limits
}
\NewDocumentCommand{\generic@limits}{e{_^}}{%
  \IfValueT{#1}{_{\text{\medmuskip=1mu\thickmuskip=2mu\thinmuskip=0.5mu$\m@th#1$}}}%
  \IfValueT{#2}{^{\text{\medmuskip=1mu\thickmuskip=2mu\thinmuskip=0.5mu$\m@th#2$}}}%
}
\ExplSyntaxOn
\tl_map_inline:nn{\det\gcd\inf\injlim\lim\liminf\limsup\max\min\Pr\projlim\sup}
 {
  \xapptocmd{#1}{\generic@limits}{}{}
 }
\ExplSyntaxOff
\makeatother

\begin{document}
\[
\lim_{x\to 0}\frac{\sin x}{x}=1 \qquad \int_{x=1}^{x=3} x\,dx
\]
\[
\sum_{n=1}^{\infty} \prod_{k=1}^{n-k}\max_{1\le i\le n-k}
\]
\begin{center}
$\sum_{n=1}^{\infty} \prod_{k=1}^{n-k}$
\end{center}

\end{document}
1
  • This is great. I think it looks a lot better than the default for some kinds of document, particularly when you're often summing over sets and have things like x\in \{y\in Y\mid \exists z\in Z . (y,z)\in W\} in the subscripts, to choose a not particularly meaningful example. egreg's solution did have a bit too much space for my taste, so this is perfect. Commented Jun 19, 2025 at 10:19
4

Classical TeX doesn't allow to insert (simply) the given space in scriptstyle (as shown in the other answers here). But LuaTeX introduces new primitives which allow to control all atom-to-atom spaces in all styles. See section 7.5.2 in the LuaTeX documentation.

Your example can be solved using \Umathordrelspacing and \Umathrelordspacing primitives. The scriptstyle can be "normal" or "cramped". It is "cramped" in the text below something (for example below the sum operator as in your example).

\Umathordrelspacing\scriptstyle=2mu
\Umathrelordspacing\scriptstyle=2mu
\Umathordrelspacing\crampedscriptstyle=2mu
\Umathrelordspacing\crampedscriptstyle=2mu

$$\sum_{x=4}$$

\bye
3

The spacing depends on the type of symbol you insert. The example below contains a complete list of spaces and how they look like.

Spaces in mathematical mode.

\begin{align*}
f(x) =& x^2\! +3x\! +2 \\
f(x) =& x^2+3x+2 \\
f(x) =& x^2\, +3x\, +2 \\
f(x) =& x^2\: +3x\: +2 \\
f(x) =& x^2\; +3x\; +2 \\
f(x) =& x^2\ +3x\ +2 \\
f(x) =& x^2\quad +3x\quad +2 \\
f(x) =& x^2\qquad +3x\qquad +2
\end{align*}

When used with your example, you could use :

\sum_{x\ =\ 4}

for the desired effect.

1
  • 6
    Welcome to TeX.SX!. OP asked for a global solution. I interpret this as "What is a command to change the spacing globally?". Commented Jan 22, 2018 at 10:52
3

Trivial by ConTeXt, if you have time to learn it.

\starttext
Hello
\pettymuskip 2.5mu % change here

\startformula
(a + b)^n = \sum_{k=0}^{n} \binom{n}{k} a^{n-k} b^k
\stopformula
\stoptext
2
  • 2
    The \pettymuskip is also applied in other places, so it is perhaps not the best way to do it. Also, it is non-zero, so by default one indeed gets spacing in sub/superscripts in ConTeXt. If one wants to change the behavior, it is better to set it up class by class. Commented Jun 26, 2025 at 13:44
  • @mickep At least it amuses LaTeX users that ConTeXt have such many amount of skips. Also, thanks for the ConTeXt, as it scares LaTeX users even more (classes etc) and make them Ooh and Aah at ConTeXt magic. :) Commented Jul 6, 2025 at 19:43
3

OpTeX provides the macro \scriptspaces{⟨s-rel⟩}{⟨s-bin⟩}{⟨ss-rel⟩}{⟨ss-bin⟩} when you do \load[math]. This macro allows more comfortable setting these horizontal spaces than directly using LuaTeX primitives (mentioned in my other answer here). The task here can be solved by

\load[math]
\scriptspaces {2mu}{1.3mu}{}{}

$$\sum_{x=4}$$
\bye

See also section 10 in the OpTeX math package documentation.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.