Continues updating documentation, in particular the Advanced Topics and API documents. Added a number of new example files.

This commit is contained in:
Davide P. Cervone 2012-02-20 12:31:44 -05:00
parent 77e84ff894
commit 4332291f58
64 changed files with 2332 additions and 597 deletions

View File

@ -58,7 +58,7 @@ A callback specification is any one of the following:
the given function, and it would return their sum, ``5``, when
the callback is executed.
.. describe:: [object, fn]
.. describe:: [object, fn]
An array containing an object to use as `this` and a function to
call for the callback. For example,
@ -75,7 +75,7 @@ A callback specification is any one of the following:
Similar to the previous case, but with data that is passed to
the function as well.
..describe:: ["method", object]
.. describe:: ["method", object]
Here, `object` is an object that has a method called `method`, and
the callback will execute that method (with the object as
@ -220,24 +220,6 @@ MathJax.Callback Methods
- **callback** --- the callback specification
:Returns: the callback object
.. method:: ExecuteHooks(hooks[, data[,reset]])
Calls each callback in the `hooks` array (or the single hook if it
is not an array), passing it the arguments stored in the data
array. If `reset` is ``true``, then the callback's
:meth:`reset()` method will be called before each hook is
executed. If any of the hooks returns a `Callback` object, then
it collects those callbacks and returns a new callback that will
execute when all the ones returned by the hooks have been
completed. Otherwise, :meth:`MathJax.Callback.ExecuteHooks()`
returns ``null``.
:Parameters:
- **hooks** --- array of hooks to be called, or a hook
- **data** --- array of arguments to pass to each hook in turn
- **reset** --- ``true`` if the :meth:`reset()` method should be called
:Returns: callback that waits for all the hooks to complete, or ``null``
.. method:: Queue([callback,...])
Creates a `MathJax.CallBack.Queue` object and pushes the given
@ -257,3 +239,66 @@ MathJax.Callback Methods
:Parameters:
- **name** --- name of the signal to get or create
:Returns: the `Signal` object
.. method:: ExecuteHooks(hooks[, data[,reset]])
Calls each callback in the `hooks` array (or the single hook if it
is not an array), passing it the arguments stored in the data
array. If `reset` is ``true``, then the callback's
:meth:`reset()` method will be called before each hook is
executed. If any of the hooks returns a `Callback` object, then
it collects those callbacks and returns a new callback that will
execute when all the ones returned by the hooks have been
completed. Otherwise, :meth:`MathJax.Callback.ExecuteHooks()`
returns ``null``.
:Parameters:
- **hooks** --- array of hooks to be called, or a hook
- **data** --- array of arguments to pass to each hook in turn
- **reset** --- ``true`` if the :meth:`reset()` method should be called
:Returns: callback that waits for all the hooks to complete, or ``null``
.. method:: Hooks(reset)
Creates a prioritized list of hooks that are called in order based
on their priority (low priority numbers are handled first). This
is meant to replace :meth:`MathJax.Callback.ExecuteHooks()` and is
used internally for signal callbacks, pre- and post-filters, and
other lists of callbacks.
:Parameters:
- **reset** --- ``true`` if callbacks can be called more than once
:Returns: the `Hooks` object
The list has the following methods:
.. method:: Add(hook[,priority])
Add a callback to the prioritized list. If ``priority`` is
not provided, the default is 10. The ``hook`` is a `Callback`
specification as described above.
:Parameters:
- **hook** --- callback specification to add to the list
- **priority** --- priority of the hook in the list (default: 10)
:Returns: the callback object being added
.. method:: Remove(hook)
:noindex:
Remove a given hook (as returned from :meth:`Add()` above)
from the prioritized list.
:Parameters:
- **hook** --- the callback to be removed
:Returns: ``null``
.. method:: Execute()
Execute the list of callbacks, resetting them if requested.
If any of the hooks return callbacks, then ``Execute()``
returns a callback that will be executed when they all have
completed.
:Returns: a callback object or ``null``

View File

@ -42,13 +42,11 @@ Instance Properties
.. describe:: inputJax
A reference to the input jax that created the element. (In the
future, this will be changed to the name of the input jax.)
The name of the input jax that created the element.
.. describe:: outputJax
A reference to the output jax that has processed this element. (In
the future, this will be changed to the name of the output jax.)
The name of the output jax that has processed this element.
.. describe:: inputID
@ -89,13 +87,25 @@ Methods
- **callback** --- the callback specification
:Returns: the callback object
.. Method:: Rerender([callback])
:noindex:
Removes the output and produces it again (for example, if CSS has
changed that would alter the spacing of the mathematics). Note
that the internal representation isn't regenerated; only the
output is. The `callback`, if any, is called when the process
completes.
:Parameters:
- **callback** --- the callback specification
:Returns: the callback object
.. Method:: Reprocess([callback])
:noindex:
Removes the output and produces it again. This may be necessary if
there are changes to the CSS styles that would affect the layout
of the mathematics, for example. The `callback`, if any, is
called when the process completes.
Removes the output and then retranslates the input into the
internal form and reredners the output again. The `callback`, if
any, is called when the process completes.
:Parameters:
- **callback** --- the callback specification
@ -118,6 +128,16 @@ Methods
:Returns: the ``<script>`` element
.. Method:: needsUpdate()
Indicates whether the mathematics has changed so that its output
needs to be updated.
:Returns: ``true`` if the mathematics needs to be reprocessed,
``false`` otherwise
Output jax may add new methods to the base element jax class to
perform exporting to other formats. For example, a MathML output jax
could add ``toMathML()``, or an accessibility output jax could add

View File

@ -92,6 +92,15 @@ Methods
- **text** --- the text that is to be the script's new content
:Returns: ``null``
.. method:: getScript(script)
Gets the contents of the ``script`` element, properly taking into
account the browser limitations and bugs.
:Parameters:
- **script** --- the script whose content is to be retrieved
:Returns: the text of the ``script``
.. describe:: Cookie.Set(name,data)
Creates a MathJax cookie using the ``MathJax.HTML.Cookie.prefix``

View File

@ -31,7 +31,17 @@ Properties
.. describe:: processUpdateTime: 250
The minimum time (in milliseconds) between updates of the
"Processing Math" message.
"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
@ -60,6 +70,11 @@ Properties
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
@ -97,6 +112,18 @@ Properties
}
);
.. 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
=======
@ -243,13 +270,31 @@ Methods
.. 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. 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
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:
@ -315,6 +360,21 @@ Methods
- **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

View File

@ -56,13 +56,40 @@ Properties
Methods
=======
.. Method:: Translate(script)
.. 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
redefined, so when the ``jax.js`` file loads, it should override the
defined, so when the ``jax.js`` file loads, it should override the
default :meth:`Translate()` with its own version that does the actual
translation.
@ -72,6 +99,9 @@ Methods
: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)
@ -87,3 +117,14 @@ Methods
- **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

View File

@ -63,34 +63,20 @@ Instance Properties
jax. These can be modified by the author by including a
configuration subsection for the specific jax in question.
.. describe:: JAXFILE: "jax.js"
The name of the file that contains the main code for the jax.
Methods
=======
.. Method:: Process(script)
:noindex:
This is the method that the ``MathJax.Hub`` calls when it needs the
input or output jax to process the given math ``<script>``. Its
default action is to start loading the jax's ``jax.js`` file, and
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 :meth:`Translate()` method, so that subsequent calls
to :meth:`Process()` will perform the appropriate translation.
:Parameters:
- **script** --- reference to the DOM ``<script>`` object for
the mathematics to be translated
:Returns: an `ElementJax` object, or ``null``
.. Method:: Translate(script)
This is a stub for a routine that should be defined by the jax's
``jax.js`` file when it is loaded. It should perform the translation
action for the specific jax. For an input jax, it should return the
`ElementJax` object that it created. The :meth:`Translate()` method is
never called directly by MathJax; during the :meth:`loadComplete()`
never called directly by MathJax; during the ``loadComplete()``
call, this function is copied to the :meth:`Process()` method, and is
called via that name. The default :meth:`Translate()` method throws an
error indicating that the :meth:`Translate()` method was not
@ -147,7 +133,10 @@ Methods
5. Post the "[name] Jax Startup" message to the startup signal.
6. Perform the jax's :meth:`Startup()` method.
7. Post the "[name] Jax Ready" message to the startup signal.
8. Perform the :meth:`MathJax.Ajax.loadComplete()` call for the
8. Copy the ``preTranslate``, ``Translate``, and
``postTranslate`` functions to ``preProcess``, ``Process``,
and ``postProcess``.
9. Perform the :meth:`MathJax.Ajax.loadComplete()` call for the
``jax.js`` file.
Note that the configuration process (the :meth:`Config()` call) can

View File

@ -48,17 +48,65 @@ Properties
The directory where the jax files are stored (e.g., ``"[MathJax]/jax/output/HTML-CSS"``);
.. describe:: fontDir
The directory where the fonts are stored (e.g., ``"[MathJax]/fonts"``)
.. describe:: imageDir
The directory where MathJax images are found (e.g. ``"[MathJax]/images"``)
Methods
=======
.. Method:: Translate(script)
.. Method:: preProcess(state)
This is called by ``MathJax.Hub`` to ask the output processor to
prepare to process math scripts. Its default action is to start
loading the jax's ``jax.js`` file, and 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 :meth:`preTranslate()` method, so that subsequent calls
to :meth:`preProcess()` will perform the appropriate translation.
:Parameters:
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: ``null``
.. Method:: preTranslate(state)
This routine replaces :meth:`preProcess()` above when the jax's
``jax.js`` file is loaded. It is called by ``MathJax.Hub`` to ask
the output processor to prepare to process math scripts. (For
example, the HTML-CSS output jax uses this to determine em-sizes
for all the mathematics at once, to minimize page reflows that
slow down Internet Explorer.)
The routine can use ``state.jax[this.id]`` to obtain the array of
element jax that are to be processed. The output jax can use the
``state`` variable to maintain its own state information, but
any properties that it adds to the variable should have a prefix
that is the output jax's ID. For example, the HTML-CSS output jax
might use ``state.HTMLCSSlast`` to keep track of the last equation
it processed, or could add ``state.HTMLCSS = {...}`` to create an
object of its own within the state variable.
:Parameters:
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: ``null``
.. Method:: Translate(script,state)
:noindex:
This is the main routine called by MathJax when an element jax is
to be converted to output. The default :meth:`Translate()`
method throws an error indicating that :meth:`Translate()` hasn't been
redefined, so when the ``jax.js`` file loads, it should override the
defined, so when the ``jax.js`` file loads, it should override the
default :meth:`Translate()` with its own version that does the actual
translation.
@ -66,12 +114,35 @@ Methods
element jax for the given script. The translation process may
modify the element jax (e.g., if it has data that needs to be
stored with the jax), and may insert DOM elements into the
document near the jax's ``<script>`` tag.
document near the jax's ``<script>`` tag. The output jax can use
the ``state`` variable to maintain information about its
processing state, but see :meth:`preTranslate()` above for naming
conventions for properties that are added.
:Parameters:
- **script** --- the ``<script>`` element to be translated
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: the `element jax` resulting from the translation
.. Method:: postTranslate(state)
This routines is called by ``MathJax.Hub`` when the translation
of math elements is complete, and can be used by the output
processor to finalize any actions that it needs to complete.
(For example, making the mathematics visible, or forcing a reflow
of the page.)
The routine can use ``state.jax[this.id]`` to obtain the array of
element jax that were processed, or can use the ``state`` variable
to store its own state information (see :meth:`preProcess()`
above for caveats about naming properties).
:Parameters:
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: ``null``
.. Method:: Register(mimetype)
:noindex:
@ -95,3 +166,53 @@ Methods
:Parameters:
- **jax** --- the element jax whose display should be removed
:Returns: ``null``
If an output jax wants its output to handle the contextual menu item
and zooming, then it needs to tie into the event-handling code
(`MathEvents`) and the zoom-handling code (`MathZoom`). That requires
the following methods.
.. Method:: getJaxFromMath(math)
This is called by the event-handling code (`MathEvents`) to get
the element jax associated with the DOM element that caused an
event to occur. The output jax will have attached event handlers
to some DOM element that is part of its output, and the
`MathEvents` code uses this routine to map back to the jax
associated with that output.
:Parameters:
- **math** --- a DOM element that triggered a DOM event
(e.g., a mouse click)
:Returns: the `ElementJax` structure associated with the DOM element
.. Method:: Zoom(jax,span,math,Mw,Mh)
This routine is called by the zoom-handling code (`MathZoom`)
when an expression has received its zoom trigger event (e.g., a
double-click). The ``jax`` is the math that needs to be zoomed,
``span`` is a ``<span>`` element in which the zoomed version of
the math should be placed, ``math`` is the DOM element that
received the zoom trigger event, and ``Mw`` and ``Mh`` are the
maximum width and height allowed for the zoom box (the ``span``).
The return value is an object with the following properties:
- ``Y`` --- the vertical offset from the top of the ``span`` to
the baseline of the mathematics
- ``mW`` --- the width of the original mathematics element
- ``mH`` --- the height of the original mathematics element
- ``zW`` --- the width of the zoomed math
- ``zH`` --- the height of the zoomed math
All of these values are in pixels.
:Parameters:
- **jax** --- the jax to be zoomed
- **span** --- the ``<span>`` in which to place the zoomed math
- **math** --- the DOM element generating the zoom event
- **Mw** --- the maximum width of the zoom box
- **Mh** --- the maximum height of the zoom box
:Returns: a structure as described above

View File

@ -19,7 +19,7 @@ Main MathJax Components
.. describe:: MathJax.Ajax
Contains the code for loading external modules and creating
stylesheets. Most of the code that causes most of MathJax to
stylesheets. Most of the code that causes MathJax to
operate asynchronously is handled here.
.. describe:: MathJax.Message
@ -43,6 +43,11 @@ Main MathJax Components
For example, the `tex2jax` preprocessor creates
``MathJax.Extension.tex2jax`` for its code and variables.
.. describe:: MathJax.Menu
Initially null, this is where the MathJax contextual menu is
stored, when ``extensions/MathMenu.js`` is loaded.
.. describe:: MathJax.Object
Contains the code for the MathJax object-oriented programming model.
@ -75,7 +80,11 @@ Properties
.. describe:: MathJax.version
The version number of the MathJax library.
The version number of the MathJax library as a whole.
.. describe:: MathJax.fileversion
The version number of the ``MathJax.js`` file specifically.
.. describe:: MathJax.isReady

View File

@ -214,10 +214,10 @@ you simply passed the object's method to ``setTimeout()``. Or you
might want to pass an argument to the function called by
``setTimeout()``. (Altough the ``setTimeout()`` function can accept
additional arguements that are supposed to be passed on to the code
when it is called, Internet Explorer does not implement that feature,
so you can't rely on it.) You can use a `Callback` object to
do this, and the :meth:`MathJax.Callback()` method will create one for
you. For example,
when it is called, some versions of Internet Explorer do not implement
that feature, so you can't rely on it.) You can use a `Callback`
object to do this, and the :meth:`MathJax.Callback()` method will
create one for you. For example,
.. code-block:: javascript

View File

@ -6,21 +6,16 @@ Loading MathJax Dynamically
MathJax is designed to be included via a ``<script>`` tag in the
``<head>`` section of your HTML document, and it does rely on being
part of the original document in that it uses an ``onload`` event
handler to synchronize its actions with the loading of the page.
If you wish to insert MathJax into a document after it has
been loaded, that will normally occur *after* the page's ``onload``
handler has fired, and so MathJax will not be able to tell if it is
safe for it to process the contents of the page. Indeed, it will wait
forever for its ``onload`` handler to fire, and so will never process
the page.
To solve this problem, you will need to call MathJax's ``onload``
handler yourself, to let it know that it is OK to typeset the
mathematics on the page. You accomplish this by calling the
:meth:`MathJax.Hub.Startup.onload()` method as part of your MathJax
startup script. To do this, you will need to give MathJax an in-line
configuration.
part of the original document in that it uses an ``onload`` or
``DOMContentLoaded`` event handler to synchronize its actions with the
loading of the page. If you wish to insert MathJax into a document
after it has been loaded, that will normally occur *after* the page's
``onload`` handler has fired, and prior to version 2.0, MathJax had to
be told not to wait for the page ``onload`` event by calling
:meth:`MathJax.Hub.Startup.onload()` by hand. That is no longer
necessary, as MathJax v2.0 detects whether the page is already
available and when it is, it processes it immediately rather than
waiting for an event that has already happened.
Here is an example of how to load and configure MathJax dynamically:
@ -29,43 +24,37 @@ Here is an example of how to load and configure MathJax dynamically:
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js";
var config = 'MathJax.Hub.Config({' +
'extensions: ["tex2jax.js"],' +
'jax: ["input/TeX","output/HTML-CSS"]' +
'});' +
'MathJax.Hub.Startup.onload();';
if (window.opera) {script.innerHTML = config}
else {script.text = config}
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
You can adjust the ``config`` variable to your needs, but be careful to get
the commas right. The ``window.opera`` test is because some versions of
Opera don't handle setting ``script.text`` properly, while Internet
Explorer doesn't handle setting the ``innerHTML`` of a script tag.
Here is a version that uses the ``config=filename`` method to
configure MathJax:
If you need to provide in-line configuration, you can do that using a
MathJax's configuration script:
.. code-block:: javascript
(function () {
var script = document.createElement("script");
var head = document.getElementsByTagName("head")[0], script;
script = document.createElement("script");
script.type = "text/x-mathjax-config";
script[(window.opera ? "innerHTML" : "text")] =
"MathJax.Hub.Config({\n" +
" tex2jax: { inlineMath: [['$','$'], ['\\\\(','\\\\)']] }\n" +
"});"
head.appendChild(script);
script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload();';
if (window.opera) {script.innerHTML = config}
else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
head.appendChild(script);
})();
You can adjust the configuration to your needs, but be careful to get
the commas right, as Internet Explorer 6 and 7 will not tolerate an
extra comma before a closing brace. The ``window.opera`` test is
because some versions of Opera don't handle setting ``script.text``
properly, while some versions of Internet Explorer don't handle
setting ``script.innerHTML``.
Note that the **only** reliable way to configure MathJax is to use an
in-line configuration block of the type discussed above. You should
**not** call :meth:`MathJax.Hub.Config()` directly in your code, as it will
@ -116,9 +105,8 @@ IE+MathPlayer.
(document.getElementsByTagNameNS == null ? false :
(document.getElementsByTagNameNS("http://www.w3.org/1998/Math/MathML","math").length > 0))) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}
@ -157,9 +145,8 @@ converting the math images to their original TeX code.
// Load MathJax and have it process the page
//
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}

View File

@ -5,7 +5,7 @@ The MathJax Processing Model
The purpose of MathJax is to bring the ability to include mathematics
easily in web pages to as wide a range of browsers as possible.
Authors can specify mathematics in a variety of formats (e.g.,
:term:`MathML` or :term:`LaTeX`), and MathJax provides high-quality
:term:`MathML`, :term:`LaTeX`, or :term:`AsciiMath`), and MathJax provides high-quality
mathematical typesetting even in those browsers that do not have
native MathML support. This all happens without the need for special
downloads or plugins, but rendering will be enhanced if high-quality
@ -35,7 +35,8 @@ document is to be typeset as mathematics. In this case, MathJax can
run a preprocessor to locate the math delimiters and replace them by
the special tags that it uses to mark the formulas. There are
preprocessors for :ref:`TeX notation <TeX-support>`, :ref:`MathML
notation <MathML-support>`, and the :ref:`jsMath notation
notation <MathML-support>`, :ref:`AsciiMath notation
<AsciiMath-support>` and the :ref:`jsMath notation
<jsMath-support>` that uses `span` and `div` tags.
For pages that are constructed programmatically, such as HTML
@ -44,10 +45,12 @@ format (e.g., pages produced from Markdown documents, or via programs
like `tex4ht`), it would be best to use MathJax's special tags
directly, as described below, rather than having MathJax run
another preprocessor. This will speed up the final display of the
mathematics, since the extra preprocessing step would not be needed,
and it also avoids the conflict between the use of the less-than sign,
mathematics, since the extra preprocessing step would not be needed.
It also avoids the conflict between the use of the less-than sign,
``<``, in mathematics and as an HTML special character (that starts
an HTML tag).
an HTML tag), and several other issues involved in having the
mathematics directly in the text of the page (see the documentation on
the various input jax for more details on this).
.. _mathjax-script-tags:
@ -69,8 +72,9 @@ kind of script that the tag contains. The usual (and default) value
is ``type="text/javascript"``, and when a script has this type, the
browser executes the script as a javascript program. MathJax,
however, uses the type `math/tex` to identify mathematics in the TeX
and LaTeX notation, and `math/mml` for mathematics in MathML
notation. When the `tex2jax` or `mml2jax` preprocessors run, they
and LaTeX notation, `math/mml` for mathematics in MathML notation, and
`math/asciimath` for mathematics in AsciiMath notation. When the
`tex2jax`, `mml2jax`, or `asciimath2jax` preprocessors run, they
create ``<script>`` tags with these types so that MathJax can process
them when it runs its main typesetting pass.
@ -197,17 +201,25 @@ specific output format. For example, the NativeMML output jax inserts
MathML tags into the page to represent the mathematics, while the
HTML-CSS output jax uses HTML with CSS styling to lay out the
mathematics so that it can be displayed even in browsers that don't
understand MathML. Output jax could be produced that render the
mathematics using SVG, for example, or that speak an equation for
blind users. The MathJax contextual menu can be used to switch
between the output jax that are available.
understand MathML. MathJax also has an :term:`SVG` output jax that
will render the mathematics using scalable vector grtaphics. Output
jax could be produced that render the mathematics using HTML5 canvas
elements, for example, or that speak an equation for blind users. The
MathJax contextual menu can be used to switch between the output jax
that are available.
Each input and output jax has a small configuration file that is
loaded when that input jax is included in the `jax` array in the
MathJax configuration, and a larger file that implements the core
functionality of that particular jax. The latter file is loaded
the first time the jax is needed by MathJax to process some
mathematics.
functionality of that particular jax. The latter file is loaded the
first time the jax is needed by MathJax to process some mathematics.
Most of the combined configuration files include only the small
configuration portion for the input and output jax, making the
configuraiton file smaller and faster to load for those pages that
don't actually incldue mathematics; the combined configurations that
end in ``-full`` include both parts of the jax, so there is no delay
when the math is to be rendered, but at the expense of a larger
initial download.
The **MathJax Hub** keeps track of the internal representations of the
various mathematical equations on the page, and can be queried to

View File

@ -53,14 +53,14 @@ One way that MathJax makes use of this feature is in configuring its
various extensions. The extension may not be loaded when the user's
configuration code runs, so the configuration code can't modify the
extension because it isn't there yet. Fortunately, most extensions
signal when they are loaded and initialized via an ``Extension [name] Ready`` message,
so the configuration code can implement a listener for that message, and
have the listener perform the configuration when the message arrives.
But even if the extension *has* already been loaded, this will still
work, because the listener will receive the ready signal even if it
has already been posted. In this way, listening for signals is a
robust method of synchronizing code components no matter when they are
loaded and run.
signal when they are loaded and initialized via an ``Extension [name]
Ready`` message, or just ``[name] Ready``, so the configuration code
can implement a listener for that message, and have the listener
perform the configuration when the message arrives. But even if the
extension *has* already been loaded, this will still work, because the
listener will receive the ready signal even if it has already been
posted. In this way, listening for signals is a robust method of
synchronizing code components no matter when they are loaded and run.
In some cases, it may be inappropriate for a new listener to receive
past messages that were sent to a signal object. There are two ways to
@ -79,14 +79,14 @@ message, and can act on it in whatever ways they see fit.
Creating a Listener
===================
MathJax maintains two separate signal channels: the `startup signal`
and the `processing signal` (or the `hub signal`). The startup signal
is where the messages about different components starting up and
becoming ready appear. The processing signal is where the messages
are sent about processing mathematics, like the ``New Math`` messages
for when newly typeset mathematics appears on the page. The latter is
cleared when a new processing pass is started (so messages from past
processing runs are not kept).
MathJax maintains two separate pre-defined signal channels: the
`startup signal` and the `processing signal` (or the `hub signal`).
The startup signal is where the messages about different components
starting up and becoming ready appear. The processing signal is where
the messages are sent about processing mathematics, like the ``New
Math`` messages for when newly typeset mathematics appears on the
page. The latter is cleared when a new processing pass is started (so
messages from past processing runs are not kept).
The easiest way to create a listener is to use either
:meth:`MathJax.Hub.Register.StartupHook()` or
@ -103,10 +103,12 @@ called when it arrives. For example
See the :ref:`MathJax Startup Sequence <startup-sequence>` page for
details of the messages sent during startup. See also the
``test/sample-signals.html`` file (and its source) for examples of
using signals. This example lists all the signals that occur while
MathJax is processing that page, so it gives useful information about
the details of the signals produced by various components.
`test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_
file (and its source) for examples of using signals. This example
lists all the signals that occur while MathJax is processing that
page, so it gives useful information about the details of the signals
produced by various components.
In this example, the listener starts loading an extra configuration
file (from the same directory as the web page). Since it returns
@ -154,8 +156,9 @@ signal's :meth:`Interest()` method, as in the following example.
This will cause an alert for every signal that MathJax produces. You
probably don't want to try this out, since it will produce a *lot* of
them; instead, use the ``test/sample-signals.html`` file, which
displays them in the web page.
them; instead, use the `test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_
file, which displays them in the web page.
See the :ref:`Signal Object <api-signal>` reference page for details on the
structure and methods of the signal object.

View File

@ -90,7 +90,12 @@ pushed into the queue:
..
5. Load the jax configuration files:
5. Initialize the Message system (the grey information box in the
lower left)
..
6. Load the jax configuration files:
- Post the ``Begin Jax`` startup signal
- Load the jax config files from the ``MathJax.Hub.config.jax`` array
@ -101,7 +106,7 @@ pushed into the queue:
..
6. Load the extension files:
7. Load the extension files:
- Post the ``Begin Extensions`` startup signal
- Load the files from the ``MathJax.Hub.config.extensions`` array
@ -114,20 +119,22 @@ pushed into the queue:
..
7. Set the MathJax menu's renderer value based on the jax that have been
8. Set the MathJax menu's renderer value based on the jax that have been
loaded
..
8. Wait for the onload handler to fire
9. Wait for the onload handler to fire (in MathJax v2.0 this can
occur on the ``DOMContentLoaded`` event rather than the page's
``onload`` event, so processing of mathematics can start earlier)
..
9. Set ``MathJax.isReady`` to ``true``
10. Set ``MathJax.isReady`` to ``true``
..
10. Perform the typesetting pass (preprocessors and processors)
11. Perform the typesetting pass (preprocessors and processors)
- Post the ``Begin Typeset`` startup signal
- Post the ``Begin PreProcess`` hub signal
@ -137,6 +144,12 @@ pushed into the queue:
- Post the ``Begin Process`` hub signal
- Process the math script elements on the page
- There are a number of Hub signals generated during math
processing, including a signal that a ``Math`` action is
starting (with a parameter indicating what action that is),
``Begin`` and ``End Math Input`` messages, and ``Begin`` and
``End Math Output`` signals.
- Each new math element generates a ``New Math`` hub signal
with the math element's ID
@ -145,7 +158,18 @@ pushed into the queue:
..
11. Post the ``End`` startup signal
12. Jump to the location specified in the URL's hash reference, if
any.
..
13. Initiate timers to load the zoom and menu code, if it hasn't
already been loading in the configuration (so it will be ready
when the user needs it).
..
14. Post the ``End`` startup signal
The loading of the jax and extensions in steps 5 and 6 are now done in
@ -157,4 +181,6 @@ followed by `Begin Extensions`, but the order of `End Jax` and `End
Extensions` will depend on the files being loaded.) Both 5 and 6 must
complete, however, before 7 will be performed.
See the ``test/sample-signals.html`` file to see the signals in action.
See the `test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_ file
to see the signals in action.

View File

@ -12,7 +12,7 @@ yet). Actions such as loading files, loading web-based fonts, and
creating stylesheets all happen asynchronously within the browser, and
since JavaScript has no method of halting a program while waiting for
an action to complete, synchronizing your code with these types of
actions is made much more difficult. MathJax used three mechanisms to
actions is made much more difficult. MathJax uses three mechanisms to
overcome this language shortcoming: callbacks, queues, and signals.
**Callbacks** are functions that are called when an action is
@ -37,20 +37,23 @@ queues for actions that need to be synchronized with each other, but
not to MathJax as a whole. See the :ref:`Queue Object <api-queue>`
reference page for more details.
**Signals** are another means of synchronizing your own code with MathJax.
Many of the important actions that MathJax takes (like typesetting new math
on the page, or loading an external component) are "announced" by posting a
message to a special object called a `Signal`. Your code can register an
interest in receiving one or more of these signals by providing a callback
to be called when the signal is posted. When the signal arrives, MathJax
will call your code. This works somewhat like an event handler, except
that many different types of events can go through the same signal, and the
signals have a "memory", meaning that if you register an interest in a
particular type of signal and that signal has already occurred, you will be
told about the past occurrences as well as any future ones. See the
:ref:`Signal Object <api-signal>` reference page for more details. See
also the ``test/sample-signals.html`` file in the MathJax ``test``
directory for a working example of using signals.
**Signals** are another means of synchronizing your own code with
MathJax. Many of the important actions that MathJax takes (like
typesetting new math on the page, or loading an external component)
are "announced" by posting a message to a special object called a
`Signal`. Your code can register an interest in receiving one or more
of these signals by providing a callback to be called when the signal
is posted. When the signal arrives, MathJax will call your code.
This works somewhat like an event handler, except that many different
types of events can go through the same signal, and the signals have a
"memory", meaning that if you register an interest in a particular
type of signal and that signal has already occurred, you will be told
about the past occurrences as well as any future ones. See the
:ref:`Signal Object <api-signal>` reference page for more details.
See also the `test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_
file in the MathJax ``test`` directory for a working example of using
signals.
Each of these is explained in more detail in the links below:

View File

@ -127,17 +127,28 @@ The actions you can perform on an element jax include:
to set the math text of the element to `newmath` and typeset.
.. describe:: Rerender()
to remove the output and reproduce it again (for example, if
CSS has changed that would alter the spacing of the
mathematics). Note that the internal representation isn't
regenerated; only the output is.
.. describe:: Reprocess()
to remove the output and reproduce it again (for
example, if CSS has changed that would alter the spacing of the
mathematics).
to remove the output and then retranslate the input into the
internal MathML and rerender the output.
.. describe:: Remove()
to remove the output for this math element (but not
the original ``<script>`` tag).
.. describe:: needsUpdate()
to find out if the mathematics has changed so that its output
needs to be updated.
.. describe:: SourceElement()
to obtain a reference to the original
@ -161,7 +172,7 @@ queue. If your startup code performs the commands
var studentDisplay = null;
MathJax.Hub.Queue(function () {
studentDisplay = MathJax.Hub.getAllJax("MathDiv");
studentDisplay = MathJax.Hub.getAllJax("MathDiv")[0];
});
then you can use
@ -173,8 +184,12 @@ then you can use
to change the student's answer to be the typeset version of whatever
is in the ``studentAnswer`` variable.
Here is a complete example that illustrates this approach (available in a
more full-featured version as ``test/sample-dynamic.html``):
Here is a complete example that illustrates this approach. Note,
however, that Internet Explorer does not fire the ``onchange`` event
when you press RETURN, so this example does not work as expected in
IE. A more full-featured version that addresses this problem is
available in `test/sample-dynamic.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-dynamic.html>`_.
.. code-block:: html
@ -232,3 +247,8 @@ more full-featured version as ``test/sample-dynamic.html``):
</body>
</html>
There are a number of additional example pages at `test/examples.html
<http://cdn.mathjax.org/mathjax/latest/test/examples.html>`_ that
illustrate how to call MathJax dynamically or perform other actions
with MathJax.

View File

@ -10,9 +10,9 @@ if ((window.unsafeWindow == null ? window : unsafeWindow).MathJax == null) {
(document.getElementsByTagNameNS == null ? false :
(document.getElementsByTagNameNS("http://www.w3.org/1998/Math/MathML","math").length > 0))) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}

View File

@ -23,9 +23,8 @@ if ((window.unsafeWindow == null ? window : unsafeWindow).MathJax == null) {
// Load MathJax and have it process the page
//
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}

View File

