1.14. Mathematics¶
In Sphinx you can include inline math \(x\leftarrow y\ x\forall y\ x-y\)
(as role :math:`x\leftarrow y\ x\forall y\ x-y`
) or display math as
directive block which is able to cross-referencing equations:
-
.. math::
¶ To include math in your document, just use the
.. math::
directive. For more details, seemath
directive.- The example
1 2 3 4
.. math:: W^{3\beta}_{\delta_1 \rho_1 \sigma_2} \approx U^{3\beta}_{\delta_1 \rho_1}
- Which gives
- (1.2)¶\[W^{3\beta}_{\delta_1 \rho_1 \sigma_2} \approx U^{3\beta}_{\delta_1 \rho_1}\]
-
:math:numref:
¶ The math domain (name math) provides the role
:math:numref:`label`
which is for cross-referencing equations defined by.. math::
directive via their label. For more details, seemath:numref
role.- The example
1 2 3 4 5
.. math:: e^{i\pi} + 1 = 0 :label: euler Euler's identity, :math:numref:`euler`, was elected one of the most beautiful mathematical formulas.
- Which gives
- (1.3)¶\[e^{i\pi} + 1 = 0\]
Euler’s identity, Equastion 1.3, was elected one of the most beautiful mathematical formulas.
When the equation is only one line of text, it can also be given as a directive argument (as used in Euler’s identity above).
Recent versions of Sphinx include built-in support for math. There are three flavors:
sphinx.ext.imgmath
: uses dvipng to render the equationsphinx.ext.mathjax
: renders the math in the browser using Javascriptsphinx.ext.jsmath
: it’s an older code, but it checks out
Additionally, there are special Sphinx extensions provided by matplotlib that has its own math support for writing mathematical expressions and inserting automatically-generated plots:
matplotlib.sphinxext.mathmpl
See also
See Mathematical Plots for more details about the Sphinx matplotlib extensions with examples.