asciimath.html 12.4 KB
Newer Older
Matthew Mongeau committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

<!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>MathJax AsciiMath Support &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="next" title="MathJax Output Formats" href="output.html" />
    <link rel="prev" title="MathJax MathML Support" href="mathml.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="output.html" title="MathJax Output Formats"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mathml.html" title="MathJax MathML Support"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">MathJax v2.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="mathjax-asciimath-support">
<span id="asciimath-support"></span><h1>MathJax AsciiMath Support<a class="headerlink" href="#mathjax-asciimath-support" title="Permalink to this headline"></a></h1>
<p>The support for <a class="reference internal" href="glossary.html#term-asciimath"><em class="xref std std-term">AsciiMath</em></a> in MathJax consists of two parts:
the <cite>asciimath2jax</cite> preprocessor, and the <cite>AsciiMath</cite> input processor.
The first of these looks for mathematics within your web page
(indicated by delimiters like <tt class="docutils literal"><span class="pre">`...`</span></tt>) and marks the mathematics for
later processing by MathJax.  The AsciiMath input processor is what
converts the AsciiMath notation into MathJax&#8217;s internal format, where
one of MathJax&#8217;s output processors then displays it in the web page.</p>
<p>The AsciiMath input jax actually includes a copy of Peter Jipsen&#8217;s
<tt class="docutils literal"><span class="pre">ASCIIMathML.js</span></tt> file (see the <a class="reference external" href="http://www1.chapman.edu/~jipsen/mathml/asciimath.html">AsciiMath home page</a> for
details), and is included by permission of the author.  This means
that the results of MathJax&#8217;s AsciiMath processing should be the same
as using the actual <tt class="docutils literal"><span class="pre">ASCIIMathML.js</span></tt> package (at least as far as the
MathML that it generates is concerned).  Thanks go to David Lippman
for writing the initial version of the AsciiMath preprocessor and
input jax.</p>
<p>The <cite>asciimath2jax</cite> preprocessor can be configured to look for whatever
markers you want to use for your math delimiters.  See the
<a class="reference internal" href="options/asciimath2jax.html#configure-asciimath2jax"><em>asciimath2jax configuration options</em></a> section for
details on how to customize the action of <cite>asciimath2jax</cite>.</p>
<p>The AsciiMath input processor handles conversion of your mathematical
notation into MathJax&#8217;s internal format (which is essentially MathML).
The AsciiMath input processor has few configuration options (see the
<a class="reference internal" href="options/AsciiMath.html#configure-asciimath"><em>AsciiMath options</em></a> section for details).</p>
<p>The AsciiMath input jax handles only the original ASCIIMathML notation
(from ASCIIMathML v1.4.7), not the extened LaTeXMathML notation added
in version 2.0 of ASCIIMathML, though the AsciiMath input jax does
expose the tables that define the symbols that AsciiMath processes,
and so it would be possible to extend them to include additional
symbols.  In general, it is probably better to use MathJax&#8217;s <a class="reference internal" href="tex.html#tex-support"><em>TeX
input jax</em></a> to handle LaTeX notation instead.</p>
<div class="section" id="asciimath-delimiters">
<h2>AsciiMath delimiters<a class="headerlink" href="#asciimath-delimiters" title="Permalink to this headline"></a></h2>
<p>By default, the <cite>asciimath2jax</cite> preprocessor defines the back-tick
(<tt class="docutils literal"><span class="pre">`</span></tt>) as the delimiters for mathematics in AsciiMath format.  It
does <strong>not</strong> define <tt class="docutils literal"><span class="pre">$...$</span></tt> as math delimiters.  That is because
dollar signs appear too often in non-mathematical settings, which
could cause some text to be treated as mathematics unexpectedly.  For
example, with single-dollar delimiters, &#8221;... the cost is $2.50 for the
first one, and $2.00 for each additional one ...&#8221; would cause the
phrase &#8220;2.50 for the first one, and&#8221; to be treated as mathematics
since it falls between dollar signs.  For this reason, if you want to
use single-dollars for AsciiMath notation, you must enable that
explicitly in your configuration:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="nx">MathJax</span><span class="p">.</span><span class="nx">Hub</span><span class="p">.</span><span class="nx">Config</span><span class="p">({</span>
  <span class="nx">asciimath2jax</span><span class="o">:</span> <span class="p">{</span>
    <span class="nx">delimiters</span><span class="o">:</span> <span class="p">[[</span><span class="s1">&#39;$&#39;</span><span class="p">,</span><span class="s1">&#39;$&#39;</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;`&#39;</span><span class="p">,</span><span class="s1">&#39;`&#39;</span><span class="p">]]</span>
  <span class="p">}</span>
<span class="p">});</span>
</pre></div>
</div>
<p>Note that the dollar signs are frequently used as a delimiter for
mathematics in the <a class="reference internal" href="glossary.html#term-tex"><em class="xref std std-term">TeX</em></a> format, and you can not enable the
dollar-sign delimiter for both.  It is probably best to leave dollar
signs for TeX notation.</p>
<p>See the <tt class="docutils literal"><span class="pre">config/default.js</span></tt> file, or the <a class="reference internal" href="options/asciimath2jax.html#configure-asciimath2jax"><em>asiimath2jax
configuration options</em></a> page, for additional
configuration parameters that you can specify for the <cite>asciimath2jax</cite>
preprocessor, which is the component of MathJax that identifies
AsciiMath notation within the page.</p>
</div>
<div class="section" id="asciimath-in-html-documents">
<h2>AsciiMath in HTML documents<a class="headerlink" href="#asciimath-in-html-documents" title="Permalink to this headline"></a></h2>
<p>The AsciiMath syntax is descibed in the <a class="reference external" href="http://www1.chapman.edu/~jipsen/mathml/asciimathsyntax.html">ASCIIMathML syntax page</a>.</p>
<p>Keep in mind that your mathematics is part of an HTML document, so you
need to be aware of the special characters used by HTML as part of its
markup.  There cannot be HTML tags within the math delimiters (other
than <tt class="docutils literal"><span class="pre">&lt;BR&gt;</span></tt>) as AsciiMath-formatted math does not include HTML tags.
Also, since the mathematics is initially given as text on the page,
you need to be careful that your mathematics doesn&#8217;t look like HTML
tags to the browser (which parses the page before MathJax gets to see
it).  In particular, that means that you have to be careful about
things like less-than and greater-than signs (<tt class="docutils literal"><span class="pre">&lt;</span></tt> and <tt class="docutils literal"><span class="pre">&gt;</span></tt>), and
ampersands (<tt class="docutils literal"><span class="pre">&amp;</span></tt>), which have special meaning to the browsers.  For
example,</p>
<div class="highlight-html"><pre>... when `x&lt;y` we have ...</pre>
</div>
<p>will cause a problem, because the brower will think <tt class="docutils literal"><span class="pre">&lt;y</span></tt> is the
beginning of a tag named <tt class="docutils literal"><span class="pre">y</span></tt> (even though there is no such tag in
HTML).  When this happens, the browser will think the tag continues up
to the next <tt class="docutils literal"><span class="pre">&gt;</span></tt> in the document (typically the end of the next
actual tag in the HTML file), and you may notice that you are missing
part of the text of the document.  In the example above, the &#8220;<tt class="docutils literal"><span class="pre">we</span>
<span class="pre">have</span> <span class="pre">...</span></tt>&#8221; will not be displayed because the browser thinks it is
part of the tag starting at <tt class="docutils literal"><span class="pre">&lt;y</span></tt>.  This is one indication you can
use to spot this problem; it is a common error and should be avoided.</p>
<p>Usually, it is sufficient to simply put spaces around these symbols to
cause the browser to avoid them, so</p>
<div class="highlight-html"><pre>... when `x &lt; y` we have ...</pre>
</div>
<p>should work.  Alternatively, you can use the HTML entities <tt class="docutils literal"><span class="pre">&amp;lt;</span></tt>,
<tt class="docutils literal"><span class="pre">&amp;gt;</span></tt> and <tt class="docutils literal"><span class="pre">&amp;amp;</span></tt> to encode these characters so that the browser
will not interpret them, but MathJax will.  E.g.,</p>
<div class="highlight-html"><div class="highlight"><pre>... when `x <span class="ni">&amp;lt;</span> y` we have ...
</pre></div>
</div>
<p>Keep in mind that the browser interprets your text before MathJax
does.</p>
</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="#">MathJax AsciiMath Support</a><ul>
<li><a class="reference internal" href="#asciimath-delimiters">AsciiMath delimiters</a></li>
<li><a class="reference internal" href="#asciimath-in-html-documents">AsciiMath in HTML documents</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="mathml.html"
                        title="previous chapter">MathJax MathML Support</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="output.html"
                        title="next chapter">MathJax Output Formats</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="output.html" title="MathJax Output Formats"
             >next</a> |</li>
        <li class="right" >
          <a href="mathml.html" title="MathJax MathML Support"
             >previous</a> |</li>
        <li><a href="index.html">MathJax v2.0 documentation</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>