@ -102,12 +102,12 @@ the window object. For example,</p>
<p>would specify a callback that would pass <tt class="docutils literal"><span class="pre">2</span></tt> and <tt class="docutils literal"><span class="pre">3</span></tt> to
the given function, and it would return their sum, <tt class="docutils literal"><span class="pre">5</span></tt>, when
the callback is executed.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">[object, fn]</tt></dt>
<dd></dd></dl>
<p>An array containing an object to use as <cite>this</cite> and a function to
<dd><p>An array containing an object to use as <cite>this</cite> and a function to
call for the callback. For example,</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="p">[{</span><span class="nx">x</span><span class="o">:</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span><span class="s1">&#39;bar&#39;</span><span class="p">},</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span><span class="k">this</span><span class="p">.</span><span class="nx">x</span><span class="p">}]</span>
</pre></div>
@ -123,9 +123,10 @@ when it is called.</p>
the function as well.</p>
</dd></dl>
<p>..describe:: [&#8220;method&#8221;, object]</p>
<blockquote>
<div><p>Here, <cite>object</cite> is an object that has a method called <cite>method</cite>, and
<dl class="describe">
<dt>
<tt class="descname">[&quot;method&quot;, object]</tt></dt>
<dd><p>Here, <cite>object</cite> is an object that has a method called <cite>method</cite>, and
the callback will execute that method (with the object as
<cite>this</cite>) when it is called. For example,</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="p">[</span><span class="s2">&quot;toString&quot;</span><span class="p">,[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]]</span>
@ -133,7 +134,8 @@ the callback will execute that method (with the object as
</div>
<p>would call the <cite>toString</cite> method on the array <tt class="docutils literal"><span class="pre">[1,2,3,4]</span></tt> when
the callback is called, returning <tt class="docutils literal"><span class="pre">1,2,3,4</span></tt>.</p>
</div></blockquote>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">[&quot;method&quot;, object, data...]</tt></dt>
@ -288,36 +290,6 @@ commands.</p>
</table>
</dd></dl>
<dl class="method">
<dt id="ExecuteHooks">
<tt class="descname">ExecuteHooks</tt><big>(</big><em>hooks</em><span class="optional">[</span>, <em>data</em><span class="optional">[</span>, <em>reset</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#ExecuteHooks" title="Permalink to this definition"></a></dt>
<dd><p>Calls each callback in the <cite>hooks</cite> array (or the single hook if it
is not an array), passing it the arguments stored in the data
array. If <cite>reset</cite> is <tt class="docutils literal"><span class="pre">true</span></tt>, then the callback&#8217;s
<a class="reference internal" href="#reset" title="reset"><tt class="xref py py-meth docutils literal"><span class="pre">reset()</span></tt></a> method will be called before each hook is
executed. If any of the hooks returns a <cite>Callback</cite> object, then
it collects those callbacks and returns a new callback that will
execute when all the ones returned by the hooks have been
completed. Otherwise, <tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Callback.ExecuteHooks()</span></tt>
returns <tt class="docutils literal"><span class="pre">null</span></tt>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>hooks</strong> &#8212; array of hooks to be called, or a hook</li>
<li><strong>data</strong> &#8212; array of arguments to pass to each hook in turn</li>
<li><strong>reset</strong> &#8212; <tt class="docutils literal"><span class="pre">true</span></tt> if the <a class="reference internal" href="#reset" title="reset"><tt class="xref py py-meth docutils literal"><span class="pre">reset()</span></tt></a> method should be called</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">callback that waits for all the hooks to complete, or <tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="Queue">
<tt class="descname">Queue</tt><big>(</big><span class="optional">[</span><em>callback</em>, <em>...</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Queue" title="Permalink to this definition"></a></dt>
@ -362,6 +334,122 @@ and returns the signal object. See
</table>
</dd></dl>
<dl class="method">
<dt id="ExecuteHooks">
<tt class="descname">ExecuteHooks</tt><big>(</big><em>hooks</em><span class="optional">[</span>, <em>data</em><span class="optional">[</span>, <em>reset</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#ExecuteHooks" title="Permalink to this definition"></a></dt>
<dd><p>Calls each callback in the <cite>hooks</cite> array (or the single hook if it
is not an array), passing it the arguments stored in the data
array. If <cite>reset</cite> is <tt class="docutils literal"><span class="pre">true</span></tt>, then the callback&#8217;s
<a class="reference internal" href="#reset" title="reset"><tt class="xref py py-meth docutils literal"><span class="pre">reset()</span></tt></a> method will be called before each hook is
executed. If any of the hooks returns a <cite>Callback</cite> object, then
it collects those callbacks and returns a new callback that will
execute when all the ones returned by the hooks have been
completed. Otherwise, <tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Callback.ExecuteHooks()</span></tt>
returns <tt class="docutils literal"><span class="pre">null</span></tt>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>hooks</strong> &#8212; array of hooks to be called, or a hook</li>
<li><strong>data</strong> &#8212; array of arguments to pass to each hook in turn</li>
<li><strong>reset</strong> &#8212; <tt class="docutils literal"><span class="pre">true</span></tt> if the <a class="reference internal" href="#reset" title="reset"><tt class="xref py py-meth docutils literal"><span class="pre">reset()</span></tt></a> method should be called</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">callback that waits for all the hooks to complete, or <tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="Hooks">
<tt class="descname">Hooks</tt><big>(</big><em>reset</em><big>)</big><a class="headerlink" href="#Hooks" title="Permalink to this definition"></a></dt>
<dd><p>Creates a prioritized list of hooks that are called in order based
on their priority (low priority numbers are handled first). This
is meant to replace <tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Callback.ExecuteHooks()</span></tt> and is
used internally for signal callbacks, pre- and post-filters, and
other lists of callbacks.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>reset</strong> &#8212; <tt class="docutils literal"><span class="pre">true</span></tt> if callbacks can be called more than once</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">the <cite>Hooks</cite> object</p>
</td>
</tr>
</tbody>
</table>
<p>The list has the following methods:</p>
<dl class="method">
<dt id="Add">
<tt class="descname">Add</tt><big>(</big><em>hook</em><span class="optional">[</span>, <em>priority</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Add" title="Permalink to this definition"></a></dt>
<dd><p>Add a callback to the prioritized list. If <tt class="docutils literal"><span class="pre">priority</span></tt> is
not provided, the default is 10. The <tt class="docutils literal"><span class="pre">hook</span></tt> is a <cite>Callback</cite>
specification as described above.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>hook</strong> &#8212; callback specification to add to the list</li>
<li><strong>priority</strong> &#8212; priority of the hook in the list (default: 10)</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">the callback object being added</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">Remove</tt><big>(</big><em>hook</em><big>)</big></dt>
<dd><p>Remove a given hook (as returned from <a class="reference internal" href="#Add" title="Add"><tt class="xref py py-meth docutils literal"><span class="pre">Add()</span></tt></a> above)
from the prioritized list.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>hook</strong> &#8212; the callback to be removed</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="Execute">
<tt class="descname">Execute</tt><big>(</big><big>)</big><a class="headerlink" href="#Execute" title="Permalink to this definition"></a></dt>
<dd><p>Execute the list of callbacks, resetting them if requested.
If any of the hooks return callbacks, then <tt class="docutils literal"><span class="pre">Execute()</span></tt>
returns a callback that will be executed when they all have
completed.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns :</th><td class="field-body">a callback object or <tt class="docutils literal"><span class="pre">null</span></tt></td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
</div>

View File

@ -91,15 +91,13 @@ that class.</p>
<dl class="describe">
<dt>
<tt class="descname">inputJax</tt></dt>
<dd><p>A reference to the input jax that created the element. (In the
future, this will be changed to the name of the input jax.)</p>
<dd><p>The name of the input jax that created the element.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">outputJax</tt></dt>
<dd><p>A reference to the output jax that has processed this element. (In
the future, this will be changed to the name of the output jax.)</p>
<dd><p>The name of the output jax that has processed this element.</p>
</dd></dl>
<dl class="describe">
@ -157,13 +155,36 @@ new one given by <cite>text</cite>). When the processing is complete, the
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">Rerender</tt><big>(</big><span class="optional">[</span><em>callback</em><span class="optional">]</span><big>)</big></dt>
<dd><p>Removes the output and produces it again (for example, if CSS has
changed that would alter the spacing of the mathematics). Note
that the internal representation isn&#8217;t regenerated; only the
output is. The <cite>callback</cite>, if any, is called when the process
completes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>callback</strong> &#8212; the callback specification</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">the callback object</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">Reprocess</tt><big>(</big><span class="optional">[</span><em>callback</em><span class="optional">]</span><big>)</big></dt>
<dd><p>Removes the output and produces it again. This may be necessary if
there are changes to the CSS styles that would affect the layout
of the mathematics, for example. The <cite>callback</cite>, if any, is
called when the process completes.</p>
<dd><p>Removes the output and then retranslates the input into the
internal form and reredners the output again. The <cite>callback</cite>, if
any, is called when the process completes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
@ -212,6 +233,22 @@ associated to this element jax.</p>
</table>
</dd></dl>
<dl class="method">
<dt id="needsUpdate">
<tt class="descname">needsUpdate</tt><big>(</big><big>)</big><a class="headerlink" href="#needsUpdate" title="Permalink to this definition"></a></dt>
<dd><p>Indicates whether the mathematics has changed so that its output
needs to be updated.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><tt class="docutils literal"><span class="pre">true</span></tt> if the mathematics needs to be reprocessed,
<tt class="docutils literal"><span class="pre">false</span></tt> otherwise</td>
</tr>
</tbody>
</table>
</dd></dl>
<p>Output jax may add new methods to the base element jax class to
perform exporting to other formats. For example, a MathML output jax
could add <tt class="docutils literal"><span class="pre">toMathML()</span></tt>, or an accessibility output jax could add

View File

@ -199,6 +199,27 @@ bugs.</p>
</table>
</dd></dl>
<dl class="method">
<dt id="getScript">
<tt class="descname">getScript</tt><big>(</big><em>script</em><big>)</big><a class="headerlink" href="#getScript" title="Permalink to this definition"></a></dt>
<dd><p>Gets the contents of the <tt class="docutils literal"><span class="pre">script</span></tt> element, properly taking into
account the browser limitations and bugs.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>script</strong> &#8212; the script whose content is to be retrieved</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">the text of the <tt class="docutils literal"><span class="pre">script</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">Cookie.Set(name,data)</tt></dt>

View File

@ -79,7 +79,19 @@ Options</em></a> reference page.</p>
<dt>
<tt class="descname">processUpdateTime: 250</tt></dt>
<dd><p>The minimum time (in milliseconds) between updates of the
&#8220;Processing Math&#8221; message.</p>
&#8220;Processing Math&#8221; 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.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">processUpdateDelay: 10</tt></dt>
<dd><p>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).</p>
</dd></dl>
<dl class="describe">
@ -117,6 +129,13 @@ running on a Macintosh computer or a Windows computer. They
will both be <tt class="docutils literal"><span class="pre">false</span></tt> for a Linux computer.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">isMobile</tt></dt>
<dd><p>This is <tt class="docutils literal"><span class="pre">true</span></tt> when MathJax is running a mobile version of a
WebKit or Gecko-based browser.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">isFirefox, isSafari, isChrome, isOpera, isMSIE, isKonqueror</tt></dt>
@ -161,6 +180,21 @@ need to do special processing. For example:</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">inputJax</tt></dt>
<dd><p>An object storing the MIME types associated with the various
registered input jax (these are the types of the <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tags
that store the math to be processed by each input jax).</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">outputJax</tt></dt>
<dd><p>An object storing the output jax associate with the various
element jax MIME types for the registered output jax.</p>
</dd></dl>
</div>
<div class="section" id="methods">
<h2>Methods<a class="headerlink" href="#methods" title="Permalink to this headline"></a></h2>
@ -434,13 +468,43 @@ references. The <cite>callback</cite> is called when the processing is complete
<dl class="method">
<dt id="Reprocess">
<tt class="descname">Reprocess</tt><big>(</big><span class="optional">[</span><em>element</em><span class="optional">[</span>, <em>callback</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#Reprocess" title="Permalink to this definition"></a></dt>
<dd><p>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. The <cite>element</cite> is either the DOM <cite>id</cite> of the
element to scan, a reference to the DOM element itself, or an array of
id&#8217;s or references. The <cite>callback</cite> is called when the processing is
<dd><p>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 <cite>element</cite> is either the DOM <cite>id</cite> of the element
to scan, a reference to the DOM element itself, or an array of
id&#8217;s or references. The <cite>callback</cite> is called when the processing
is complete.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>element</strong> &#8212; the element(s) to be reprocessed</li>
<li><strong>callback</strong> &#8212; the callback specification</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">the callback object</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="Rerender">
<tt class="descname">Rerender</tt><big>(</big><span class="optional">[</span><em>element</em><span class="optional">[</span>, <em>callback</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#Rerender" title="Permalink to this definition"></a></dt>
<dd><p>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
<cite>element</cite> is either the DOM <cite>id</cite> of the element to scan, a
reference to the DOM element itself, or an array of id&#8217;s or
references. The <cite>callback</cite> is called when the processing is
complete.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
@ -577,6 +641,33 @@ handled by MathJax, and returns <tt class="docutils literal"><span class="pre">1
</table>
</dd></dl>
<dl class="method">
<dt id="setRenderer">
<tt class="descname">setRenderer</tt><big>(</big><em>renderer</em><span class="optional">[</span>, <em>type</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#setRenderer" title="Permalink to this definition"></a></dt>
<dd><p>Sets the output jax for the given element jax <tt class="docutils literal"><span class="pre">type</span></tt> (or <tt class="docutils literal"><span class="pre">jax/mml</span></tt>
if none is specified) to be the one given by <tt class="docutils literal"><span class="pre">renderer</span></tt>, which
must be the name of a renderer, such as <tt class="docutils literal"><span class="pre">NativeMML</span></tt> or
<tt class="docutils literal"><span class="pre">HTML-CSS</span></tt>. 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:<tt class="docutils literal"><span class="pre">Rerender()</span></tt> above to replace the current
renderings by new ones).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>renderer</strong> &#8212; the name of the output jax to use for rendering</li>
<li><strong>type</strong> &#8212; the element jax MIME type whose renderer to set</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="Insert">
<tt class="descname">Insert</tt><big>(</big><em>dst</em>, <em>src</em><big>)</big><a class="headerlink" href="#Insert" title="Permalink to this definition"></a></dt>

View File

@ -107,11 +107,57 @@ that class.</p>
<h2>Methods<a class="headerlink" href="#methods" title="Permalink to this headline"></a></h2>
<dl class="method">
<dt>
<tt class="descname">Translate</tt><big>(</big><em>script</em><big>)</big></dt>
<tt class="descname">Process</tt><big>(</big><em>script</em>, <em>state</em><big>)</big></dt>
<dd><p>This is the method that the <tt class="docutils literal"><span class="pre">MathJax.Hub</span></tt> calls when it needs
the input jax to process the given math <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt>. Its default
action is to do the following:</p>
<ol class="arabic simple">
<li>Start loading any element jax specified in the <tt class="docutils literal"><span class="pre">elementJax</span></tt> array;</li>
<li>Start loading the jax&#8217;s <tt class="docutils literal"><span class="pre">jax.js</span></tt> file;</li>
<li>Start loading the required output jax (so it is ready when needed); and</li>
<li>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).</li>
</ol>
<p>Once the <tt class="docutils literal"><span class="pre">jax.js</span></tt> file has loaded, this method is replaced by
the jax&#8217;s <tt class="docutils literal"><span class="pre">Translate()</span></tt> method (see below), so that
subsequent calls to <tt class="docutils literal"><span class="pre">Process()</span></tt> will perform the appropriate
translation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><dl class="first docutils">
<dt><strong>script</strong> &#8212; reference to the DOM <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> object for</dt>
<dd><p class="first last">the mathematics to be translated</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><strong>state</strong> &#8212; a structure containing information about the</dt>
<dd><p class="first last">current proccessing state of the mathematics
(internal use)</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">an <cite>ElementJax</cite> object, or <tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">Translate</tt><big>(</big><em>script</em>, <em>state</em><big>)</big></dt>
<dd><p>This is the main routine called by MathJax when a <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> of the
appropriate type is found. The default <a class="reference internal" href="jax.html#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> method
throws an error indicating that <a class="reference internal" href="jax.html#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> hasn&#8217;t been
redefined, so when the <tt class="docutils literal"><span class="pre">jax.js</span></tt> file loads, it should override the
defined, so when the <tt class="docutils literal"><span class="pre">jax.js</span></tt> file loads, it should override the
default <a class="reference internal" href="jax.html#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> with its own version that does the actual
translation.</p>
<p>The translation process should include the creation of an
@ -121,8 +167,16 @@ for this element.</p>
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>script</strong> &#8212; the <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> element to be translated</li>
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><p class="first"><strong>script</strong> &#8212; the <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> element to be translated</p>
</li>
<li><dl class="first docutils">
<dt><strong>state</strong> &#8212; a structure containing information about the</dt>
<dd><p class="first last">current proccessing state of the mathematics
(internal use)</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
@ -157,6 +211,28 @@ of the various types from one another.</p>
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">needsUpdate</tt><big>(</big><em>jax</em><big>)</big></dt>
<dd><p>This implements the element jax&#8217;s <tt class="docutils literal"><span class="pre">needsUpdate()</span></tt> method, and
returns <tt class="docutils literal"><span class="pre">true</span></tt> if the <tt class="docutils literal"><span class="pre">jax</span></tt> needs to be rerendered (i.e., the
text has changed), and <tt class="docutils literal"><span class="pre">false</span></tt> otherwise.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Perameters :</th><td class="field-body"><ul class="first simple">
<li><strong>jax</strong> &#8212; the element jax to be checked</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">true</span></tt> if the jax&#8217;s text has changed, <tt class="docutils literal"><span class="pre">false</span></tt> otherwise</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
</div>

View File

@ -119,41 +119,15 @@ jax. These can be modified by the author by including a
configuration subsection for the specific jax in question.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">JAXFILE: &quot;jax.js&quot;</tt></dt>
<dd><p>The name of the file that contains the main code for the jax.</p>
</dd></dl>
</div>
<div class="section" id="methods">
<h2>Methods<a class="headerlink" href="#methods" title="Permalink to this headline"></a></h2>
<dl class="method">
<dt>
<tt class="descname">Process</tt><big>(</big><em>script</em><big>)</big></dt>
<dd><p>This is the method that the <tt class="docutils literal"><span class="pre">MathJax.Hub</span></tt> calls when it needs the
input or output jax to process the given math <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt>. Its
default action is to start loading the jax&#8217;s <tt class="docutils literal"><span class="pre">jax.js</span></tt> file, and
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 <tt class="docutils literal"><span class="pre">jax.js</span></tt> file has loaded, this method is
replaced by the jax&#8217;s <a class="reference internal" href="#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> method, so that subsequent calls
to <a class="reference internal" href="hub.html#Process" title="Process"><tt class="xref py py-meth docutils literal"><span class="pre">Process()</span></tt></a> will perform the appropriate translation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><dl class="first docutils">
<dt><strong>script</strong> &#8212; reference to the DOM <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> object for</dt>
<dd><p class="first last">the mathematics to be translated</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">an <cite>ElementJax</cite> object, or <tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="Translate">
<tt class="descname">Translate</tt><big>(</big><em>script</em><big>)</big><a class="headerlink" href="#Translate" title="Permalink to this definition"></a></dt>
@ -161,7 +135,7 @@ to <a class="reference internal" href="hub.html#Process" title="Process"><tt cla
<tt class="docutils literal"><span class="pre">jax.js</span></tt> file when it is loaded. It should perform the translation
action for the specific jax. For an input jax, it should return the
<cite>ElementJax</cite> object that it created. The <a class="reference internal" href="#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> method is
never called directly by MathJax; during the <a class="reference internal" href="ajax.html#loadComplete" title="loadComplete"><tt class="xref py py-meth docutils literal"><span class="pre">loadComplete()</span></tt></a>
never called directly by MathJax; during the <tt class="docutils literal"><span class="pre">loadComplete()</span></tt>
call, this function is copied to the <a class="reference internal" href="hub.html#Process" title="Process"><tt class="xref py py-meth docutils literal"><span class="pre">Process()</span></tt></a> method, and is
called via that name. The default <a class="reference internal" href="#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> method throws an
error indicating that the <a class="reference internal" href="#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> method was not
@ -249,6 +223,9 @@ following:</p>
<li>Post the &#8220;[name] Jax Startup&#8221; message to the startup signal.</li>
<li>Perform the jax&#8217;s <a class="reference internal" href="#Startup" title="Startup"><tt class="xref py py-meth docutils literal"><span class="pre">Startup()</span></tt></a> method.</li>
<li>Post the &#8220;[name] Jax Ready&#8221; message to the startup signal.</li>
<li>Copy the <tt class="docutils literal"><span class="pre">preTranslate</span></tt>, <tt class="docutils literal"><span class="pre">Translate</span></tt>, and
<tt class="docutils literal"><span class="pre">postTranslate</span></tt> functions to <tt class="docutils literal"><span class="pre">preProcess</span></tt>, <tt class="docutils literal"><span class="pre">Process</span></tt>,
and <tt class="docutils literal"><span class="pre">postProcess</span></tt>.</li>
<li>Perform the <tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Ajax.loadComplete()</span></tt> call for the
<tt class="docutils literal"><span class="pre">jax.js</span></tt> file.</li>
</ol>

View File

@ -96,29 +96,121 @@ that class.</p>
<dd><p>The directory where the jax files are stored (e.g., <tt class="docutils literal"><span class="pre">&quot;[MathJax]/jax/output/HTML-CSS&quot;</span></tt>);</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">fontDir</tt></dt>
<dd><p>The directory where the fonts are stored (e.g., <tt class="docutils literal"><span class="pre">&quot;[MathJax]/fonts&quot;</span></tt>)</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">imageDir</tt></dt>
<dd><p>The directory where MathJax images are found (e.g. <tt class="docutils literal"><span class="pre">&quot;[MathJax]/images&quot;</span></tt>)</p>
</dd></dl>
</div>
<div class="section" id="methods">
<h2>Methods<a class="headerlink" href="#methods" title="Permalink to this headline"></a></h2>
<dl class="method">
<dt id="preProcess">
<tt class="descname">preProcess</tt><big>(</big><em>state</em><big>)</big><a class="headerlink" href="#preProcess" title="Permalink to this definition"></a></dt>
<dd><p>This is called by <tt class="docutils literal"><span class="pre">MathJax.Hub</span></tt> to ask the output processor to
prepare to process math scripts. Its default action is to start
loading the jax&#8217;s <tt class="docutils literal"><span class="pre">jax.js</span></tt> file, and 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).</p>
<p>Once the <tt class="docutils literal"><span class="pre">jax.js</span></tt> file has loaded, this method is replaced by
the jax&#8217;s <a class="reference internal" href="#preTranslate" title="preTranslate"><tt class="xref py py-meth docutils literal"><span class="pre">preTranslate()</span></tt></a> method, so that subsequent calls
to <a class="reference internal" href="#preProcess" title="preProcess"><tt class="xref py py-meth docutils literal"><span class="pre">preProcess()</span></tt></a> will perform the appropriate translation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><dl class="first docutils">
<dt><strong>state</strong> &#8212; a structure containing information about the</dt>
<dd><p class="first last">current proccessing state of the mathematics</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="preTranslate">
<tt class="descname">preTranslate</tt><big>(</big><em>state</em><big>)</big><a class="headerlink" href="#preTranslate" title="Permalink to this definition"></a></dt>
<dd><p>This routine replaces <a class="reference internal" href="#preProcess" title="preProcess"><tt class="xref py py-meth docutils literal"><span class="pre">preProcess()</span></tt></a> above when the jax&#8217;s
<tt class="docutils literal"><span class="pre">jax.js</span></tt> file is loaded. It is called by <tt class="docutils literal"><span class="pre">MathJax.Hub</span></tt> to ask
the output processor to prepare to process math scripts. (For
example, the HTML-CSS output jax uses this to determine em-sizes
for all the mathematics at once, to minimize page reflows that
slow down Internet Explorer.)</p>
<p>The routine can use <tt class="docutils literal"><span class="pre">state.jax[this.id]</span></tt> to obtain the array of
element jax that are to be processed. The output jax can use the
<tt class="docutils literal"><span class="pre">state</span></tt> variable to maintain its own state information, but
any properties that it adds to the variable should have a prefix
that is the output jax&#8217;s ID. For example, the HTML-CSS output jax
might use <tt class="docutils literal"><span class="pre">state.HTMLCSSlast</span></tt> to keep track of the last equation
it processed, or could add <tt class="docutils literal"><span class="pre">state.HTMLCSS</span> <span class="pre">=</span> <span class="pre">{...}</span></tt> to create an
object of its own within the state variable.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><dl class="first docutils">
<dt><strong>state</strong> &#8212; a structure containing information about the</dt>
<dd><p class="first last">current proccessing state of the mathematics</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">Translate</tt><big>(</big><em>script</em><big>)</big></dt>
<tt class="descname">Translate</tt><big>(</big><em>script</em>, <em>state</em><big>)</big></dt>
<dd><p>This is the main routine called by MathJax when an element jax is
to be converted to output. The default <a class="reference internal" href="jax.html#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a>
method throws an error indicating that <a class="reference internal" href="jax.html#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> hasn&#8217;t been
redefined, so when the <tt class="docutils literal"><span class="pre">jax.js</span></tt> file loads, it should override the
defined, so when the <tt class="docutils literal"><span class="pre">jax.js</span></tt> file loads, it should override the
default <a class="reference internal" href="jax.html#Translate" title="Translate"><tt class="xref py py-meth docutils literal"><span class="pre">Translate()</span></tt></a> with its own version that does the actual
translation.</p>
<p>You should use <tt class="docutils literal"><span class="pre">MathJax.Hub.getJaxFor(script)</span></tt> to obtain the
element jax for the given script. The translation process may
modify the element jax (e.g., if it has data that needs to be
stored with the jax), and may insert DOM elements into the
document near the jax&#8217;s <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tag.</p>
document near the jax&#8217;s <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tag. The output jax can use
the <tt class="docutils literal"><span class="pre">state</span></tt> variable to maintain information about its
processing state, but see <a class="reference internal" href="#preTranslate" title="preTranslate"><tt class="xref py py-meth docutils literal"><span class="pre">preTranslate()</span></tt></a> above for naming
conventions for properties that are added.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>script</strong> &#8212; the <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> element to be translated</li>
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><p class="first"><strong>script</strong> &#8212; the <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> element to be translated</p>
</li>
<li><dl class="first docutils">
<dt><strong>state</strong> &#8212; a structure containing information about the</dt>
<dd><p class="first last">current proccessing state of the mathematics</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
@ -129,6 +221,39 @@ document near the jax&#8217;s <tt class="docutils literal"><span class="pre">&lt
</table>
</dd></dl>
<dl class="method">
<dt id="postTranslate">
<tt class="descname">postTranslate</tt><big>(</big><em>state</em><big>)</big><a class="headerlink" href="#postTranslate" title="Permalink to this definition"></a></dt>
<dd><p>This routines is called by <tt class="docutils literal"><span class="pre">MathJax.Hub</span></tt> when the translation
of math elements is complete, and can be used by the output
processor to finalize any actions that it needs to complete.
(For example, making the mathematics visible, or forcing a reflow
of the page.)</p>
<p>The routine can use <tt class="docutils literal"><span class="pre">state.jax[this.id]</span></tt> to obtain the array of
element jax that were processed, or can use the <tt class="docutils literal"><span class="pre">state</span></tt> variable
to store its own state information (see <a class="reference internal" href="#preProcess" title="preProcess"><tt class="xref py py-meth docutils literal"><span class="pre">preProcess()</span></tt></a>
above for caveats about naming properties).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><dl class="first docutils">
<dt><strong>state</strong> &#8212; a structure containing information about the</dt>
<dd><p class="first last">current proccessing state of the mathematics</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">null</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">Register</tt><big>(</big><em>mimetype</em><big>)</big></dt>
@ -175,6 +300,88 @@ tag associated with the element jax.</p>
</table>
</dd></dl>
<p>If an output jax wants its output to handle the contextual menu item
and zooming, then it needs to tie into the event-handling code
(<cite>MathEvents</cite>) and the zoom-handling code (<cite>MathZoom</cite>). That requires
the following methods.</p>
<dl class="method">
<dt id="getJaxFromMath">
<tt class="descname">getJaxFromMath</tt><big>(</big><em>math</em><big>)</big><a class="headerlink" href="#getJaxFromMath" title="Permalink to this definition"></a></dt>
<dd><p>This is called by the event-handling code (<cite>MathEvents</cite>) to get
the element jax associated with the DOM element that caused an
event to occur. The output jax will have attached event handlers
to some DOM element that is part of its output, and the
<cite>MathEvents</cite> code uses this routine to map back to the jax
associated with that output.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first">
<li><dl class="first docutils">
<dt><strong>math</strong> &#8212; a DOM element that triggered a DOM event</dt>
<dd><p class="first last">(e.g., a mouse click)</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">the <cite>ElementJax</cite> structure associated with the DOM element</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="Zoom">
<tt class="descname">Zoom</tt><big>(</big><em>jax</em>, <em>span</em>, <em>math</em>, <em>Mw</em>, <em>Mh</em><big>)</big><a class="headerlink" href="#Zoom" title="Permalink to this definition"></a></dt>
<dd><p>This routine is called by the zoom-handling code (<cite>MathZoom</cite>)
when an expression has received its zoom trigger event (e.g., a
double-click). The <tt class="docutils literal"><span class="pre">jax</span></tt> is the math that needs to be zoomed,
<tt class="docutils literal"><span class="pre">span</span></tt> is a <tt class="docutils literal"><span class="pre">&lt;span&gt;</span></tt> element in which the zoomed version of
the math should be placed, <tt class="docutils literal"><span class="pre">math</span></tt> is the DOM element that
received the zoom trigger event, and <tt class="docutils literal"><span class="pre">Mw</span></tt> and <tt class="docutils literal"><span class="pre">Mh</span></tt> are the
maximum width and height allowed for the zoom box (the <tt class="docutils literal"><span class="pre">span</span></tt>).</p>
<p>The return value is an object with the following properties:</p>
<ul>
<li><dl class="first docutils">
<dt><tt class="docutils literal"><span class="pre">Y</span></tt> &#8212; the vertical offset from the top of the <tt class="docutils literal"><span class="pre">span</span></tt> to</dt>
<dd><p class="first last">the baseline of the mathematics</p>
</dd>
</dl>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">mW</span></tt> &#8212; the width of the original mathematics element</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">mH</span></tt> &#8212; the height of the original mathematics element</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">zW</span></tt> &#8212; the width of the zoomed math</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">zH</span></tt> &#8212; the height of the zoomed math</p>
</li>
</ul>
<p>All of these values are in pixels.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><ul class="first simple">
<li><strong>jax</strong> &#8212; the jax to be zoomed</li>
<li><strong>span</strong> &#8212; the <tt class="docutils literal"><span class="pre">&lt;span&gt;</span></tt> in which to place the zoomed math</li>
<li><strong>math</strong> &#8212; the DOM element generating the zoom event</li>
<li><strong>Mw</strong> &#8212; the maximum width of the zoom box</li>
<li><strong>Mh</strong> &#8212; the maximum height of the zoom box</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">a structure as described above</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
</div>

View File

@ -70,7 +70,7 @@ code, the onload handler, the browser data, and so forth.</p>
<dt>
<tt class="descname">MathJax.Ajax</tt></dt>
<dd><p>Contains the code for loading external modules and creating
stylesheets. Most of the code that causes most of MathJax to
stylesheets. Most of the code that causes MathJax to
operate asynchronously is handled here.</p>
</dd></dl>
@ -103,6 +103,13 @@ For example, the <cite>tex2jax</cite> preprocessor creates
<tt class="docutils literal"><span class="pre">MathJax.Extension.tex2jax</span></tt> for its code and variables.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">MathJax.Menu</tt></dt>
<dd><p>Initially null, this is where the MathJax contextual menu is
stored, when <tt class="docutils literal"><span class="pre">extensions/MathMenu.js</span></tt> is loaded.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">MathJax.Object</tt></dt>
@ -142,7 +149,13 @@ itself as <tt class="docutils literal"><span class="pre">MathJax.ElementJax.mml<
<dl class="describe">
<dt>
<tt class="descname">MathJax.version</tt></dt>
<dd><p>The version number of the MathJax library.</p>
<dd><p>The version number of the MathJax library as a whole.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">MathJax.fileversion</tt></dt>
<dd><p>The version number of the <tt class="docutils literal"><span class="pre">MathJax.js</span></tt> file specifically.</p>
</dd></dl>
<dl class="describe">

View File

@ -223,10 +223,10 @@ you simply passed the object&#8217;s method to <tt class="docutils literal"><spa
might want to pass an argument to the function called by
<tt class="docutils literal"><span class="pre">setTimeout()</span></tt>. (Altough the <tt class="docutils literal"><span class="pre">setTimeout()</span></tt> function can accept
additional arguements that are supposed to be passed on to the code
when it is called, Internet Explorer does not implement that feature,
so you can&#8217;t rely on it.) You can use a <cite>Callback</cite> object to
do this, and the <tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Callback()</span></tt> method will create one for
you. For example,</p>
when it is called, some versions of Internet Explorer do not implement
that feature, so you can&#8217;t rely on it.) You can use a <cite>Callback</cite>
object to do this, and the <tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Callback()</span></tt> method will
create one for you. For example,</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="kd">function</span> <span class="nx">f</span><span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="p">{</span><span class="nx">alert</span><span class="p">(</span><span class="s2">&quot;x = &quot;</span><span class="o">+</span><span class="nx">x</span><span class="p">)}</span>
<span class="nx">setTimeout</span><span class="p">(</span><span class="nx">MathJax</span><span class="p">.</span><span class="nx">Callback</span><span class="p">([</span><span class="nx">f</span><span class="p">,</span><span class="s2">&quot;Hello World!&quot;</span><span class="p">]),</span><span class="mi">500</span><span class="p">);</span>
</pre></div>

View File

@ -53,59 +53,49 @@
<span id="ajax-mathjax"></span><h1>Loading MathJax Dynamically<a class="headerlink" href="#loading-mathjax-dynamically" title="Permalink to this headline"></a></h1>
<p>MathJax is designed to be included via a <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tag in the
<tt class="docutils literal"><span class="pre">&lt;head&gt;</span></tt> section of your HTML document, and it does rely on being
part of the original document in that it uses an <tt class="docutils literal"><span class="pre">onload</span></tt> event
handler to synchronize its actions with the loading of the page.
If you wish to insert MathJax into a document after it has
been loaded, that will normally occur <em>after</em> the page&#8217;s <tt class="docutils literal"><span class="pre">onload</span></tt>
handler has fired, and so MathJax will not be able to tell if it is
safe for it to process the contents of the page. Indeed, it will wait
forever for its <tt class="docutils literal"><span class="pre">onload</span></tt> handler to fire, and so will never process
the page.</p>
<p>To solve this problem, you will need to call MathJax&#8217;s <tt class="docutils literal"><span class="pre">onload</span></tt>
handler yourself, to let it know that it is OK to typeset the
mathematics on the page. You accomplish this by calling the
<tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Hub.Startup.onload()</span></tt> method as part of your MathJax
startup script. To do this, you will need to give MathJax an in-line
configuration.</p>
part of the original document in that it uses an <tt class="docutils literal"><span class="pre">onload</span></tt> or
<tt class="docutils literal"><span class="pre">DOMContentLoaded</span></tt> event handler to synchronize its actions with the
loading of the page. If you wish to insert MathJax into a document
after it has been loaded, that will normally occur <em>after</em> the page&#8217;s
<tt class="docutils literal"><span class="pre">onload</span></tt> handler has fired, and prior to version 2.0, MathJax had to
be told not to wait for the page <tt class="docutils literal"><span class="pre">onload</span></tt> event by calling
<tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Hub.Startup.onload()</span></tt> by hand. That is no longer
necessary, as MathJax v2.0 detects whether the page is already
available and when it is, it processes it immediately rather than
waiting for an event that has already happened.</p>
<p>Here is an example of how to load and configure MathJax dynamically:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">script</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;script&quot;</span><span class="p">);</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s2">&quot;text/javascript&quot;</span><span class="p">;</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js&quot;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="s1">&#39;MathJax.Hub.Config({&#39;</span> <span class="o">+</span>
<span class="s1">&#39;extensions: [&quot;tex2jax.js&quot;],&#39;</span> <span class="o">+</span>
<span class="s1">&#39;jax: [&quot;input/TeX&quot;,&quot;output/HTML-CSS&quot;]&#39;</span> <span class="o">+</span>
<span class="s1">&#39;});&#39;</span> <span class="o">+</span>
<span class="s1">&#39;MathJax.Hub.Startup.onload();&#39;</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">opera</span><span class="p">)</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span>
<span class="k">else</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">text</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&quot;head&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">script</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div>
<p>You can adjust the <tt class="docutils literal"><span class="pre">config</span></tt> variable to your needs, but be careful to get
the commas right. The <tt class="docutils literal"><span class="pre">window.opera</span></tt> test is because some versions of
Opera don&#8217;t handle setting <tt class="docutils literal"><span class="pre">script.text</span></tt> properly, while Internet
Explorer doesn&#8217;t handle setting the <tt class="docutils literal"><span class="pre">innerHTML</span></tt> of a script tag.</p>
<p>Here is a version that uses the <tt class="docutils literal"><span class="pre">config=filename</span></tt> method to
configure MathJax:</p>
<p>If you need to provide in-line configuration, you can do that using a
MathJax&#8217;s configuration script:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">script</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;script&quot;</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">head</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&quot;head&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">script</span><span class="p">;</span>
<span class="nx">script</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;script&quot;</span><span class="p">);</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s2">&quot;text/x-mathjax-config&quot;</span><span class="p">;</span>
<span class="nx">script</span><span class="p">[(</span><span class="nb">window</span><span class="p">.</span><span class="nx">opera</span> <span class="o">?</span> <span class="s2">&quot;innerHTML&quot;</span> <span class="o">:</span> <span class="s2">&quot;text&quot;</span><span class="p">)]</span> <span class="o">=</span>
<span class="s2">&quot;MathJax.Hub.Config({\n&quot;</span> <span class="o">+</span>
<span class="s2">&quot; tex2jax: { inlineMath: [[&#39;$&#39;,&#39;$&#39;], [&#39;\\\\(&#39;,&#39;\\\\)&#39;]] }\n&quot;</span> <span class="o">+</span>
<span class="s2">&quot;});&quot;</span>
<span class="nx">head</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">script</span><span class="p">);</span>
<span class="nx">script</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;script&quot;</span><span class="p">);</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s2">&quot;text/javascript&quot;</span><span class="p">;</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full&quot;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="s1">&#39;MathJax.Hub.Startup.onload();&#39;</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">opera</span><span class="p">)</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span>
<span class="k">else</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">text</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&quot;head&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">script</span><span class="p">);</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;</span><span class="p">;</span>
<span class="nx">head</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">script</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div>
<p>You can adjust the configuration to your needs, but be careful to get
the commas right, as Internet Explorer 6 and 7 will not tolerate an
extra comma before a closing brace. The <tt class="docutils literal"><span class="pre">window.opera</span></tt> test is
because some versions of Opera don&#8217;t handle setting <tt class="docutils literal"><span class="pre">script.text</span></tt>
properly, while some versions of Internet Explorer don&#8217;t handle
setting <tt class="docutils literal"><span class="pre">script.innerHTML</span></tt>.</p>
<p>Note that the <strong>only</strong> reliable way to configure MathJax is to use an
in-line configuration block of the type discussed above. You should
<strong>not</strong> call <tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Hub.Config()</span></tt> directly in your code, as it will
@ -148,9 +138,8 @@ IE+MathPlayer.</p>
<span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagNameNS</span> <span class="o">==</span> <span class="kc">null</span> <span class="o">?</span> <span class="kc">false</span> <span class="o">:</span>
<span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagNameNS</span><span class="p">(</span><span class="s2">&quot;http://www.w3.org/1998/Math/MathML&quot;</span><span class="p">,</span><span class="s2">&quot;math&quot;</span><span class="p">).</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)))</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">script</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;script&quot;</span><span class="p">);</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s2">&quot;text/javascript&quot;</span><span class="p">;</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full&quot;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="s1">&#39;MathJax.Hub.Startup.onload()&#39;</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">opera</span><span class="p">)</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span> <span class="k">else</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">text</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&quot;head&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">script</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
@ -185,9 +174,8 @@ converting the math images to their original TeX code.</p>
<span class="c1">// Load MathJax and have it process the page</span>
<span class="c1">//</span>
<span class="kd">var</span> <span class="nx">script</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;script&quot;</span><span class="p">);</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s2">&quot;text/javascript&quot;</span><span class="p">;</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full&quot;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="s1">&#39;MathJax.Hub.Startup.onload()&#39;</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">opera</span><span class="p">)</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span> <span class="k">else</span> <span class="p">{</span><span class="nx">script</span><span class="p">.</span><span class="nx">text</span> <span class="o">=</span> <span class="nx">config</span><span class="p">}</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&quot;head&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">script</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>

View File

@ -45,11 +45,12 @@
<h1 id="index">Index</h1>
<div class="genindex-jumpbox">
<a href="#A"><strong>A</strong></a> | <a href="#C"><strong>C</strong></a> | <a href="#D"><strong>D</strong></a> | <a href="#E"><strong>E</strong></a> | <a href="#F"><strong>F</strong></a> | <a href="#G"><strong>G</strong></a> | <a href="#H"><strong>H</strong></a> | <a href="#I"><strong>I</strong></a> | <a href="#J"><strong>J</strong></a> | <a href="#L"><strong>L</strong></a> | <a href="#M"><strong>M</strong></a> | <a href="#N"><strong>N</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#Q"><strong>Q</strong></a> | <a href="#R"><strong>R</strong></a> | <a href="#S"><strong>S</strong></a> | <a href="#T"><strong>T</strong></a> | <a href="#U"><strong>U</strong></a> | <a href="#W"><strong>W</strong></a>
<a href="#A"><strong>A</strong></a> | <a href="#C"><strong>C</strong></a> | <a href="#D"><strong>D</strong></a> | <a href="#E"><strong>E</strong></a> | <a href="#F"><strong>F</strong></a> | <a href="#G"><strong>G</strong></a> | <a href="#H"><strong>H</strong></a> | <a href="#I"><strong>I</strong></a> | <a href="#J"><strong>J</strong></a> | <a href="#L"><strong>L</strong></a> | <a href="#M"><strong>M</strong></a> | <a href="#N"><strong>N</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#Q"><strong>Q</strong></a> | <a href="#R"><strong>R</strong></a> | <a href="#S"><strong>S</strong></a> | <a href="#T"><strong>T</strong></a> | <a href="#U"><strong>U</strong></a> | <a href="#W"><strong>W</strong></a> | <a href="#Z"><strong>Z</strong></a>
</div>
<h2 id="A">A</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/callback.html#Add">Add()</a></dt>
<dt><a href="api/html.html#addElement">addElement()</a></dt>
<dt><a href="api/html.html#addText">addText()</a></dt>
</dl></td>
@ -85,9 +86,10 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/html.html#Element">Element()</a></dt>
<dt><a href="api/signal.html#ExecuteHook">ExecuteHook()</a></dt>
<dt><a href="api/callback.html#Execute">Execute()</a></dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/signal.html#ExecuteHook">ExecuteHook()</a></dt>
<dt><a href="api/callback.html#ExecuteHooks">ExecuteHooks()</a></dt>
</dl></td>
</tr></table>
@ -109,10 +111,12 @@
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/hub.html#getAllJax">getAllJax()</a></dt>
<dt><a href="api/hub.html#getJaxByInputType">getJaxByInputType()</a></dt>
<dt><a href="api/hub.html#getJaxByType">getJaxByType()</a></dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/hub.html#getJaxByType">getJaxByType()</a></dt>
<dt><a href="api/hub.html#getJaxFor">getJaxFor()</a></dt>
<dt><a href="api/outputjax.html#getJaxFromMath">getJaxFromMath()</a></dt>
<dt><a href="api/html.html#getScript">getScript()</a></dt>
</dl></td>
</tr></table>
@ -120,6 +124,7 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/object.html#has">has()</a></dt>
<dt><a href="api/callback.html#Hooks">Hooks()</a></dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="glossary.html#term-html-css">HTML-CSS</a></dt>
@ -174,6 +179,9 @@
<h2 id="N">N</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/elementjax.html#needsUpdate">needsUpdate()</a></dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/signal.html#NoInterest">NoInterest()</a></dt>
</dl></td>
@ -183,10 +191,13 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/signal.html#Post">Post()</a></dt>
<dt><a href="api/outputjax.html#postTranslate">postTranslate()</a></dt>
<dt><a href="api/ajax.html#Preloading">Preloading()</a></dt>
<dt><a href="api/hub.html#PreProcess">PreProcess()</a></dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/outputjax.html#preProcess">preProcess()</a></dt>
<dt><a href="api/outputjax.html#preTranslate">preTranslate()</a></dt>
<dt><a href="api/hub.html#Process">Process()</a></dt>
<dt><a href="api/queue.html#Push">Push()</a></dt>
</dl></td>
@ -205,9 +216,10 @@
<dt><a href="api/jax.html#Register">Register()</a></dt>
<dt><a href="api/message.html#Remove">Remove()</a></dt>
<dt><a href="api/hub.html#Reprocess">Reprocess()</a></dt>
<dt><a href="api/ajax.html#Require">Require()</a></dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/ajax.html#Require">Require()</a></dt>
<dt><a href="api/hub.html#Rerender">Rerender()</a></dt>
<dt><a href="api/callback.html#reset">reset()</a></dt>
<dt><a href="api/queue.html#Resume">Resume()</a></dt>
</dl></td>
@ -217,6 +229,7 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/message.html#Set">Set()</a></dt>
<dt><a href="api/hub.html#setRenderer">setRenderer()</a></dt>
<dt><a href="api/html.html#setScript">setScript()</a></dt>
<dt><a href="api/callback.html#Signal">Signal()</a></dt>
<dt><a href="api/elementjax.html#SourceElement">SourceElement()</a></dt>
@ -258,6 +271,13 @@
</dl></td>
</tr></table>
<h2 id="Z">Z</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="api/outputjax.html#Zoom">Zoom()</a></dt>
</dl></td>
</tr></table>
</div>

View File

@ -122,7 +122,7 @@ MathML, and AsciiMath notaion that works in all modern browsers.</p>
</li>
</ul>
<hr class="docutils" />
<p>This version of the documentation was built February 15, 2012.</p>
<p>This version of the documentation was built February 20, 2012.</p>
</div>
</div>

View File

@ -54,7 +54,7 @@
<p>The purpose of MathJax is to bring the ability to include mathematics
easily in web pages to as wide a range of browsers as possible.
Authors can specify mathematics in a variety of formats (e.g.,
<a class="reference internal" href="glossary.html#term-mathml"><em class="xref std std-term">MathML</em></a> or <a class="reference internal" href="glossary.html#term-latex"><em class="xref std std-term">LaTeX</em></a>), and MathJax provides high-quality
<a class="reference internal" href="glossary.html#term-mathml"><em class="xref std std-term">MathML</em></a>, <a class="reference internal" href="glossary.html#term-latex"><em class="xref std std-term">LaTeX</em></a>, or <a class="reference internal" href="glossary.html#term-asciimath"><em class="xref std std-term">AsciiMath</em></a>), and MathJax provides high-quality
mathematical typesetting even in those browsers that do not have
native MathML support. This all happens without the need for special
downloads or plugins, but rendering will be enhanced if high-quality
@ -81,17 +81,19 @@ document is to be typeset as mathematics. In this case, MathJax can
run a preprocessor to locate the math delimiters and replace them by
the special tags that it uses to mark the formulas. There are
preprocessors for <a class="reference internal" href="tex.html#tex-support"><em>TeX notation</em></a>, <a class="reference internal" href="mathml.html#mathml-support"><em>MathML
notation</em></a>, and the <a class="reference internal" href="jsMath.html#jsmath-support"><em>jsMath notation</em></a> that uses <cite>span</cite> and <cite>div</cite> tags.</p>
notation</em></a>, <a class="reference internal" href="asciimath.html#asciimath-support"><em>AsciiMath notation</em></a> and the <a class="reference internal" href="jsMath.html#jsmath-support"><em>jsMath notation</em></a> that uses <cite>span</cite> and <cite>div</cite> tags.</p>
<p>For pages that are constructed programmatically, such as HTML
pages that result from running a processor on text in some other
format (e.g., pages produced from Markdown documents, or via programs
like <cite>tex4ht</cite>), it would be best to use MathJax&#8217;s special tags
directly, as described below, rather than having MathJax run
another preprocessor. This will speed up the final display of the
mathematics, since the extra preprocessing step would not be needed,
and it also avoids the conflict between the use of the less-than sign,
mathematics, since the extra preprocessing step would not be needed.
It also avoids the conflict between the use of the less-than sign,
<tt class="docutils literal"><span class="pre">&lt;</span></tt>, in mathematics and as an HTML special character (that starts
an HTML tag).</p>
an HTML tag), and several other issues involved in having the
mathematics directly in the text of the page (see the documentation on
the various input jax for more details on this).</p>
<div class="section" id="how-mathematics-is-stored-in-the-page">
<span id="mathjax-script-tags"></span><h2>How mathematics is stored in the page<a class="headerlink" href="#how-mathematics-is-stored-in-the-page" title="Permalink to this headline"></a></h2>
<p>In order to identify mathematics in the page, MathJax uses special
@ -107,8 +109,9 @@ kind of script that the tag contains. The usual (and default) value
is <tt class="docutils literal"><span class="pre">type=&quot;text/javascript&quot;</span></tt>, and when a script has this type, the
browser executes the script as a javascript program. MathJax,
however, uses the type <cite>math/tex</cite> to identify mathematics in the TeX
and LaTeX notation, and <cite>math/mml</cite> for mathematics in MathML
notation. When the <cite>tex2jax</cite> or <cite>mml2jax</cite> preprocessors run, they
and LaTeX notation, <cite>math/mml</cite> for mathematics in MathML notation, and
<cite>math/asciimath</cite> for mathematics in AsciiMath notation. When the
<cite>tex2jax</cite>, <cite>mml2jax</cite>, or <cite>asciimath2jax</cite> preprocessors run, they
create <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tags with these types so that MathJax can process
them when it runs its main typesetting pass.</p>
<p>For example,</p>
@ -214,16 +217,24 @@ specific output format. For example, the NativeMML output jax inserts
MathML tags into the page to represent the mathematics, while the
HTML-CSS output jax uses HTML with CSS styling to lay out the
mathematics so that it can be displayed even in browsers that don&#8217;t
understand MathML. Output jax could be produced that render the
mathematics using SVG, for example, or that speak an equation for
blind users. The MathJax contextual menu can be used to switch
between the output jax that are available.</p>
understand MathML. MathJax also has an <a class="reference internal" href="glossary.html#term-svg"><em class="xref std std-term">SVG</em></a> output jax that
will render the mathematics using scalable vector grtaphics. Output
jax could be produced that render the mathematics using HTML5 canvas
elements, for example, or that speak an equation for blind users. The
MathJax contextual menu can be used to switch between the output jax
that are available.</p>
<p>Each input and output jax has a small configuration file that is
loaded when that input jax is included in the <cite>jax</cite> array in the
MathJax configuration, and a larger file that implements the core
functionality of that particular jax. The latter file is loaded
the first time the jax is needed by MathJax to process some
mathematics.</p>
functionality of that particular jax. The latter file is loaded the
first time the jax is needed by MathJax to process some mathematics.
Most of the combined configuration files include only the small
configuration portion for the input and output jax, making the
configuraiton file smaller and faster to load for those pages that
don&#8217;t actually incldue mathematics; the combined configurations that
end in <tt class="docutils literal"><span class="pre">-full</span></tt> include both parts of the jax, so there is no delay
when the math is to be rendered, but at the expense of a larger
initial download.</p>
<p>The <strong>MathJax Hub</strong> keeps track of the internal representations of the
various mathematical equations on the page, and can be queried to
obtain information about those equations. For example, one can obtain

File diff suppressed because one or more lines are too long

View File

@ -99,14 +99,14 @@ it starts listening after they were sent.</p>
various extensions. The extension may not be loaded when the user&#8217;s
configuration code runs, so the configuration code can&#8217;t modify the
extension because it isn&#8217;t there yet. Fortunately, most extensions
signal when they are loaded and initialized via an <tt class="docutils literal"><span class="pre">Extension</span> <span class="pre">[name]</span> <span class="pre">Ready</span></tt> message,
so the configuration code can implement a listener for that message, and
have the listener perform the configuration when the message arrives.
But even if the extension <em>has</em> already been loaded, this will still
work, because the listener will receive the ready signal even if it
has already been posted. In this way, listening for signals is a
robust method of synchronizing code components no matter when they are
loaded and run.</p>
signal when they are loaded and initialized via an <tt class="docutils literal"><span class="pre">Extension</span> <span class="pre">[name]</span>
<span class="pre">Ready</span></tt> message, or just <tt class="docutils literal"><span class="pre">[name]</span> <span class="pre">Ready</span></tt>, so the configuration code
can implement a listener for that message, and have the listener
perform the configuration when the message arrives. But even if the
extension <em>has</em> already been loaded, this will still work, because the
listener will receive the ready signal even if it has already been
posted. In this way, listening for signals is a robust method of
synchronizing code components no matter when they are loaded and run.</p>
<p>In some cases, it may be inappropriate for a new listener to receive
past messages that were sent to a signal object. There are two ways to
handle this: first, a new listener can indicate that it doesn&#8217;t want
@ -121,14 +121,14 @@ also be a JavaScript array containing data, or an object containing
message, and can act on it in whatever ways they see fit.</p>
<div class="section" id="creating-a-listener">
<h2>Creating a Listener<a class="headerlink" href="#creating-a-listener" title="Permalink to this headline"></a></h2>
<p>MathJax maintains two separate signal channels: the <cite>startup signal</cite>
and the <cite>processing signal</cite> (or the <cite>hub signal</cite>). The startup signal
is where the messages about different components starting up and
becoming ready appear. The processing signal is where the messages
are sent about processing mathematics, like the <tt class="docutils literal"><span class="pre">New</span> <span class="pre">Math</span></tt> messages
for when newly typeset mathematics appears on the page. The latter is
cleared when a new processing pass is started (so messages from past
processing runs are not kept).</p>
<p>MathJax maintains two separate pre-defined signal channels: the
<cite>startup signal</cite> and the <cite>processing signal</cite> (or the <cite>hub signal</cite>).
The startup signal is where the messages about different components
starting up and becoming ready appear. The processing signal is where
the messages are sent about processing mathematics, like the <tt class="docutils literal"><span class="pre">New</span>
<span class="pre">Math</span></tt> messages for when newly typeset mathematics appears on the
page. The latter is cleared when a new processing pass is started (so
messages from past processing runs are not kept).</p>
<p>The easiest way to create a listener is to use either
<tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Hub.Register.StartupHook()</span></tt> or
<tt class="xref py py-meth docutils literal"><span class="pre">MathJax.Hub.Register.MessageHook()</span></tt>. The first sets a listener
@ -142,10 +142,11 @@ called when it arrives. For example</p>
</div>
<p>See the <a class="reference internal" href="startup.html#startup-sequence"><em>MathJax Startup Sequence</em></a> page for
details of the messages sent during startup. See also the
<tt class="docutils literal"><span class="pre">test/sample-signals.html</span></tt> file (and its source) for examples of
using signals. This example lists all the signals that occur while
MathJax is processing that page, so it gives useful information about
the details of the signals produced by various components.</p>
<a class="reference external" href="http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html">test/sample-signals.html</a>
file (and its source) for examples of using signals. This example
lists all the signals that occur while MathJax is processing that
page, so it gives useful information about the details of the signals
produced by various components.</p>
<p>In this example, the listener starts loading an extra configuration
file (from the same directory as the web page). Since it returns
the callback from that request, the signal processing will wait until
@ -185,8 +186,8 @@ signal&#8217;s <a class="reference internal" href="api/signal.html#Interest" tit
</div>
<p>This will cause an alert for every signal that MathJax produces. You
probably don&#8217;t want to try this out, since it will produce a <em>lot</em> of
them; instead, use the <tt class="docutils literal"><span class="pre">test/sample-signals.html</span></tt> file, which
displays them in the web page.</p>
them; instead, use the <a class="reference external" href="http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html">test/sample-signals.html</a>
file, which displays them in the web page.</p>
<p>See the <a class="reference internal" href="api/signal.html#api-signal"><em>Signal Object</em></a> reference page for details on the
structure and methods of the signal object.</p>
</div>

View File

@ -131,6 +131,10 @@ pushed into the queue:</p>
</li>
</ol>
<ol class="arabic simple" start="5">
<li>Initialize the Message system (the grey information box in the
lower left)</li>
</ol>
<ol class="arabic simple" start="6">
<li>Load the jax configuration files:<ul>
<li>Post the <tt class="docutils literal"><span class="pre">Begin</span> <span class="pre">Jax</span></tt> startup signal</li>
<li>Load the jax config files from the <tt class="docutils literal"><span class="pre">MathJax.Hub.config.jax</span></tt> array<ul>
@ -141,7 +145,7 @@ pushed into the queue:</p>
</ul>
</li>
</ol>
<ol class="arabic simple" start="6">
<ol class="arabic simple" start="7">
<li>Load the extension files:<ul>
<li>Post the <tt class="docutils literal"><span class="pre">Begin</span> <span class="pre">Extensions</span></tt> startup signal</li>
<li>Load the files from the <tt class="docutils literal"><span class="pre">MathJax.Hub.config.extensions</span></tt> array<ul>
@ -154,17 +158,19 @@ pushed into the queue:</p>
</ul>
</li>
</ol>
<ol class="arabic simple" start="7">
<ol class="arabic simple" start="8">
<li>Set the MathJax menu&#8217;s renderer value based on the jax that have been
loaded</li>
</ol>
<ol class="arabic simple" start="8">
<li>Wait for the onload handler to fire</li>
</ol>
<ol class="arabic simple" start="9">
<li>Set <tt class="docutils literal"><span class="pre">MathJax.isReady</span></tt> to <tt class="docutils literal"><span class="pre">true</span></tt></li>
<li>Wait for the onload handler to fire (in MathJax v2.0 this can
occur on the <tt class="docutils literal"><span class="pre">DOMContentLoaded</span></tt> event rather than the page&#8217;s
<tt class="docutils literal"><span class="pre">onload</span></tt> event, so processing of mathematics can start earlier)</li>
</ol>
<ol class="arabic simple" start="10">
<li>Set <tt class="docutils literal"><span class="pre">MathJax.isReady</span></tt> to <tt class="docutils literal"><span class="pre">true</span></tt></li>
</ol>
<ol class="arabic simple" start="11">
<li>Perform the typesetting pass (preprocessors and processors)<ul>
<li>Post the <tt class="docutils literal"><span class="pre">Begin</span> <span class="pre">Typeset</span></tt> startup signal</li>
<li>Post the <tt class="docutils literal"><span class="pre">Begin</span> <span class="pre">PreProcess</span></tt> hub signal</li>
@ -173,6 +179,11 @@ loaded</li>
<li>Clear the hub signal history</li>
<li>Post the <tt class="docutils literal"><span class="pre">Begin</span> <span class="pre">Process</span></tt> hub signal</li>
<li>Process the math script elements on the page<ul>
<li>There are a number of Hub signals generated during math
processing, including a signal that a <tt class="docutils literal"><span class="pre">Math</span></tt> action is
starting (with a parameter indicating what action that is),
<tt class="docutils literal"><span class="pre">Begin</span></tt> and <tt class="docutils literal"><span class="pre">End</span> <span class="pre">Math</span> <span class="pre">Input</span></tt> messages, and <tt class="docutils literal"><span class="pre">Begin</span></tt> and
<tt class="docutils literal"><span class="pre">End</span> <span class="pre">Math</span> <span class="pre">Output</span></tt> signals.</li>
<li>Each new math element generates a <tt class="docutils literal"><span class="pre">New</span> <span class="pre">Math</span></tt> hub signal
with the math element&#8217;s ID</li>
</ul>
@ -182,7 +193,16 @@ with the math element&#8217;s ID</li>
</ul>
</li>
</ol>
<ol class="arabic simple" start="11">
<ol class="arabic simple" start="12">
<li>Jump to the location specified in the URL&#8217;s hash reference, if
any.</li>
</ol>
<ol class="arabic simple" start="13">
<li>Initiate timers to load the zoom and menu code, if it hasn&#8217;t
already been loading in the configuration (so it will be ready
when the user needs it).</li>
</ol>
<ol class="arabic simple" start="14">
<li>Post the <tt class="docutils literal"><span class="pre">End</span></tt> startup signal</li>
</ol>
<p>The loading of the jax and extensions in steps 5 and 6 are now done in
@ -193,7 +213,8 @@ extensions can be intermixed. (In general, you will get <cite>Begin Jax</cite>
followed by <cite>Begin Extensions</cite>, but the order of <cite>End Jax</cite> and <cite>End
Extensions</cite> will depend on the files being loaded.) Both 5 and 6 must
complete, however, before 7 will be performed.</p>
<p>See the <tt class="docutils literal"><span class="pre">test/sample-signals.html</span></tt> file to see the signals in action.</p>
<p>See the <a class="reference external" href="http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html">test/sample-signals.html</a> file
to see the signals in action.</p>
</div>

View File

@ -59,7 +59,7 @@ yet). Actions such as loading files, loading web-based fonts, and
creating stylesheets all happen asynchronously within the browser, and
since JavaScript has no method of halting a program while waiting for
an action to complete, synchronizing your code with these types of
actions is made much more difficult. MathJax used three mechanisms to
actions is made much more difficult. MathJax uses three mechanisms to
overcome this language shortcoming: callbacks, queues, and signals.</p>
<p><strong>Callbacks</strong> are functions that are called when an action is
completed, so that your code can continue where it left off when the
@ -81,20 +81,22 @@ synchronize with MathJax, but you can also create your own private
queues for actions that need to be synchronized with each other, but
not to MathJax as a whole. See the <a class="reference internal" href="api/queue.html#api-queue"><em>Queue Object</em></a>
reference page for more details.</p>
<p><strong>Signals</strong> are another means of synchronizing your own code with MathJax.
Many of the important actions that MathJax takes (like typesetting new math
on the page, or loading an external component) are &#8220;announced&#8221; by posting a
message to a special object called a <cite>Signal</cite>. Your code can register an
interest in receiving one or more of these signals by providing a callback
to be called when the signal is posted. When the signal arrives, MathJax
will call your code. This works somewhat like an event handler, except
that many different types of events can go through the same signal, and the
signals have a &#8220;memory&#8221;, meaning that if you register an interest in a
particular type of signal and that signal has already occurred, you will be
told about the past occurrences as well as any future ones. See the
<a class="reference internal" href="api/signal.html#api-signal"><em>Signal Object</em></a> reference page for more details. See
also the <tt class="docutils literal"><span class="pre">test/sample-signals.html</span></tt> file in the MathJax <tt class="docutils literal"><span class="pre">test</span></tt>
directory for a working example of using signals.</p>
<p><strong>Signals</strong> are another means of synchronizing your own code with
MathJax. Many of the important actions that MathJax takes (like
typesetting new math on the page, or loading an external component)
are &#8220;announced&#8221; by posting a message to a special object called a
<cite>Signal</cite>. Your code can register an interest in receiving one or more
of these signals by providing a callback to be called when the signal
is posted. When the signal arrives, MathJax will call your code.
This works somewhat like an event handler, except that many different
types of events can go through the same signal, and the signals have a
&#8220;memory&#8221;, meaning that if you register an interest in a particular
type of signal and that signal has already occurred, you will be told
about the past occurrences as well as any future ones. See the
<a class="reference internal" href="api/signal.html#api-signal"><em>Signal Object</em></a> reference page for more details.
See also the <a class="reference external" href="http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html">test/sample-signals.html</a>
file in the MathJax <tt class="docutils literal"><span class="pre">test</span></tt> directory for a working example of using
signals.</p>
<p>Each of these is explained in more detail in the links below:</p>
<div class="toctree-wrapper compound">
<ul>

View File

@ -154,12 +154,20 @@ will not occur before the math is typeset.</p>
<dd><p>to set the math text of the element to <cite>newmath</cite> and typeset.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">Rerender()</tt></dt>
<dd><p>to remove the output and reproduce it again (for example, if
CSS has changed that would alter the spacing of the
mathematics). Note that the internal representation isn&#8217;t
regenerated; only the output is.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">Reprocess()</tt></dt>
<dd><p>to remove the output and reproduce it again (for
example, if CSS has changed that would alter the spacing of the
mathematics).</p>
<dd><p>to remove the output and then retranslate the input into the
internal MathML and rerender the output.</p>
</dd></dl>
<dl class="describe">
@ -169,6 +177,13 @@ mathematics).</p>
the original <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tag).</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">needsUpdate()</tt></dt>
<dd><p>to find out if the mathematics has changed so that its output
needs to be updated.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">SourceElement()</tt></dt>
@ -190,7 +205,7 @@ time. This is another situation where you want to use the MathJax
queue. If your startup code performs the commands</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="kd">var</span> <span class="nx">studentDisplay</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="nx">MathJax</span><span class="p">.</span><span class="nx">Hub</span><span class="p">.</span><span class="nx">Queue</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">studentDisplay</span> <span class="o">=</span> <span class="nx">MathJax</span><span class="p">.</span><span class="nx">Hub</span><span class="p">.</span><span class="nx">getAllJax</span><span class="p">(</span><span class="s2">&quot;MathDiv&quot;</span><span class="p">);</span>
<span class="nx">studentDisplay</span> <span class="o">=</span> <span class="nx">MathJax</span><span class="p">.</span><span class="nx">Hub</span><span class="p">.</span><span class="nx">getAllJax</span><span class="p">(</span><span class="s2">&quot;MathDiv&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span>
<span class="p">});</span>
</pre></div>
</div>
@ -200,8 +215,11 @@ queue. If your startup code performs the commands</p>
</div>
<p>to change the student&#8217;s answer to be the typeset version of whatever
is in the <tt class="docutils literal"><span class="pre">studentAnswer</span></tt> variable.</p>
<p>Here is a complete example that illustrates this approach (available in a
more full-featured version as <tt class="docutils literal"><span class="pre">test/sample-dynamic.html</span></tt>):</p>
<p>Here is a complete example that illustrates this approach. Note,
however, that Internet Explorer does not fire the <tt class="docutils literal"><span class="pre">onchange</span></tt> event
when you press RETURN, so this example does not work as expected in
IE. A more full-featured version that addresses this problem is
available in <a class="reference external" href="http://cdn.mathjax.org/mathjax/latest/test/sample-dynamic.html">test/sample-dynamic.html</a>.</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;html&gt;</span>
<span class="nt">&lt;head&gt;</span>
<span class="nt">&lt;title&gt;</span>MathJax Dynamic Math Test Page<span class="nt">&lt;/title&gt;</span>
@ -258,6 +276,9 @@ You typed: ${}$
<span class="nt">&lt;/html&gt;</span>
</pre></div>
</div>
<p>There are a number of additional example pages at <a class="reference external" href="http://cdn.mathjax.org/mathjax/latest/test/examples.html">test/examples.html</a> that
illustrate how to call MathJax dynamically or perform other actions
with MathJax.</p>
</div>
</div>

View File

@ -10,9 +10,9 @@ if ((window.unsafeWindow == null ? window : unsafeWindow).MathJax == null) {
(document.getElementsByTagNameNS == null ? false :
(document.getElementsByTagNameNS("http://www.w3.org/1998/Math/MathML","math").length > 0))) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}

View File

@ -23,9 +23,8 @@ if ((window.unsafeWindow == null ? window : unsafeWindow).MathJax == null) {
// Load MathJax and have it process the page
//
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}

View File

@ -58,7 +58,7 @@ A callback specification is any one of the following:
the given function, and it would return their sum, ``5``, when
the callback is executed.
.. describe:: [object, fn]
.. describe:: [object, fn]
An array containing an object to use as `this` and a function to
call for the callback. For example,
@ -75,7 +75,7 @@ A callback specification is any one of the following:
Similar to the previous case, but with data that is passed to
the function as well.
..describe:: ["method", object]
.. describe:: ["method", object]
Here, `object` is an object that has a method called `method`, and
the callback will execute that method (with the object as
@ -220,24 +220,6 @@ MathJax.Callback Methods
- **callback** --- the callback specification
:Returns: the callback object
.. method:: ExecuteHooks(hooks[, data[,reset]])
Calls each callback in the `hooks` array (or the single hook if it
is not an array), passing it the arguments stored in the data
array. If `reset` is ``true``, then the callback's
:meth:`reset()` method will be called before each hook is
executed. If any of the hooks returns a `Callback` object, then
it collects those callbacks and returns a new callback that will
execute when all the ones returned by the hooks have been
completed. Otherwise, :meth:`MathJax.Callback.ExecuteHooks()`
returns ``null``.
:Parameters:
- **hooks** --- array of hooks to be called, or a hook
- **data** --- array of arguments to pass to each hook in turn
- **reset** --- ``true`` if the :meth:`reset()` method should be called
:Returns: callback that waits for all the hooks to complete, or ``null``
.. method:: Queue([callback,...])
Creates a `MathJax.CallBack.Queue` object and pushes the given
@ -257,3 +239,66 @@ MathJax.Callback Methods
:Parameters:
- **name** --- name of the signal to get or create
:Returns: the `Signal` object
.. method:: ExecuteHooks(hooks[, data[,reset]])
Calls each callback in the `hooks` array (or the single hook if it
is not an array), passing it the arguments stored in the data
array. If `reset` is ``true``, then the callback's
:meth:`reset()` method will be called before each hook is
executed. If any of the hooks returns a `Callback` object, then
it collects those callbacks and returns a new callback that will
execute when all the ones returned by the hooks have been
completed. Otherwise, :meth:`MathJax.Callback.ExecuteHooks()`
returns ``null``.
:Parameters:
- **hooks** --- array of hooks to be called, or a hook
- **data** --- array of arguments to pass to each hook in turn
- **reset** --- ``true`` if the :meth:`reset()` method should be called
:Returns: callback that waits for all the hooks to complete, or ``null``
.. method:: Hooks(reset)
Creates a prioritized list of hooks that are called in order based
on their priority (low priority numbers are handled first). This
is meant to replace :meth:`MathJax.Callback.ExecuteHooks()` and is
used internally for signal callbacks, pre- and post-filters, and
other lists of callbacks.
:Parameters:
- **reset** --- ``true`` if callbacks can be called more than once
:Returns: the `Hooks` object
The list has the following methods:
.. method:: Add(hook[,priority])
Add a callback to the prioritized list. If ``priority`` is
not provided, the default is 10. The ``hook`` is a `Callback`
specification as described above.
:Parameters:
- **hook** --- callback specification to add to the list
- **priority** --- priority of the hook in the list (default: 10)
:Returns: the callback object being added
.. method:: Remove(hook)
:noindex:
Remove a given hook (as returned from :meth:`Add()` above)
from the prioritized list.
:Parameters:
- **hook** --- the callback to be removed
:Returns: ``null``
.. method:: Execute()
Execute the list of callbacks, resetting them if requested.
If any of the hooks return callbacks, then ``Execute()``
returns a callback that will be executed when they all have
completed.
:Returns: a callback object or ``null``

View File

@ -42,13 +42,11 @@ Instance Properties
.. describe:: inputJax
A reference to the input jax that created the element. (In the
future, this will be changed to the name of the input jax.)
The name of the input jax that created the element.
.. describe:: outputJax
A reference to the output jax that has processed this element. (In
the future, this will be changed to the name of the output jax.)
The name of the output jax that has processed this element.
.. describe:: inputID
@ -89,13 +87,25 @@ Methods
- **callback** --- the callback specification
:Returns: the callback object
.. Method:: Rerender([callback])
:noindex:
Removes the output and produces it again (for example, if CSS has
changed that would alter the spacing of the mathematics). Note
that the internal representation isn't regenerated; only the
output is. The `callback`, if any, is called when the process
completes.
:Parameters:
- **callback** --- the callback specification
:Returns: the callback object
.. Method:: Reprocess([callback])
:noindex:
Removes the output and produces it again. This may be necessary if
there are changes to the CSS styles that would affect the layout
of the mathematics, for example. The `callback`, if any, is
called when the process completes.
Removes the output and then retranslates the input into the
internal form and reredners the output again. The `callback`, if
any, is called when the process completes.
:Parameters:
- **callback** --- the callback specification
@ -118,6 +128,16 @@ Methods
:Returns: the ``<script>`` element
.. Method:: needsUpdate()
Indicates whether the mathematics has changed so that its output
needs to be updated.
:Returns: ``true`` if the mathematics needs to be reprocessed,
``false`` otherwise
Output jax may add new methods to the base element jax class to
perform exporting to other formats. For example, a MathML output jax
could add ``toMathML()``, or an accessibility output jax could add

View File

@ -92,6 +92,15 @@ Methods
- **text** --- the text that is to be the script's new content
:Returns: ``null``
.. method:: getScript(script)
Gets the contents of the ``script`` element, properly taking into
account the browser limitations and bugs.
:Parameters:
- **script** --- the script whose content is to be retrieved
:Returns: the text of the ``script``
.. describe:: Cookie.Set(name,data)
Creates a MathJax cookie using the ``MathJax.HTML.Cookie.prefix``

View File

@ -31,7 +31,17 @@ Properties
.. describe:: processUpdateTime: 250
The minimum time (in milliseconds) between updates of the
"Processing Math" message.
"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
@ -60,6 +70,11 @@ Properties
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
@ -97,6 +112,18 @@ Properties
}
);
.. 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
=======
@ -243,13 +270,31 @@ Methods
.. 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. 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
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:
@ -315,6 +360,21 @@ Methods
- **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

View File

@ -56,13 +56,40 @@ Properties
Methods
=======
.. Method:: Translate(script)
.. 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
redefined, so when the ``jax.js`` file loads, it should override the
defined, so when the ``jax.js`` file loads, it should override the
default :meth:`Translate()` with its own version that does the actual
translation.
@ -72,6 +99,9 @@ Methods
: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)
@ -87,3 +117,14 @@ Methods
- **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

View File

@ -63,34 +63,20 @@ Instance Properties
jax. These can be modified by the author by including a
configuration subsection for the specific jax in question.
.. describe:: JAXFILE: "jax.js"
The name of the file that contains the main code for the jax.
Methods
=======
.. Method:: Process(script)
:noindex:
This is the method that the ``MathJax.Hub`` calls when it needs the
input or output jax to process the given math ``<script>``. Its
default action is to start loading the jax's ``jax.js`` file, and
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 :meth:`Translate()` method, so that subsequent calls
to :meth:`Process()` will perform the appropriate translation.
:Parameters:
- **script** --- reference to the DOM ``<script>`` object for
the mathematics to be translated
:Returns: an `ElementJax` object, or ``null``
.. Method:: Translate(script)
This is a stub for a routine that should be defined by the jax's
``jax.js`` file when it is loaded. It should perform the translation
action for the specific jax. For an input jax, it should return the
`ElementJax` object that it created. The :meth:`Translate()` method is
never called directly by MathJax; during the :meth:`loadComplete()`
never called directly by MathJax; during the ``loadComplete()``
call, this function is copied to the :meth:`Process()` method, and is
called via that name. The default :meth:`Translate()` method throws an
error indicating that the :meth:`Translate()` method was not
@ -147,7 +133,10 @@ Methods
5. Post the "[name] Jax Startup" message to the startup signal.
6. Perform the jax's :meth:`Startup()` method.
7. Post the "[name] Jax Ready" message to the startup signal.
8. Perform the :meth:`MathJax.Ajax.loadComplete()` call for the
8. Copy the ``preTranslate``, ``Translate``, and
``postTranslate`` functions to ``preProcess``, ``Process``,
and ``postProcess``.
9. Perform the :meth:`MathJax.Ajax.loadComplete()` call for the
``jax.js`` file.
Note that the configuration process (the :meth:`Config()` call) can

View File

@ -48,17 +48,65 @@ Properties
The directory where the jax files are stored (e.g., ``"[MathJax]/jax/output/HTML-CSS"``);
.. describe:: fontDir
The directory where the fonts are stored (e.g., ``"[MathJax]/fonts"``)
.. describe:: imageDir
The directory where MathJax images are found (e.g. ``"[MathJax]/images"``)
Methods
=======
.. Method:: Translate(script)
.. Method:: preProcess(state)
This is called by ``MathJax.Hub`` to ask the output processor to
prepare to process math scripts. Its default action is to start
loading the jax's ``jax.js`` file, and 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 :meth:`preTranslate()` method, so that subsequent calls
to :meth:`preProcess()` will perform the appropriate translation.
:Parameters:
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: ``null``
.. Method:: preTranslate(state)
This routine replaces :meth:`preProcess()` above when the jax's
``jax.js`` file is loaded. It is called by ``MathJax.Hub`` to ask
the output processor to prepare to process math scripts. (For
example, the HTML-CSS output jax uses this to determine em-sizes
for all the mathematics at once, to minimize page reflows that
slow down Internet Explorer.)
The routine can use ``state.jax[this.id]`` to obtain the array of
element jax that are to be processed. The output jax can use the
``state`` variable to maintain its own state information, but
any properties that it adds to the variable should have a prefix
that is the output jax's ID. For example, the HTML-CSS output jax
might use ``state.HTMLCSSlast`` to keep track of the last equation
it processed, or could add ``state.HTMLCSS = {...}`` to create an
object of its own within the state variable.
:Parameters:
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: ``null``
.. Method:: Translate(script,state)
:noindex:
This is the main routine called by MathJax when an element jax is
to be converted to output. The default :meth:`Translate()`
method throws an error indicating that :meth:`Translate()` hasn't been
redefined, so when the ``jax.js`` file loads, it should override the
defined, so when the ``jax.js`` file loads, it should override the
default :meth:`Translate()` with its own version that does the actual
translation.
@ -66,12 +114,35 @@ Methods
element jax for the given script. The translation process may
modify the element jax (e.g., if it has data that needs to be
stored with the jax), and may insert DOM elements into the
document near the jax's ``<script>`` tag.
document near the jax's ``<script>`` tag. The output jax can use
the ``state`` variable to maintain information about its
processing state, but see :meth:`preTranslate()` above for naming
conventions for properties that are added.
:Parameters:
- **script** --- the ``<script>`` element to be translated
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: the `element jax` resulting from the translation
.. Method:: postTranslate(state)
This routines is called by ``MathJax.Hub`` when the translation
of math elements is complete, and can be used by the output
processor to finalize any actions that it needs to complete.
(For example, making the mathematics visible, or forcing a reflow
of the page.)
The routine can use ``state.jax[this.id]`` to obtain the array of
element jax that were processed, or can use the ``state`` variable
to store its own state information (see :meth:`preProcess()`
above for caveats about naming properties).
:Parameters:
- **state** --- a structure containing information about the
current proccessing state of the mathematics
:Returns: ``null``
.. Method:: Register(mimetype)
:noindex:
@ -95,3 +166,53 @@ Methods
:Parameters:
- **jax** --- the element jax whose display should be removed
:Returns: ``null``
If an output jax wants its output to handle the contextual menu item
and zooming, then it needs to tie into the event-handling code
(`MathEvents`) and the zoom-handling code (`MathZoom`). That requires
the following methods.
.. Method:: getJaxFromMath(math)
This is called by the event-handling code (`MathEvents`) to get
the element jax associated with the DOM element that caused an
event to occur. The output jax will have attached event handlers
to some DOM element that is part of its output, and the
`MathEvents` code uses this routine to map back to the jax
associated with that output.
:Parameters:
- **math** --- a DOM element that triggered a DOM event
(e.g., a mouse click)
:Returns: the `ElementJax` structure associated with the DOM element
.. Method:: Zoom(jax,span,math,Mw,Mh)
This routine is called by the zoom-handling code (`MathZoom`)
when an expression has received its zoom trigger event (e.g., a
double-click). The ``jax`` is the math that needs to be zoomed,
``span`` is a ``<span>`` element in which the zoomed version of
the math should be placed, ``math`` is the DOM element that
received the zoom trigger event, and ``Mw`` and ``Mh`` are the
maximum width and height allowed for the zoom box (the ``span``).
The return value is an object with the following properties:
- ``Y`` --- the vertical offset from the top of the ``span`` to
the baseline of the mathematics
- ``mW`` --- the width of the original mathematics element
- ``mH`` --- the height of the original mathematics element
- ``zW`` --- the width of the zoomed math
- ``zH`` --- the height of the zoomed math
All of these values are in pixels.
:Parameters:
- **jax** --- the jax to be zoomed
- **span** --- the ``<span>`` in which to place the zoomed math
- **math** --- the DOM element generating the zoom event
- **Mw** --- the maximum width of the zoom box
- **Mh** --- the maximum height of the zoom box
:Returns: a structure as described above

View File

@ -19,7 +19,7 @@ Main MathJax Components
.. describe:: MathJax.Ajax
Contains the code for loading external modules and creating
stylesheets. Most of the code that causes most of MathJax to
stylesheets. Most of the code that causes MathJax to
operate asynchronously is handled here.
.. describe:: MathJax.Message
@ -43,6 +43,11 @@ Main MathJax Components
For example, the `tex2jax` preprocessor creates
``MathJax.Extension.tex2jax`` for its code and variables.
.. describe:: MathJax.Menu
Initially null, this is where the MathJax contextual menu is
stored, when ``extensions/MathMenu.js`` is loaded.
.. describe:: MathJax.Object
Contains the code for the MathJax object-oriented programming model.
@ -75,7 +80,11 @@ Properties
.. describe:: MathJax.version
The version number of the MathJax library.
The version number of the MathJax library as a whole.
.. describe:: MathJax.fileversion
The version number of the ``MathJax.js`` file specifically.
.. describe:: MathJax.isReady

View File

@ -214,10 +214,10 @@ you simply passed the object's method to ``setTimeout()``. Or you
might want to pass an argument to the function called by
``setTimeout()``. (Altough the ``setTimeout()`` function can accept
additional arguements that are supposed to be passed on to the code
when it is called, Internet Explorer does not implement that feature,
so you can't rely on it.) You can use a `Callback` object to
do this, and the :meth:`MathJax.Callback()` method will create one for
you. For example,
when it is called, some versions of Internet Explorer do not implement
that feature, so you can't rely on it.) You can use a `Callback`
object to do this, and the :meth:`MathJax.Callback()` method will
create one for you. For example,
.. code-block:: javascript

View File

@ -6,21 +6,16 @@ Loading MathJax Dynamically
MathJax is designed to be included via a ``<script>`` tag in the
``<head>`` section of your HTML document, and it does rely on being
part of the original document in that it uses an ``onload`` event
handler to synchronize its actions with the loading of the page.
If you wish to insert MathJax into a document after it has
been loaded, that will normally occur *after* the page's ``onload``
handler has fired, and so MathJax will not be able to tell if it is
safe for it to process the contents of the page. Indeed, it will wait
forever for its ``onload`` handler to fire, and so will never process
the page.
To solve this problem, you will need to call MathJax's ``onload``
handler yourself, to let it know that it is OK to typeset the
mathematics on the page. You accomplish this by calling the
:meth:`MathJax.Hub.Startup.onload()` method as part of your MathJax
startup script. To do this, you will need to give MathJax an in-line
configuration.
part of the original document in that it uses an ``onload`` or
``DOMContentLoaded`` event handler to synchronize its actions with the
loading of the page. If you wish to insert MathJax into a document
after it has been loaded, that will normally occur *after* the page's
``onload`` handler has fired, and prior to version 2.0, MathJax had to
be told not to wait for the page ``onload`` event by calling
:meth:`MathJax.Hub.Startup.onload()` by hand. That is no longer
necessary, as MathJax v2.0 detects whether the page is already
available and when it is, it processes it immediately rather than
waiting for an event that has already happened.
Here is an example of how to load and configure MathJax dynamically:
@ -29,43 +24,37 @@ Here is an example of how to load and configure MathJax dynamically:
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js";
var config = 'MathJax.Hub.Config({' +
'extensions: ["tex2jax.js"],' +
'jax: ["input/TeX","output/HTML-CSS"]' +
'});' +
'MathJax.Hub.Startup.onload();';
if (window.opera) {script.innerHTML = config}
else {script.text = config}
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
You can adjust the ``config`` variable to your needs, but be careful to get
the commas right. The ``window.opera`` test is because some versions of
Opera don't handle setting ``script.text`` properly, while Internet
Explorer doesn't handle setting the ``innerHTML`` of a script tag.
Here is a version that uses the ``config=filename`` method to
configure MathJax:
If you need to provide in-line configuration, you can do that using a
MathJax's configuration script:
.. code-block:: javascript
(function () {
var script = document.createElement("script");
var head = document.getElementsByTagName("head")[0], script;
script = document.createElement("script");
script.type = "text/x-mathjax-config";
script[(window.opera ? "innerHTML" : "text")] =
"MathJax.Hub.Config({\n" +
" tex2jax: { inlineMath: [['$','$'], ['\\\\(','\\\\)']] }\n" +
"});"
head.appendChild(script);
script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload();';
if (window.opera) {script.innerHTML = config}
else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
head.appendChild(script);
})();
You can adjust the configuration to your needs, but be careful to get
the commas right, as Internet Explorer 6 and 7 will not tolerate an
extra comma before a closing brace. The ``window.opera`` test is
because some versions of Opera don't handle setting ``script.text``
properly, while some versions of Internet Explorer don't handle
setting ``script.innerHTML``.
Note that the **only** reliable way to configure MathJax is to use an
in-line configuration block of the type discussed above. You should
**not** call :meth:`MathJax.Hub.Config()` directly in your code, as it will
@ -116,9 +105,8 @@ IE+MathPlayer.
(document.getElementsByTagNameNS == null ? false :
(document.getElementsByTagNameNS("http://www.w3.org/1998/Math/MathML","math").length > 0))) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}
@ -157,9 +145,8 @@ converting the math images to their original TeX code.
// Load MathJax and have it process the page
//
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full";
var config = 'MathJax.Hub.Startup.onload()';
if (window.opera) {script.innerHTML = config} else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
}
}

View File

@ -5,7 +5,7 @@ The MathJax Processing Model
The purpose of MathJax is to bring the ability to include mathematics
easily in web pages to as wide a range of browsers as possible.
Authors can specify mathematics in a variety of formats (e.g.,
:term:`MathML` or :term:`LaTeX`), and MathJax provides high-quality
:term:`MathML`, :term:`LaTeX`, or :term:`AsciiMath`), and MathJax provides high-quality
mathematical typesetting even in those browsers that do not have
native MathML support. This all happens without the need for special
downloads or plugins, but rendering will be enhanced if high-quality
@ -35,7 +35,8 @@ document is to be typeset as mathematics. In this case, MathJax can
run a preprocessor to locate the math delimiters and replace them by
the special tags that it uses to mark the formulas. There are
preprocessors for :ref:`TeX notation <TeX-support>`, :ref:`MathML
notation <MathML-support>`, and the :ref:`jsMath notation
notation <MathML-support>`, :ref:`AsciiMath notation
<AsciiMath-support>` and the :ref:`jsMath notation
<jsMath-support>` that uses `span` and `div` tags.
For pages that are constructed programmatically, such as HTML
@ -44,10 +45,12 @@ format (e.g., pages produced from Markdown documents, or via programs
like `tex4ht`), it would be best to use MathJax's special tags
directly, as described below, rather than having MathJax run
another preprocessor. This will speed up the final display of the
mathematics, since the extra preprocessing step would not be needed,
and it also avoids the conflict between the use of the less-than sign,
mathematics, since the extra preprocessing step would not be needed.
It also avoids the conflict between the use of the less-than sign,
``<``, in mathematics and as an HTML special character (that starts
an HTML tag).
an HTML tag), and several other issues involved in having the
mathematics directly in the text of the page (see the documentation on
the various input jax for more details on this).
.. _mathjax-script-tags:
@ -69,8 +72,9 @@ kind of script that the tag contains. The usual (and default) value
is ``type="text/javascript"``, and when a script has this type, the
browser executes the script as a javascript program. MathJax,
however, uses the type `math/tex` to identify mathematics in the TeX
and LaTeX notation, and `math/mml` for mathematics in MathML
notation. When the `tex2jax` or `mml2jax` preprocessors run, they
and LaTeX notation, `math/mml` for mathematics in MathML notation, and
`math/asciimath` for mathematics in AsciiMath notation. When the
`tex2jax`, `mml2jax`, or `asciimath2jax` preprocessors run, they
create ``<script>`` tags with these types so that MathJax can process
them when it runs its main typesetting pass.
@ -197,17 +201,25 @@ specific output format. For example, the NativeMML output jax inserts
MathML tags into the page to represent the mathematics, while the
HTML-CSS output jax uses HTML with CSS styling to lay out the
mathematics so that it can be displayed even in browsers that don't
understand MathML. Output jax could be produced that render the
mathematics using SVG, for example, or that speak an equation for
blind users. The MathJax contextual menu can be used to switch
between the output jax that are available.
understand MathML. MathJax also has an :term:`SVG` output jax that
will render the mathematics using scalable vector grtaphics. Output
jax could be produced that render the mathematics using HTML5 canvas
elements, for example, or that speak an equation for blind users. The
MathJax contextual menu can be used to switch between the output jax
that are available.
Each input and output jax has a small configuration file that is
loaded when that input jax is included in the `jax` array in the
MathJax configuration, and a larger file that implements the core
functionality of that particular jax. The latter file is loaded
the first time the jax is needed by MathJax to process some
mathematics.
functionality of that particular jax. The latter file is loaded the
first time the jax is needed by MathJax to process some mathematics.
Most of the combined configuration files include only the small
configuration portion for the input and output jax, making the
configuraiton file smaller and faster to load for those pages that
don't actually incldue mathematics; the combined configurations that
end in ``-full`` include both parts of the jax, so there is no delay
when the math is to be rendered, but at the expense of a larger
initial download.
The **MathJax Hub** keeps track of the internal representations of the
various mathematical equations on the page, and can be queried to

View File

@ -53,14 +53,14 @@ One way that MathJax makes use of this feature is in configuring its
various extensions. The extension may not be loaded when the user's
configuration code runs, so the configuration code can't modify the
extension because it isn't there yet. Fortunately, most extensions
signal when they are loaded and initialized via an ``Extension [name] Ready`` message,
so the configuration code can implement a listener for that message, and
have the listener perform the configuration when the message arrives.
But even if the extension *has* already been loaded, this will still
work, because the listener will receive the ready signal even if it
has already been posted. In this way, listening for signals is a
robust method of synchronizing code components no matter when they are
loaded and run.
signal when they are loaded and initialized via an ``Extension [name]
Ready`` message, or just ``[name] Ready``, so the configuration code
can implement a listener for that message, and have the listener
perform the configuration when the message arrives. But even if the
extension *has* already been loaded, this will still work, because the
listener will receive the ready signal even if it has already been
posted. In this way, listening for signals is a robust method of
synchronizing code components no matter when they are loaded and run.
In some cases, it may be inappropriate for a new listener to receive
past messages that were sent to a signal object. There are two ways to
@ -79,14 +79,14 @@ message, and can act on it in whatever ways they see fit.
Creating a Listener
===================
MathJax maintains two separate signal channels: the `startup signal`
and the `processing signal` (or the `hub signal`). The startup signal
is where the messages about different components starting up and
becoming ready appear. The processing signal is where the messages
are sent about processing mathematics, like the ``New Math`` messages
for when newly typeset mathematics appears on the page. The latter is
cleared when a new processing pass is started (so messages from past
processing runs are not kept).
MathJax maintains two separate pre-defined signal channels: the
`startup signal` and the `processing signal` (or the `hub signal`).
The startup signal is where the messages about different components
starting up and becoming ready appear. The processing signal is where
the messages are sent about processing mathematics, like the ``New
Math`` messages for when newly typeset mathematics appears on the
page. The latter is cleared when a new processing pass is started (so
messages from past processing runs are not kept).
The easiest way to create a listener is to use either
:meth:`MathJax.Hub.Register.StartupHook()` or
@ -103,10 +103,12 @@ called when it arrives. For example
See the :ref:`MathJax Startup Sequence <startup-sequence>` page for
details of the messages sent during startup. See also the
``test/sample-signals.html`` file (and its source) for examples of
using signals. This example lists all the signals that occur while
MathJax is processing that page, so it gives useful information about
the details of the signals produced by various components.
`test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_
file (and its source) for examples of using signals. This example
lists all the signals that occur while MathJax is processing that
page, so it gives useful information about the details of the signals
produced by various components.
In this example, the listener starts loading an extra configuration
file (from the same directory as the web page). Since it returns
@ -154,8 +156,9 @@ signal's :meth:`Interest()` method, as in the following example.
This will cause an alert for every signal that MathJax produces. You
probably don't want to try this out, since it will produce a *lot* of
them; instead, use the ``test/sample-signals.html`` file, which
displays them in the web page.
them; instead, use the `test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_
file, which displays them in the web page.
See the :ref:`Signal Object <api-signal>` reference page for details on the
structure and methods of the signal object.

View File

@ -90,7 +90,12 @@ pushed into the queue:
..
5. Load the jax configuration files:
5. Initialize the Message system (the grey information box in the
lower left)
..
6. Load the jax configuration files:
- Post the ``Begin Jax`` startup signal
- Load the jax config files from the ``MathJax.Hub.config.jax`` array
@ -101,7 +106,7 @@ pushed into the queue:
..
6. Load the extension files:
7. Load the extension files:
- Post the ``Begin Extensions`` startup signal
- Load the files from the ``MathJax.Hub.config.extensions`` array
@ -114,20 +119,22 @@ pushed into the queue:
..
7. Set the MathJax menu's renderer value based on the jax that have been
8. Set the MathJax menu's renderer value based on the jax that have been
loaded
..
8. Wait for the onload handler to fire
9. Wait for the onload handler to fire (in MathJax v2.0 this can
occur on the ``DOMContentLoaded`` event rather than the page's
``onload`` event, so processing of mathematics can start earlier)
..
9. Set ``MathJax.isReady`` to ``true``
10. Set ``MathJax.isReady`` to ``true``
..
10. Perform the typesetting pass (preprocessors and processors)
11. Perform the typesetting pass (preprocessors and processors)
- Post the ``Begin Typeset`` startup signal
- Post the ``Begin PreProcess`` hub signal
@ -137,6 +144,12 @@ pushed into the queue:
- Post the ``Begin Process`` hub signal
- Process the math script elements on the page
- There are a number of Hub signals generated during math
processing, including a signal that a ``Math`` action is
starting (with a parameter indicating what action that is),
``Begin`` and ``End Math Input`` messages, and ``Begin`` and
``End Math Output`` signals.
- Each new math element generates a ``New Math`` hub signal
with the math element's ID
@ -145,7 +158,18 @@ pushed into the queue:
..
11. Post the ``End`` startup signal
12. Jump to the location specified in the URL's hash reference, if
any.
..
13. Initiate timers to load the zoom and menu code, if it hasn't
already been loading in the configuration (so it will be ready
when the user needs it).
..
14. Post the ``End`` startup signal
The loading of the jax and extensions in steps 5 and 6 are now done in
@ -157,4 +181,6 @@ followed by `Begin Extensions`, but the order of `End Jax` and `End
Extensions` will depend on the files being loaded.) Both 5 and 6 must
complete, however, before 7 will be performed.
See the ``test/sample-signals.html`` file to see the signals in action.
See the `test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_ file
to see the signals in action.

View File

@ -12,7 +12,7 @@ yet). Actions such as loading files, loading web-based fonts, and
creating stylesheets all happen asynchronously within the browser, and
since JavaScript has no method of halting a program while waiting for
an action to complete, synchronizing your code with these types of
actions is made much more difficult. MathJax used three mechanisms to
actions is made much more difficult. MathJax uses three mechanisms to
overcome this language shortcoming: callbacks, queues, and signals.
**Callbacks** are functions that are called when an action is
@ -37,20 +37,23 @@ queues for actions that need to be synchronized with each other, but
not to MathJax as a whole. See the :ref:`Queue Object <api-queue>`
reference page for more details.
**Signals** are another means of synchronizing your own code with MathJax.
Many of the important actions that MathJax takes (like typesetting new math
on the page, or loading an external component) are "announced" by posting a
message to a special object called a `Signal`. Your code can register an
interest in receiving one or more of these signals by providing a callback
to be called when the signal is posted. When the signal arrives, MathJax
will call your code. This works somewhat like an event handler, except
that many different types of events can go through the same signal, and the
signals have a "memory", meaning that if you register an interest in a
particular type of signal and that signal has already occurred, you will be
told about the past occurrences as well as any future ones. See the
:ref:`Signal Object <api-signal>` reference page for more details. See
also the ``test/sample-signals.html`` file in the MathJax ``test``
directory for a working example of using signals.
**Signals** are another means of synchronizing your own code with
MathJax. Many of the important actions that MathJax takes (like
typesetting new math on the page, or loading an external component)
are "announced" by posting a message to a special object called a
`Signal`. Your code can register an interest in receiving one or more
of these signals by providing a callback to be called when the signal
is posted. When the signal arrives, MathJax will call your code.
This works somewhat like an event handler, except that many different
types of events can go through the same signal, and the signals have a
"memory", meaning that if you register an interest in a particular
type of signal and that signal has already occurred, you will be told
about the past occurrences as well as any future ones. See the
:ref:`Signal Object <api-signal>` reference page for more details.
See also the `test/sample-signals.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html>`_
file in the MathJax ``test`` directory for a working example of using
signals.
Each of these is explained in more detail in the links below:

View File

@ -127,17 +127,28 @@ The actions you can perform on an element jax include:
to set the math text of the element to `newmath` and typeset.
.. describe:: Rerender()
to remove the output and reproduce it again (for example, if
CSS has changed that would alter the spacing of the
mathematics). Note that the internal representation isn't
regenerated; only the output is.
.. describe:: Reprocess()
to remove the output and reproduce it again (for
example, if CSS has changed that would alter the spacing of the
mathematics).
to remove the output and then retranslate the input into the
internal MathML and rerender the output.
.. describe:: Remove()
to remove the output for this math element (but not
the original ``<script>`` tag).
.. describe:: needsUpdate()
to find out if the mathematics has changed so that its output
needs to be updated.
.. describe:: SourceElement()
to obtain a reference to the original
@ -161,7 +172,7 @@ queue. If your startup code performs the commands
var studentDisplay = null;
MathJax.Hub.Queue(function () {
studentDisplay = MathJax.Hub.getAllJax("MathDiv");
studentDisplay = MathJax.Hub.getAllJax("MathDiv")[0];
});
then you can use
@ -173,8 +184,12 @@ then you can use
to change the student's answer to be the typeset version of whatever
is in the ``studentAnswer`` variable.
Here is a complete example that illustrates this approach (available in a
more full-featured version as ``test/sample-dynamic.html``):
Here is a complete example that illustrates this approach. Note,
however, that Internet Explorer does not fire the ``onchange`` event
when you press RETURN, so this example does not work as expected in
IE. A more full-featured version that addresses this problem is
available in `test/sample-dynamic.html
<http://cdn.mathjax.org/mathjax/latest/test/sample-dynamic.html>`_.
.. code-block:: html
@ -232,3 +247,8 @@ more full-featured version as ``test/sample-dynamic.html``):
</body>
</html>
There are a number of additional example pages at `test/examples.html
<http://cdn.mathjax.org/mathjax/latest/test/examples.html>`_ that
illustrate how to call MathJax dynamically or perform other actions
with MathJax.

36
test/examples.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>MathJax Example Page</title>
<!-- Copyright (c) 2012 Design Science, Inc. -->
<style>
li {margin-top: .25em}
</style>
</head>
<body>
<h1>MathJax Example Pages</h1>
View the page source for any of these examples to see how they work.
<ul>
<li><a href="sample-tex.html">Page using TeX notation</a></li>
<li><a href="sample-mml.html">Page using MathML notation</a></li>
<li><a href="sample-asciimath.html">Page using AsciiMath notation</a></li>
<li><a href="sample.html">Page included several examples TeX equations</a></li>
<li><a href="sample-eqnum.html">Page of TeX equations with automatic numbering</a></li>
<li><a href="sample-eqnum.html">Page of TeX equations with equation references</a></li>
<p>
<li><a href="sample-signals.html">Page showing MathJax signals during page processing</a></li>
<p>
<li><a href="sample-dynamic-steps.html">Showing an equation one step at a time</a></li>
<li><a href="sample-dynamic.html">Display an equation typed in by a user</a></li>
<li><a href="sample-dynamic-2.html">Preview text containing math typed in by a user</a></li>
<p>
<li><a href="sample-loader.html">Loading MathJax into a page after it is loaded</a></li>
<li><a href="sample-loader-config.html">Loading MathJax dynamically with in-line configuration</a></li>
</ul>
</body>
</html>

View File

@ -2,9 +2,9 @@
<html>
<head>
<title>MathJax Test Page</title>
<!-- Copyright (c) 2009-2011 Design Science, Inc. -->
<!-- Copyright (c) 2009-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
//

View File

@ -2,9 +2,9 @@
<html>
<head>
<title>MathJax Test Page</title>
<!-- Copyright (c) 2009-2011 Design Science, Inc. -->
<!-- Copyright (c) 2009-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
//

117
test/sample-dynamic-2.html Normal file
View File

@ -0,0 +1,117 @@
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Preview of Textarea with MathJax Content</title>
<!-- Copyright (c) 2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showProcessingMessages: false,
tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
});
</script>
<script type="text/javascript" src="../MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
var Preview = {
delay: 150, // delay after keystroke before updating
preview: null, // filled in by Init below
buffer: null, // filled in by Init below
timeout: null, // store setTimout id
mjRunning: false, // true when MathJax is processing
oldText: null, // used to check if an update is needed
//
// Get the preview and buffer DIV's
//
Init: function () {
this.preview = document.getElementById("MathPreview");
this.buffer = document.getElementById("MathBuffer");
},
//
// Switch the buffer and preview, and display the right one.
// (We use visibility:hidden rather than display:none since
// the results of running MathJax are more accurate that way.)
//
SwapBuffers: function () {
var buffer = this.preview, preview = this.buffer;
this.buffer = buffer; this.preview = preview;
buffer.style.visibility = "hidden"; buffer.style.position = "absolute";
preview.style.position = ""; preview.style.visibility = "";
},
//
// This gets called when a key is pressed in the textarea.
// We check if there is already a pending update and clear it if so.
// Then set up an update to occur after a small delay (so if more keys
// are pressed, the update won't occur until after there has been
// a pause in the typing).
// The callback function is set up below, after the Preview object is set up.
//
Update: function () {
if (this.timeout) {clearTimeout(this.timeout)}
this.timeout = setTimeout(this.callback,this.delay);
},
//
// Creates the preview and runs MathJax on it.
// If MathJax is already trying to render the code, return
// If the text hasn't changed, return
// Otherwise, indicate that MathJax is running, and start the
// typesetting. After it is done, call PreviewDone.
//
CreatePreview: function () {
Preview.timeout = null;
if (this.mjRunning) return;
var text = document.getElementById("MathInput").value;
if (text === this.oldtext) return;
this.buffer.innerHTML = this.oldtext = text;
this.mjRunning = true;
MathJax.Hub.Queue(
["Typeset",MathJax.Hub,this.buffer],
["PreviewDone",this]
);
},
//
// Indicate that MathJax is no longer running,
// and swap the buffers to show the results.
//
PreviewDone: function () {
this.mjRunning = false;
this.SwapBuffers();
}
};
//
// Cache a callback to the CreatePreview action
//
Preview.callback = MathJax.Callback(["CreatePreview",Preview]);
Preview.callback.autoReset = true; // make sure it can run more than once
</script>
</head>
<body>
Type text in the box below:<br/>
<textarea id="MathInput" cols="60" rows="10" onkeyup="Preview.Update()" style="margin-top:5px">
</textarea>
<br/><br/>
Preview is shown here:
<div id="MathPreview" style="border:1px solid; padding: 3px; width:50%; margin-top:5px"></div>
<div id="MathBuffer" style="border:1px solid; padding: 3px; width:50%; margin-top:5px;
visibility:hidden; position:absolute; top:0; left: 0"><div>
<script>
Preview.Init();
</script>
</body>
</html>

