In his answer to a question about crossing out units in dimensional analysis, Loong notes that the \cancel{} LaTeX command can be enabled in MathJax by using \require{cancel} at the start of a MathJax block.

What other commands/features can be enabled in MathJax through the use of \require{}, or other similar MathJax-internal commands?

Peter's answer points to the MathJax documentation, which lists the additional features available using \require{}. Many of these features are sufficiently cool and potentially useful that I want to make them more visible. So, I plan to lay out the available features and examples of their usage in the answers below. For convenience, below is a table of contents—you may want to wait to click these until the page has fully loaded and all of the MathJax has rendered, otherwise the entry you want may "run away" from you:

To note, even though mhchem has been enabled on Chem.SE by default, it is not enabled on many other sites in the Stack Exchange network. If for some reason you have need of chemical equations somewhere else and \ce isn't rendering properly for you, including \require{mhchem} should make it work. Per the developer's comment and chat post, though, beware that sites that do not specifically load the newest mhchem will load whatever version is packaged with the current version of MathJax, and therefore some behavior may differ, possibly significantly.

The amsmath and amssymbols extensions are also enabled by default on Chem.SE. The symbols available by default, as well as those that require activation by \require{mediawiki-texvc}, can be browsed at the relevant section of the MathJax documentation. In particular, if you are interested in using the symbol for Angstrom units, use \AA after supplying \require{mediawiki-texvc}:

$$ \require{mediawiki-texvc} \AA $$

Finally, note that using any of these \require{} commands will enable the feature set for the entire webpage in which they will appear. This shouldn't be a problem for most the commands laid out here; the primary exception is \require{color}, which will interfere with any uses of the default $\mathrm\TeX$ form of \color{}. As such, \bbox is preferred, when possible. There do exist a couple of additional MathJax extensions not listed above that can be loaded with \require{}, but I've omitted them here because they will essentially always have significant side-effects beyond just the post in which they're included.

  • $\begingroup$ Note: bbox, and unicode get loaded automatically when the \bbox, and \unicode macros are first used, so no need for \require for these. Similarly, the html extension is loaded by the first use of \href, \style, \class, or \cssId, so no need for \require there, either. Also, SE's configuration already includes AMSsymbols, so no need to include that via \require. Finally, note that the \color macro from the color extension is incompatible with the default \color macro, so loading that can cause problems for people used to using the default \color macro. $\endgroup$ Commented Feb 1, 2017 at 16:03
  • $\begingroup$ @DavideCervone Ah, I wondered about some of that auto-load behavior -- I'll edit to incorporate. Also, I dunno why I thought AMSsymbols wasn't enabled by default -- on a quick test, you're absolutely right. Will edit there, too. Thanks! $\endgroup$
    – hBy2Py
    Commented Feb 1, 2017 at 16:11
  • $\begingroup$ @DavideCervone I was definitely aware of the change in behavior of \color, but it hadn't occurred that this has potential to break other users' posts -- will add a warning for that, too. $\endgroup$
    – hBy2Py
    Commented Feb 1, 2017 at 16:32
  • 1
    $\begingroup$ The correct way to write Ångstrom: $\times 10^{-10}\,\pu{m}$. $\endgroup$ Commented Feb 3, 2017 at 9:51
  • $\begingroup$ @Martin-マーチン Oh? The Scandinavian condensed 'AA' isn't appropriate? $\endgroup$
    – hBy2Py
    Commented Feb 3, 2017 at 12:58
  • $\begingroup$ I actually prefer pico-metre and it has the benefit of being more SI than Ångstrom. $\endgroup$ Commented Feb 3, 2017 at 14:44
  • 2
    $\begingroup$ Tbph, I only used pm to date here because I was unable to generate Å via \AA. I shall now go back and reedit all my relevant posts to read ångströms instead. $\endgroup$
    – Jan
    Commented Feb 3, 2017 at 18:38
  • 2
    $\begingroup$ Please note that for the time being, \require{mhchem} (used at another SE site) will load the 'legacy' version from MathJax core, while chemistry.SE already uses the improved version 3. So not all input will render identical. $\endgroup$
    – mhchem
    Commented Feb 16, 2017 at 8:51
  • $\begingroup$ @DavideCervone I've finished all of the entries for this post -- would you be willing to review them, now that it's complete? $\endgroup$
    – hBy2Py
    Commented Mar 24, 2017 at 1:52
  • $\begingroup$ @hBy2Py, Thanks for putting this page together. You have done a great job, and made some points that I hadn't thought of myself. Good work! I made a few comments, and edited one of the entries to clarify a couple of things, but other than that, I think it is good. $\endgroup$ Commented Apr 2, 2017 at 23:12
  • $\begingroup$ @DavideCervone Thanks for your assistance in touching it up! It's much better having your input woven into it. I especially appreciate you correcting the post about \color -- I've never used $\TeX$ directly, so I had no idea that it was a MathJax thing, not a $\TeX$ thing. $\endgroup$
    – hBy2Py
    Commented Apr 2, 2017 at 23:18

12 Answers 12


As described in the MathJax documentation, any of the core MathJax extensions can be loaded this way (though this can be restricted via the MathJax configuration).

  • $\begingroup$ Great! Is it only those core extensions, listed at that link, that can be used with \require? Or are there custom/third-party ones that are available as well? $\endgroup$
    – hBy2Py
    Commented Jan 31, 2017 at 16:09
  • $\begingroup$ Those are the only ones you can call via require. $\endgroup$ Commented Jan 31, 2017 at 16:11
  • $\begingroup$ Ok -- everything else you have to work up a custom script for, or somesuch? $\endgroup$
    – hBy2Py
    Commented Jan 31, 2017 at 16:11
  • $\begingroup$ Essentially, yes. If you control the MathJax configuration, it's easy to load extensions from our official third party extension repository (and possible to load them from anywhere else too). See the docs for more information. $\endgroup$ Commented Jan 31, 2017 at 16:57
  • $\begingroup$ Peter, with \bbox, is there any way to apply more than one explicitly named CSS style element? Or is it restricted to exactly one? {time passes} AH! Semicolons. Never mind! $\endgroup$
    – hBy2Py
    Commented Jan 31, 2017 at 22:33
  • $\begingroup$ @hByPy glad you could work it out. MathJax also offers a non-standard \style{css}{math} macro for adding inline-styles to subexpressions, cf. docs.mathjax.org/en/latest/tex.html#html. Note that styles might not have the same effect on all outputs and that they might be overruled by MathJax's own styles further down the cascade. $\endgroup$ Commented Feb 2, 2017 at 9:59
  • $\begingroup$ Thanks for noting \style (w/caveats) -- I'll add that in! $\endgroup$
    – hBy2Py
    Commented Feb 2, 2017 at 12:42
  • $\begingroup$ Peter, I can get \style to work, but when I try to use \href in an example it doesn't apply the hyperlink -- it just echoes the url and the math as regular math input, with no hyperlink generated. Does it generate links for you? $\endgroup$
    – hBy2Py
    Commented Mar 6, 2017 at 3:19
  • $\begingroup$ Also, Peter, please see the Extensible Arrows answer. In particular, (1) can you check whether \xtofrom works for you at present; and (2), would it be possible to implement the equilibrium arrows $($0x21cc, $\unicode{x21cc})$ into \extpfeil? $\endgroup$
    – hBy2Py
    Commented Mar 6, 2017 at 4:43
  • $\begingroup$ @hBy2Py I believe \href is disabled for security reasons. \xtofrom works but won't be stretchy with the default fonts (for now anyway). For equilibrium, have you tried \rightleftharpoons? $\endgroup$ Commented Mar 6, 2017 at 15:55
  • $\begingroup$ <nod> that works fine for a non-stretching arrow, optionally with \overset, but I haven't been able to make it work with \Newextarrow. $\endgroup$
    – hBy2Py
    Commented Mar 6, 2017 at 16:02
  • $\begingroup$ Peter, we discovered that applying a border to math with a \bbox command causes an hemorrhagic render-splosion in Firefox: chat.stackexchange.com/rooms/3229/conversation/…. Safari (AFAIK) and Chrome still have the alignment troubles noted below but it doesn't munge the rest of the page. $\endgroup$
    – hBy2Py
    Commented Mar 24, 2017 at 13:23
  • $\begingroup$ I'm afraid I don't follow. For the "hemorrhage", could you create an isolated sample that exhibits the problem, say on jsbin or just a snippet that exhibits the problem when pasted to the answer form here? For the "noted below", that's expected behavior right now; MathJax does not know about the 5px border being added via a style element and thus does not take it into account. $\endgroup$ Commented Mar 24, 2017 at 15:03
  • $\begingroup$ @hBy2Py, in order for an arrow to be stretchable by MathJax, the fonts in use must include the needed glyphs for the three needed pieces: the left end, the middle repeating part, and the right end. For U+21CC (⇌), you would need to have U+296B (⥫) for the left, U+296C (⥬) for the right, and something like the equal sign (=) for the middle, as long as it has the same spacing between the lines and they are at the same vertical positions as the other two. Most fonts don't have these characters, and the MathJax TeX fonts don't. But the STIX fonts do, so if you use those, it will work. $\endgroup$ Commented Apr 2, 2017 at 22:53
  • $\begingroup$ @hBy2Py, for \xtofrom, you would need an arrow with a line over it for the left end, an arrow with a line under it for the right, and something like an equal sign with the right spacing and position to match the other two. Unfortunately, Unicode doesn't seem to have glyphs for the left and right ends. So none of the MathJax fonts can make this character stretch. And for a font to be able to support that, you would probably have to use the Private Use Area to include non-standard glyphs. We have certainly done that for some needed glyphs, but don't have the ones needed for this array. $\endgroup$ Commented Apr 2, 2017 at 22:58

Command Grouping

Enable with: \require{begingroup}

Environment: \begingroup ... \endgroup

Quite a few things are possible with MathJax when you set your mind to it. For example you can define new commands with \newcommand{...}. In order to preserve default behaviour for the other posts, you might want enclose your post in a group with \require{begingroup}. $\require{begingroup}$

As a result you can use the following code without destroying our nice site for the next post.

\op{H}\Psi=E\Psi \tag{mathbf}\label{schrödi1}
\op{H}\Psi=E\Psi \tag{hat}\label{schrödi2}

Which gives us: $$ \begingroup \newcommand{\op}[1]{\mathbf{#1}} \op{H}\Psi=E\Psi \tag{mathbf}\label{schrödi1} \endgroup $$ $$ \begingroup \newcommand{\op}[1]{\hat{#1}} \op{H}\Psi=E\Psi \tag{hat}\label{schrödi2} \endgroup $$

Note that labels added with \label{} still have to be unique regardless of grouping: $\eqref{schrödi1}$ and $\eqref{schrödi2}$. Also, note that using \begingroup .. \endgroup does not contain the effects of loading other packages: once loaded, a package affects the entire page.

  • $\begingroup$ Ah, thanks Mart. I didn't see any particular use cases for \begingroup/\endgroup, so I was going to leave them out. In particular, I was thinking of them as possibly a way to contain the effects of other \require commands, but they don't work for that purpose. Didn't think about \newcommand! $\endgroup$
    – hBy2Py
    Commented Feb 3, 2017 at 12:56
  • $\begingroup$ @hBy2Py It is actually one of the most important packages. One ill-placed macro and it can wreck the whole site. I could invert all your fractions and you wouldn't even notice. See here: meta.stackexchange.com/q/290616/260760 $\endgroup$ Commented Feb 3, 2017 at 14:47
  • $\begingroup$ @Martin-マーチン Well this certainly answers why Loong's post was full of $^\text{troll}$... $\endgroup$ Commented Feb 3, 2017 at 20:39
  • $\begingroup$ @orthocresol Well, that was a side effect and I only included this to make the changes visible. With a simple \def\frac#1#2{#2\over#1} it would have been barely noticeable. $\endgroup$ Commented Feb 4, 2017 at 7:24
  • $\begingroup$ Does a loaded extension affect the entire page? Or just the rest of the page that loads after that point? Of course, if this is the case, the answer order can vary, so the effects may 'wander' as the post order changes? $\endgroup$
    – hBy2Py
    Commented Feb 17, 2017 at 5:29
  • $\begingroup$ @hBy2Py Yes, only the sections after the definitions are affected. After commands/packages are loaded, it affects everything that is rendered new. If a command/package gets defined/loaded in the last answer and then you edit one of the posts above it, it will temporarily (until a refresh) affect also these posts. $\endgroup$ Commented Feb 17, 2017 at 5:58

2-D Reaction Networks

Enable with: \require{AMScd}

Environment: \begin{CD} ... \end{CD}

Construct two-dimensional grids connected with single-headed arrows. Double-headed and double-lined arrows appear not to be supported, unfortunately. mwchem (\ce{...}) is supported, but you have to apply it to each item in the grid, not the entire grid as a single item.

Annotations above/below/beside the arrows are indicated by interleaving them into the codes for the arrows:

Up:      @AAA
Down: @VVV
Left:    @<<<
Right: @>>>

Double-lines can be used, but unfortunately without arrowheads:

Vertical:      @|||
Horizontal: @===

Anywhere a 'non-arrow' needs to be inserted, @. can be used.

More information is available in the PDF here.

\ce A         @>k_1>>    \ce B         @.         ~       \\
@Vk_2VV                  @VVk_4V                  @.      \\
\ce C         @>k_3>>    \ce D         @<k_5<<    \ce E   \\
@Ak_7AA                  @VVk_6V                  @.      \\
\ce G         @.         \ce F         @.         ~       \\

$$ \require{AMScd} ~\\ \begin{CD} \ce A @>k_1>> \ce B @. ~ \\ @Vk_2VV @VVk_4V @. \\ \ce C @>k_3>> \ce D @<k_5<< \ce E \\ @Ak_7AA @VVk_6V @. \\ \ce G @. \ce F @. ~ \\ \end{CD} $$


Cancellation Lines

Enable with: \require{cancel}

Commands: \cancel{}, \bcancel{}, \xcancel{}, \cancelto{}

Overstrike math content with:

  • \cancel:     A diagonal line rising to the right
  • \bcancel:   A diagonal line falling to the right
  • \xcancel:   An 'X'
  • \cancelto: A single-headed arrow rising to the right, with a value indicated at the end of the arrow


{\cancel{x} y \over \cancel{x}} = y \\
{x^\bcancel{3} \over \cancel{x^2}} = x \\
\xcancel{0 = 1} \\
\cancelto{\,5}{25 \over 5}

$$ \require{cancel} ~\\ {\cancel{x} y \over \cancel{x}} = y \\ {x^\bcancel{3} \over \cancel{x^2}} = x \\ \xcancel{0 = 1} \\ \cancelto{\,5}{25 \over 5} $$


Tooltips and Toggleable Math

Enable with: \require{action}

Commands: \mathtip{math}{tip} and \texttip{math}{tip}

Apply tooltips to math expressions (text shown when the cursor is hovered over the expression). \mathtip shows tip using math-mode rendering; \texttip shows tip using text-mode rendering.

\texttip{a+b}{This is addition!} \\ ~ \\
\mathtip{\ln{\!\left( e^x \right)}}{=x}

$$ \require{action} ~\\ \texttip{a+b}{This is addition!} \\ ~ \\ \mathtip{\ln{\!\left( e^x \right)}}{=x} $$

Command: \toggle{math1}{math2}...\endtoggle

Create a math object that cycles through different expressions when clicked.


$$ \require{action} ~\\ \toggle{a}{a+b}{a+b+c}{a+b+c+d}\endtoggle $$


Overlay/Enclosure Annotations

Enable with: \require{enclose} $\require{enclose}$

Command: \enclose{type}[options]{math}

Apply a MathML 3 enclosure, with optional text or background color formatting (see here for available color descriptors), to math.

Available enclosures include:

  • longdiv - Long division symbol (it's apparently possible to construct entire long division problems; I did not take the time to figure out how, though)
    \enclose{longdiv}[mathcolor="red"]{x^2+5} $\rightarrow \enclose{longdiv}[mathcolor="red"]{x^2+5}$

  • actuarial - Symbol from actuarial notation (no particular relevance to chemistry)
    \enclose{actuarial}[mathbackground="#6ad898"]{2x} $\rightarrow \enclose{actuarial}[mathbackground="#6ad898"]{2x}$

  • phasorangle - Phasor angle symbol (also no particular relevance to chemistry):
    A_1\enclose{phasorangle}{\theta_1} $\rightarrow A_1\enclose{phasorangle}{\theta_1}$

  • radical - Root symbol
    ^3\enclose{radical}{x^6} = x^2 $\rightarrow~^3\enclose{radical}{x^6} = x^2$

  • box - Box with hard corners
    \enclose{box}{x = 1 \pm 3} $\rightarrow \enclose{box}{x = 1 \pm 3}$

  • roundedbox - Box with rounded corners
    \enclose{roundedbox}{y = {1\over x}} $\rightarrow \enclose{roundedbox}{y = {1\over x}}$

  • circle - Ellipse (ironically); may have to include extra horizontal or vertical whitespace to avoid clipping
    \enclose{circle}{f(x)=x^2} $\rightarrow \enclose{circle}{f(x)=x^2}$
    \enclose{circle}{~~~~f(x)=x^2\phantom{x^2\over 1}} $\rightarrow \enclose{circle}{~~~~f(x)=x^2\phantom{x^2\over 1}}$

  • left, right, top, bottom - Line on one side of the math
    \enclose{bottom}{x+y}\cdots\enclose{right}{x\over y} $\rightarrow\enclose{bottom}{x+y}\cdots\enclose{right}{x\over y}$

  • updiagonalstrike, downdiagonalstrike,
    verticalstrike, horizontalstrike - Strikethroughs
    \enclose{verticalstrike}{a+b^2\over c+d}$\rightarrow\enclose{verticalstrike}{a+b^2\over c+d}$
    \enclose{updiagonalstrike}{a+b^2\over c+d}$\rightarrow\enclose{updiagonalstrike}{a+b^2\over c+d}$

  • madruwb - Arabic factorial (renders an approximation on my browser)
    enclose{madruwb}{55} $\rightarrow\enclose{madruwb}{55}$

Multiple enclosures can be applied to the same math by passing a space-separated list of enclosures to \enclose:

      \enclose{circle updiagonalstrike horizontalstrike}{y^3 - xy^2} $\rightarrow\enclose{circle updiagonalstrike horizontalstrike}{y^3 - xy^2}$

At this time (5 Feb 2017) it appears that MathJax does not implement the arrows defined in the MathML specification (northeastarrow, updownarrow, etc.) except for updiagonalarrow (thanks, Davide!):

      \enclose{updiagonalarrow}{3x^2} $\rightarrow\enclose{updiagonalarrow}{3x^2}$

  • $\begingroup$ As you mention, MathJax does not implement does not implement most of the arrows, only the updiagonalarrow. $\endgroup$ Commented Feb 6, 2017 at 11:51

Unicode Characters

Enable with: \require{unicode} (optional; loads automatically on first use)

Command: \unicode{#####} or \unicode{x####}

Insert the Unicode character at decimal code point ##### or hexadecimal code point x####. As usual, proper rendering depends on browser encoding support. There are many resources for Unicode code points around the Internet; searching "Unicode [thing]" will frequently point you in the right direction. I discovered this site recently, which has a nice categorized listing of an extremely large set of Unicode code points.



From here and here:

$ \require{begingroup} \begingroup \newcommand{graybox}[1]{\bbox[whitesmoke,1px]{\texttt{x#1}}} ~~~~~~~~\begin{array}{ccccccc} \hline \graybox{00bd} & \graybox{2153} & \graybox{2154} & \graybox{00bc} & \graybox{00be} \\ \unicode{x00bd} & \unicode{x2153} & \unicode{x2154} & \unicode{x00bc} & \unicode{x00be} \\ \hline \graybox{2155} & \graybox{2156} & \graybox{2157} & \graybox{2158} & \graybox{2159} & \graybox{215a} \\ \unicode{x2155} & \unicode{x2156} & \unicode{x2157} & \unicode{x2158} & \unicode{x2159} & \unicode{x215a} \\ \hline \graybox{2150} & \graybox{215b} & \graybox{215c} & \graybox{215d} & \graybox{215e} & \graybox{2151} & \graybox{2152} \\ \unicode{x2150} & \unicode{x215b} & \unicode{x215c} & \unicode{x215d} & \unicode{x215e} & \unicode{x2151} & \unicode{x2152} \\ \hline \end{array} $

Geometric Shapes

A few examples from here:



Examples from here:


And from here:


Currency Symbols

Examples from here:


And from here:



Examples from here:

$\unicode{x2192}~~\unicode{x2194}~~\unicode{x2197}~~\unicode{x219b}~~\unicode{x219d}~~\unicode{x21a0}~~\unicode{x21a6}~~\unicode{x21aa}~~\unicode{x21ac}~~\unicode{x21b3}~~\unicode{x21b7}~~\unicode{x21c0}~~\unicode{x21c4} \\ \unicode{x21c9}~~\unicode{x21cc}~~\unicode{x21cf}~~\unicode{x21d2}~~\unicode{x21d7}~~\unicode{x21dd}~~\unicode{x21e2}~~\unicode{x21e5}~~\unicode{x21f0}~~\unicode{x21f2}~~\unicode{x21f6}~~\unicode{x21f8}~~\unicode{x21fb}~~\unicode{x21fe}$

Mathematical Operators/Symbols

Examples from here:


And from here:


And from here:



  • $\begingroup$ Note that you can specify symbols that are not in the MathJax fonts using \unicode{}, and in that case, the glyph will be taken from another font on your system, if there is one that contains the character. Different systems will have different fonts, and there is no guarantee that everyone will be able to see the character you specified. Older versions of Windows are particularly bad at locating these characters, even when there is a font that contains them. Also, the size of the glyph might not match well with the rest of the math. So use this feature with caution. $\endgroup$ Commented Apr 2, 2017 at 23:01

mediawiki-texvc Symbols

Enable with: \require{mediawiki-texvc}

Commands: (various)

As noted in the question, the full set of symbols exposed through the mediawiki-texvc extension can be browsed at the MathJax documentation. Many of these symbols are (or appear to me to be) one-to-one substitutions for commands already available in MathJax as it is presently configured on Chem.SE.

Included in the table below are a subset of the mediawiki-texvc symbols of particular note, either because they are unavailable in the default Chem.SE MathJax or because their mediawiki-texvc commands are appreciably shorter and/or clearer. Some are not of particular relevance to chemistry, but are included for the possible benefit of users from (GASP) other sites in the SE network.

$ \require{mediawiki-texvc} \require{begingroup} \begingroup \def\grbx#1{\bbox[2pt,lightgray,font-size:75%]{\text{#1}}} \def\smx{--} $

$ \begin{array}{cccccc} \hline {\small\text{Default}} & \grbx{\spadesuit} & \grbx{\heartsuit} & \grbx{\diamondsuit} & \grbx{\clubsuit} \\ {\small\text{mediawiki-texvc}} & \grbx{\spades} & \grbx{\hearts} & \grbx{\diamonds} & \grbx{\clubs} \\ {\small\text{Symbol}} & \spades & \hearts & \diamonds & \clubs \\ \hline {\small\text{Default}} & \grbx{\mathbb{C}} & \grbx{\mathbb{H}} & \grbx{\mathbb{N}} \\ {\small\text{mediawiki-texvc}} & \grbx{\C} & \grbx{\H} & \grbx{\N} \\ {\small\text{Symbol}} & \C & \H & \N \\ {\small\text{Default}} & \grbx{\mathbb{Q}} & \grbx{\mathbb{R}} & \grbx{\mathbb{Z}}\\ {\small\text{mediawiki-texvc}} & \grbx{\Q} & \grbx{\R} & \grbx{\Z} \\ {\small\text{Symbol}} & \Q & \R & \Z \\ \hline {\small\text{Default}} & \grbx{\rightarrow} & \grbx{\Rightarrow} & \grbx{\leftrightarrow} & \grbx{\Leftrightarrow} \\ {\small\text{mediawiki-texvc}} & \grbx{\rarr} & \grbx{\Rarr} & \grbx{\lrarr} & \grbx{\Lrarr} \\ {\small\text{Symbol}} & \rarr & \Rarr & \lrarr & \Lrarr \\ \hline {\small\text{Default}} & \smx & \smx & \smx & \smx \\ {\small\text{mediawiki-texvc}} & \grbx{\coppa} & \grbx{\Koppa} & \grbx{\sampi} & \grbx{\Sampi} \\ {\small\text{Symbol}} & \coppa & \Koppa & \sampi & \Sampi \\ {\small\text{Default}} & \smx & \smx & \grbx{\vartheta} \\ {\small\text{mediawiki-texvc}} & \grbx{\stigma} & \grbx{\Stigma} & \grbx{\thetasym} \\ {\small\text{Symbol}} & \stigma & \Stigma & \thetasym \\ \hline {\small\text{Default}} & \grbx{\subset} & \grbx{\subseteq} & \grbx{\supset} & \grbx{\supseteq} \\ {\small\text{mediawiki-texvc}} & \grbx{\sub} & \grbx{\sube} & \smx & \grbx{\supe} \\ {\small\text{Symbol}} & \sub & \sube & \supset & \supe \\ {\small\text{Default}} & \grbx{\land} & \grbx{\lor} \\ {\small\text{mediawiki-texvc}} & \grbx{\and} & \grbx{\or} \\ {\small\text{Symbol}} & \and & \or \\ \hline {\small\text{Default}} & \smx & \smx & \smx \\ {\small\text{mediawiki-texvc}} & \grbx{\AA} & \grbx{\euro} & \grbx{\textvisiblespace} \\ {\small\text{Symbol}} & \AA & \euro & \textvisiblespace \\ {\small\text{Default}} & \smx & \grbx{\wp} \\ {\small\text{mediawiki-texvc}} & \grbx{\vline} & \grbx{\weierp} \\ {\small\text{Symbol}} & \vline & \weierp \\ \hline \end{array} $

Note that \vline and the pipe symbol are not the same:
   \vline – $\vline$
   {pipe} – |


  • $\begingroup$ I added some defaults that were missing. Also, there are a number of macros in the mediawiki-texvc extension that are not listed here. You can see the complete list in the source code $\endgroup$ Commented Feb 17, 2017 at 14:15
  • $\begingroup$ Thanks, @DavideCervone! Yeah, I wasn't trying to make it an exhaustive list -- it's much too extensive for that. $\endgroup$
    – hBy2Py
    Commented Feb 17, 2017 at 14:24

Coloring ($\rm\LaTeX$ Style)

Enable with: \require{color}

Commands: \color (redefinition), \colorbox, \fcolorbox, \definecolor, \textcolor

MathJax ships by default with a non-standard implementation of the \color command, which applies a case-insensitive predefined or svgnames color to some math passed to it as an argument:

\color{reD}{x+y}+z = \color{bLUe}{m^2} \\

$$ {\color{reD}{x+y}}+z = {\color{bLUe}{m^2}} \\ {\color{NAVY}{\ce{HCl}}}~~{\color{MedIUMSEaGREeN}{\ce{NaCl}}} $$

Invoking \require{color} loads a much broader set of commands. First, \color is overwritten, turning it into a to-end-of-scope modifier instead of a pure command that takes the material to be colored as an argument:

\color{red}{this} that \\
{or \color{red} this} that

$$ \require{color} \color{red}{this} that \\ {or \color{red} this} that $$

This redefinition applies to everything parsed after the \require invocation, page-wide. It thus has the potential to break uses of the default argument-based \color in other posts on the page!

A command with the argument-coloring behavior, \textcolor, is defined:

\textcolor{RED}{this} that

$$ \textcolor{RED}{this} that $$

The case-sensitive dvipsnames color space is loaded:

\textcolor{Apricot}{noodle} \\
{this \color{Thistle} that} other {\color{thistle} wise}

$$ \textcolor{Apricot}{noodle} \\ {this \color{Thistle} that} other {\color{thistle} wise} $$

The difference in color above is due to $\color{Thistle}that$ being colored with dvipsnames case-sensitive "Thistle" but $\color{thistle}wise$ being colored with svgnames case-insensitive "Thistle"/"thistle".

New color names can be defined with \definecolor in a variety of ways:

\textcolor{mygray2!}{12345}~\textcolor{MyGray2!}{67890} \\
\textcolor{clay}{whiplash}~\textcolor{cLAy}{sagebrush} \\

$$ \definecolor{mygray2!}{gray}{0.4} \definecolor{clay}{rgb}{0.8,0.32,0.0} \definecolor{newBlue21}{RGB}{25,65,180} ~ \textcolor{mygray2!}{12345}~\textcolor{MyGray2!}{67890} \\ \textcolor{clay}{whiplash}~\textcolor{cLAy}{sagebrush} \\ \textcolor{newBlue21}{undertow}~\textcolor{newblue21}{no~good} $$

Color names defined with \definecolor are strictly case-sensitive. It appears that as of this writing the HTML and cmyk color models described at the above link are not available.

Text highlighting and framed text highlighting are provided by \colorbox and \fcolorbox, respectively. Font coloring is not available as a direct argument to either command, and the contents of both of these commands are set as plain text, not as mathematics or formatted $\rm\LaTeX$. If desired, though, math (and thus full $\rm\LaTeX$ formatting, including text coloration) can be included by surrounding the relevant portions in the typical dollar signs:

\colorbox{clay}{$\textcolor{SkyBlue}{\text{This is text.}}$} \\

$$ \colorbox{clay}{$\textcolor{SkyBlue}{\text{This is text.}}$} \\ \fcolorbox{burlywood}{mygray2!}{$\textcolor{Goldenrod}{This~is~\mathbf{framed}~math~text.}$} $$


Links and CSS Styling/Formatting

Enable with: \require{html} (optional; loads automatically on first use)

Commands: \href, \class, \cssId, \style

\style allows (nearly) arbitrary CSS formatting to be applied to a math (sub-)expression. Per usual CSS syntax, separate individual CSS directives by semicolons. w3schools.com has a pretty good CSS tutorial.

\style{color: blue}{a+b}+\style{padding: 3pt; background-color: green}{c+d}

$$ \style{color: blue}{a+b}+\style{padding: 3pt; background-color: green}{c+d} $$

Much the same effect can be achieved with the \bbox command. As with \bbox, the output is only well-behaved if a numerical pixel value is explicitly supplied for border-width:

\style{border-style: solid; border-width: 5px; padding: 2px}{x^2-3x+2}

$$ \style{border-style: solid; border-width: 5px; padding: 2px}{x^2-3x+2} $$

Nesting \style directives can also have dramatic side effects. For example, when drafting this post, I managed to create a math expression that made the webpage page "infinitely long", and totally blank below the CSS-formatted math expression. (For what are hopefully obvious reasons, I removed this expression from the final version of the post....) I hadn't yet discovered the need for explicitly specifying the border-width property to avoid misbehavior at that point, though, so it's possible this weirdness stemmed from that same problem.

Unfortunately, the remaining three commands supplied by this extension are somewhat useless on Stack Exchange. Per a comment by Peter Krautzberger, \href, which would allow construction of links within math expressions, appears to be disabled on SE sites for security reasons. Instead of creating a link, the URL is just echoed into the expression:



In theory, \class would permit formatting arbitrary MathJax expressions with the same styles applied to the 'native' Stack Exchange CSS classes. Considering that 2002 was the last time I worked directly with CSS, I have not had success in extracting class names from the SE .css file. (Alternatively, it is possible that \class has also been disabled by the SE developers.) If anyone can get this command to work, please feel free to edit instructions into this answer.

\cssId, which attaches an id attribute to a math (sub-)expression, is of little use on Stack Exchange since to my knowledge post authors don't have the ability to modify the CSS or Javascript running on the site.

  • $\begingroup$ Again, the caveats about using styles that change the size or position of the affected element mentioned in my comments to the \bbox command apply here as well. Note that \style{border: 5px solid black}{x^2-3x+1} is easier than giving each of the sub-styles separately. Also, the width doesn't have to be in pixels, it can be any of the available units, like em or mm. $\endgroup$ Commented Apr 2, 2017 at 1:10
  • 1
    $\begingroup$ You are correct that \href is disabled, though unfortunately it was clumsily handled. They should have defined it as essentially \def\href#1#2{#2} so that the URL (and the extra braces around the math) would be removed, but they did \def\href{} instead, so the URL is typeset, as you point out. $\endgroup$ Commented Apr 2, 2017 at 1:12

Extensible Arrows

Enable with: \require{extpfeil}

Commands: \xtwoheadrightarrow, \xtwoheadleftarrow, \xmapsto, \xlongequal, \xtofrom, \Newextarrow

Create an arrow with overset content, sized to fit that content. Five built-in arrows are defined, of which four work properly in my browser: $\require{begingroup}\begingroup\def\rar{\quad\longrightarrow\quad}\require{extpfeil}$

  • \xtwoheadrightarrow{a+b+c}: $\quad\xtwoheadrightarrow{a+b+c}$

  • \xtwoheadleftarrow{a+b+d+c}: $\quad\xtwoheadleftarrow{a+b+d+c}$

  • \xmapsto{\text{This is a real, actual sentence.}}: $\quad\xmapsto{\text{This is a real, actual sentence.}}$

  • \xlongequal{\text{extremely long equals sign}}: $\quad\xlongequal{\text{extremely long equals sign}}$

I have not been able to get \xtofrom to work:

  • \xtofrom{ax^2+bx+c=0}: $\quad\xtofrom{ax^2+bx+c=0}$

A variety of other extensible arrows can be crafted with this extension, via the \Newextarrow{\cmd}{lspace,rspace}{unicode-char} command. Here, \cmd is the name of the new command to be defined, lspace and rspace are integers defining the left and right padding, respectively, for the text to be overset (in units of pixels?), and unicode-char is the Unicode code point for the arrow to be typeset in extended form. To note, unicode-char must be specified in hexadecimal, and must be prefixed by 0x (not just x). For example:

\xtriple{\text{This is an extended triple arrow!}} \\
\xtriplepadded{\text{This is an extended triple arrow with lots of padding!}}

$$ \Newextarrow{\xtriple}{10,10}{0x21db} \Newextarrow{\xtriplepadded}{50,50}{0x21db} \xtriple{\text{This is an extended triple arrow!}} \\ \xtriplepadded{\text{This is an extended triple arrow with lots of padding!}} $$

The following table lays out all of the arrows I have observed to work with \Newextarrow; three of these are duplicates of the arrows built into the extension. Conspicuously absent (for now?), unfortunately, is the equilibrium reaction arrow, 0x21cc $(\unicode{x21cc})$.

$$ \newcommand{graybox}[1]{\bbox[whitesmoke,1px]{\texttt{0x#1}}} \begin{array}{cccccc} \hline \graybox{2190} & \graybox{2192} & \graybox{2194} & \graybox{21d0} & \graybox{21d2} & \graybox{21d4} \\ \unicode{x2190} & \unicode{x2192} & \unicode{x2194} & \unicode{x21d0} & \unicode{x21d2} & \unicode{x21d4} \\ \hline \graybox{21bc} & \graybox{21c0} & \graybox{294e} & \graybox{21bd} & \graybox{21c1} & \graybox{2950} \\ \unicode{x21bc} & \unicode{x21c0} & \unicode{x294e} & \unicode{x21bd} & \unicode{x21c1} & \unicode{x2950} \\ \hline \graybox{219e} & \graybox{21a0} & \graybox{21a4} & \graybox{21a6} & \graybox{295a} & \graybox{295b} \\ \unicode{x219e} & \unicode{x21a0} & \unicode{x21a4} & \unicode{x21a6} & \unicode{x295a} & \unicode{x295b} \\ \hline \graybox{295e} & \graybox{295f} & \graybox{27fd} & \graybox{27fe} & \graybox{21da} & \graybox{21db} \\ \unicode{x295e} & \unicode{x295f} & \unicode{x27fd} & \unicode{x27fe} & \unicode{x21da} & \unicode{x21db} \\ \hline \end{array} $$ $\endgroup$

  • $\begingroup$ you don't actually have to use hexadecimal for the Unicode code point in \Newextarrow. You can use \Newextarrow{\xtripple}{10,10}{8667} if you want. Y9ou are correct that if you do use hexadecimal, you must include 0x to indicate that. $\endgroup$ Commented Apr 2, 2017 at 23:11

Coloring (CSS-Style)

Enable with: \require{bbox} (optional; loads automatically on first use)

Command: \bbox[options]{math}

\bbox is somewhat similar to \style, in that it applies CSS styling to the indicated math. The main difference is that it makes two specific assumptions about unqualified CSS directives passed into options:

  1. An unqualified (case-insensitive) CSS or svgnames color is taken as the background-color:

          \bbox[cyan]{a+b} $\quad\rightarrow\quad \bbox[cyan]{a+b}$

  1. An unqualified CSS distance measurement is taken as the padding:

          \bbox[10px,cyan]{a+b} $\quad\rightarrow\quad \bbox[10px,cyan]{a+b}$

As shown above, these unqualified CSS directives are separated by a comma.

Arbitrary CSS styling (w3schools.com has a pretty good tutorial) can also be applied to the math, regardless of the presence or absence of the above unqualified directives, by providing a series of semicolon-separated full CSS directives:

\bbox[lightblue,5px,border-style: solid; border-color:greenyellow; border-width: 4px]{a+b}

          $\rightarrow\quad \bbox[lightblue,5px,border-style: solid; border-color:greenyellow; border-width: 4px]{a+b}$

IMPORTANT: If you specify a border around the math, in order for the MathJax to render correctly you MUST supply at minimum both the border-style and border-width properties. Further, the border-width property must be specified as a pixel value (e.g., 4px). If you omit border-style, no border will be drawn. If you omit border-width or supply it as a relative-size keyword (e.g., thick), the text will be misaligned to the box and, on some browsers, will mess up the alignment of all following MathJax on the page!

ADDENDUM: From DavideCervone's comment:

Note that it is easier to give the combined version for borders, e.g., border: 4px solid greenyellow rather than giving each part separately. Finally, you can give the width in values other than pixels (e.g., 2em or 3mm), but you are correct that it must be an explicit width, not a keyword like thick in order for MathJax to be able to compensate for it properly.

  • $\begingroup$ The alignment issue is expected behavior. MathJax does not "know" about the 5px border in its internal process (it just passes it along) and thus does not take it into account during layout. That kind of compatibility with CSS is very hard to achieve but a long term goal for us. $\endgroup$ Commented Mar 24, 2017 at 15:05
  • $\begingroup$ @PeterKrautzberger Hmm. Sounds like \fcolorbox is for now the best way to put a colored border around some text, then? $\endgroup$
    – hBy2Py
    Commented Mar 24, 2017 at 15:38
  • $\begingroup$ @PeterKrautzberger I think I discovered a fix -- explicitly specifying a value for border-width appears to fix the problem in Chrome. $\endgroup$
    – hBy2Py
    Commented Mar 24, 2017 at 15:52
  • $\begingroup$ In Firefox, too. This is good. $\endgroup$
    – hBy2Py
    Commented Mar 24, 2017 at 16:04
  • $\begingroup$ A couple of comments. MathJax does know about the border width that you give. It does scan the list of attributes for some specific ones that it knows how to handle (and will compensate for the width in its calculations). Note that it is easier to give the combined version for borders, e.g., border: 4px solid greenyellow rather than giving each part separately. Finally, you can give the width in values other than pixels (e.g., 2em or 3mm), but you are correct that it must be an explicit width, not a keyword like thick in order for MathJax to be able to compensate for it properly. $\endgroup$ Commented Apr 2, 2017 at 0:49
  • $\begingroup$ In terms of arbitrary CSS, you are right, it can be passed on, but you should only use CSS that doesn't change the size of the element (other than padding and border styles). If you change the size or position, MathJax won't know that you have done so and the spacing can get messed up, as you have seen. Still, some interesting effects can be achieved. For example, try \bbox[transform:scalex(-1);display:inline-block]{a+b} for some fun. $\endgroup$ Commented Apr 2, 2017 at 1:04

You must log in to answer this question.

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