Is it possible for Stack Exchange to make available $\LaTeX$ abbreviations for \mathrm{E}, \mathrm{Var}, \mathrm{Cov} (possibly with new commands \E, \Var and \Cov)? The problem is that things like $\mathrm{Var}[X\mid Y]$ look much better than $Var[X\mid Y]$, but we end up losing a lot of time typing that.

Just FYI, you can also try: \$\text{Var}[X|Y]\$ (ie $\text{Var}[X|Y]$), if that's more convenient. –  gung Oct 5 '12 at 18:08
gung's suggestion saves two keystrokes, which is good, but I was wondering if \Var would make life easier for us. I understand that it would not be universally used, since it is not plain $\LaTeX$. –  Zen Oct 5 '12 at 18:13
In my answers I often declare such a macro using \newcommand at the beginning and then use the macro in the rest of the answer. That's often helpful, especially if you need to use it many times. –  cardinal Oct 5 '12 at 18:46
(+1) Can I use \newcommand in my answers?!?!?!?!? Whoooaaaa! Problem solved. I'll setup a txt with definitions I normally use. Thank you a lot, Prof.! –  Zen Oct 5 '12 at 19:03
@cardinal, I'm not familiar w/ \newcommand, since it seems that is the answer to this Q, can you make it official, perhaps w/ a brief tutorial re how it would work? –  gung Oct 5 '12 at 20:18

1 Answer 1

$\newcommand{\E}{\mathrm{E}}$ $\newcommand{\Var}{\mathrm{Var}}$ $\newcommand{\Cov}{\mathrm{Cov}}$ $\newcommand{\Expect}{{\rm I\kern-.3em E}}$

Here is cardinal's solution. At the beginning of your answer type.




After that, just use it. For example:

$$ \Var[X] = \E[\Var[X\mid Y]] + \Var[[\E\mid X]] $$

$$ \Cov[X,Y] = \E[XY] - \E[X]\E[Y] $$

Stask suggested

$\newcommand{\Expect}{{\rm I\kern-.3em E}}$


which looks pretty.

A somewhat fancier solution is $\newcommand{\Expect}{{\rm I\kern-.3em E}}$ that produces $\Expect[X]$. Unfortunately, you cannot easily extend it to the variance operator. –  StasK Oct 6 '12 at 2:28
@Stas: That's an old hack for \mathbb E, i.e., $\mathbb E$. This does extend to variance $\mathbb V(X)$ or similar, as you like. The latter doesn't seem too popular though. :-) –  cardinal Oct 6 '12 at 13:59
Yay! Thanks, cardinal. I need to learn my $\LaTeX$ better, apparently :) –  StasK Oct 6 '12 at 15:08
Neat solution. :) But I for one would prefer if these commands were available out-of-the-box. –  MånsT Oct 8 '12 at 12:12
(+1 a couple days ago) As a side note, if you want to avoid the empty space at the top of the answer caused by the macro definitions, you can just slip the \newcommand calls in at the beginning of the first math-mode block you use in your answer. :-) –  cardinal Oct 8 '12 at 17:35
(+1) Another great tip! –  Zen Oct 8 '12 at 20:15
How do you use this? I have $\Var{\beta}$ but it misses those square brackets. How can you have them? –  Masi Feb 28 at 21:21

You must log in to answer this question.

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