File: hub.rst

package info (click to toggle)
mathjax-docs 2.7%2B20171212-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,100 kB
  • sloc: javascript: 28; sh: 22; python: 19; makefile: 8
file content (424 lines) | stat: -rw-r--r-- 16,701 bytes parent folder | download | duplicates (2)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
.. _api-hub:

**********************
The MathJax.Hub Object
**********************

The MathJax Hub, `MathJax.Hub`, is the main control structure for
MathJax.  It is where input and output :term:`jax` are tied together,
and it is what handles processing of the MathJax ``<script>`` tags.
Processing of the mathematics on the page may require external files
to be loaded (when the mathematics includes less common functionality,
for example, that is defined in an extension file), and since file
loading is asynchronous, a number of the methods below may return
before their actions are completed.  For this reason, they include
callback functions that are called when the action completes.  These
can be used to synchronize actions that require the mathematics to be
completed before those actions occur. See the :ref:`Using Callbacks
<using-callbacks>` documentation for more details.


Properties
==========

.. describe:: config: { ... }

    This holds the configuration parameters for MathJax.  Set these
    values using :meth:`MathJax.Hub.Config()` described below.  The
    options and their default values are given in the :ref:`Core
    Options <configure-hub>` reference page.

.. describe:: processSectionDelay: 50

    The pause (in milliseconds) between input and output phases of MathJax's processing. Set this to ``0`` to avoid jitter when updating output frequently (e.g., in a live preview environment).

.. describe:: processUpdateTime: 250

    The minimum time (in milliseconds) between updates of the
    "Processing Math" message.  After this amount of time has passed,
    and after the next equation has finished being processed,
    MathJax will stop processing momentarily so that the update
    message can be displayed, and so that the browser can handle user
    interaction.

.. describe:: processUpdateDelay: 10

   The amount of time (in milliseconds) that MathJax pauses after
   issuing its processing message before starting the processing again
   (to give browsers time to handle user interaction).

.. describe:: signal

    The hub processing signal (tied to the
    :meth:`MathJax.Hub.Register.MessageHook()` method).

.. describe:: queue

    MathJax's main processing queue.  Use :meth:`MathJax.Hub.Queue()` to push
    callbacks onto this queue.

.. describe:: Browser

    The name of the browser as determined by MathJax.  It will be one
    of ``Firefox``, ``Safari``, ``Chrome``, ``Opera``, ``MSIE``,
    ``Konqueror``, or ``unknown``.  This is actually an object with
    additional properties and methods concerning the browser:

    .. describe:: version

        The browser version number, e.g., ``"4.0"``

    .. describe:: isMac and isPC

        These are boolean values that indicate whether the browser is
        running on a Macintosh computer or a Windows computer.  They
        will both be ``false`` for a Linux computer.

    .. describe:: isMobile

        This is ``true`` when MathJax is running a mobile version of a
        WebKit or Gecko-based browser.

    .. describe:: isFirefox, isSafari, isChrome, isOpera, isMSIE, isKonqueror

        These are ``true`` when the browser is the indicated one, and
        ``false`` otherwise.

    .. describe:: versionAtLeast(version)

        This tests whether the browser version is at least that given
        in the `version` string.  Note that you can not simply do a
        numeric comparison, as version 4.10 should be considered later
        than 4.9, for example.  Similarly, 4.10 is different from 4.1,
        for instance.

    .. describe:: Select(choices)

        This lets you perform browser-specific functions.  Here,
        `choices` is an object whose properties are the names of the
        browsers and whose values are the functions to be performed.
        Each function is passed one parameter, which is the
        ``MathJax.Hub.Browser`` object.  You do not need to include
        every browser as one of your choices --- only those for which you
        need to do special processing.  For example:

	.. code-block:: javascript

	    MathJax.Hub.Browser.Select({
	      MSIE: function (browser) {
	        if (browser.versionAtLeast("8.0")) {... do version 8 stuff ... }
		... do general MSIE stuff ...
	      },

	      Firefox: function (browser) {
	        if (browser.isMac) {... do Mac stuff ... }
		... do general Firefox stuff
	      }
	    });

.. describe:: inputJax

    An object storing the MIME types associated with the various
    registered input jax (these are the types of the ``<script>`` tags
    that store the math to be processed by each input jax).

.. describe:: outputJax

    An object storing the output jax associate with the various
    element jax MIME types for the registered output jax.


Methods
=======

.. Method:: Config(options)

    Sets the configuration options (stored in ``MathJax.Hub.config``)
    to the values stored in the `options` object.  See
    :ref:`Configuring MathJax <configuration>` for details on how this
    is used and the options that you can set.

    :Parameters:
        - **options** --- object containing options to be set
    :Returns: ``null``

