How to set the space between the \int with its superscript?

You can use the e argument specifier of xparse to scan and see whether subscripts or superscripts come along. If they do, add \, to superscripts and \! to subscripts.

This happens by adding \fixlimits at the end of the working of \int. You may want to do similarly to other integral types, with a similar \xapptocmd line for each.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{sansmathfonts}
\usepackage{mdsymbol}
\usepackage{xparse,xpatch}

\newcommand{\uppi}{\pi}
\newcommand{\diff}{\mathop{}\!\mathrm{d}}

\NewDocumentCommand{\fixlimits}{e{^_}}{%
  \IfValueT{#1}{^{\,#1}}%
  \IfValueT{#2}{_{\!#2}}%
}
\xapptocmd{\int}{\fixlimits}{}{}

\begin{document}

\begin{align*}
     \int_{-\frac{\uppi}2}^{\frac{\uppi}2} \frac{\sin^2 x}{1+\sin^4 x}\diff x
&{} = 2\int_0^{\frac{\uppi}2} \frac{\sin^2 x}{1+\sin^4 x}\diff x
    = 2\int_0^{\frac{\uppi}2} \frac{\cos^2 x}{1+\cos^4 x}\diff x\\
&{} = 2\int_0^{\frac{\uppi}2} \frac{\sec^2 x}{\sec^4 x + 1}\diff x
    = 2\int_0^{\frac{\uppi}2} \frac{\diff (\tan x)}{(1+\tan^2 x)^2 + 1}\\
(\tan x \wedgeq u)\quad
&{} = 2\int_0^{+\infty} \frac{\diff t}{(1+t^2)^2 + 1}
    = \int_{-\infty}^{+\infty} \frac{\diff t}{(1+t^2)^2 + 1}\\
\Bigl(t \wedgeq \frac1u\Bigr)\quad
&{} = \frac12\int_{-\infty}^{+\infty} \frac{\diff u}{u^2 + \frac1{2u^2}+1}
    = \frac12\int_{-\infty}^{+\infty} \frac{\diff u}{\bigl(u-\frac1{u\sqrt{2}}\bigr)^2 + (\sqrt{2}+1)}\\
&{} = \frac12\int_{-\infty}^{+\infty} \frac{\diff u}{u^2 + (\sqrt{2}+1)}
    = \frac{\uppi}{2\sqrt{\sqrt{2}+1}} = \frac{\uppi}{2}\sqrt{\sqrt{2}-1}.
\end{align*}
It's using follow $\int^0 \dotsi \int^\infty \dotsi \int^d \dotsi \int^g$\quad%
$\displaystyle \int^0 \dotsi \int^\infty \dotsi \int^d \dotsi \int^g$
\[
  \int_{-\infty}^{+\infty} f\Bigl(x-\frac{a}{x}\Bigr)\diff x
= \int_{-\infty}^{+\infty} f(x)\diff x, \quad
  \int_{-\infty}^{+\infty} \frac{\diff x}{x^2 + \alpha^2}
= \frac{\uppi}{\alpha}\quad (a>0,\alpha>0).
\]

\end{document}

In the meantime, I changed all explicit \mathrm{d} so when you will eventually return in the world of mathematicians you'll be able to make your d's italic by simply changing one line. ;-)

enter image description here


Assuming you can use LuaLaTeX, it's straightforward to apply some spacing adjustments "on the fly", before TeX starts its usual processing.

The working assumption in the following, LuaLaTeX-based solution is that the lower and upper limits of integration either consist of a single letter or digit or are encased in curly braces. Thus, \int_0^1 can be processed, whereas \int^\infty cannot. (You would need to write \int^{\infty} -- which is probably good practice anyway.) It's also assumed that the lower limit is always entered before the upper limit. Finally, it's ok to have an integral with just an upper limit.

The code below shifts the lower limit to the left (by 2mu) and shifts the upper limit to the right (also by 2mu); feel free to adjust the shift amounts. Oh, 3mu is equivalent to 1 unit of thinspace (=1/6em).

The Lua function is activated by running \AdjustIntSpacingOn. If you ever need to deactivate it, just run \AdjustIntSpacingOff.

enter image description here

\documentclass[10pt]{beamer}
\usepackage[T1]{fontenc}
\usepackage{sansmathfonts,mdsymbol}
\let\uppi\pi

\usepackage{luacode}
\begin{luacode}
function int_spacing ( s )
  s = s:gsub ( "\\int%s-_%s-(%b{})%s-^%s-(%b{})" , "\\int_{\\mkern-2mu%1}^{\\mkern2mu%2}" ) 
  s = s:gsub ( "\\int%s-_%s-(%w)%s-^%s-(%b{})" , "\\int_{\\mkern-2mu%1}^{\\mkern2mu%2}" )
  s = s:gsub ( "\\int%s-_%s-(%w)%s-^%s-(%w)" , "\\int_{\\mkern-2mu%1}^{\\mkern2mu%2}" )
  s = s:gsub ( "\\int%s-^%s-(%b{})"          , "\\int^{\\mkern2mu%1}" )
  s = s:gsub ( "\\int%s-^%s-(%w)"            , "\\int^{\\mkern2mu%1}" )
  return s
end
\end{luacode}
\newcommand\AdjustIntSpacingOn{\directlua{luatexbase.add_to_callback(
   "process_input_buffer", int_spacing, "int_spacing")}}
\newcommand\AdjustIntSpacingOff{\directlua{luatexbase.remove_from_callback(
   "process_input_buffer", "int_spacing")}}
\AtBeginDocument{\AdjustIntSpacingOn}

\begin{document}
\begin{frame}
\begin{align*}
\int_{-\frac{\uppi}2}^{\frac{\uppi}2} \frac{\sin^2 x}{1+\sin^4 x}\,\mathrm{d}x
&= 2\int_0^{\frac{\uppi}2} \frac{\sin^2 x}{1+\sin^4 x}\,\mathrm{d}x
    = 2\int_0^{\frac{\uppi}2} \frac{\cos^2 x}{1+\cos^4 x}\,\mathrm{d}x\\
&= 2\int_0^{\frac{\uppi}2} \frac{\sec^2 x}{\sec^4 x + 1}\,\mathrm{d}x
    = 2\int_0^{\frac{\uppi}2} \frac{\mathrm{d}(\tan x)}{(1+\tan^2 x)^2 + 1}\\
(\tan x \wedgeq u)\quad
&= 2\int_0^{+\infty} \frac{\mathrm{d}t}{(1+t^2)^2 + 1}
    = \int_{-\infty}^{+\infty} \frac{\mathrm{d}t}{(1+t^2)^2 + 1}\\
\Bigl(t \wedgeq \frac1u\Bigr)\quad
&= \frac12\int_{-\infty}^{+\infty} \frac{\mathrm{d}u}{u^2 + \frac1{2u^2}+1}
    = \frac12\int_{-\infty}^{+\infty} \frac{\mathrm{d}u}{\bigl(u-\frac1{u\sqrt{2}}\bigr)^2 + (\sqrt{2}+1)}\\
&= \frac12\int_{-\infty}^{+\infty} \frac{\mathrm{d}u}{u^2 + (\sqrt{2}+1)}
    = \frac{\uppi}{2\sqrt{\sqrt{2}+1}} = \frac{\uppi}{2}\sqrt{\sqrt{2}-1}\,.
\end{align*}
It's using
$\int_0^1 \dotsi \int{^\infty} \dotsi \int^d \dotsi \int^g$\quad
$\displaystyle 
 \int_0^1 \dotsi \int^{\infty} \dotsi \int^d \dotsi \int^g$
\[
\int_{-\infty}^{+\infty} f\Bigl(x-\frac{a}{x}\Bigr)\,\mathrm{d}x
  = \int_{-\infty}^{+\infty} f(x)\,\mathrm{d}x, \quad
\int_{-\infty}^{+\infty} \frac{\mathrm{d}x}{x^2 + \alpha^2}
  = \frac{\uppi}{\alpha}\quad (a>0,\alpha>0)\,.
\]
\end{frame}
\end{document}