9

MdSymbol is an excellent sans math (just symbol) font macro package

I think \int with its superscript are too tight, how to set the space between the \int with its superscript?

enter image description here

here a example, please use it

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

\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 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)\,\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}
  • Off-topic: Do replace all 5 instances of &{} = with &=. If nothing else, this change will help cut down on code clutter. – Mico Mar 31 at 7:51
  • tks, sometime will make a difference between the two methods, the difference is that adding {} can ensure = be a binary relational symbol, without {}, the spacing of = two sides maybe not equal... I don’t know for sure if it ’s true. It became my habit.. – poorich Mar 31 at 8:36
  • That is true for the right-aligned columns, and you indeed need ={}&. Left-aligned columns always start with an empty group. – campa Mar 31 at 13:18
  • Just by the way you wrote \tan x \wedgeq u but you made the substitution tan(x) ↦ t. – gen-z ready to perish Apr 1 at 6:13
  • @gen-z-ready-to-perish Tks for correct, I have selected examples with more \int from my document, without double checking – poorich Apr 1 at 7:01
8

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

| improve this answer | |
  • Yes, this is the answer I desire, simple and general, and thank you for your \diff, I completely forgot the trouble this d caused me – poorich Mar 31 at 9:23
  • One more detail, In text mode, this spacing seems wider, how to set \displaystyle and \textstyle separately? – poorich Mar 31 at 9:50
  • @poorich That's much more complicated. – egreg Mar 31 at 10:08
  • {^{\:#1}} -> {^{\if (in displaystyle) {\,} \else {length2}\fi}#1}} is this feasible? Don't know how to express (in displaystyle) – poorich Mar 31 at 10:34
  • @poorich No, it doesn't work like that. You need to scan the current style in advance and this requires an extensive change in the definition of \int. – egreg Mar 31 at 10:36
4

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}
| improve this answer | |
  • 2
    +1: I did not expect \int^{\infty} being different from \int^\infty. – Dr. Manuel Kuehner Mar 31 at 9:00

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.