sphinx-math-dollar 1.2__tar.gz → 1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sphinx_math_dollar-1.3/PKG-INFO +152 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/README.rst +35 -1
- sphinx_math_dollar-1.3/docs/conf.py +67 -0
- sphinx_math_dollar-1.3/pyproject.toml +3 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/setup.cfg +1 -1
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/setup.py +12 -7
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar/__init__.py +4 -3
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar/_version.py +4 -4
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar/extension.py +46 -12
- sphinx_math_dollar-1.3/sphinx_math_dollar/tests/__init__.py +0 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar/tests/test_extension.py +7 -8
- sphinx_math_dollar-1.3/sphinx_math_dollar.egg-info/PKG-INFO +152 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar.egg-info/SOURCES.txt +3 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/versioneer.py +500 -213
- sphinx-math-dollar-1.2/PKG-INFO +0 -103
- sphinx-math-dollar-1.2/sphinx_math_dollar.egg-info/PKG-INFO +0 -103
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/LICENSE +0 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/MANIFEST.in +0 -0
- {sphinx-math-dollar-1.2/sphinx_math_dollar/tests → sphinx_math_dollar-1.3/docs}/__init__.py +0 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar/math_dollar.py +0 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar/tests/test_math_dollar.py +0 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar.egg-info/dependency_links.txt +0 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar.egg-info/requires.txt +0 -0
- {sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sphinx-math-dollar
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: Sphinx extension to let you write LaTeX math using $$
|
|
5
|
+
Home-page: https://github.com/sympy/sphinx-math-dollar/
|
|
6
|
+
Author: SymPy Development Team
|
|
7
|
+
Author-email: sympy@googlegroups.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: sphinx
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
Dynamic: requires-dist
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
Dynamic: summary
|
|
29
|
+
|
|
30
|
+
====================
|
|
31
|
+
sphinx-math-dollar
|
|
32
|
+
====================
|
|
33
|
+
|
|
34
|
+
sphinx-math-dollar is a Sphinx extension to let you write LaTeX math in RST using $$.
|
|
35
|
+
|
|
36
|
+
To enable install it
|
|
37
|
+
|
|
38
|
+
.. code::
|
|
39
|
+
|
|
40
|
+
pip install sphinx-math-dollar
|
|
41
|
+
|
|
42
|
+
or
|
|
43
|
+
|
|
44
|
+
.. code::
|
|
45
|
+
|
|
46
|
+
conda install -c conda-forge sphinx-math-dollar
|
|
47
|
+
|
|
48
|
+
Then in your ``conf.py``, add ``'sphinx_math_dollar'`` to your extensions list:
|
|
49
|
+
|
|
50
|
+
.. code:: python
|
|
51
|
+
|
|
52
|
+
extensions = ['sphinx_math_dollar', 'sphinx.ext.mathjax']
|
|
53
|
+
|
|
54
|
+
mathjax_config = {
|
|
55
|
+
'tex2jax': {
|
|
56
|
+
'inlineMath': [ ["\\(","\\)"] ],
|
|
57
|
+
'displayMath': [["\\[","\\]"] ],
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
mathjax3_config = {
|
|
62
|
+
"tex": {
|
|
63
|
+
"inlineMath": [['\\(', '\\)']],
|
|
64
|
+
"displayMath": [["\\[", "\\]"]],
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
The ``mathjax_config`` is needed to prevent MathJax from parsing dollar signs
|
|
70
|
+
which are ignored by the extension because they should not be parsed as math.
|
|
71
|
+
|
|
72
|
+
You will now be able to use dollar signs for math, like ``$\int\sin(x)\,dx$``,
|
|
73
|
+
which will produce $\int\sin(x)\,dx$. You can also use double dollar signs for
|
|
74
|
+
display math, like ``$$\int\sin(x)\,dx$$``, which produces $$\int\sin(x)\,dx$$
|
|
75
|
+
(if you are reading this on GitHub, look at the version built by Sphinx `here
|
|
76
|
+
<https://www.sympy.org/sphinx-math-dollar/>`_). The usual Sphinx ``:math:``
|
|
77
|
+
and ``.. math::`` directives will also continue to work.
|
|
78
|
+
|
|
79
|
+
The extension will also work with docstrings when combined with the
|
|
80
|
+
`sphinx.ext.autodoc
|
|
81
|
+
<https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>`_
|
|
82
|
+
extension.
|
|
83
|
+
|
|
84
|
+
Configuration
|
|
85
|
+
=============
|
|
86
|
+
|
|
87
|
+
sphinx-math-dollar uses a blacklist to determine which `docutils nodes
|
|
88
|
+
<http://docutils.sourceforge.net/docs/ref/doctree.html>`_ should not be
|
|
89
|
+
parsed. The default blacklist is
|
|
90
|
+
|
|
91
|
+
.. code::
|
|
92
|
+
|
|
93
|
+
(FixedTextElement, literal, math)
|
|
94
|
+
|
|
95
|
+
``FixedTextElement`` covers the `Simple Body Elements
|
|
96
|
+
<http://docutils.sourceforge.net/docs/ref/doctree.html>`_ nodes.
|
|
97
|
+
|
|
98
|
+
Any docutils node that is contained in a blacklisted node or a subclass of a
|
|
99
|
+
blacklisted node will not have ``$math$`` parsed as LaTeX.
|
|
100
|
+
|
|
101
|
+
You can modify this by setting ``math_dollar_node_blacklist`` in ``conf.py``.
|
|
102
|
+
For example, to also prevent ``$math$`` from rendering in `headers nodes
|
|
103
|
+
<http://docutils.sourceforge.net/docs/ref/doctree.html#header>`_, add
|
|
104
|
+
|
|
105
|
+
.. code:: python
|
|
106
|
+
|
|
107
|
+
from sphinx_math_dollar import NODE_BLACKLIST
|
|
108
|
+
from docutils.nodes import header
|
|
109
|
+
|
|
110
|
+
math_dollar_node_blacklist = NODE_BLACKLIST + (header,)
|
|
111
|
+
|
|
112
|
+
Note that configuring this variable replaces the default, so it is recommended
|
|
113
|
+
to always include the above default values (``NODE_BLACKLIST``) in addition to
|
|
114
|
+
additional nodes.
|
|
115
|
+
|
|
116
|
+
To debug which nodes are skipped, set the environment variable
|
|
117
|
+
``MATH_DOLLAR_DEBUG=1`` or set ``math_dollar_debug = True`` in ``conf.py``.
|
|
118
|
+
|
|
119
|
+
If you feel a node should always be part of the default blacklist, please make
|
|
120
|
+
a `pull request <https://github.com/sympy/sphinx-math-dollar>`_.
|
|
121
|
+
|
|
122
|
+
Known Issues
|
|
123
|
+
============
|
|
124
|
+
|
|
125
|
+
See `the issue tracker <https://github.com/sympy/sphinx-math-dollar/issues>`__
|
|
126
|
+
for a full list of known issues.
|
|
127
|
+
|
|
128
|
+
- Absolute values can produce errors like ``Inline substitution_reference
|
|
129
|
+
start-string without end-string.``. See `issue #16
|
|
130
|
+
<https://github.com/sympy/sphinx-math-dollar/issues/16>`__.
|
|
131
|
+
|
|
132
|
+
This is because Sphinx parses the vertical bars ``|x|`` as inline
|
|
133
|
+
substitutions. To work around this, add spaces around the absolute value
|
|
134
|
+
bars, like ``1 + | x | + y``. If an absolute value bar is at the beginning
|
|
135
|
+
or end of the math expression, use curly braces (to avoid false positives,
|
|
136
|
+
sphinx-math-dollar will not parse dollar signs as math if there is a space
|
|
137
|
+
after the first ``$`` or before the last ``$``). For example, replace ``$|y|
|
|
138
|
+
\geq |x^e|$`` with ``${ | y | \geq | x^e | }$``, which produces ${ | y |
|
|
139
|
+
\geq | x^e | }$.
|
|
140
|
+
|
|
141
|
+
Markdown
|
|
142
|
+
========
|
|
143
|
+
|
|
144
|
+
sphinx-math-dollar is designed to work with RST, which does not natively
|
|
145
|
+
support dollar signs for LaTeX math. If you prefer Markdown, we recommend
|
|
146
|
+
using [MyST](https://myst-parser.readthedocs.io/en/latest/), which natively
|
|
147
|
+
supports dollar math (this extension is not required).
|
|
148
|
+
|
|
149
|
+
License
|
|
150
|
+
=======
|
|
151
|
+
|
|
152
|
+
MIT.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
sphinx-math-dollar
|
|
3
3
|
====================
|
|
4
4
|
|
|
5
|
-
sphinx-math-dollar is a Sphinx extension to let you write LaTeX math using $$.
|
|
5
|
+
sphinx-math-dollar is a Sphinx extension to let you write LaTeX math in RST using $$.
|
|
6
6
|
|
|
7
7
|
To enable install it
|
|
8
8
|
|
|
@@ -29,6 +29,13 @@ Then in your ``conf.py``, add ``'sphinx_math_dollar'`` to your extensions list:
|
|
|
29
29
|
},
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
mathjax3_config = {
|
|
33
|
+
"tex": {
|
|
34
|
+
"inlineMath": [['\\(', '\\)']],
|
|
35
|
+
"displayMath": [["\\[", "\\]"]],
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
|
|
33
40
|
The ``mathjax_config`` is needed to prevent MathJax from parsing dollar signs
|
|
34
41
|
which are ignored by the extension because they should not be parsed as math.
|
|
@@ -83,6 +90,33 @@ To debug which nodes are skipped, set the environment variable
|
|
|
83
90
|
If you feel a node should always be part of the default blacklist, please make
|
|
84
91
|
a `pull request <https://github.com/sympy/sphinx-math-dollar>`_.
|
|
85
92
|
|
|
93
|
+
Known Issues
|
|
94
|
+
============
|
|
95
|
+
|
|
96
|
+
See `the issue tracker <https://github.com/sympy/sphinx-math-dollar/issues>`__
|
|
97
|
+
for a full list of known issues.
|
|
98
|
+
|
|
99
|
+
- Absolute values can produce errors like ``Inline substitution_reference
|
|
100
|
+
start-string without end-string.``. See `issue #16
|
|
101
|
+
<https://github.com/sympy/sphinx-math-dollar/issues/16>`__.
|
|
102
|
+
|
|
103
|
+
This is because Sphinx parses the vertical bars ``|x|`` as inline
|
|
104
|
+
substitutions. To work around this, add spaces around the absolute value
|
|
105
|
+
bars, like ``1 + | x | + y``. If an absolute value bar is at the beginning
|
|
106
|
+
or end of the math expression, use curly braces (to avoid false positives,
|
|
107
|
+
sphinx-math-dollar will not parse dollar signs as math if there is a space
|
|
108
|
+
after the first ``$`` or before the last ``$``). For example, replace ``$|y|
|
|
109
|
+
\geq |x^e|$`` with ``${ | y | \geq | x^e | }$``, which produces ${ | y |
|
|
110
|
+
\geq | x^e | }$.
|
|
111
|
+
|
|
112
|
+
Markdown
|
|
113
|
+
========
|
|
114
|
+
|
|
115
|
+
sphinx-math-dollar is designed to work with RST, which does not natively
|
|
116
|
+
support dollar signs for LaTeX math. If you prefer Markdown, we recommend
|
|
117
|
+
using [MyST](https://myst-parser.readthedocs.io/en/latest/), which natively
|
|
118
|
+
supports dollar math (this extension is not required).
|
|
119
|
+
|
|
86
120
|
License
|
|
87
121
|
=======
|
|
88
122
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# This file only contains a selection of the most common options. For a full
|
|
4
|
+
# list see the documentation:
|
|
5
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
6
|
+
|
|
7
|
+
# -- Path setup --------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
# If extensions (or modules to document with autodoc) are in another directory,
|
|
10
|
+
# add these directories to sys.path here. If the directory is relative to the
|
|
11
|
+
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
12
|
+
#
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
sys.path.insert(0, os.path.abspath('..'))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# -- Project information -----------------------------------------------------
|
|
19
|
+
|
|
20
|
+
project = 'sphinx-math-dollar'
|
|
21
|
+
copyright = '2019, SymPy Development Team'
|
|
22
|
+
author = 'SymPy Development Team'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# -- General configuration ---------------------------------------------------
|
|
26
|
+
|
|
27
|
+
# Add any Sphinx extension module names here, as strings. They can be
|
|
28
|
+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
29
|
+
# ones.
|
|
30
|
+
extensions = [
|
|
31
|
+
'sphinx_math_dollar',
|
|
32
|
+
'sphinx.ext.mathjax',
|
|
33
|
+
'sphinx.ext.githubpages',
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
html_theme_options = {
|
|
37
|
+
'github_user': 'sympy',
|
|
38
|
+
'github_repo': 'sphinx-math-dollar',
|
|
39
|
+
'github_banner': True,
|
|
40
|
+
'logo_name': True,
|
|
41
|
+
'travis_button': True,
|
|
42
|
+
'show_related': True,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Add any paths that contain templates here, relative to this directory.
|
|
47
|
+
templates_path = ['_templates']
|
|
48
|
+
|
|
49
|
+
# List of patterns, relative to source directory, that match files and
|
|
50
|
+
# directories to ignore when looking for source files.
|
|
51
|
+
# This pattern also affects html_static_path and html_extra_path.
|
|
52
|
+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# -- Options for HTML output -------------------------------------------------
|
|
56
|
+
|
|
57
|
+
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
58
|
+
# a list of builtin themes.
|
|
59
|
+
#
|
|
60
|
+
html_theme = 'alabaster'
|
|
61
|
+
|
|
62
|
+
# Add any paths that contain custom static files (such as style sheets) here,
|
|
63
|
+
# relative to this directory. They are copied after the builtin static files,
|
|
64
|
+
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
65
|
+
# html_static_path = ['_static']
|
|
66
|
+
|
|
67
|
+
master_doc = 'index'
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
sys.path.append(str(pathlib.Path(__file__).parent))
|
|
1
5
|
import setuptools
|
|
2
6
|
|
|
3
7
|
with open("README.rst", "r") as fh:
|
|
@@ -14,16 +18,17 @@ setuptools.setup(
|
|
|
14
18
|
description="Sphinx extension to let you write LaTeX math using $$",
|
|
15
19
|
long_description=long_description,
|
|
16
20
|
url="https://github.com/sympy/sphinx-math-dollar/",
|
|
17
|
-
packages=setuptools.find_packages(),
|
|
21
|
+
packages=setuptools.find_packages(include=["sphinx_math_dollar"]),
|
|
18
22
|
classifiers=[
|
|
19
|
-
"Programming Language :: Python :: 2",
|
|
20
23
|
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
21
28
|
"License :: OSI Approved :: MIT License",
|
|
22
29
|
"Operating System :: OS Independent",
|
|
23
30
|
],
|
|
24
|
-
|
|
25
|
-
install_requires=[
|
|
26
|
-
|
|
27
|
-
],
|
|
28
|
-
license='MIT',
|
|
31
|
+
python_requires=">=3.11",
|
|
32
|
+
install_requires=["sphinx"],
|
|
33
|
+
license="MIT",
|
|
29
34
|
)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
from . import _version
|
|
2
|
+
__version__ = _version.get_versions()['version']
|
|
3
|
+
|
|
4
|
+
|
|
1
5
|
from .math_dollar import split_dollars
|
|
2
6
|
from .extension import setup, NODE_BLACKLIST
|
|
3
7
|
|
|
4
8
|
__all__ = ['split_dollars', 'setup', 'NODE_BLACKLIST']
|
|
5
9
|
|
|
6
|
-
from ._version import get_versions
|
|
7
|
-
__version__ = get_versions()['version']
|
|
8
|
-
del get_versions
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
# This file was generated by 'versioneer.py' (0.
|
|
2
|
+
# This file was generated by 'versioneer.py' (0.21) from
|
|
3
3
|
# revision-control system data, or from the parent directory name of an
|
|
4
4
|
# unpacked source archive. Distribution tarballs contain a pre-generated copy
|
|
5
5
|
# of this file.
|
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "
|
|
11
|
+
"date": "2026-02-05T11:06:39-0700",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.
|
|
14
|
+
"full-revisionid": "3c9592e9d1bb9ec9e3bfe9e07ed8f6468012014a",
|
|
15
|
+
"version": "1.3"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -1,29 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
import logging
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
4
|
|
|
5
|
-
from .
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
from docutils.nodes import (
|
|
6
|
+
FixedTextElement,
|
|
7
|
+
GenericNodeVisitor,
|
|
8
|
+
SkipNode,
|
|
9
|
+
Text,
|
|
10
|
+
literal,
|
|
11
|
+
math,
|
|
12
|
+
math_block,
|
|
13
|
+
)
|
|
8
14
|
from docutils.transforms import Transform
|
|
9
15
|
|
|
16
|
+
from . import __version__
|
|
17
|
+
from .math_dollar import split_dollars
|
|
18
|
+
|
|
10
19
|
NODE_BLACKLIST = node_blacklist = (FixedTextElement, literal, math)
|
|
11
20
|
|
|
12
21
|
DEBUG = bool(os.environ.get("MATH_DOLLAR_DEBUG", False))
|
|
13
22
|
|
|
23
|
+
|
|
14
24
|
class MathDollarReplacer(GenericNodeVisitor):
|
|
15
25
|
def default_visit(self, node):
|
|
16
26
|
return node
|
|
17
27
|
|
|
28
|
+
def unknown_visit(self, node):
|
|
29
|
+
logging.warning("sphinx-math-dollar: Skipping unknown node type %s", type(node))
|
|
30
|
+
raise SkipNode
|
|
31
|
+
|
|
18
32
|
def visit_Text(self, node):
|
|
19
33
|
parent = node.parent
|
|
20
34
|
while parent:
|
|
21
35
|
if isinstance(parent, node_blacklist):
|
|
22
|
-
if DEBUG and any(
|
|
23
|
-
|
|
36
|
+
if DEBUG and any(
|
|
37
|
+
i == "math"
|
|
38
|
+
for i, _ in split_dollars(str(node).replace("\x00", "\\"))
|
|
39
|
+
):
|
|
40
|
+
print(
|
|
41
|
+
"sphinx-math-dollar: Skipping",
|
|
42
|
+
node,
|
|
43
|
+
"(node_blacklist = %s)" % (node_blacklist,),
|
|
44
|
+
file=sys.stderr,
|
|
45
|
+
)
|
|
24
46
|
return
|
|
25
47
|
parent = parent.parent
|
|
26
|
-
|
|
48
|
+
# See https://github.com/sympy/sphinx-math-dollar/issues/22
|
|
49
|
+
data = split_dollars(str(node).replace("\x00", "\\"))
|
|
27
50
|
nodes = []
|
|
28
51
|
has_math = False
|
|
29
52
|
for typ, text in data:
|
|
@@ -35,14 +58,15 @@ class MathDollarReplacer(GenericNodeVisitor):
|
|
|
35
58
|
elif typ == "display math":
|
|
36
59
|
has_math = True
|
|
37
60
|
new_node = math_block(text, Text(text))
|
|
38
|
-
new_node.attributes.setdefault(
|
|
39
|
-
new_node.attributes.setdefault(
|
|
61
|
+
new_node.attributes.setdefault("nowrap", False)
|
|
62
|
+
new_node.attributes.setdefault("number", None)
|
|
40
63
|
nodes.append(new_node)
|
|
41
64
|
else:
|
|
42
65
|
raise ValueError("Unrecognized type from split_dollars %r" % typ)
|
|
43
66
|
if has_math:
|
|
44
67
|
node.parent.replace(node, nodes)
|
|
45
68
|
|
|
69
|
+
|
|
46
70
|
class TransformMath(Transform):
|
|
47
71
|
# See http://docutils.sourceforge.net/docs/ref/transforms.html. We want it
|
|
48
72
|
# to apply before things that change rawsource, since we have to use that
|
|
@@ -50,19 +74,29 @@ class TransformMath(Transform):
|
|
|
50
74
|
# transforms are relevant here, other than SmartQuotes, so this may need
|
|
51
75
|
# to be adjusted.
|
|
52
76
|
default_priority = 500
|
|
77
|
+
|
|
53
78
|
def apply(self, **kwargs):
|
|
54
79
|
self.document.walk(MathDollarReplacer(self.document))
|
|
55
80
|
|
|
81
|
+
|
|
56
82
|
def config_inited(app, config):
|
|
57
83
|
global node_blacklist, DEBUG
|
|
58
84
|
node_blacklist = config.math_dollar_node_blacklist
|
|
59
85
|
DEBUG = config.math_dollar_debug
|
|
60
86
|
|
|
87
|
+
|
|
61
88
|
def setup(app):
|
|
62
89
|
app.add_transform(TransformMath)
|
|
63
90
|
# We can't force a rebuild here because it will always appear different
|
|
64
91
|
# since the tuple contains classes
|
|
65
|
-
app.add_config_value(
|
|
66
|
-
app.add_config_value(
|
|
92
|
+
app.add_config_value("math_dollar_node_blacklist", NODE_BLACKLIST, "")
|
|
93
|
+
app.add_config_value("math_dollar_debug", DEBUG, "")
|
|
94
|
+
app.add_config_value("parallel_read_safe", True, "")
|
|
95
|
+
|
|
96
|
+
app.connect("config-inited", config_inited)
|
|
67
97
|
|
|
68
|
-
|
|
98
|
+
return {
|
|
99
|
+
"version": __version__,
|
|
100
|
+
"parallel_read_safe": True,
|
|
101
|
+
"parallel_write_safe": True,
|
|
102
|
+
}
|
|
File without changes
|
{sphinx-math-dollar-1.2 → sphinx_math_dollar-1.3}/sphinx_math_dollar/tests/test_extension.py
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pytest
|
|
2
2
|
|
|
3
|
-
from sphinx_testing import with_app
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
def test(app):
|
|
5
|
+
app.build()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.mark.sphinx(buildername='html')
|
|
9
|
+
def test_sphinx_build(app, status, warning):
|
|
8
10
|
app.build()
|
|
9
11
|
html = (app.outdir/'index.html').read_text()
|
|
10
12
|
|
|
@@ -23,6 +25,3 @@ def _test_sphinx_build(app, status, warning):
|
|
|
23
25
|
|
|
24
26
|
assert not status.read()
|
|
25
27
|
assert not warning.read()
|
|
26
|
-
|
|
27
|
-
def test_sphinx_build():
|
|
28
|
-
_test_sphinx_build()
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sphinx-math-dollar
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: Sphinx extension to let you write LaTeX math using $$
|
|
5
|
+
Home-page: https://github.com/sympy/sphinx-math-dollar/
|
|
6
|
+
Author: SymPy Development Team
|
|
7
|
+
Author-email: sympy@googlegroups.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: sphinx
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
Dynamic: requires-dist
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
Dynamic: summary
|
|
29
|
+
|
|
30
|
+
====================
|
|
31
|
+
sphinx-math-dollar
|
|
32
|
+
====================
|
|
33
|
+
|
|
34
|
+
sphinx-math-dollar is a Sphinx extension to let you write LaTeX math in RST using $$.
|
|
35
|
+
|
|
36
|
+
To enable install it
|
|
37
|
+
|
|
38
|
+
.. code::
|
|
39
|
+
|
|
40
|
+
pip install sphinx-math-dollar
|
|
41
|
+
|
|
42
|
+
or
|
|
43
|
+
|
|
44
|
+
.. code::
|
|
45
|
+
|
|
46
|
+
conda install -c conda-forge sphinx-math-dollar
|
|
47
|
+
|
|
48
|
+
Then in your ``conf.py``, add ``'sphinx_math_dollar'`` to your extensions list:
|
|
49
|
+
|
|
50
|
+
.. code:: python
|
|
51
|
+
|
|
52
|
+
extensions = ['sphinx_math_dollar', 'sphinx.ext.mathjax']
|
|
53
|
+
|
|
54
|
+
mathjax_config = {
|
|
55
|
+
'tex2jax': {
|
|
56
|
+
'inlineMath': [ ["\\(","\\)"] ],
|
|
57
|
+
'displayMath': [["\\[","\\]"] ],
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
mathjax3_config = {
|
|
62
|
+
"tex": {
|
|
63
|
+
"inlineMath": [['\\(', '\\)']],
|
|
64
|
+
"displayMath": [["\\[", "\\]"]],
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
The ``mathjax_config`` is needed to prevent MathJax from parsing dollar signs
|
|
70
|
+
which are ignored by the extension because they should not be parsed as math.
|
|
71
|
+
|
|
72
|
+
You will now be able to use dollar signs for math, like ``$\int\sin(x)\,dx$``,
|
|
73
|
+
which will produce $\int\sin(x)\,dx$. You can also use double dollar signs for
|
|
74
|
+
display math, like ``$$\int\sin(x)\,dx$$``, which produces $$\int\sin(x)\,dx$$
|
|
75
|
+
(if you are reading this on GitHub, look at the version built by Sphinx `here
|
|
76
|
+
<https://www.sympy.org/sphinx-math-dollar/>`_). The usual Sphinx ``:math:``
|
|
77
|
+
and ``.. math::`` directives will also continue to work.
|
|
78
|
+
|
|
79
|
+
The extension will also work with docstrings when combined with the
|
|
80
|
+
`sphinx.ext.autodoc
|
|
81
|
+
<https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>`_
|
|
82
|
+
extension.
|
|
83
|
+
|
|
84
|
+
Configuration
|
|
85
|
+
=============
|
|
86
|
+
|
|
87
|
+
sphinx-math-dollar uses a blacklist to determine which `docutils nodes
|
|
88
|
+
<http://docutils.sourceforge.net/docs/ref/doctree.html>`_ should not be
|
|
89
|
+
parsed. The default blacklist is
|
|
90
|
+
|
|
91
|
+
.. code::
|
|
92
|
+
|
|
93
|
+
(FixedTextElement, literal, math)
|
|
94
|
+
|
|
95
|
+
``FixedTextElement`` covers the `Simple Body Elements
|
|
96
|
+
<http://docutils.sourceforge.net/docs/ref/doctree.html>`_ nodes.
|
|
97
|
+
|
|
98
|
+
Any docutils node that is contained in a blacklisted node or a subclass of a
|
|
99
|
+
blacklisted node will not have ``$math$`` parsed as LaTeX.
|
|
100
|
+
|
|
101
|
+
You can modify this by setting ``math_dollar_node_blacklist`` in ``conf.py``.
|
|
102
|
+
For example, to also prevent ``$math$`` from rendering in `headers nodes
|
|
103
|
+
<http://docutils.sourceforge.net/docs/ref/doctree.html#header>`_, add
|
|
104
|
+
|
|
105
|
+
.. code:: python
|
|
106
|
+
|
|
107
|
+
from sphinx_math_dollar import NODE_BLACKLIST
|
|
108
|
+
from docutils.nodes import header
|
|
109
|
+
|
|
110
|
+
math_dollar_node_blacklist = NODE_BLACKLIST + (header,)
|
|
111
|
+
|
|
112
|
+
Note that configuring this variable replaces the default, so it is recommended
|
|
113
|
+
to always include the above default values (``NODE_BLACKLIST``) in addition to
|
|
114
|
+
additional nodes.
|
|
115
|
+
|
|
116
|
+
To debug which nodes are skipped, set the environment variable
|
|
117
|
+
``MATH_DOLLAR_DEBUG=1`` or set ``math_dollar_debug = True`` in ``conf.py``.
|
|
118
|
+
|
|
119
|
+
If you feel a node should always be part of the default blacklist, please make
|
|
120
|
+
a `pull request <https://github.com/sympy/sphinx-math-dollar>`_.
|
|
121
|
+
|
|
122
|
+
Known Issues
|
|
123
|
+
============
|
|
124
|
+
|
|
125
|
+
See `the issue tracker <https://github.com/sympy/sphinx-math-dollar/issues>`__
|
|
126
|
+
for a full list of known issues.
|
|
127
|
+
|
|
128
|
+
- Absolute values can produce errors like ``Inline substitution_reference
|
|
129
|
+
start-string without end-string.``. See `issue #16
|
|
130
|
+
<https://github.com/sympy/sphinx-math-dollar/issues/16>`__.
|
|
131
|
+
|
|
132
|
+
This is because Sphinx parses the vertical bars ``|x|`` as inline
|
|
133
|
+
substitutions. To work around this, add spaces around the absolute value
|
|
134
|
+
bars, like ``1 + | x | + y``. If an absolute value bar is at the beginning
|
|
135
|
+
or end of the math expression, use curly braces (to avoid false positives,
|
|
136
|
+
sphinx-math-dollar will not parse dollar signs as math if there is a space
|
|
137
|
+
after the first ``$`` or before the last ``$``). For example, replace ``$|y|
|
|
138
|
+
\geq |x^e|$`` with ``${ | y | \geq | x^e | }$``, which produces ${ | y |
|
|
139
|
+
\geq | x^e | }$.
|
|
140
|
+
|
|
141
|
+
Markdown
|
|
142
|
+
========
|
|
143
|
+
|
|
144
|
+
sphinx-math-dollar is designed to work with RST, which does not natively
|
|
145
|
+
support dollar signs for LaTeX math. If you prefer Markdown, we recommend
|
|
146
|
+
using [MyST](https://myst-parser.readthedocs.io/en/latest/), which natively
|
|
147
|
+
supports dollar math (this extension is not required).
|
|
148
|
+
|
|
149
|
+
License
|
|
150
|
+
=======
|
|
151
|
+
|
|
152
|
+
MIT.
|