2

Is there a global macro available to add space automatically before every superscript and subscript in math present in an entire document.

2 Answers 2

5

No. There is control over space after, but not space before, it is always attached directly to the base.

3

I am the author of the package altsubsup which provides alternative formats for subscripts and superscripts when used with square brackets, like _[...] or ^[...].

You can define your own command and set it with

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

Then all subscripts and superscripts written with square brackets will be formatted with the command \mysubsupformat.

Full example

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

with altsubsup alternative commands

But maybe you don't want to rewrite your entire document. Since the altsubsup package save the original definitions of ^ and _ in \altsbsp@standardsub and \altsbsp@standardsup, you can try to hack them (in \AtBeginDocument because they are created there, and with \maketatletter and \makeatother to handle the character @ in macro names):

\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

Full example:

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

Obviously, don't use squared forms in this case, they're broken.

3
  • Thank you, sounds good to me. Let me check on these macros for my content.
    – RampSmart
    Apr 10 at 16:51
  • @RampSmart I just saw that the hack gives a Double superscript error when used with a prime symbol, like in x'^a. I'll see if I can find a workaround.
    – jlab
    Apr 10 at 18:01
  • @RampSmart Finally, no new Double superscript error (it was triggered by x'_a^b, this happen also with bare latex). So everything should work fine.
    – jlab
    Apr 10 at 19:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .