What do you think about this suggestion:
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstdefinestyle{Bash}
{language=bash,
keywordstyle=\color{blue},
basicstyle=\ttfamily,
morekeywords={peter@kbpet},
alsoletter={:~$},
morekeywords=[2]{peter@kbpet:},
keywordstyle=[2]{\color{red}},
literate={\$}{{\textcolor{red}{\$}}}1
{:}{{\textcolor{red}{:}}}1
{~}{{\textcolor{red}{\textasciitilde}}}1,
}
\begin{document}
\begin{lstlisting}[style=Bash]
peter@kbpet:~$ echo $(uname -i)
x86_64
\end{lstlisting}
\end{document}
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:
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}
Best Answer
Note that I do not actually recommend you do the following. But, since you ask: You can force TeX/LaTeX to issue the directive
\displaystyle
automatically whenever you initiate inline-math mode -- via either an opening-$
or a\(
instruction -- by inserting the following command in your document's preamble:Again, I do not recommend you take this route. There are excellent typographic reasons for not using large summation, product, and integral symbols while in inline-math mode. Likewise, it's almost invariably a bad idea to typeset display-style fraction constructs while in inline math mode.
For much more information on this matter, I suggest you take a look at the posting Show inline math as if it were display math.
I can think of only one exception to the broad stricture against the automatic use of
\displaystyle
: Inbeamer
-class documents, it is quite important not to let the math symbols become too small. One way of achieving this is to use\displaystyle
throughout. Even forbeamer
documents, though, providing the instruction\everymath{\displaystyle}
may be too much of a good thing.Addendum, prompted by a follow-up comment by the OP: To revert back to "text style" while in inline math mode, just issue the command
\textstyle
. The following MWE illustrates the look of various math objects if\displaystyle
and\textstyle
are in effect: