LaTeX Tip: Operator Names

I’ve always written:

P(X>Y)
E[X=3]

Which gives you something like this:

P(X>Y)\\E[X=3]

The problem here is that the probability and expected value operators are italicized as if they were variables. I should have been writing:

\operatorname{P}(X>Y)
\operatorname{E}[X=3]

Which will render them in the plain old Roman font like \lim or \min.

Wikibooks has a nice snippet on it with some more details.