[Tex/LaTex] Integral sign not covering entire fraction

amsmathintegral

I have a case where I'm showing an integral of a fraction, but the integral sign doesn't stretch down to cover the entirety of the fraction:

incorrect

This results from the following MWE:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
    \frac{3Q}{2\pi z^2} \displaystyle\int\frac{1}{\left( 1 + \dfrac{x^2 + y^2}{z^2} \right)^{\frac{5}{2}}}
\end{equation*}

\end{document}

The way I'm used to writing integrals looks more like this:

desired result

This question describes using packages like bigints and mtpro2 to scale the integral size. However, these appear to scale the integral sign relative to the location of the fraction's horizontal bar, which would not be the desired result here. Is there a way to get the integral to stretch to cover the entire fraction, as shown above? Also, I'd like to be able to set limits of the integration as well as the indefinite integral.

Note to the mathematicians out there – if I am violating some sort of typesetting convention with my request, please let me know. I'm not particularly well-versed with the convention used in mathematical circles for this sort of thing.

Best Answer

It is very uncharacteristic to typeset an integral sign uncentered at horizontal math axis. All variable-with math elements like braces, big operators etc are centered in traditional typography.

But if you wish such behaviour then, of course, it is possible. TeX is flexible. You can try the following macros, where \flexibleint macro is created. Usage is:

\flexibleint_a^b {integrand}   or    \flexibleint {integrand}

The integrand must be in braces.

\def\tmp#1 #2\relax{#1}
\setbox0=\hbox{$\xdef\intfont{%
    \expandafter\tmp\fontname\textfont3\expandafter\space\space\relax}$}
\font\tmp=\intfont\space at10pt\relax
\setbox0=\hbox{$\textfont3=\tmp \displaystyle \int$}
\dimen0=\ht0 \advance\dimen0 by\dp0 \divide\dimen0 by10 
\xdef\intsize{\the\dimen0}

\def\dividedimen (#1/#2){\expandafter\ignorept\the
   \dimexpr\numexpr\number\dimexpr#1\relax
   *65536/\number\dimexpr#2\relax\relax sp\relax
}
{\lccode`\?=`\p \lccode`\!=`\t  \lowercase{\gdef\ignorept#1?!{#1}}}

\def\flexibleint{\def\fxintL{}\def\fxintU{}\futurelet\next\fxintA}
\def\fxintA{\ifx\next_\expandafter\fxintB\else\expandafter\fxintC\fi}
\def\fxintB_#1{\def\fxintL{#1}\fxintC}
\def\fxintC{\futurelet\next\fxintD}
\def\fxintD{\ifx\next^\expandafter\fxintE\else\expandafter\fxintF\fi}
\def\fxintE^#1{\def\fxintU{#1}\fxintF}
\def\fxintF#1{\begingroup
   \setbox0=\hbox{$\displaystyle{#1}$}%
   \dimen0=\ht0 \advance\dimen0 by\dp0
   \setbox1=\hbox{$\vcenter{\copy0}$}%
   \font\tmp=\intfont\space at\dividedimen(\dimen0/\intsize)pt
   \lower\dimexpr\dp0-\dp1\hbox{%
      $\textfont3=\tmp \displaystyle\int_{\fxintL}^{\fxintU}$}
   \box0
   \endgroup
}

$$
  X = \sum_{i=0}^\infty 
      \flexibleint_a^b {u\over {\displaystyle v + {\strut x\over y}}}
$$

\bye

fxint

How it works: First, the fontname of \textfont3 (where \int sign is expected) is extracted at 10pt size (into \intfont) and the \int in \displaystyle at 10pt is measured (in \intsize).

Secondly, the scanning of _a or ^b is performed using auxiliary macros \fxintA to \fxintE.

Finally, the integrand in box is measured, its vertically different positions is compared using \box0 and \box1 (the second box is \vcentered), the font for \textfont3 scaled to desired size is temporary loaded and the flexible integral is typeset.

Related Question