12
\$\begingroup\$

There are strong reasons to prefer Markdown tables to MathJax discussed in this meta, please take a look there before deciding to use MathJax tables on RPG.SE


For a more exhaustive tutorial please see Math.SE's Mathjax quick reference which covers many more things than this post does. This is trying to focus on the formatting which is typically needed here, which is a lot less than a maths site does.

  • How do I format good-looking equations?

  • How do I format good-looking tables?


Return to FAQ Index

\$\endgroup\$
4
  • 1
    \$\begingroup\$ related: MathJaX is live on RPGSE (which also has some examples, but not as well gathered/organized as this) \$\endgroup\$
    – nitsua60 Mod
    Jul 12, 2020 at 13:32
  • 2
    \$\begingroup\$ Relevant: Are Markdown tables superior to MathJax arrays for accessibility? \$\endgroup\$
    – V2Blast
    Jan 26, 2021 at 23:14
  • \$\begingroup\$ @V2Blast I added that link in the answer when discussing MathJax tables, on the assumption that markdown will be the default (which would become doubly true once it is incorporated into the editor) \$\endgroup\$
    – Someone_Evil Mod
    Jan 26, 2021 at 23:16
  • \$\begingroup\$ @Someone_Evil: I know. Figured I'd link it here for more visibility as well. \$\endgroup\$
    – V2Blast
    Jan 26, 2021 at 23:17

1 Answer 1

7
\$\begingroup\$

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 &dagger; for † and &times; 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 (left, centered, or right) 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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ If you align the = and the \approx in your align example (rather than aligning the first entity after them) you won't have that spacing problem and won't need the invisible brackets. I've gone ahead and done it in the LaTeX (but not the code version) so that you can see and decide if you want to edit. \$\endgroup\$
    – nitsua60 Mod
    Jul 12, 2020 at 13:30
  • 1
    \$\begingroup\$ @nitsua60 Huh.. Cheers! I left the note in about the brackets, because it is sometimes needed, depending on what you do with it. \$\endgroup\$
    – Someone_Evil Mod
    Jul 12, 2020 at 20:21
  • \$\begingroup\$ That's funny--I've literally never had to do that, nor seen that trick used. And tex.se is how I made my way to the Stack! As usual with (La)TeX, running across something new every time =) \$\endgroup\$
    – nitsua60 Mod
    Jul 12, 2020 at 20:32
  • \$\begingroup\$ I always use a generator to format my markdown tables. It's faster than doing it by hand, especially if you're copying from a website. \$\endgroup\$
    – Laurel
    Jul 8, 2021 at 0:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .