summaryrefslogtreecommitdiff
path: root/sphinx/ext/mathbase.py
blob: 90ad4563df53198918503eba99a52d8b32d0b303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
    sphinx.ext.mathbase
    ~~~~~~~~~~~~~~~~~~~

    Set up math support in source files and LaTeX/text output.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import warnings

from docutils import nodes
from docutils.parsers.rst.roles import math_role as math_role_base

from sphinx.addnodes import math, math_block as displaymath  # NOQA  # to keep compatibility
from sphinx.builders.latex.nodes import math_reference as eqref  # NOQA  # to keep compatibility
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.directives.patches import MathDirective as MathDirectiveBase
from sphinx.domains.math import MathDomain  # NOQA  # to keep compatibility
from sphinx.domains.math import MathReferenceRole as EqXRefRole  # NOQA  # to keep compatibility

if False:
    # For type annotation
    from typing import Any, Callable, List, Tuple  # NOQA
    from sphinx.application import Sphinx  # NOQA
    from sphinx.writers.html import HTMLTranslator  # NOQA


class MathDirective(MathDirectiveBase):
    def run(self):
        warnings.warn('sphinx.ext.mathbase.MathDirective is moved to '
                      'sphinx.directives.patches package.',
                      RemovedInSphinx30Warning, stacklevel=2)
        return super().run()


def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    warnings.warn('sphinx.ext.mathbase.math_role() is deprecated. '
                  'Please use docutils.parsers.rst.roles.math_role() instead.',
                  RemovedInSphinx30Warning, stacklevel=2)
    return math_role_base(role, rawtext, text, lineno, inliner, options, content)


def get_node_equation_number(writer, node):
    # type: (HTMLTranslator, nodes.math_block) -> str
    warnings.warn('sphinx.ext.mathbase.get_node_equation_number() is moved to '
                  'sphinx.util.math package.',
                  RemovedInSphinx30Warning, stacklevel=2)
    from sphinx.util.math import get_node_equation_number
    return get_node_equation_number(writer, node)


def wrap_displaymath(text, label, numbering):
    # type: (str, str, bool) -> str
    warnings.warn('sphinx.ext.mathbase.wrap_displaymath() is moved to '
                  'sphinx.util.math package.',
                  RemovedInSphinx30Warning, stacklevel=2)
    from sphinx.util.math import wrap_displaymath
    return wrap_displaymath(text, label, numbering)


def is_in_section_title(node):
    # type: (nodes.Element) -> bool
    """Determine whether the node is in a section title"""
    from sphinx.util.nodes import traverse_parent

    warnings.warn('is_in_section_title() is deprecated.',
                  RemovedInSphinx30Warning, stacklevel=2)

    for ancestor in traverse_parent(node):
        if isinstance(ancestor, nodes.title) and \
           isinstance(ancestor.parent, nodes.section):
            return True
    return False


def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
    # type: (Sphinx, Tuple[Callable, Callable], Tuple[Callable, Callable]) -> None
    warnings.warn('setup_math() is deprecated. '
                  'Please use app.add_html_math_renderer() instead.',
                  RemovedInSphinx30Warning, stacklevel=2)

    app.add_html_math_renderer('unknown', htmlinlinevisitors, htmldisplayvisitors)