Package: texext
texextcontains a couple ofSphinxextensions for working with LaTeX math.math_dollarmath_dollarreplaces math expressions between dollars inReSTwith
equivalent inline math.For example:Here is some math: $a = 2$will be replaced by:Here is some math: :math:`a = 2`The extension makes some effort not to replace dollars that aren’t meant as
math, but please check your output carefully, and submit an issue on thetexext issue trackerif we have messed up.To enable math_dollar, make sure that thetexextpackage is on your
Python path, and addtexext.math_dollarto your list of extensions in the
Sphinxconf.py.  If you want math_dollar to process docstrings, you
should addsphinx.ext.autodochigher up your extensions list thanmath_dollar.mathcode directiveUsers ofsympymay want to generate LaTeX
expressions dynamically in Sympy, and then render them in LaTeX in the built
pages.  You can do this with themathcodedirective:.. mathcode::

    import sympy
    a, b = sympy.symbols('a, b')
    a * 10 + 2 * bThe directive runssympy.latex()on the return result of the final
expression, and embeds it in a.. math::directive, resulting in
equivalent output to sphinx of:.. math::

    10 a + 2 bContext (namespace) is preserved by default, so you can use context in
subsequent directives, e.g.:.. mathcode::

    a * 5 + 3 * bIf the last expression in the mathcode block is not an expression, the context
gets updated, but the extension generates no math directive to the output.
This allows you to have blocks that fill in calculations without rendering to
the page.  For example, this generates no output:.. mathcode::

    expr = a * 4You can use the generated context in a later directive:.. mathcode::

    exprTo reset the context (namespace), use thenewcontextoption:.. mathcode::
    :newcontext:

    import sympy  # againIf you would like mathcode to share a namespace with thematplotlib
plot_directive, set the following in yourconf.py:# Config of mathcode directive
mathcode_use_plot_ns = TrueNoteIf you want to use the plot_directive context from within mathcode
directives, you need to list the plot_directive above the mathcode
directive in your sphinx extension list.  All the plot directives code
will get run before all the mathcode directive code.Conversely, if you want to use the mathcode directive context from the
plot_directive, list mathcode first in your sphinx extension list.NoteBy default, the Matplotlibplot_directivewill clear the namespace
context for each directive, so you may want to use the:context:option to the plot directive, most of the time.If you are usingNb2plotsfor your plots, and you want Mathcode to share a
namespace with the Nb2plots plot directive, you will need to specify the
Nb2plots plot context directly:# Config of mathcode directive
mathcode_use_plot_ns = True
mathcode_plot_context = 'nb2plots.nbplots.plot_context'More generally if you want to work with a customized version of the
plot_directive, you need to supply the name of the plot context dictionary for
the plot directive, as a string.  For example, if you have a custom plot
directive module importable asimport my_path.plot_directive, with the
plot context inmy_path.plot_directive.plot_context, then yourconf.pyshould have lines like these:# Config of mathcode directive
mathcode_plot_context = "my_path.plot_directive.plot_context"The plot context is a string rather than the attribute itself in order to let
sphinx pickle the configuration between runs.  This allows sphinx to avoid
building pages that have not changed between calls tosphinx-build.To enable the mathcode directive, make sure that thetexextpackage is on
your Python path, and addtextext.mathcodeto your list of extensions in
the Sphinxconf.py.CodeSeehttps://github.com/matthew-brett/texextReleased under the BSD two-clause license - see the fileLICENSEin the
source distribution.travis-cikindly tests the
code automatically under Python versions 2.7, and 3.6 through 3.8.The latest released version is athttps://pypi.python.org/pypi/texextSupportPlease put up issues on thetexext issue tracker.