View File

@ -2,9 +2,9 @@
<html>
<head>
<title>MathJax Dynamic Steps Test Page</title>
<!-- Copyright (c) 2011 Design Science, Inc. -->
<!-- Copyright (c) 2011-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
//

View File

@ -2,17 +2,11 @@
<html>
<head>
<title>MathJax Dynamic Math Test Page</title>
<!-- Copyright (c) 2010-2011 Design Science, Inc. -->
<!-- Copyright (c) 2010-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"]
});
</script>
<script type="text/javascript" src="../MathJax.js"></script>
<script type="text/javascript" src="../MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<style>
input {margin-top: .7em}
@ -53,8 +47,9 @@ input {margin-top: .7em}
});
//
// The onchange event handler that typesets the
// math entered by the user
// The onchange event handler that typesets the math entered
// by the user. Hide the box, then typeset, then show it again
// so we don't see a flash as the math is cleared and replaced.
//
window.UpdateMath = function (TeX) {
QUEUE.Push(HIDEBOX,["Text",math,"\\displaystyle{"+TeX+"}"],SHOWBOX);

138
test/sample-eqnum.html Normal file
View File

@ -0,0 +1,138 @@
<!DOCTYPE html>
<html>
<head>
<title>MathJax Equation Numbering</title>
<!-- Copyright (c) 2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
</script>
<script type="text/javascript" src="../MathJax.js?config=TeX-AMS_HTML"></script>
<style>
h1 {
background: #CCCCCC;
padding: .2em 1em;
border-top: 3px solid #666666;
border-bottom: 3px solid #999999;
}
</style>
</head>
<body>
<center>
<h1>A test of Equation Numbering</h1>
</center>
<div style="padding:0 2em">
<hr>
Equation:
\begin{equation}
E = mc^2
\end{equation}
Equation*:
\begin{equation*}
E = mc^2
\end{equation*}
<hr>
Brackets:
\[E = mc^2\]
Brackets tagged:
\[E = mc^2\tag{x}\]
<hr>
Split:
\begin{equation}
\begin{split}
a& =b+c-d\\
& \quad +e-f\\
& =g+h\\
& =i
\end{split}
\end{equation}
<hr>
Multline:
\begin{multline}
a+b+c+d+e+f+g\\
M+N+O+P+Q\\
R+S+T\\
u+v+w+x+y+z
\end{multline}
Multline*:
\begin{multline*}
a+b+c+d+e+f+g\\
M+N+O+P+Q\\
R+S+T\\
u+v+w+x+y+z
\end{multline*}
<hr>
Gather:
\begin{gather}
a_1=b_1+c_1\\
a_2=b_2+c_2-d_2+e_2
\end{gather}
Gather*:
\begin{gather*}
a_1=b_1+c_1\\
a_2=b_2+c_2-d_2+e_2
\end{gather*}
<hr>
Align:
\begin{align}
a_1& =b_1+c_1\\
a_2& =b_2+c_2-d_2+e_2
\end{align}
Align*:
\begin{align*}
a_1& =b_1+c_1\\
a_2& =b_2+c_2-d_2+e_2
\end{align*}
Align:
\begin{align}
a_{11}& =b_{11}& a_{12}& =b_{12}\\
a_{21}& =b_{21}& a_{22}& =b_{22}+c_{22}
\end{align}
Align with \notag and \tag:
\begin{align}
a_{11}& =b_{11}& a_{12}& =b_{12}\notag\\
a_{21}& =b_{21}& a_{22}& =b_{22}+c_{22} \tag{y}
\end{align}
Align* with \tag:
\begin{align*}
a_1& =b_1+c_1\tag{z}\\
a_2& =b_2+c_2-d_2+e_2
\end{align*}
</div>
</body>
</html>

85
test/sample-eqrefs.html Normal file
View File

@ -0,0 +1,85 @@
<!DOCTYPE html>
<html>
<head>
<title>MathJax Equation References</title>
<!-- Copyright (c) 2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "all"} } });
</script>
<script type="text/javascript" src="../MathJax.js?config=TeX-AMS_HTML"></script>
<style>
h1 {
background: #CCCCCC;
padding: .2em 1em;
border-top: 3px solid #666666;
border-bottom: 3px solid #999999;
}
</style>
</head>
<body>
<center>
<h1>A test of Equation References</h1>
</center>
<div style="padding:0 2em">
<hr>
Here is a labeled equation:
$$x+1\over\sqrt{1-x^2}\label{ref1}$$
with a reference to ref1: \ref{ref1},
and another numbered one with no label:
$$x+1\over\sqrt{1-x^2}$$
This one uses \nonumber:
$$x+1\over\sqrt{1-x^2}\nonumber$$
<p>
<HR>
<p>
Here's one using the equation environment:
\begin{equation}
x+1\over\sqrt{1-x^2}
\end{equation}
and one with equation* environment:
\begin{equation*}
x+1\over\sqrt{1-x^2}
\end{equation*}
<p>
<HR>
<p>
This is a forward reference [\ref{ref2}] and another \eqref{ref2} for the
following equation:
$$x+1\over\sqrt{1-x^2}\label{ref2}$$
More math:
$$x+1\over\sqrt{1-x^2}$$
Here is a ref inside math: $\ref{ref2}+1$ and text after it.
\begin{align}
x& = y_1-y_2+y_3-y_5+y_8-\dots
&& \text{by \eqref{ref1}}\\
& = y'\circ y^* && \text{(by \eqref{ref3})}\\
& = y(0) y' && \text {by Axiom 1.}
\end{align}
Here's a bad ref [\ref{ref4}] to a nonexistent label.
<p>
<HR>
<p>
An alignment:
\begin{align}
a&=b\label{ref3}\cr
&=c+d
\end{align}
and a starred one:
\begin{align*}
a&=b\cr
&=c+d
\end{align*}
</div>
</body>
</html>

