4

Consider the following:

\documentclass{article}

\begin{document}

What I have:
\[x^{1+1}\]

What I would like:
\[x^{1\,+\,1}\]

That is, I will like to have spacing around the operator as in `$1+1$'.\\[\baselineskip]
\textsf{Question:} How do I get the above throughout my document without having to add \verb|\,| on each side of the operator every time?

\end{document}

output

  • 1
    see tex.stackexchange.com/questions/214147/… you can define a macro \myplus that adds the space and removes it again:-) then if you are feeling brave you could define + to access that macro. – David Carlisle Dec 23 '14 at 20:24
  • 1
    the spacing you see is built into the design of tex. the spacing used in math is laid out in a table in the texbook on p.170. essentially the same table is in tex by topic (texdoc texbytopic) on p.205. it's not easy to change globally. the suggestion by david is probably your best "way out". – barbara beeton Dec 23 '14 at 20:30
  • @DavidCarlisle Thanks for the pointer. (If you create an answer, I'll accept it.) – Svend Tveskæg Dec 23 '14 at 20:34
  • 1
    @SvendTveskæg -- nope. + and - are "bin", and digits are "ord". the notation in the table is "(2)" for either order. while "2" = medium space, the fact that the value is enclosed in parentheses indicates that the space is inserted "only in text and display mode, not in script or scriptscript mode". in most situations laid out in the table, parentheses are the order of the day, so ... not in scripts. when in doubt, assume "tight spacing" in scripts. (the relevant note is on p.205 in tex by topic.) – barbara beeton Dec 23 '14 at 21:03
  • 2
    I think that this trick is by @barbarabeeton: x^{\text{$1+1$}}. But, no, you don't want it. – egreg Dec 23 '14 at 21:07
6

enter image description here

Luatex has primitives to control the space added between each class in each math style, so to control the space between a mathord and a mathbin in script style:

\documentclass{article}

\begin{document}
$a+b x^{a+b}$

\Umathordbinspacing\scriptstyle=10mu
\Umathbinordspacing\scriptstyle=10mu

$a+b x^{a+b}$

\end{document}

For classic TeX engines You can do

enter image description here

\documentclass{article}
\DeclareMathSymbol{\realplus}{\mathbin}{operators}{"2B}
\begin{document}
$a+b x^{a+b} +cx^{+c}$

%\Umathordbinspacing\scriptstyle=10mu
%\Umathbinordspacing\scriptstyle=10mu


\def\z{{\mskip\medmuskip{\realplus}\mskip\medmuskip}}

$a\z b x^{a \z b} \z  cx^{\z c}$

\catcode`\+\active\let+\z
\catcode`\+12
\mathcode`\+="8000

$a+b x^{a+b} +cx^{+c}$

\end{document}

But it's not so good, it always adds the space so only works if + is used as a binary operator between to mathord atoms. Note the final prefix +c in the last term gets the wide space, which isn't really what you want, you'd need a separate command to access a prefix +.

In an answer linked via comments I suggested a construct using \nonscript which looks more involved but actually I think it has the same flaw.

The version suggested by egreg using \text gets the correct spacing but it requires more markup than just adding the space (although of course you could define your own variant \sp command that made superscripts using this construct).

  • Please see updated question, David. – Svend Tveskæg Dec 23 '14 at 22:14
6

No, you don't want it. The rules for mathematical spaces have been studied by Knuth by examining several documents with mathematical contents produced during a wide amount of time.

Perhaps some national typographic tradition spaces operation and relation symbols also in superscripts and subscripts. This doesn't mean it's good: tight spacing there is good, in general. Some occasional mishap can be fixed by hand: if you want a beautiful document, you have to work on it. Michelangelo didn't just use hammer and chisel to make his famous Pietà.

This is an image from a book by Karl Weierstraß, “Theorie der Abel'schen Functionen: Erstes Heft”, 1856 (see on Google Books)

enter image description here

You can see that sums in superscripts are tightly set, which is not the case for sums in normal type.


Here's a trick that I remember used by barbara beeton:

\documentclass{article}
\usepackage{amsmath}

\catcode`^=12
\catcode`_=12

\begingroup\lccode`~=`^\lowercase{\endgroup\def~}{\SPACED\sp}
\begingroup\lccode`~=`_\lowercase{\endgroup\def~}{\SPACED\sb}
\AtBeginDocument{\mathcode`^="8000 \mathcode`_="8000 }

\makeatletter
\def\SPACED#1#2{#1{\text{$\m@th#2$}}}
\makeatother

\begin{document}
$\displaystyle x^{1+1}+\sum_{1\le k\le n}k^2$

The original: {\catcode`^=7 \catcode`_=8
  $\displaystyle x^{1+1}+\sum_{1\le k\le n}k^2$}
\end{document}

The \displaystyle is just by way of example.

enter image description here

I have no doubt about what version I'd choose.

  • Thanks, egreg. Are you sure Michelangelo didn't just mock something up? :) – Svend Tveskæg Dec 23 '14 at 21:40
  • did i really do that??? (if so, i should be scolded severely!) – barbara beeton Dec 23 '14 at 21:46
  • @barbarabeeton did you really set the book by Weierstraß? Probably:-) – David Carlisle Dec 23 '14 at 22:01
  • Aaah, so leqno is the reason for that weird single brace habit!! Finally I know. – percusse Dec 23 '14 at 22:17
  • 1
    @DavidCarlisle -- you know, obviously, that i'm old enough to be your mother, but really, weierstraß died before my mother was born. hmmmmph. – barbara beeton Dec 24 '14 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.