.. describe:: Configured()

    When ``delayStartupUntil`` is specified in the configuration file or
    in the script that loads ``MathJax.js``, MathJax's startup sequence is
    delayed until this routine is called.  See :ref:`Configuring MathJax
    <configuration>` for details on how this is used.

    :Returns: ``null``

.. describe:: Register.PreProcessor(callback)

    Used by preprocessors to register themselves with MathJax so that
    they will be called during the :meth:`MathJax.Hub.PreProcess()`
    action.

    :Parameters:
        - **callback** ---  the callback specification for the preprocessor
    :Returns: ``null``

.. describe:: Register.MessageHook(type,callback)

    Registers a listener for a particular message being sent to the
    hub processing signal (where `PreProcessing`, `Processing`, and
    `New Math` messages are sent).  When the message equals the
    `type`, the `callback` will be called with the message as its
    parameter.

    The following is an example for using the MessageHook to list
    internal errors within MathJax which would otherwise be silent:

    .. code-block:: javascript

		MathJax.Hub.Register.MessageHook("TeX Jax - parse error",function (message) {
		// do something with the error.  message[1] will contain the data about the error.
		});

		MathJax.Hub.Register.MessageHook("Math Processing Error",function (message) {
		//  do something with the error.  message[2] is the Error object that records the problem.
		});

    :Parameters:
        - **type** --- a string indicating the message to look for
        - **callback** --- a callback specification
    :Returns: ``null``

.. describe:: Register.StartupHook(type,callback)

    Registers a listener for a particular message being sent to the
    startup signal (where initialization and component startup
    messages are sent).  When the message equals the `type`, the
    `callback` will be called with the message as its parameter.
    See the :ref:`Using Signals <using-signals>` documentation for
    more details.

    :Parameters:
        - **type** --- a string indicating the message to look for
        - **callback** --- a callback specification
    :Returns: ``null``

.. describe:: Register.LoadHook(file,callback)

    Registers a callback to be called when a particular file is
    completely loaded and processed.  (The callback is called when the
    file makes its :meth:`MathJax.Ajax.loadComplete()` call.) The
    `file` should be the complete file name, e.g.,
    ``"[MathJax]/config/default.js"``.

    :Parameters:
        - **file** --- the name of the file to wait for
        - **callback** --- a callback specification
    :Returns: the callback object

.. Method:: Queue(callback,...)
    :noindex:

    Pushes the given callbacks onto the main MathJax command queue.
    This synchronizes the commands with MathJax so that they will be
    performed in the proper order even when some run asynchronously.
    See :ref:`Using Queues <using-queues>` for more details about how
    to use queues, and the MathJax queue in particular.  You may
    supply as many `callback` specifications in one call to the
    :meth:`Queue()` method as you wish.

    :Parameters:
        - **callback** --- a callback specification
    :Returns: the callback object for the last callback added to the queue

.. Method:: Typeset([element[,callback]])

    Calls the preprocessors on the given element (or elements if it is an
    array of elements), and then typesets any math elements within the
    element.  If no `element` is provided, the whole document is processed.
    The `element` is either the DOM `id` of the element, a reference to
    the DOM element itself, or an array of id's or references.  The
    `callback` is called when the process is complete.  See the
    :ref:`Modifying Math <typeset-math>` section for details of how to use
    this method properly.

    :Parameters:
        - **element** --- the element(s) whose math is to be typeset
        - **callback** --- the callback specification
    :Returns: the callback object

.. method:: PreProcess([element[,callback]])

    Calls the loaded preprocessors on the entire document, or on the given
    DOM element (or elements, if it is an array of elements).  The
    `element` is either the DOM `id` of the element, a reference to the
    DOM element itself, or an array of id's or references.  The `callback`
    is called when the processing is complete.

    :Parameters:
        - **element** --- the element to be preprocessed
        - **callback** --- the callback specification
    :Returns: the callback object

.. method:: Process([element[,callback]])

    Scans either the entire document or a given DOM `element` (or array of
    elements) for MathJax ``<script>`` tags and processes the math those
    tags contain.  The `element` is either the DOM `id` of the element to
    scan, a reference to the DOM element itself, or an array of id's or
    references.  The `callback` is called when the processing is complete.

    :Parameters:
        - **element** --- the element(s) to be processed
        - **callback** --- the callback specification
    :Returns: the callback object

.. method:: Update([element[,callback]])

    Scans either the entire document or a given DOM element (or elements if
    it is an array of elements) for mathematics that has changed since the
    last time it was processed, or is new, and typesets the mathematics
    they contain.  The `element` is either the DOM `id` of the element to
    scan, a reference to the DOM element itself, or an array of id's or
    references.  The `callback` is called when the processing is complete.

    :Parameters:
        - **element** --- the element(s) to be updated
        - **callback** --- the callback specification
    :Returns: the callback object