View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<title>Load MathJax with in-line configuration after the page is ready</title>
<!-- Copyright (c) 2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript">
//
// We wait for the onload function to show that MathJax is laoded after
// the page is ready, and then use setTimeout to prove that MathJax is
// definitely loaded after the page is displayed and active. MathJax is
// loaded two seconds after the page is ready.
//
window.onload = function () {
setTimeout(function () {
var head = document.getElementsByTagName("head")[0], script;
script = document.createElement("script");
script.type = "text/x-mathjax-config";
script[(window.opera ? "innerHTML" : "text")] =
"MathJax.Hub.Config({\n" +
" tex2jax: { inlineMath: [['$','$'], ['\\\\(','\\\\)']] }\n" +
"});"
head.appendChild(script);
script = document.createElement("script");
script.type = "text/javascript";
script.src = "../MathJax.js?config=TeX-AMS-MML_HTMLorMML";
head.appendChild(script);
},2000)
}
</script>
<style>
h1 {
text-align: center;
background: #CCCCCC;
padding: .2em 1em;
border-top: 3px solid #666666;
border-bottom: 3px solid #999999;
}
</style>
</head>
<body>
<h1>Adding MathJax with In-Line Configuration</h1>
<p>
When $a \ne 0$, there are two solutions to $ax^2 + bx + c = 0$ and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</p>
</body>
</html>

