2008-08-06 08:04:14 -05:00
|
|
|
.. highlight:: rest
|
|
|
|
|
2017-06-20 08:57:32 -05:00
|
|
|
.. _math-support:
|
|
|
|
|
2018-06-17 22:58:32 -05:00
|
|
|
Math support for HTML outputs in Sphinx
|
|
|
|
=======================================
|
2008-08-06 08:04:14 -05:00
|
|
|
|
|
|
|
.. module:: sphinx.ext.mathbase
|
2015-12-22 21:48:21 -06:00
|
|
|
:synopsis: Common math support for imgmath and mathjax / jsmath.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
|
|
|
.. versionadded:: 0.5
|
2018-06-17 22:58:32 -05:00
|
|
|
.. versionchanged:: 1.8
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2018-06-17 22:58:32 -05:00
|
|
|
Math support for non-HTML builders is integrated to sphinx-core.
|
|
|
|
So mathbase extension is no longer needed.
|
2009-01-10 15:18:18 -06:00
|
|
|
|
2018-06-17 22:58:32 -05:00
|
|
|
Since mathematical notation isn't natively supported by HTML in any way, Sphinx
|
2019-03-27 10:43:51 -05:00
|
|
|
gives a math support to HTML document with several extensions. These use the
|
2019-03-29 09:40:18 -05:00
|
|
|
reStructuredText math :rst:dir:`directive <math>` and :rst:role:`role <math>`.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
:mod:`sphinx.ext.imgmath` -- Render math as images
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
.. module:: sphinx.ext.imgmath
|
|
|
|
:synopsis: Render math as PNG or SVG images.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
.. versionadded:: 1.4
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
This extension renders math via LaTeX and dvipng_ or dvisvgm_ into PNG or SVG
|
|
|
|
images. This of course means that the computer where the docs are built must
|
|
|
|
have both programs available.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2019-04-24 05:03:45 -05:00
|
|
|
There are various configuration values you can set to influence how the images
|
|
|
|
are built:
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
.. confval:: imgmath_image_format
|
|
|
|
|
2019-04-24 05:03:45 -05:00
|
|
|
The output image format. The default is ``'png'``. It should be either
|
|
|
|
``'png'`` or ``'svg'``. The image is produced by first executing ``latex``
|
|
|
|
on the TeX mathematical mark-up then (depending on the requested format)
|
|
|
|
either `dvipng`_ or `dvisvgm`_.
|
|
|
|
|
|
|
|
.. confval:: imgmath_use_preview
|
|
|
|
|
|
|
|
``dvipng`` and ``dvisvgm`` both have the ability to collect from LaTeX the
|
|
|
|
"depth" of the rendered math: an inline image should use this "depth" in a
|
|
|
|
``vertical-align`` style to get correctly aligned with surrounding text.
|
|
|
|
|
|
|
|
This mechanism requires the `LaTeX preview package`_ (available as
|
|
|
|
``preview-latex-style`` on Ubuntu xenial). Therefore, the default for this
|
|
|
|
option is ``False`` but it is strongly recommended to set it to ``True``.
|
|
|
|
|
2019-08-01 11:24:28 -05:00
|
|
|
.. versionchanged:: 2.2
|
2019-04-24 05:03:45 -05:00
|
|
|
|
|
|
|
This option can be used with the ``'svg'`` :confval:`imgmath_image_format`.
|
|
|
|
|
|
|
|
.. confval:: imgmath_add_tooltips
|
|
|
|
|
|
|
|
Default: ``True``. If false, do not add the LaTeX code as an "alt" attribute
|
|
|
|
for math images.
|
|
|
|
|
|
|
|
.. confval:: imgmath_font_size
|
|
|
|
|
|
|
|
The font size (in ``pt``) of the displayed math. The default value is
|
|
|
|
``12``. It must be a positive integer.
|
2015-12-22 21:48:21 -06:00
|
|
|
|
|
|
|
.. confval:: imgmath_latex
|
2008-08-06 08:04:14 -05:00
|
|
|
|
|
|
|
The command name with which to invoke LaTeX. The default is ``'latex'``; you
|
2009-03-04 16:49:32 -06:00
|
|
|
may need to set this to a full path if ``latex`` is not in the executable
|
|
|
|
search path.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
|
|
|
Since this setting is not portable from system to system, it is normally not
|
|
|
|
useful to set it in ``conf.py``; rather, giving it on the
|
2016-01-11 22:36:12 -06:00
|
|
|
:program:`sphinx-build` command line via the :option:`-D <sphinx-build -D>`
|
|
|
|
option should be preferable, like this::
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
sphinx-build -b html -D imgmath_latex=C:\tex\latex.exe . _build/html
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
This value should only contain the path to the latex executable, not further
|
|
|
|
arguments; use :confval:`imgmath_latex_args` for that purpose.
|
2008-12-15 12:24:34 -06:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
.. confval:: imgmath_latex_args
|
2008-12-15 12:24:34 -06:00
|
|
|
|
|
|
|
Additional arguments to give to latex, as a list. The default is an empty
|
|
|
|
list.
|
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
.. confval:: imgmath_latex_preamble
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2019-04-24 05:03:45 -05:00
|
|
|
Additional LaTeX code to put into the preamble of the LaTeX files used to
|
|
|
|
translate the math snippets. This is left empty by default. Use it
|
|
|
|
e.g. to add packages which modify the fonts used for math, such as
|
|
|
|
``'\\usepackage{newtxsf}'`` for sans-serif fonts, or
|
|
|
|
``'\\usepackage{fouriernc}'`` for serif fonts. Indeed, the default LaTeX
|
|
|
|
math fonts have rather thin glyphs which (in HTML output) often do not
|
|
|
|
match well with the font for text.
|
|
|
|
|
|
|
|
.. confval:: imgmath_dvipng
|
|
|
|
|
|
|
|
The command name to invoke ``dvipng``. The default is
|
|
|
|
``'dvipng'``; you may need to set this to a full path if ``dvipng`` is not in
|
|
|
|
the executable search path. This option is only used when
|
|
|
|
``imgmath_image_format`` is set to ``'png'``.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2015-12-22 21:48:21 -06:00
|
|
|
.. confval:: imgmath_dvipng_args
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2008-11-16 11:44:46 -06:00
|
|
|
Additional arguments to give to dvipng, as a list. The default value is
|
2012-10-28 13:06:48 -05:00
|
|
|
``['-gamma', '1.5', '-D', '110', '-bg', 'Transparent']`` which makes the
|
2019-04-24 05:03:45 -05:00
|
|
|
image a bit darker and larger then it is by default (this compensates
|
|
|
|
somewhat for the thinness of default LaTeX math fonts), and produces PNGs with a
|
2015-12-22 21:48:21 -06:00
|
|
|
transparent background. This option is used only when
|
|
|
|
``imgmath_image_format`` is ``'png'``.
|
|
|
|
|
2019-04-24 05:03:45 -05:00
|
|
|
.. confval:: imgmath_dvisvgm
|
2011-01-08 12:08:38 -06:00
|
|
|
|
2019-04-24 05:03:45 -05:00
|
|
|
The command name to invoke ``dvisvgm``. The default is
|
|
|
|
``'dvisvgm'``; you may need to set this to a full path if ``dvisvgm`` is not
|
|
|
|
in the executable search path. This option is only used when
|
|
|
|
``imgmath_image_format`` is ``'svg'``.
|
2011-01-08 12:08:38 -06:00
|
|
|
|
2019-04-24 05:03:45 -05:00
|
|
|
.. confval:: imgmath_dvisvgm_args
|
2015-12-23 23:28:32 -06:00
|
|
|
|
2019-04-24 05:03:45 -05:00
|
|
|
Additional arguments to give to dvisvgm, as a list. The default value is
|
|
|
|
``['--no-fonts']``, which means that ``dvisvgm`` will render glyphs as path
|
|
|
|
elements (cf the `dvisvgm FAQ`_). This option is used only when
|
|
|
|
``imgmath_image_format`` is ``'svg'``.
|
2015-12-23 23:28:32 -06:00
|
|
|
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2011-01-06 06:21:36 -06:00
|
|
|
:mod:`sphinx.ext.mathjax` -- Render math via JavaScript
|
|
|
|
-------------------------------------------------------
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2011-01-06 06:21:36 -06:00
|
|
|
.. module:: sphinx.ext.mathjax
|
|
|
|
:synopsis: Render math using JavaScript via MathJax.
|
|
|
|
|
|
|
|
.. versionadded:: 1.1
|
2008-08-06 08:04:14 -05:00
|
|
|
|
|
|
|
This extension puts math as-is into the HTML files. The JavaScript package
|
2011-01-06 06:21:36 -06:00
|
|
|
MathJax_ is then loaded and transforms the LaTeX markup to readable math live in
|
2019-03-29 09:40:18 -05:00
|
|
|
the browser.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2011-01-06 06:21:36 -06:00
|
|
|
Because MathJax (and the necessary fonts) is very large, it is not included in
|
2019-03-29 09:40:18 -05:00
|
|
|
Sphinx but is set to automatically include it from a third-party site.
|
|
|
|
|
|
|
|
.. attention::
|
|
|
|
|
|
|
|
You should use the math :rst:dir:`directive <math>` and
|
|
|
|
:rst:role:`role <math>`, not the native MathJax ``$$``, ``\(``, etc.
|
|
|
|
|
2008-08-06 08:04:14 -05:00
|
|
|
|
2011-01-06 06:21:36 -06:00
|
|
|
.. confval:: mathjax_path
|
|
|
|
|
|
|
|
The path to the JavaScript file to include in the HTML files in order to load
|
2011-07-19 15:35:52 -05:00
|
|
|
MathJax.
|
2011-05-15 04:57:23 -05:00
|
|
|
|
2017-06-19 17:20:22 -05:00
|
|
|
The default is the ``https://`` URL that loads the JS files from the
|
|
|
|
`cdnjs`__ Content Delivery Network. See the `MathJax Getting Started
|
2019-03-29 09:40:18 -05:00
|
|
|
page`__ for details. If you want MathJax to be available offline or
|
|
|
|
without including resources from a third-party site, you have to
|
|
|
|
download it and set this value to a different path.
|
2017-06-19 17:20:22 -05:00
|
|
|
|
2018-06-08 06:56:45 -05:00
|
|
|
__ https://cdnjs.com
|
2017-06-19 17:20:22 -05:00
|
|
|
|
2018-01-20 16:04:57 -06:00
|
|
|
__ https://docs.mathjax.org/en/latest/start.html
|
2011-01-06 06:21:36 -06:00
|
|
|
|
|
|
|
The path can be absolute or relative; if it is relative, it is relative to
|
|
|
|
the ``_static`` directory of the built docs.
|
|
|
|
|
2011-07-19 15:35:52 -05:00
|
|
|
For example, if you put MathJax into the static path of the Sphinx docs, this
|
2011-01-06 06:21:36 -06:00
|
|
|
value would be ``MathJax/MathJax.js``. If you host more than one Sphinx
|
|
|
|
documentation set on one server, it is advisable to install MathJax in a
|
|
|
|
shared location.
|
|
|
|
|
2018-01-20 16:04:57 -06:00
|
|
|
You can also give a full ``https://`` URL different from the CDN URL.
|
2011-01-06 06:21:36 -06:00
|
|
|
|
2018-06-13 09:24:14 -05:00
|
|
|
.. confval:: mathjax_options
|
|
|
|
|
|
|
|
The options to script tag for mathjax. For example, you can set integrity
|
|
|
|
option with following setting::
|
|
|
|
|
|
|
|
mathjax_options = {
|
|
|
|
'integrity': 'sha384-......',
|
|
|
|
}
|
|
|
|
|
|
|
|
The default is empty (``{}``).
|
2011-01-06 06:21:36 -06:00
|
|
|
|
2018-06-01 03:23:08 -05:00
|
|
|
.. confval:: mathjax_config
|
|
|
|
|
|
|
|
The inline configuration options for mathjax. The value is used as a
|
|
|
|
parameter of ``MathJax.Hub.Config()``. For more information, please
|
|
|
|
read `Using in-line configuration options`_.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
mathjax_config = {
|
|
|
|
'extensions': ['tex2jax.js'],
|
|
|
|
'jax': ['input/TeX', 'output/HTML-CSS'],
|
|
|
|
}
|
|
|
|
|
|
|
|
The default is empty (not configured).
|
|
|
|
|
2018-09-23 11:36:25 -05:00
|
|
|
.. _Using in-line configuration options: https://docs.mathjax.org/en/latest/configuration.html#using-in-line-configuration-options
|
2018-06-01 03:23:08 -05:00
|
|
|
|
2011-01-06 06:21:36 -06:00
|
|
|
:mod:`sphinx.ext.jsmath` -- Render math via JavaScript
|
|
|
|
------------------------------------------------------
|
|
|
|
|
|
|
|
.. module:: sphinx.ext.jsmath
|
|
|
|
:synopsis: Render math using JavaScript via JSMath.
|
|
|
|
|
|
|
|
This extension works just as the MathJax extension does, but uses the older
|
|
|
|
package jsMath_. It provides this config value:
|
|
|
|
|
2008-08-06 08:04:14 -05:00
|
|
|
.. confval:: jsmath_path
|
|
|
|
|
|
|
|
The path to the JavaScript file to include in the HTML files in order to load
|
|
|
|
JSMath. There is no default.
|
|
|
|
|
|
|
|
The path can be absolute or relative; if it is relative, it is relative to
|
2010-01-01 16:54:45 -06:00
|
|
|
the ``_static`` directory of the built docs.
|
2008-08-06 08:04:14 -05:00
|
|
|
|
|
|
|
For example, if you put JSMath into the static path of the Sphinx docs, this
|
2010-01-01 16:54:45 -06:00
|
|
|
value would be ``jsMath/easy/load.js``. If you host more than one
|
2008-08-06 08:04:14 -05:00
|
|
|
Sphinx documentation set on one server, it is advisable to install jsMath in
|
|
|
|
a shared location.
|
|
|
|
|
|
|
|
|
2018-01-20 16:04:57 -06:00
|
|
|
.. _dvipng: https://savannah.nongnu.org/projects/dvipng/
|
2019-04-17 03:07:30 -05:00
|
|
|
.. _dvisvgm: https://dvisvgm.de/
|
2019-04-24 05:03:45 -05:00
|
|
|
.. _dvisvgm FAQ: https://dvisvgm.de/FAQ
|
2016-02-13 09:00:42 -06:00
|
|
|
.. _MathJax: https://www.mathjax.org/
|
2008-08-06 08:04:14 -05:00
|
|
|
.. _jsMath: http://www.math.union.edu/~dpvc/jsmath/
|
2019-04-24 04:17:27 -05:00
|
|
|
.. _LaTeX preview package: https://www.gnu.org/software/auctex/preview-latex.html
|