Fractions

To complete our ability to typeset basic math expressions, we should find out how to render fractions.

Fractions are on a separate page as, unlike the previous math commands we used, they require parameters. This is necessary because fractions have two parts - a numerator and denominator - and we must specify which is which.

Fractions

To type a fraction, we use a command with two parameters: one for the numerator and one for the denominator.

Fractions are typeset with \frac{}{}

The first group contains the numerator. The second group contains the denominator.

Fraction command with the numerator and denominator highlighted.

Exercise 5.1.1

Paste the code below into your project and compile the preview. What happens?

Then, correct the code to typeset the fraction 12/17.

\( \frac12 17 \)

Solution 5.1.1

When the given code is compiled, the result looks like the fraction 1/2 followed by 17. This is because the command \frac took the first object following it, 1, as the numerator, and the second object 2 as the denominator.

In order to properly type the fraction 12/17, we must use curly braces to group the numerator and denominator.

\( \frac{12}{17} \ )

Display style

If you change the previously typeset fraction into display math mode, you can see that the inline version is significantly smaller.

Inline fractions can be difficult to read, especially when there are more complex expressions in the numerator or denominator.

For example, try adding the following sentence into your project, and compile the preview.

The function \( f(x) = \frac{1}{x^2 + 1} \) is continuous everywhere.

The denominator looks a bit cramped, right?

Result of compiling the code given above. The fraction defining the function is small in order to fit in the line height.

Let's try display mode instead:

The function \[ f(x) = \frac{1}{x^2 + 1} \] is continuous everywhere.

Now, the function expression certainly looks better. However, the line breaks and changing alignment have annoyingly broken our sentence up.

Result of compiling the code above. As described, the fraction is larger, but it is centered with line breaks before and after.

Happily, there is a way to get the larger fraction from display mode at the same position inline.

The \displaystyle command makes inline math the same size as display math.

Try adding the command \displaystyle to the beginning of the inline math expression:

The function \( \displaystyle f(x) = \frac{1}{x^2 + 1} \) is continuous everywhere.

The result of compiling the code above. As described below, the fraction is larger but remains inline with the text.

Success! The math stays in its same inline position, but the fraction is now in display size.

Note that since normal letters and numerals do not change size in display mode, the f(x) part of the expression does not change - only the fraction.

On the next page, we will study some more commands which require parameters.