上標和下標之前有空格

上標和下標之前有空格

是否有一個全域巨集可用於在整個文件中存在的數學中的每個上標和下標之前自動添加空格。

答案1

不能。

答案2

我是該包的作者替代子集當與方括號(如_[...]或 )一起使用時,它提供了下標和上標的替代格式^[...]

您可以定義自己的命令並使用

\newcommand*{\mysubsupformat}[1]{\,#1}% add a thin space
\SetAltSubSupCommands{\mysubsupformat}

然後,所有用方括號書寫的下標和上標都將使用指令進行格式化\mysubsupformat

完整範例

\documentclass{article}

\usepackage{amsmath}% for align*

\usepackage{altsubsup}
\newcommand*{\mysubsupformat}[1]{\,#1}% add a thin space
\SetAltSubSupCommands{\mysubsupformat}

\begin{document}

\begin{align*}
  x_a &  & x^b &  & x_a^b \\
  x_[a] &  & x^[b] &  & x_[a]^[b]
\end{align*}

\end{document}

使用 altsubsup 替代指令

但也許您不想重寫整個文件。自從替代子集^套件將和的原始定義保存_\altsbsp@standardsub和中\altsbsp@standardsup,您可以嘗試破解它們(\AtBeginDocument因為它們是在那裡創建的,並且使用\maketatletter和來處理巨集名稱中的\makeatother字元):@

\makeatletter
\AtBeginDocument{%
  \let\rampsmart@standardsub\altsbsp@standardsub
  \def\altsbsp@standardsub#1{\rampsmart@standardsub{\,#1}}% add a thin space
  \let\rampsmart@standardsup\altsbsp@standardsup
  \def\altsbsp@standardsup#1{\rampsmart@standardsup{\,#1}}% add a thin space
}
\makeatother

完整範例:

\documentclass{article}

\usepackage{amsmath}% for align*

\usepackage{altsubsup}

\makeatletter
\AtBeginDocument{%
  \let\rampsmart@standardsub\altsbsp@standardsub
  \def\altsbsp@standardsub#1{\rampsmart@standardsub{\,#1}}% add a thin space
  \let\rampsmart@standardsup\altsbsp@standardsup
  \def\altsbsp@standardsup#1{\rampsmart@standardsup{\,#1}}% add a thin space
}
\makeatother


\begin{document}



\begin{align*}
  x_a &  & x^b &  & x_a^b
\end{align*}

\end{document}

顯然,在這種情況下不要使用方形,它們會被破壞。

相關內容