47
test/sample-loader.html Normal file
View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Load MathJax after the page is ready</title>
<!-- Copyright (c) 2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript">
//
// We wait for the onload function to show that MathJax is laoded after
// the page is ready, and then use setTimeout to prove that MathJax is
// definitely loaded after the page is displayed and active. MathJax is
// loaded two seconds after the page is ready.
//
window.onload = function () {
setTimeout(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "../MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
},2000)
}
</script>
<style>
h1 {
text-align: center;
background: #CCCCCC;
padding: .2em 1em;
border-top: 3px solid #666666;
border-bottom: 3px solid #999999;
}
</style>
</head>
<body>
<h1>Adding MathJax After the Page is Loaded</h1>
<p>
When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</p>
</body>
</html>

View File

@ -2,9 +2,9 @@
<html>
<head>
<title>MathJax Signals Test Page</title>
<!-- Copyright (c) 2010-2011 Design Science, Inc. -->
<!-- Copyright (c) 2010-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!--
| This example shows how to use MathJax's signal mechanism to find out

View File

@ -2,9 +2,9 @@
<html>
<head>
<title>MathJax Test Page</title>
<!-- Copyright (c) 2009-2011 Design Science, Inc. -->
<!-- Copyright (c) 2009-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/x-mathjax-config">
MathJax.Hub.Config({