Note that MathJax will make a page slower to load and can be jarring if there's a lot of inline equations (note that typeface and size is different). For superscript in normal text, say for footnotes, use <sup></sup>
and html codes for special characters, such as †
for † and ×
for ×.
Equations and Maths
First, a definition. MathJax lets us format things as \$\LaTeX\$ math-mode, which means maths looks good and text looks bad. (Different kerning and no spacing which makes it difficult to read.)
You can make in-line equations by enclosing in \$..\$
and on separate, centred lines by enclosing in $$..$$
. So, for example \$1+2=3\$
renders as \$1+2=3\$ while $$1+2=3$$
renders as $$1+2=3$$
Super and subscript is achieved via ^
and _
respectively. If these are to contain more than a single character, enclose them in {..}
. Example: \$M_{x, b}^n = x_b + n^3\$
gives \$M_{x, b}^n = x_b + n^3\$
There a number functions for special characters and formatting. \times
gives \$\times\$, \$\sum\$
gives \$\sum\$, and similarly for greek letters \$\alpha\$
gives \$\alpha\$ and common functions \$\ln\$
gives \$\ln\$
Fractions can be achieved using \frac{}{}
. When putting a fraction in parenthesis use \left
and \right
on those to make then scale with the height of the fraction. Example with and without
$$ \frac{1}{20} + (\frac{1}{20})^2 + \left(\frac{1}{20}\right)^2 $$
$$
\frac{1}{20} + (\frac{1}{20})^2 + \left(\frac{1}{20}\right)^2
$$
If you have long equations you can the align
environment to make it align over multiple lines. Use \\
to mark line breaks and &
to define anchors, ie. points which are to be aligned on the vertical. (Note the spacing sometimes can go weird around the &
which should be fixable by injecting some empty brackets {}
)
\begin{align}
P &= 1 + 2 + 3 + 4 + 5 + \frac{3}{7} \\
&\approx 15.429
\end{align}
\begin{align}
P &= 1 + 2 + 3 + 4 + 5 + \frac{3}{7} \\
&\approx 15.429
\end{align}
Markdown Tables
In December 2020, we got support for markdown tables (Announcement post on main meta).
Cells are divided by |
and the mandatory header is delineated by the row of dashes (--
). Column alignment can be set by including colons in that row. Spacing and number of dashes is not critical (line breaks are), but can be useful to keep the markdown version readable. Markdown tables should support most of markdown and other formatting available. Below is an example table and the code producing it.
A header |
A split header |
Last Header |
First |
row |
cell entry |
Second |
row |
It is possible to include quite a lot of text in a cell, and it will wrap if needed. |
| A header | A split<br> header | Last Header |
| :------- | :----------------: | ----------: |
| First | row | cell entry |
| Second | row | It is possible to include quite a lot of text in a
cell, and it will wrap if needed. |
The <br>
breaks the header at that line, which is useful for headers that longer that the column content (such as for columns of numbers) which is especially useful to avoid overly wide tables.
Note: markdown tables require an empty/blank line before the table to render correctly. The editing preview will show them as tables, but it will not do so once you submit.
MathJax Tables
Markdown tables are generally preferable because they are handled much better by screen readers, however if need be MathJax tables are usable.
In order to make tables with MathJax we make use of the array
environment. This has the side effect that it makes text look bad, unless we use the \text
command. This makes it render like text, but note that MarkDown does not work inside such commands. You can use \textit
and \textbf
instead to make the text italicized or bold respectively.
Use \\
to end rows, and &
to separate cells. You need a column definer at the start (otherwise your first character will be eaten). It defines how your columns will be justified (l
eft, c
entered, or r
ight) and you can use |
to introduce vertical lines. Use \hline
after a line break to make a horizontal line. Consider using as few lines as necessary to make the table readable. Column justification defaults to centered.
\begin{array}{r|lc}
\textbf{Number} & \textbf{Left Justified Text} & N_{i+1} \\ \hline
1 & Text in math mode & 3\\
3 & \text{Text as normal text} & 97 \\
13 & \textit{Text in italics} & - \\
42 & \text{Text } \textbf{bolded} \text{ for effect}
\end{array}
\begin{array}{r|lc}
\textbf{Number} & \textbf{Left Justified Text} & N_{i+1} \\ \hline
1 & Text in math mode & 3\\
3 & \text{Text as normal text} & 97 \\
13 & \textit{Text in italics} & - \\
42 & \text{Text } \textbf{bolded} \text{ for effect}
\end{array}
There are a number of webapps which let you generate LaTeX tables using a more visual front end. You will need to change tabular
to array
and put in \text
functions as appropriate.