Fractions
This collection of LaTeX macros make it easier to insert fractions, including defining a \fracshort
macro that causes a fraction to be rendered like $a/b$ (making it easier to switch between $\frac{a}{b}$ and $a/b$). The slash inserted by \fracshort
scales with the height of the numerator and denominator. Also included are common fractions, $\frac{1}{2}$ (\half
), $\frac{1}{3}$ (\third
), etc. Each of these commands can take one optional argument that sets the numerator to the given values, such as \half[x]
($\frac{x}{2}$), and have short versions (\quartershort[\theta]
creates $\theta/4$) and a display style version (e.g., \dtenth[n]
creates $\dfrac{n}{10}$, but you should never use display style fractions in a line of text). Finally, the \oneover
, \oneovershort
, and \doneover
macros inserts fractions with $1$ in the numerator and the denominator given as an argument: \oneover{x}
creates $\frac{1}{x}$.
When using the short fractions, make sure you insert parentheses, as needed, around the numerator and denominator!
Examples
Code | Output |
---|---|
\fracshort{a}{b} |
$$a/b $$ |
\fracshort{1}{\left(1 + e^{x^{-2}}\right)} |
$$\left. 1 \middle/ \left(1 + e^{x^{-2}}\right) \right. $$ |
\half |
$$\frac{1}{2} $$ |
\half[x] |
$$\frac{x}{2} $$ |
\third \fourth \fifth \sixth \twelfth |
$$\frac{1}{3}\frac{1}{4}\frac{1}{5}\frac{1}{6}\frac{1}{12} $$ |
\third[a] \fourth[b] \fifth[c] \sixth[d] \twelfth[e] |
$$\frac{a}{3}\frac{b}{4}\frac{c}{5}\frac{d}{6}\frac{e}{12} $$ |
\thirdshort[a] + \fourthshort[b] |
$$a/3 + b/4 $$ |
Definition
\newcommand{\fracshort}[2]{\left.#1 \middle/ #2\right.} \newcommand{\oneover}[1]{\frac{1}{#1}} \newcommand{\doneover}[1]{\dfrac{1}{#1}} % \displaystyle fraction \newcommand{\oneovershort}[1]{\fracshort{1}{#1}} % Common Fractions \newcommand{\half} [1][1]{\frac{#1}{2}} \newcommand{\third} [1][1]{\frac{#1}{3}} \newcommand{\quarter}[1][1]{\frac{#1}{4}} \newcommand{\fifth} [1][1]{\frac{#1}{5}} \newcommand{\sixth} [1][1]{\frac{#1}{6}} \newcommand{\eighth} [1][1]{\frac{#1}{8}} \newcommand{\tenth} [1][1]{\frac{#1}{10}} \newcommand{\twelfth}[1][1]{\frac{#1}{12}} % Short fractions for inline equations. \newcommand{\halfshort} [1][1]{\fracshort{#1}{2}} \newcommand{\thirdshort} [1][1]{\fracshort{#1}{3}} \newcommand{\quartershort}[1][1]{\fracshort{#1}{4}} \newcommand{\fifthshort} [1][1]{\fracshort{#1}{5}} \newcommand{\sixthshort} [1][1]{\fracshort{#1}{6}} \newcommand{\eighthshort} [1][1]{\fracshort{#1}{8}} \newcommand{\tenthshort} [1][1]{\fracshort{#1}{10}} \newcommand{\twelfthshort}[1][1]{\fracshort{#1}{12}} % Display style fractions. \newcommand{\dhalf} [1][1]{\dfrac{#1}{2}} \newcommand{\dthird} [1][1]{\dfrac{#1}{3}} \newcommand{\dquarter}[1][1]{\dfrac{#1}{4}} \newcommand{\dfifth} [1][1]{\dfrac{#1}{5}} \newcommand{\dsixth} [1][1]{\dfrac{#1}{6}} \newcommand{\deighth} [1][1]{\dfrac{#1}{8}} \newcommand{\dtenth} [1][1]{\dfrac{#1}{10}} \newcommand{\dtwelfth}[1][1]{\dfrac{#1}{12}}Output: