Typesetting mathematics

This blog post is a quick introduction to typesetting mathematical notation using LaTeX commands, which in WordPress is done using MathJax.

You can start typing mathematical notation by entering a dollar sign, and then when you’re done enter another dollar sign.

Example: The square of a number is given by $x^2$ (\$x^2\$)

If you actually want to type a dollar sign, put a backslash before it. For example, typing \\\$300 gives: \$300.

Most of the commands for typing mathematics are pretty intuitive:

  • Most stuff: Just type it. For example, $a+b+c$ (\$a+b+c\$)
  • Multiplication: $12 \times 20$ (\times) or $12 \cdot 20$ (\cdot) but not $12*20$ (*)
  • Fractions: $\frac{x^2 + y^2}{a^2 + b^2}$ or $\dfrac{x^2 + y^2}{a^2 + b^2}$ (\frac{top}{bottom} or \dfrac{top}{bottom})
  • Radicals: $\sqrt{100}$ or $\sqrt[5]{100}$ (\sqrt{100} or \sqrt[5]{100})
  • Exponents: $e^-x^2$ is bad (\$e^-x^2\$) but $e^{-x^2}$ is good (\$e^{-x^2}\$)
  • Subscripts: $a_2$ (\$a_2\$) or $x_{100}$ (\$x_{100}\$), but not $x_100$ (\$x_100\$)
  • Trig and log functions: $\sin(x), \cos(x), \ln(x)$ (\sin, \cos, \ln)
  • Parentheses around fractions: $\sin ( \dfrac{\pi}{4} )$ (\$\sin( \dfrac{\pi}{4} )\$) vs $\sin \left( \dfrac{\pi}{4} \right)$ (\$\sin \left( \dfrac{\pi}{4} \right)\$)

Sometimes we want to put long equations on their own line so that they don’t clutter a paragraph. We can do this using \$\$double dollar signs\$\$ on both ends: $$\dfrac{d}{dx} ( x^2 + \sin(x) + e^x) = 2x + \cos(x) + e^x$$

Common mistakes:

  • Forgetting to close a brace or dollar sign: $\sqrt{x^2 + e^x + \ln(2x)$
  • Using (parentheses) instead of {braces} for arguments to commands: $\sqrt(100 + 2x)$ vs $\sqrt{100+2x}$
  • Exponents without braces surrounding them: $e^100$ vs $e^{100}$
  • Misspelling a command

Example putting this together:

$\dfrac{d}{dx} ( \sqrt{1 + x^2} ) = \dfrac{x}{\sqrt{1+x^2}}$

Post a comment