File: inputjax.rst

package info (click to toggle)
mathjax-docs 2.7+20171212-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,100 kB
  • sloc: sh: 22; python: 19; makefile: 8
file content (128 lines) | stat: -rw-r--r-- 4,839 bytes parent folder | download | duplicates (3)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
.. _api-input-jax:

**************************
The MathJax.InputJax Class
**************************

Input jax are the components of MathJax that translate
mathematics from its original format (like :term:`TeX` or
:term:`MathML`) to the MathJax internal format (an `element jax`).

An input jax is stored as a pair of files in a subdirectory of the
``jax/input`` directory, with the subdirectory name being the name of
the input jax.  For example, the TeX input jax is stored in
`jax/input/TeX`.  The first file, ``config.js``, is loaded when
MathJax is being loaded and configured, and is indicated by listing
the input jax directory in the `jax` array of the MathJax
configuration.  The ``config.js`` file creates a subclass of the
`MathJax.InputJax` object for the new input jax and registers that
with MathJax, along with the MIME-type that will be used to indicate
the mathematics that is to be processed by the input jax.

The main body of the input jax is stored in the second file,
``jax.js``, which is loaded when the input jax is first called on to
translate some mathematics.  This file augments the original input jax
subclass with the additional methods needed to do the translation.
MathJax calls the input jax's :meth:`Translate()` method when it needs
the input jax to translate the contents of a math ``<script>`` tag.

The `MathJax.InputJax` class is a subclass of the :ref:`MathJax Jax
<api-jax>` class, and inherits the properties and methods of that
class.  Those listed below are the additional or overridden ones from
that class.


Properties
==========

.. describe:: id

    The name of the jax.

.. describe:: version

    The version number of the jax.

.. describe:: directory

    The directory where the jax files are stored (e.g., ``"[MathJax]/jax/input/TeX"``).

.. describe:: elementJax

    The name of the ElementJax class that this input jax will produce 
    (typically ``mml``, as that is the only ElementJax at the moment).


Methods
=======

.. Method:: Process(script,state)
    :noindex:

    This is the method that the ``MathJax.Hub`` calls when it needs
    the input jax to process the given math ``<script>``.  Its default
    action is to do the following:

    1. Start loading any element jax  specified in the ``elementJax`` array;
    2. Start loading the jax's ``jax.js`` file;
    3. Start loading the required output jax (so it is ready when needed); and
    4. Redefine itself to simply return the callback for the load operation 
       (so that further calls to it will cause the processing to wait for the 
       callback).

    Once the ``jax.js`` file has loaded, this method is replaced by
    the jax's ``Translate()`` method (see below), so that
    subsequent calls to ``Process()`` will perform the appropriate
    translation.

    :Parameters:
        - **script**  --- reference to the DOM ``<script>`` object for
          the mathematics to be translated
        - **state**   --- a structure containing information about the
          current proccessing state of the mathematics (internal use)
    :Returns: an `ElementJax` object, or ``null``

.. Method:: Translate(script,state)
    :noindex:

    This is the main routine called by MathJax when a ``<script>`` of the
    appropriate type is found.  The default :meth:`Translate()` method
    throws an error indicating that :meth:`Translate()` hasn't been
    defined, so when the ``jax.js`` file loads, it should override the
    default :meth:`Translate()` with its own version that does the actual
    translation. 

    The translation process should include the creation of an
    :ref:`Element Jax <api-element-jax>` that stores the data needed
    for this element.

    :Parameters:
        - **script**  --- the ``<script>`` element to be translated
        - **state**   --- a structure containing information about the
          current proccessing state of the mathematics (internal use)
    :Returns: the `element jax` resulting from the translation
 
.. Method:: Register(mimetype)
    :noindex:

    This registers the MIME-type associated with this input jax so
    that MathJax knows to call this input jax when it sees a
    ``<script>`` of that type.  An input jax can register more than
    one type, but it will be responsible for distinguishing elements
    of the various types from one another.

    :Parameters:
        - **mimetype**  --- the MIME-type of the input this jax processes
    :Returns: ``null``

.. Method:: needsUpdate(jax)
    :noindex:

    This implements the element jax's ``needsUpdate()`` method, and
    returns ``true`` if the ``jax`` needs to be rerendered (i.e., the
    text has changed), and ``false`` otherwise.

    :Perameters:
        - **jax**  --- the element jax to be checked
    :Returns: ``true`` if the jax's text has changed, ``false`` otherwise