下標/上標中數學運算符周圍的間距

下標/上標中數學運算符周圍的間距

考慮以下:

\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}

輸出

答案1

在此輸入影像描述

Luatex 有原語來控制每個數學風格中每個類別之間添加的空間,因此可以控制腳本風格中 mathord 和 mathbin 之間的空間:

\documentclass{article}

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

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

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

\end{document}

對於經典的 TeX 引擎你可以這樣做

在此輸入影像描述

\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}

但它不太好,它總是添加空格,因此只有在+用作數學原子之間的二元運算符時才有效。請注意,最後一項中的最後一個前綴+c會獲得較寬的空間,這並不是您真正想要的,您需要一個單獨的命令來存取 prefix +

在透過評論連結的答案中,我建議使用\nonscript看起來更複雜的構造,但實際上我認為它具有相同的缺陷。

egreg 使用建議的版本\text獲得了正確的間距,但它需要更多的標記,而不僅僅是添加空格(儘管您當然可以定義自己的變體\sp命令來使用此構造製作上標)。

答案2

不,你不要它。高德納 (Knuth) 透過檢查在很長一段時間內產生的包含數學內容的幾篇文檔,研究了數學空間的規則。

也許一些國家的印刷傳統空間操作和關係符號也在上標和下標。這並不意味著它很好:那裡的間距很小不錯,整體來說。一些偶然的錯誤可以透過手動修復:如果你想要一份漂亮的文檔,你必須對其進行處理。米開朗基羅的成名不僅僅在於錘子和鑿子聖母憐子圖

這是 Karl Weierstraß 所著《Theorie der Abel'schen Functionen: Erstes Heft》一書中的圖像,1856 年(在 Google 圖書上查看

在此輸入影像描述

您可以看到上標中的和是嚴格設定的,而普通類型中的和則不是這樣。


我記得芭芭拉·比頓(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}

\displaystyle只是舉例。

在此輸入影像描述

我毫不懷疑我會選擇哪個版本。

相關內容