/ Garden

Introducing the mathplus package for LaTeX

/ ABSTRACT

A quick introduction to mathplus package for typesetting bracketed operators fast in LaTeX

As far as I know, the standard way to typeset the expectation operator in LaTeX is one of the following:

  1. Simply each time: \mathbb{E}[X] and \mathbb{E}\left[ X \right]
  2. Define a new command: \newcommand{\E}{\mathbb{E}} and then use \E[X] and \E\left[ X \right]
  3. Or slightly more sophisticated, define a new command that takes an argument: \newcommand{\E}[1]{\mathbb{E}\left[ #1 \right]} and then use \E{X}

In my experience, the trouble with these is as follows:

  1. The first option is just too verbose and repetitive, especially if you have to write a lot of expectations in your document.
  2. The second option is better, but it still requires you to manually add the brackets and adjust their size if needed. Writing \left[ and \right] every time can be tedious to edit, error-prone, and hard to read as opposed to operator braces {}.
  3. The third option is better in terms of readability and ease of use, and almost enough for most cases, but it can be restrictive if you want to add conditional time subscripts, or measure changes; both frequently appear in mathematical finance and economics.

This is not to even mention the fact that standard conditional expectation notation with a vertical bar '\mid' doesn't adjust its size to the content, and you have to manually add \left. and \right| to make it look good, which is even more tedious; see for instance,

EtQ[XYZ]\mathbb{E}_t^{\mathbb Q}\left[ \frac{X}{Y} \mid Z \right]

The mathplus package solves all of these issues, and prioritises ease of use and readability. The syntax for the above is simply: \expect_t^{\mathbb Q}*{ \frac{X}{Y}} | Z } (I cannot demonstrate here, as it requires loading custom packages into this markdown-based blog). Note:

  • the use of * to indicate that the brackets (and conditioning bar when given) should auto adjust their size to the content; or use square brackets if you want to explicitly specify the size: \expect_t^{\mathbb Q}[\big]{\frac{X}{Y} | Z}.
  • the intuitive use of subscript and superscript to modify the operator itself, which is consistent with the rest of LaTeX syntax; far superior to some commong solutions using square brackets argument for sub/superscripts.

This extends to other standard operators as well, such as variance \var, covariance \cov, probability \prob, and more. The package also allows you to define your own custom operators with the same syntax (I have pp-th variation as an inner product style operator with bracketed superscript, X(p)\langle X\rangle^{(p)}); change the default operator names and symbols (i.e. use normal E instead of \mathbb{E}). Check it out here if it sounds cool!