For example if there is a lot of $R^2$ and $C^2$ in a post, how to map the plain text R2 to $R^2$ only in this post like:

(start of define block mark)
define R2 $R^2$
define C2 $C^2$
(end of define block mark)

LaTeX commands is still too complex to reference again and again.


1 Answer 1


You can define macros in MathJax. As far as I can tell, you cannot use numbers in macro names. For example, this defines a macro called \Rsq which then types $\newcommand{\Rsq}{\mathbb R^2}\Rsq$.

$\newcommand{\Rsq}{\mathbb R^2}$ $\Rsq$

Macros can also use parameters. For example, the macro define below can be used as $\newcommand{\Map}[3]{{#1}\colon{#2}\to{#3}}$ \Map fXY to get $\Map fXY$ or \Map\phi{[0,1]}{[0,1]} $\Map\phi{[0,1]}{[0,1]}$.


Other commands which can be used to define some "shortcut" are \renewcommand, \DeclareMathOperator, \def and \let. You can find many examples on the main site, if you search for \newcommand, \renewcommand, \DeclareMathOperator. It might be easier to find examples of \def and examples of \let using SEDE, since the built-in search might return some false positives.

It is recommended to avoid using macros in the title. If you define a macro, it will be available within the post where you defined it.

Syntax is basically the same as in LaTeX, you can find some basics in various places. For example, TeX FAQ, Overleaf, Wikibooks


You must log in to answer this question.

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