One important element when working with mathematics is fractions. We are taught to use fractions in school, but their presence is constant throughout all fields of mathematics and sciences. Writing fractions inside a LaTeX document is straightforward: you just have to use the \frac{}{} command in math mode:
- The first argument of this command is the numerator of the fraction,
- while the second is the denominator.
So for example:
% LaTeX fraction \[ \frac{\pi^2}{6} \]
produces the output:
\( \displaystyle \frac{\pi^2}{6} \)
Inside the numerator and the denominator, we can write any mathematical expression, and its size will be adjusted to look nice inside the fraction.
LaTeX nested fractions
We can easily nest fractions one inside the other, as in the following example:
% Nested LaTeX fractions \[ \frac{\frac{1}{2}\int_{-\infty}^{\infty} xe^{-x^2}\,dx} {\frac{1}{2}\int_{-\infty}^{\infty} e^{-x^2}\,dx} \]
which produces the more complex output:
\( \displaystyle \frac{\frac{1}{2}\int_{-\infty}^{\infty} xe^{-x^2}\,dx} {\frac{1}{2}\int_{-\infty}^{\infty} e^{-x^2}\,dx} \)
In all the previous examples, the fractions were written in display math mode. But one could ask what happens when we insert a fraction inside inline math mode since the fraction notation is itself designed to take up two lines. The fact is that LaTeX does its best to keep the readability of the fraction while not taking up much more space than a usual line.
Inline fractions?!
For example, $\frac{3}{4}$ produces the output \(\frac{3}{4}\). You can judge yourself if you would like it on your document or not; in any case, for simple fractions (the only ones that should be written inline) you can always use the slash notation 3/4. Although uglier and less readable for large fractions, this last notation seems preferable when working with math that goes inline with text.
Infinite nest fractrions
We have seen that LaTeX does a fairly good job with spacing and sizes when we nest one fraction inside another. But what if we go wild and nest infinite fractions? Then we are talking about infinite fractions in mathematics, which are expressions that look something like this:
\( \displaystyle x_0+\cfrac{1}{x_1+\cfrac{1}{x_2+\cfrac{1}{x_3+\cdots}}} \)
and continue forever. Well, I have not been completely honest, since although the nesting is theoretically infinite, the notation must end at some point. But the fact is that the notation is affected by this infinite nesting since it is customary not to make the elements inside the numerator and denominator of each fraction smaller. This looks much better and can be accomplished using the \cfrac command, provided by the amsmath package. So the previously continued fraction was produced by the following code:
% Infinite nested fractions \[ x_0+\cfrac{1}{x_1+\cfrac{1}{x_2+\cfrac{1}{x_3+\cdots}}} \]
If instead, we write
% Infinite nested fractions (Ugly version) \[ x_0+\frac{1}{x_1+\frac{1}{x_2+\frac{1}{x_3+\cdots}}} \]
the output doesn’t look that good; you can compare it yourself:
\( \displaystyle x_0+\frac{1}{x_1+\frac{1}{x_2+\frac{1}{x_3+\cdots}}} \)
binomial coefficients
Finally, there are fraction-like environments to produce certain mathematical notations, the most remarkable case being the binomial coefficients. These coefficients are the ones that appear in the algebraic expansion of the expression \((a+b)^{n}\), and are denoted like a fraction surrounded by a parenthesis, but without the dividing bar:
\( \displaystyle \binom{n}{k} \)
This last expression was produced with the command:
% Fraction without bar for binomial coefficients \[ \binom{n}{k} \]
We reached the end of this tutorial, If you have any remarks or suggestions, please feel free to reach us via email at admin@latex-tutorial.com