.. method:: Reprocess([element[,callback]])

    Removes any typeset mathematics from the document or DOM element
    (or elements if it is an array of elements), and then processes
    the mathematics again, re-typesetting everything.  This may be
    necessary, for example, if the CSS styles have changed and those
    changes would affect the mathematics.  Reprocess calls both the
    input and output jax to completely rebuild the data for
    mathematics.  The `element` is either the DOM `id` of the element
    to scan, a reference to the DOM element itself, or an array of
    id's or references.  The `callback` is called when the processing
    is complete.

    :Parameters:
        - **element** --- the element(s) to be reprocessed
        - **callback** --- the callback specification
    :Returns: the callback object

.. method:: Rerender([element[,callback]])

    Removes any typeset mathematics from the document or DOM element
    (or elements if it is an array of elements), and then renders the
    mathematics again, re-typesetting everything from the current
    internal version (without calling the input jax again).  The
    `element` is either the DOM `id` of the element to scan, a
    reference to the DOM element itself, or an array of id's or
    references.  The `callback` is called when the processing is
    complete.

    :Parameters:
        - **element** --- the element(s) to be reprocessed
        - **callback** --- the callback specification
    :Returns: the callback object

.. method:: getAllJax([element])

    Returns a list of all the element jax in the document or a
    specific DOM element.  The `element` is either the DOM `id` of the
    element, or a reference to the DOM element itself.

    :Parameters:
        - **element** --- the element to be searched
    :Returns: array of `element jax` objects

.. method:: getJaxByType(type[,element])

    Returns a list of all the element jax of a given MIME-type in the
    document or a specific DOM element.  The `element` is either the
    DOM `id` of the element to search, or a reference to the DOM
    element itself.

    :Parameters:
        - **type** --- MIME-type of `element jax` to find
        - **element** --- the element to be searched
    :Returns: array of `element jax` objects

.. method:: getJaxByInputType(type[,element])

    Returns a list of all the element jax associated with input
    ``<script>`` tags with the given MIME-type within the given DOM
    element or the whole document.  The `element` is either the DOM
    `id` of the element to search, or a reference to the DOM element
    itself.

    :Parameters:
        - **type** --- MIME-type of input (e.g., ``"math/tex"``)
        - **element** --- the element to be searched
    :Returns: array  of `element jax` objects

.. method:: getJaxFor(element)

    Returns the element jax associated with a given DOM
    element.  If the element does not have an associated element jax,
    ``null`` is returned.  The `element` is either the DOM `id` of the
    element, or a reference to the DOM element itself.

    :Parameters:
        - **element** --- the element whose element jax is required
    :Returns: `element jax` object or ``null``

.. method:: isJax(element)

    Returns ``0`` if the element is not a ``<script>`` that can be
    processed by MathJax or the result of an output jax, returns ``-1``
    if the element is an unprocessed ``<script>`` tag that could be
    handled by MathJax, and returns ``1`` if the element is a processed
    ``<script>`` tag or an element that is the result of an output jax.

    :Parameters:
        - **element** --- the element to inspect
    :Returns: integer (-1, 0, 1)

.. Method:: setRenderer(renderer[,type])

    Sets the output jax for the given element jax ``type`` (or ``jax/mml``
    if none is specified) to be the one given by ``renderer``, which
    must be the name of a renderer, such as ``NativeMML`` or
    ``HTML-CSS``.  Note that this does not cause the math on the page
    to be rerendered; it just sets the renderer for output in the
    future (call :meth:``Rerender()`` above to replace the current
    renderings by new ones).

    :Parameters:
        - **renderer** --- the name of the output jax to use for rendering
	- **type** --- the element jax MIME type whose renderer to set
    :Returns: ``null``

.. Method:: Insert(dst,src)

    Inserts data from the `src` object into the `dst` object.  The
    `key:value` pairs in `src` are (recursively) copied into `dst`, so
    that if `value` is itself an object, its content is copied into
    the corresponding object in `dst`.  That is, objects within `src`
    are merged into the corresponding objects in `dst` (they don't
    replace them).

    :Parameters:
        - **dst** --- the destination object
        - **src** --- the source object
    :Returns: the modified destination object

.. Method:: formatError(script,error)

    This is called when an internal error occurs during the processing
    of a math element (i.e., an error in the MathJax code itself).
    The `script` is a reference to the ``<script>`` tag where the
    error occurred, and `error` is the ``Error`` object for the error.
    The default action is to insert an HTML snippet at the location of
    the script, but this routine can be overriden during MathJax
    configuration in order to perform some other action.
    ``MathJax.Hub.lastError`` holds the ``error`` value of the last
    error on the page.

    :Parameters:
        - **script** --- the ``<script>`` tag causing the error
        - **error** --- the ``Error`` object for the error
    :Returns: ``null``