To typeset an operator, it is much better to use \operatorname
instead of \mathrm
, as explained on tex.SE: What's the difference between \mathrm and \operatorname?What's the difference between \mathrm and \operatorname?
Compare (first line uses \mathrm
, second line uses \operatorname
):
$$\mathrm{Var}[x] + 2\mathrm{Var}[y] - \mathrm{E}[x]\mathrm{E}[y]$$
$$\operatorname{Var}[x] + 2\operatorname{Var}[y] - \operatorname{E}[x]\operatorname{E}[y]$$
and notice small white spaces before the operator name in the second line.
As noted by @cardinal, MathJax supports \newcommand
. The best way to use it is to put into the formula where the operator first appears, because putting it into a separate formula creates an annoying empty line (see @Zen's answer). So whenever you first need variance, you can type \newcommand{\Var}{\operatorname{Var}}
, e.g.
$$\newcommand{\Var}{\operatorname{Var}} \Var[x]+\Var[y]$$
and this will be displayed as
$$\newcommand{\Var}{\operatorname{Var}} \Var[x]+\Var[y]$$
All subsequent formulas can simply use \Var
in them, e.g. $\Var[z]$
will become $\Var[z]$.