Skip to main content

Sphinx extensions for working with LaTeX math

Project description

texext contains a couple of Sphinx extensions for working with LaTeX math.

math_dollar

math_dollar replaces math expressions between dollars in ReST with 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 the texext issue tracker if we have messed up.

To enable math_dollar, make sure that the texext package is on your Python path, and add textext.math_dollar to your list of extensions in the Sphinx conf.py. If you want math_dollar to process docstrings, you should add sphinx.ext.autodoc higher up your extensions list than math_dollar.

mathcode directive

Users of sympy may want to generate LaTeX expressions dynamically in Sympy, and then render them in LaTeX in the built pages. You can do this with the mathcode directive:

.. mathcode::

    import sympy
    a, b = sympy.symbols('a, b')
    a * 10 + 2 * b

The directive runs sympy.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 b

Context (namespace) is preserved by default, so you can use context in subsequent directives, e.g.:

.. mathcode::

    a * 5 + 3 * b

If 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 * 4

You can use the generated context in a later directive:

.. mathcode::

    expr

To reset the context (namespace), use the newcontext option:

.. mathcode::
    :newcontext:

    import sympy  # again

If you would like mathcode to share a namespace with the matplotlib plot_directive, set the following in your conf.py:

# Config of mathcode directive
mathcode_use_plot_ns = True

Remember that, by default, the plot_directive will 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 want to use a customized version of the plot_directive, supply the plot_directive module yourself, in the conf.py file:

# Config of mathcode directive
from my_path import plot_directive
mathcode_plot_directive = plot_directive

To enable the mathcode directive, make sure that the texext package is on your Python path, and add textext.mathcode to your list of extensions in the Sphinx conf.py.

Code

See https://github.com/matthew-brett/texext

Released under the BSD two-clause license - see the file LICENSE in the source distribution.

travis-ci kindly tests the code automatically under Python versions 2.6 through 2.7, and 3.2 through 3.5.

The latest released version is at https://pypi-hypernode.com/pypi/texext

Support

Please put up issues on the texext issue tracker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

texext-0.3.zip (52.5 kB view details)

Uploaded Source

texext-0.3.tar.gz (40.1 kB view details)

Uploaded Source

File details

Details for the file texext-0.3.zip.

File metadata

  • Download URL: texext-0.3.zip
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for texext-0.3.zip
Algorithm Hash digest
SHA256 3c3764095b6b0f0df2d9955fbc9545917b0a529a66063d9ccebc2571ae9f11c4
MD5 e1ea8642855727f9f40a2332d3b39841
BLAKE2b-256 a51d8a7051b25b8f205aabc646b5df8bac96c747e49b807ac6ea61d4767da740

See more details on using hashes here.

File details

Details for the file texext-0.3.tar.gz.

File metadata

  • Download URL: texext-0.3.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for texext-0.3.tar.gz
Algorithm Hash digest
SHA256 4e338f6f81cb1ff0881229fa5533ad0f9abf868d2e8b38e4f8f8645b442f3484
MD5 ca0c756fd2d890a1c4c09b8939e9103d
BLAKE2b-256 3fdaac5a4d21acbffc3a7942fe5f41f52f33ead6a96bc9483e4306aaffdf2409

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page