I'm editing a markdown file intended for hosting on github in vscode and using the built-in preview functionality to see how it displays.
I cannot get the subscripts to display properly for the Expectation symbol, as they do with $$ \sum_{x} $$
.
I've tried doing this with:
$$ \mathop{{}\mathbb{E}}_{\mathcal{h \in H}} $$
but I end up getting the expectation symbol (\mathbb{E}
) with the subscript (_{\mathcal{h \in H}}
) displayed side-by-side, instead of the subscript centered underneath.
I tried following the syntax for probability but it doesn't work the same way:
$$ \Pr_{h \in \mathcal{H}}$$
That works fine, but $$ \E $$
gives a KaTeX parse error: undefined control sequence.
trying \mathop{\E}{E}
doesn't work either.
There's really two issues in your question: how to get KaTeX (the TeX that vscode preview uses) to do what you want, and how to get github-flavored markdown (GHFM)'s TeX to do what you want.
Let's look at KaTeX first.
There are two ways I'm aware of to manually place subscripts under another symbol in KaTeX. The
_under^over
pattern and the\underset{under}{over}
(these both have their opposites:base^exponent
and\overset{over}{under}
). [1]The first pattern didn't work well for me, but the second did.
$$ _\mathcal{h \in H}^\mathbb{E} $$
will give you an expectation E with the subscripts below it, but the E will appear small. Changing to$$ _\mathcal{h \in H}^\mathbb{\large E} $$
fixes this, but the subscripts are not centered (they are left-aligned with the beginning of the E).$$ \underset{\mathcal{h \in H}}{\mathbb{E}} $$
gives you centered subscripts under a normally sized expectation symbol E.For GHFM, it's important to recognize that math rendering in vscode may not match what happens on GHFM.
For example, your first solution renders properly on GHFM. On GHFM,
$$ \mathop{{}\mathbb{E}}_{\mathcal{h \in H}} $$
is equivalent to$$ \underset{\mathcal{h \in H}}{\mathbb{E}} $$
, while only the latter displays as you'd like in vscode's markdown preview.It's worth periodically checking your TeX on GHFM to ensure things are actually rendering as you desire!
[1] See https://katex.org/docs/supported.html for more.