This page shows how to add a new \var TeX command to MathJax 3, which parses its (non-TeX) input and returns TeX code to go be substituted for the macro.
\var
See the code
\( \var{x*x} \)
\( \var[upper]{a*b} \)