4

I stumbled upon those two ways of writing a mathematical expression inside a text:

enter image description here

I could easily do the first one by writing the expression inside $s, but what about the second one? If I use \begin{displaymath}, it looks like this:

enter image description here

What is the correct command for this?

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036

2 Answers2

10

Actually there's a third way:

\documentclass{article}

\setlength{\textwidth}{.8\textwidth} % just for the example

\begin{document}

Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny. Ala ma kota 
$e=\lim_{n\to\infty}(1+\frac{1}{n})^n=\sum_{n=0}^{\infty}\frac{1}{n!}$ i kot
jest czarny. Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny.

Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny. Ala ma kota 
$e=\lim\limits_{n\to\infty}(1+\frac{1}{n})^n=\sum\limits_{n=0}^{\infty}\frac{1}{n!}$ i kot
jest czarny. Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny.

Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny. Ala ma kota 
$\displaystyle e=\lim_{n\to\infty}(1+\frac{1}{n})^n=\sum_{n=0}^{\infty}\frac{1}{n!}$ i kot
jest czarny. Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny.

\end{document}

enter image description here

Which one to prefer? The third way is definitely to avoid, because it creates too much space between lines; also the second way has the same defect, but less evident. The first way ensures constant advancement between baselines, making for a better appearance and better readability. Setting limits to the right, rather than above and below is a device very commonly used in mathematical typography exactly for avoiding the problem of getting bad white stripes in a page. The \limits trick can be handy in some cases, but should not be abused. Using \displaystyle is definitely the wrong way to go.

However, when a formula is rather complex, you should consider setting it in a display, which avoids the problem and makes the formula to stand out.

\documentclass{article}

\setlength{\textwidth}{.8\textwidth} % just for the example

\begin{document}

Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny. Ala ma kota
\[
e=\lim_{n\to\infty}\Bigl(1+\frac{1}{n}\Bigr)^{\!n}=\sum_{n=0}^{\infty}\frac{1}{n!}
\]
i kot jest czarny. Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny.

\end{document}

enter image description here

egreg
  • 1,121,712
2

\displaystyle switches between those two math styles, producing the effect you're looking for.

\documentclass{article}
\begin{document}
Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny. 

Ala ma kota $\displaystyle e = \lim_{n\to\infty} (1 + \frac{1}{n})^n
= \sum_{n=0}^\infty \frac{1}{n!}$ i kot jest czarny.

Ala ma kota i kot jest czarny. Ala ma kota i kot jest czarny. 
\end{document}

Here's the output:

enter image description here

Arun Debray
  • 7,126
  • 2
  • 30
  • 54
  • 2
    No need for the braces, \displaystyle is just a switch, not a command that takes an argument. In fact, the braces makes things worse, as they prevent linebreaks from occurring. – Torbjørn T. Dec 25 '15 at 22:41
  • 1
    @TorbjørnT. thank you, I've edited my post (and learned something new today)! – Arun Debray Dec 25 '15 at 23:07