How to define string remap in MathJax

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.

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]}$$.

$$\newcommand{\Map}[3]{{#1}\colon{#2}\to{#3}}$$



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