Displaying Fractions
- There are two ways of displaying fractions in KaTEX: using
\fracor\over - Depending on your use case, it might be readable to use one over the other.
Fractions with \frac
-
Using the
\frac{}{}command allows us to display fractions.- Any math inside the first bracket is displayed in the numerator and any math in the second gets displayed in the denominator.
-
\frac{2x}{x + 1}
1 + \frac{x^2 -1}{x^3 + x + 1}
\frac{1}{x} - \frac{2}{x + 1}
Fractions with \over
-
The
\overcommand acts as a separator between the numerator and denominator.- Anything to the left is displayed in the numerator and anything in the right is displayed in the denominator.
-
1+ 3x + 4x^2 \over 3x - 1
-
However, if we want a part of the expression to not include as part of the fraction, we would enclose the part that we want to include into our expression with grouping symbols
{...}. -
1 + {3x + 4x^2 \over 3x - 1}
Variations in Displaying Fractions
-
Fractions are displayed differently in both inline and display math modes.
-
Inline math fractions are much smaller in size to fit the actual text size like
, or . -
Display math fractions are much larger and often intended for display.
-
f^{-1}(x) = \frac{2x-5}{1-x}
-
\frac{}{}automatically switches to inline fractions or display fractions depending on the math mode.- However, you can use
\dfrac{}{}to force fractions in display mode. - Likewise, you can use
\tfrac{}{}to force fractions in inline mode.
- However, you can use
-
Here are some inline cases that uses
\dfrac:1 - \dfrac{1}{2} + \dfrac{1}{3} - \cdotsdisplays as\dfrac{1 - x + x^2}{x^2 + x + 1}displays as
Here’s an example of a display case that uses \tfrac:
\tfrac{1}{x^3 - x} = \tfrac{A}{x} + \tfrac{B}{x-1} + \tfrac{C}{x+1}
Complex Fractions
-
We can create complex fractions by nesting combinations of
\frac’s or\over’s. -
\frac{1 + \frac{1}{2}}{3}
1 + {\frac{1}{a} - \frac{1}{b} \over \frac{b}{a}}
-
By default, fractions nested in the numerator or denominator are displayed in inline mode, even if the entire expression is written in display mode.
- You can force them to display mode by using
\dfrac.
- You can force them to display mode by using
-
\frac{1}{1 + \frac{1}{2 + \frac{1}{3 + \cdots}}}
\frac{1}{1 + \dfrac{1}{2 + \dfrac{1}{3 + \cdots}}}