TransWikia.com

Spacing in subscripts

TeX - LaTeX Asked on July 17, 2021

Obviously if you put n{=}1 into a LaTeX document you don’t get the proper spacing that you get with n=1, except that in things like sum_{n=1}^infty the spacing seems no different from what it would be if you write sum_{n{=}1}^infty.

But if I recall correctly, in Walter Rudin’s Principles of Mathematical Analysis it’s not like that; it looks the way it would if you wrote sum_{n,=,1}^infty.

Is there some standard way of having it do that every time by putting something above the begin{document} line? Or if not that, some reasonable non-standard way?

One Answer

TeX suppresses spaces around binary operation symbols in subscripts and superscripts.

Can you reinstate it? Yes, if you wrap the subscript/superscript in text{$...$}.

documentclass{article}
usepackage{amsmath}

letoldsumsum % for comparison

makeatletter
renewcommand{sum}{DOTSBspaced@sum}
NewDocumentCommand{spaced@sum}{e{_^}}{%
  sum@slimits@
  IfValueT{#1}{_{text{m@th $#1$}}}%
  IfValueT{#2}{^{text{m@th $#2$}}}%
}
makeatother

begin{document}

begin{gather}
oldsumdotsoldsum_{n=1}^infty a_n

sumdotssum_{n=1}^infty a_n
end{gather}

end{document}

enter image description here

If you're running an older version of LaTeX you may need usepackage{xparse}.

If you replace the main definition with

NewDocumentCommand{spaced@sum}{e{_^}}{%
  sum@slimits@
  IfValueT{#1}{_{text{thickmuskip=3mu m@th $#1$}}}%
  IfValueT{#2}{^{text{thickmuskip=3mu m@th $#2$}}}%
}

you get less space.

enter image description here

You can abstract the setting:

documentclass{article}
usepackage{amsmath}

letoldsumsum % for comparison

makeatletter
NewDocumentCommand{spaced@operator}{me{_^}}{%
  csname #1@endcsnameslimits@
  IfValueT{#2}{_{text{thickmuskip=3mu m@th $#2$}}}%
  IfValueT{#3}{^{text{thickmuskip=3mu m@th $#3$}}}%
}
defoperator@list{%
  coprod,bigvee,bigwedge,biguplus,%
  bigcap,bigcup,prod,sum,bigotimes,%
  bigoplus,bigodot,bigsqcup%
}
@fornext:=operator@listdo{%
  expandafteredefcsnamenextendcsname{%
    noexpandDOTSBspaced@operator{next}%
  }%
}
renewcommandlim{spaced@lim{lim}}
renewcommandliminf{spaced@lim{lim,inf}}
renewcommandlimsup{spaced@lim{lim,sup}}
NewDocumentCommand{spaced@lim}{me{_^}}{%
  qopnamerelax m{#1}%
  IfValueT{#2}{_{text{thickmuskip=3mu m@th $#2$}}}%
  IfValueT{#3}{^{text{thickmuskip=3mu m@th $#3$}}}%
}
makeatother


begin{document}

begin{gather}
oldsumdotsoldsum_{n=1}^infty a_n

sumdotssum_{n=1}^infty a_n

prod_{a=1}lim_{ntoinfty}
end{gather}

end{document}

enter image description here

Correct answer by egreg on July 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP