scribble-mathjax/docs/html/api/inputjax.html

299 lines
14 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The MathJax.InputJax Class &mdash; MathJax v2.0 documentation</title>
<link rel="stylesheet" href="../_static/mj.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<!--<script type="text/javascript" src="../../../MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>-->
<link rel="top" title="MathJax v2.0 documentation" href="../index.html" />
<link rel="up" title="The MathJax API" href="index.html" />
<link rel="next" title="The MathJax.OutputJax Class" href="outputjax.html" />
<link rel="prev" title="The MathJax.Callback.Signal Class" href="signal.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="outputjax.html" title="The MathJax.OutputJax Class"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="signal.html" title="The MathJax.Callback.Signal Class"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">MathJax v2.0 documentation</a> &raquo;</li>
<li><a href="index.html" accesskey="U">The MathJax API</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="the-mathjax-inputjax-class">
<span id="api-input-jax"></span><h1>The MathJax.InputJax Class<a class="headerlink" href="#the-mathjax-inputjax-class" title="Permalink to this headline"></a></h1>
<p>Input jax are the components of MathJax that translate
mathematics from its original format (like <a class="reference internal" href="../glossary.html#term-tex"><em class="xref std std-term">TeX</em></a> or
<a class="reference internal" href="../glossary.html#term-mathml"><em class="xref std std-term">MathML</em></a>) to the MathJax internal format (an <cite>element jax</cite>).</p>
<p>An input jax is stored as a pair of files in a subdirectory of the
<tt class="docutils literal"><span class="pre">jax/input</span></tt> directory, with the subdirectory name being the name of
the input jax. For example, the TeX input jax is stored in
<cite>jax/input/TeX</cite>. The first file, <tt class="docutils literal"><span class="pre">config.js</span></tt>, is loaded when
MathJax is being loaded and configured, and is indicated by listing
the input jax directory in the <cite>jax</cite> array of the MathJax
configuration. The <tt class="docutils literal"><span class="pre">config.js</span></tt> file creates a subclass of the
<cite>MathJax.InputJax</cite> object for the new input jax and registers that
with MathJax, along with the MIME-type that will be used to indicate
the mathematics that is to be processed by the input jax.</p>
<p>The main body of the input jax is stored in the second file,
<tt class="docutils literal"><span class="pre">jax.js</span></tt>, which is loaded when the input jax is first called on to
translate some mathematics. This file augments the original input jax
subclass with the additional methods needed to do the translation.
MathJax calls the input jax&#8217;s <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 when it needs
the input jax to translate the contents of a math <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tag.</p>
<p>The <cite>MathJax.InputJax</cite> class is a subclass of the <a class="reference internal" href="jax.html#api-jax"><em>MathJax Jax</em></a> class, and inherits the properties and methods of that
class. Those listed below are the additional or overridden ones from
that class.</p>
<div class="section" id="properties">
<h2>Properties<a class="headerlink" href="#properties" title="Permalink to this headline"></a></h2>
<dl class="describe">
<dt>
<tt class="descname">id</tt></dt>
<dd><p>The name of the jax.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">version</tt></dt>
<dd><p>The version number of the jax.</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">directory</tt></dt>
<dd><p>The directory where the jax files are stored (e.g., <tt class="docutils literal"><span class="pre">&quot;[MathJax]/jax/input/TeX&quot;</span></tt>).</p>
</dd></dl>
<dl class="describe">
<dt>
<tt class="descname">elementJax</tt></dt>
<dd><p>The name of the ElementJax class that this input jax will produce
(typically <tt class="docutils literal"><span class="pre">mml</span></tt>, as that is the only ElementJax at the moment).</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>, <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
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
<a class="reference internal" href="elementjax.html#api-element-jax"><em>Element Jax</em></a> that stores the data needed
for this element.</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><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>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">the <cite>element jax</cite> resulting from the translation</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt>
<tt class="descname">Register</tt><big>(</big><em>mimetype</em><big>)</big></dt>
<dd><p>This registers the MIME-type associated with this input jax so
that MathJax knows to call this input jax when it sees a
<tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> of that type. An input jax can register more than
one type, but it will be responsible for distinguishing elements
of the various types from one another.</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>mimetype</strong> &#8212; the MIME-type of the input this jax processes</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">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>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">The MathJax.InputJax Class</a><ul>
<li><a class="reference internal" href="#properties">Properties</a></li>
<li><a class="reference internal" href="#methods">Methods</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="signal.html"
title="previous chapter">The MathJax.Callback.Signal Class</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="outputjax.html"
title="next chapter">The MathJax.OutputJax Class</a></p>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="outputjax.html" title="The MathJax.OutputJax Class"
>next</a> |</li>
<li class="right" >
<a href="signal.html" title="The MathJax.Callback.Signal Class"
>previous</a> |</li>
<li><a href="../index.html">MathJax v2.0 documentation</a> &raquo;</li>
<li><a href="index.html" >The MathJax API</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012 Design Science.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
</div>
</body>
</html>