luffe
luffe

Reputation: 1665

Adding custom latex macros in mathjax_config

I am trying to add a new expectation operator macro for use in some docstrings.

If in the math section I do:

.. math::
        \newcommand{\EE}[2][]{\mathbb{E}_{#1}\left[#2\right]}

        \EE{2+4}

I get the correct output:

Imgur

If I instead try and place my macro definitions in mathjax_config in Sphinx's conf.py (by following the instructions here)

mathjax_config = {
    'TeX': {
        'Macros': {
            'EE': [r'{\mathbb{E}_{#1}\left[#2\right]}', 2, r'[]'],
        }
    }
}

And my docstring reads:

.. math::
        \EE{2+4}

then I get two superfluous brackets:

Imgur

What I am doing wrong?

Upvotes: 2

Views: 412

Answers (1)

luffe
luffe

Reputation: 1665

I had a typo:

The MathJax macro definition had an error in the last element (default value), it should have read:

'EE': [r'{\mathbb{E}_{#1}\left[#2\right]}', 2, r''],

Upvotes: 1

Related Questions