[Tex/LaTex] Why are there no \dint or \dsum like \dfrac

amsmathdisplaystyleinline()macros

This was inspired by How to have nice-looking symbols within an \itemize environment? and Sigur's comment which remind me about the display style of math formulas and the fractions.


I know that, in the amsmath package there is already \dfrac{}{} for us to have display-style fractions (as well as \tfrac{}{} for in-line fraction).

Enter image description here

Then why don't \dsum, \dprod, \dint, etc. exist?

If they are not to exist, then why does \dfrac exist?

Actually, we can define, for example, \dint as

\DeclareMathOperator{\dint}{\displaystyle\int}

but I want to know the reason why there are no \dint, etc. Or can you tell me the packages in which these \d- are in?

Best Answer

The command \dfrac exists for rendering multistory fractions, say

\[
\frac{\dfrac{a}{b}-\dfrac{c}{d}}{\dfrac{a}{b}+\dfrac{c}{d}
\]

and is not generally intended for usage in an inline formula. It is not defined using the simplistic format \displaystyle\frac, but rather

% amsmath.sty, line 214:
\newcommand{\dfrac}{\genfrac{}{}{}0}

where \genfrac is

% amsmath.sty, line 221:
\DeclareRobustCommand{\genfrac}[4]{%
  \def\@tempa{#1#2}%
  \edef\@tempb{\@nx\@genfrac\@mathstyle{#4}%
    \csname @@\ifx @#3@over\else above\fi
    \ifx\@tempa\@empty \else withdelims\fi\endcsname}
  \@tempb{#1#2#3}}

% amsmath.sty, line 289:
\def\@genfrac#1#2#3#4#5{{#1{\begingroup#4\endgroup#2#3\relax#5}}}
\def\@mathstyle#1{%
  \ifx\@empty#1\@empty\relax
  \else\ifcase#1\displaystyle % case 0
    \or\textstyle\or\scriptstyle\else\scriptscriptstyle\fi\fi}

What happens with \dfrac{a}{b}? By definition this becomes \genfrac{}{}{}0{a}{b}, so

\def\@tempa{}%
  \edef\@tempb{\@nx\@genfrac\@mathstyle{0}%
    \csname @@\ifx @@over\else above\fi
    \ifx\@tempa\@empty \else withdelims\fi\endcsname}
  \@tempb{}{a}{b}

By definition of \@mathstyle, \@tempb is defined to be \@genfrac\displaystyle\@@over, so we're left with

\@genfrac\displaystyle\@@over{}{a}{b}

which in turn becomes

{\displaystyle{\begingroup a\endgroup\@@over\relax b}}

and \@@over is the primitive \over. Note the braces around the whole construction. You may enjoy chasing the expansion of \frac, \binom and \dbinom.

With \int one cannot do \displaystyle\int, because this wouldn't confine the scope of \displaystyle, nor {\displaystyle\int}, because this would not place correctly the limits. Indeed, the test file

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\dint}{\displaystyle\int}
\newcommand{\ddint}{\displaystyle\int}

\begin{document}

$\dint_0^1\frac{x}{2}\,dx$

$\ddint_0^1\frac{x}{2}\,dx$

\end{document}

produces wrong output in either case:

enter image description here

Can one do something about this? Yes, but I don't think it's worth the pain. Anyway, here it is:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\NewDocumentCommand{\dint}{t\limits e{_^}}{%
  \mathop{
    \displaystyle\int
    \IfBooleanT{#1}{\limits}
    \IfValueT{#2}{_{#2}}
    \IfValueT{#3}{^{#3}}
  }%
}

\begin{document}

$\dint_0^1\frac{x}{2}\,dx$
$\dint\limits_0^1\frac{x}{2}\,dx$
$\dint\frac{x}{2}\,dx$

\end{document}

enter image description here