# What interesting uses of MathJax are there, other than mathematical typesetting?

What interesting uses of MathJax are there, other than mathematical typesetting, that might be useful for Code Review?

• hmm.. this could be interesting as faq entry... – Vogel612 Jan 5 '15 at 10:04

You can make tables using \begin{array}{colspec} … \end{array}, where colspec is some string consisting of l, c, r specifying left, center, and right alignment for the columns. The colspec may also have | characters indicating the placement of vertical column-separating bars.

To draw horizontal row-separating lines, use the \hline command.

Here is a moderately complex example:

$$\newcommand{smallm}{\overset{n\ \gg\ m}{\longrightarrow}} \begin{array}{|l|c|c|} \hline \\ & \textrm{Straightforward approach, done well} & \textrm{Fenwick tree} \\ \hline \\ \textrm{Space} & O(m + n) \smallm O(n) & O(m) \smallm O(1) \\ \hline \\ \textrm{Time} & O(m + n) \smallm O(n) & O((m + n) \log m) \smallm O(n) \\ \hline \end{array}$$

Here is a very complex example of a truth table:

$$\begin{array}{ccc|c|c} \text{*p == *q} & \text{*q != '\0'} & \text{*p != '\0'} & {\begin{array}{l}\text{*p!='\0' &&}\\\text{*q!='\0' &&}\\\text{*p==*q}\end{array}} & \begin{array}{l}\text{*q != '\0' &&}\\\text{*p == *q}\end{array} \\ \hline \\ \begin{array}{c}T\\T\end{array} & \begin{array}{c}T\\T\end{array} & \begin{array}{c}T\\F\end{array} & \begin{array}{c}T\\F\ \textrm{(impossible)}\end{array} & T \\ \hline \\ \begin{array}{c}T\\T\end{array} & \begin{array}{c}F\\F\end{array} & \begin{array}{c}T\\F\end{array} & \begin{array}{c}F\ \textrm{(impossible)}\\F\end{array} & F \\ \hline \\ \begin{array}{c}F\\F\end{array} & \begin{array}{c}T\\T\end{array} & \begin{array}{c}T\\F\end{array} & \begin{array}{c}F\\F\end{array} & F \\ \hline \\ \begin{array}{c}F\\F\end{array} & \begin{array}{c}F\\F\end{array} & \begin{array}{c}T\\F\end{array} & \begin{array}{c}F\\F\end{array} & F \\ \end{array}$$

See the source for the examples above, or by right-clicking on each table and selecting Show Math As → TeX Commands.

You can draw box-and-pointer diagrams using a combination of \fbox{} and arrows.

\newcommand{ptr}{\overset{\mathtt{#1}}{\longrightarrow}} \begin{align*} &\mathtt{newNode} \\ &\quad\downarrow \\ \mathtt{head} \ptr{} \fbox{first} \ptr{next} &\fbox{another} \ptr{next} \mathtt{null} \\ &\fbox{second} \ptr{next} \fbox{rest} \ptr{next} \fbox{of} \ptr{next} \fbox{list} \ptr{next} \mathtt{null} \end{align*}

You can use it to get color text, such as $\bbox[black]{\color{white}{\textrm{white}}}\ \color{black}{\textrm{black}}\ \color{red}{\textrm{red}}\ \color{green}{\textrm{green}}\ \color{blue}{\textrm{blue}}\ \color{cyan}{\textrm{cyan}}\ \color{magenta}{\textrm{magenta}}\ \bbox[gray]{\color{yellow}{\textrm{yellow}}}$.

The MathJax \color command works differently from the $\LaTeX$ \color command. The MathJax syntax is \color{red}{apple}; the $\LaTeX$ syntax is just \color{red}, which changes the color of all subsequent text.

Any standard CSS color name should work, e.g. $\color{firebrick}{\texttt{\color{firebrick}{blah}}}$.

To change the background color, you can use \bbox[bgcolorname]{content}.

• Don't do this, but what some people did on Math.SE a while back was prepend $\bbox[red]{\color{red}{\boxed{\color{white}{+500}}}}$ to their title to indicate a promised bounty. – apnorton Jan 7 '15 at 2:42
• @anorton I don't believe Code Review allows MathJax in question titles. And if anyone tried to pull something like that, it would get Jamalized away. – 200_success Jan 7 '15 at 2:46