17
$\begingroup$

What is MathJax?

It lets you include nicely-typeset mathematics in PSE questions, answers, and comments. The syntax is described below (with links to places where you can find more details). Two-second summary of how to use it: Surround MathJax with dollar signs: $e^x$ gets you $e^x$.

When to use MathJax

When what you're writing includes mathematical formulas that can't be written satisfactorily with standard Unicode text. If you have a puzzle where the expression $\frac{A + B + C}{\frac{D}{E} - F}$ is important, you can have it appear nicely like that instead of as something such as (A + B + C)/(D/E - F), which is less readable.

When not to use MathJax

MathJax output, while nice to look at for human readers, is difficult for screen readers to parse (so that visually impaired readers who depend on those may have trouble with it). It also requires more rendering time than regular text. That means you shouldn’t be using it willy-nilly.

  • For simple math (especially plain numbers) that don’t need formatting, MathJax is unnecessary. For example, “each soldier has $20$ coins” should be just “each soldier has 20 coins”, and “the $1$st move must be to the right” should be “the first move must be to the right” or “the 1st move must be to the right”.
    • If a question or answer is already full of MathJax in order to represent complicated mathematics, it does no harm to use MathJax for simple bits of mathematics too, for consistency. If you're writing “We have $\zeta(s)=\prod_{p\ \textrm{prime}}\left(1-p^{-s}\right)^{-1}$, which converges when $\Re(s)>1$” (We have $\zeta(s)=\prod_{p\ \textrm{prime}}\left(1-p^{-s}\right)^{-1}$, which converges when $\Re(s)>1$) then even though the second formula could just have been written "Re(s)>1" without MathJax it's probably better to format it nicely and save readers worrying about whether $s$ and s are meant to be different variables.
    • If not, probably best not. Just use ordinary text, and maybe italics for things like variable names.
  • Several formatting options which MathJax provides are also available natively with Stack Exchange’s flavor of Markdown. These include tables, lists, bolding/italics, and increased font size for headers. Please do not use MathJax for these (with the exception of special table formatting that is impossible with Markdown).
  • Question titles are visible to everyone browsing using the main page or question lists. This isn’t Math Stack Exchange; specific mathematical formulas are often not necessary in the question titles. Keeping MathJax out of the titles keeps homepage elements from moving around between the initial page load and the MathJax rendering. In addition, MathJax in the title prevents a question from being a Hot Network Question.

There isn't a strict official PSE policy on when MathJax is appropriate. Please use your discretion and your common sense. Some older discussion can be found at MathJax Usage Guidelines (2016) and PSA: MathJax is for math (2020).

Common uses of MathJax

This is an abbreviated list of MathJax uses which are particularly common on Puzzling. More resources are available in the original “MathJax help” link, or the extensive Math SE tutorial, or the introduction at OR.SE. Feel free to practice in our sandbox. Many simple uses only require enclosing the expression in $ dollar signs: “$f(x) = a! + bx$” is $f(x) = a! + bx$.

  • Subscripts and superscripts: “$a_i, a_{i + 1}$” is $a_i, a_{i + 1}$, while “$a^i, a^{i + 1}$” is $a^i, a^{i + 1}$
    • Note the use of {...} for grouping; if you write $a^n+1$ you will get $a^n+1$ and not $a^{n+1}$, but enclosing the exponent in curly braces gets it treated as a unit.
  • Fractions: “$\frac{a}{b}$” is $\frac{a}{b}$
  • Selected common functions: “$\sqrt{x}$” is $\sqrt{x}$ (an nth root, e.g. “$\sqrt[3]{x}$”, is $\sqrt[3]{x}$), “$\sin(x)$” is $\sin(x)$, “$\lim_{x \to 0} x$” is $\lim_{x \to 0} x$, etc.
  • Comparison symbols: “$\lt \gt \le \ge \neq$” is $\lt \gt \le \ge \neq$
  • Common operations: “$\times \div \pm \mp \cdot$” is $\times \div \pm \mp \cdot$
  • Greek letters: e.g. “$\pi$” is $\pi$; “$\Pi$” is $\Pi$
  • Centering an important equation: $$a + b = c$$ is $$a + b = c$$
  • Parentheses, brackets, etc: (, ), [, ], are all just as you would expect, but {, } need to be “escaped” with backslashes: “$\{\}$” is $\{\}$
    • If you want to enclose something large in parentheses etc., precede the left one with \left and the right one with \right like this: “$\left(1+\frac{1}{x}\right)^{-1}$” is $\left(1+\frac{1}{x}\right)^{-1}$
  • Sums and products: “$\sum_{n=1}^{\infty}x^n$” is $\sum_{n=1}^{\infty}x^n$; “$\prod_{n=1}^{\infty}(1+x)^n$” is $\prod_{n=1}^{\infty}(1+x)^n$
  • Ellipses when writing out sums longhand: “$1+\frac{1}{2}+\frac{1}{3}+\ldots$” is $1+\frac{1}{2}+\frac{1}{3}+\ldots$; “$1+\frac{1}{2}+\frac{1}{3}+\cdots$” is $1+\frac{1}{2}+\frac{1}{3}+\cdots$. (“L” for “lower” and “c” for “center”.)

A few things that aren’t exactly mathematical but that you might want to use (but please heed the advice above and don’t use MathJax just for pretty formatting unless that pretty formatting is critical to your question/answer and you can’t do it any other way):

  • Adding color: “$123\color{red}{45}\color{blue}{67}89$” is $123\color{red}{45}\color{blue}{67}89$
  • Fonts: “$\textrm{roman}\ \textbf{boldface}\ \textit{italics}\ \texttt{typewriter}\ \textsf{sans-serif}\ \cal{ABC}\ \scr{ABC}\ \mathbb{ABC}\ \frak{ABCabc}$” is $\textrm{roman}\ \textbf{boldface}\ \textit{italics}\ \texttt{typewriter}\ \textsf{sans-serif}\ \cal{ABC}\ \scr{ABC}\ \mathbb{ABC}\ \frak{ABCabc}$. The ones with just ABC have only capital letters.
    • You might notice the \ backslash-escaped spaces. Un-escaped spaces are ignored inside MathJax formulas and MathJax will apply its own formatting which is meant to look right for actual mathematical formulas. If you’re doing anything that involves text you may need to force spaces to be included. There are also thin spaces: $a\,b$ ($a\,b$) and big wide spaces: $a\quad b$ ($a\quad b$).
$\endgroup$
1
  • 5
    $\begingroup$ Credit where due: the great majority of this was written by @bobble; most of what wasn't was written by me. $\endgroup$
    – Gareth McCaughan Mod
    Mar 25, 2023 at 11:28

0

You must log in to answer this question.

Browse other questions tagged .