Blog de Frédéric - Tag - latexFrédéric Wang's Blog, about mathematics and computer science / Blog de Frédéric Wang, sur les mathématiques et l'informatique.2015-03-21T07:36:34+01:00Frédéric Wangurn:md5:856637f86f94ed5243b6f6f713360bdaDotclearTeXZilla 0.9.7 Releasedurn:md5:0ae4eb15265f3f161a5a8dc7f32caf482014-06-03T15:30:00+02:002014-06-03T15:36:39+02:00fredwlatexmathmlmozillatexzilla <p>Today the Mozilla MathML team released a new version of <a href="https://github.com/fred-wang/TeXZilla">TeXZilla</a>. You can download a <a href="https://github.com/fred-wang/TeXZilla/releases/tag/v0.9.7">release package</a> or install it with <code>npm</code>. We fixed a few bugs, but there are known issues due to errors in the <code>unicode.xml</code> file of
<a href="http://www.w3.org/TR/xml-entity-names/">XML Entity Definitions for Characters</a>
or inherited from the <a href="http://golem.ph.utexas.edu/~distler/blog/itex2MML.html">itex2MML</a> grammar that does not make it ready for version
1.0. The main improvements in this new release are enhancements to the
public API and to the command line interface.</p>
<h2>Stream filter</h2>
<p>TeXZilla can now be used as a stream filter. Each TeX expressions delimited
by the classical <code>$ ... $</code>, <code>$$ ... $$</code>, <code>\[ ... \]</code> and <code>\( ... \)</code> will be
converted into inline or display MathML.
Outside these delimiters, you can use <code>\$</code> and
<code>\\</code> as escaped characters. We offer three ways to apply that stream filter:</p>
<ul>
<li><p>From the command line, in a UNIX pipeline:</p>
<p><code>cat foo-tex.html | phantomjs TeXZilla.js streamfilter > foo-mathml.html</code></p>
<p><code>echo "This is a **Markdown** document with a *math formula*: $ z = \\sqrt{x^2 + y^2} $" | markdown | nodejs TeXZilla.js streamfilter | sed '1s/^/\n<!-- HTML5 document -->\n/'</code></p>
<p>(note: this is <a href="https://github.com/fred-wang/TeXZilla/issues/35">not yet supported by slimerjs</a>)</p></li>
<li><p>Using the <a href="https://github.com/fred-wang/TeXZilla/wiki/Public-API#texzillafilterstring">TeXZilla.filterString(aString)</a> function, for example
<code>TeXZilla.filterString("blah $x^2$ blah")</code> will return the filtered string.</p></li>
<li><p>Using the <a href="https://github.com/fred-wang/TeXZilla/wiki/Public-API#texzillafilterelement">TeXZilla.filterElement(aElement)</a> function. This one will browse
recursively the descendants of the DOM element <code>aElement</code> and the
stream filter will be applied to the text leaves.</p></li>
</ul>
<p>By introducting these <code>TeXZilla.filter*</code> function, it becomes
tempting to use TeXZilla the same way as MathJax, that is to process all the
text nodes in your Web pages and to filter the TeX strings. This is not the
intended goal of TeXZilla and it is strongly
discouraged: not only the MathML content won't appear in crawlers
(e.g. search engines or feed readers) but also
browsing all the DOM elements and appending new ones can be very slow for large
documents. Instead, it is recommend to filter your static Web page with
<code>commonJS TeXZilla.js streamfilter</code> before publishing it or to use a
server-side conversion for example using the <a href="https://github.com/fred-wang/TeXZilla/wiki/Advanced-Usages#using-texzilla-as-a-web-server">Web server mode</a>. There
are situations where you do not have other choice, though. In that
case try to reduce as much as possible the number of elements being processed
(see the example in the next section).
Of course, if you do not care about performance and MathML availibility
outside your web site, you can
just use <a href="https://developer.mozilla.org/en-US/docs/Web/MathML/Authoring#mathjax">MathJax</a>.</p>
<h2>New Safe and Itex-Identifier parsing modes</h2>
<p>The most notable difference between TeXZilla and itex2MML is the handling of
some expressions like <code>$xy$</code> or <code>$Func$</code>. By default,
TeXZilla interprets this as individual
MathML identifiers <code><mi>x</mi><mi>y</mi></code> (so that as in LaTeX, they will
render in italic) while itex2MML interprets this
as a single indentifier <code><mi>Func</mi></code>. It is now possible to configure
TeXZilla to align with itex2MML's behavior. To do that, use
<a href="https://github.com/fred-wang/TeXZilla/wiki/Public-API#texzillasetitexidentifiermode">TeXZilla.setItexIdentifierMode</a>
or pass the appropriate boolean to the command
line. Consecutive non-basic letters (like Greek or Arabic) are still treated as
individual tokens. With that change, we hope that TeXZilla could be used to
parse all the commands supported by itex2MML into an equivalent output.
Together with the command line stream filter, this should allow to recover
all the nice itex2MML features.</p>
<p>Similarly, a safe mode is now available and can be enabled
with <a href="https://github.com/fred-wang/TeXZilla/wiki/Public-API#texzillasetsafemode">TeXZilla.setSafeMode</a> or by passing the appropriate boolean to the command line. This mode will forbid commands that could
be used for XSS injections like <code>\href</code>. With that mode and the
new <code>TeXZilla.filterElement</code> function, I'm now able to remove MathJax's use from
my blog (users of browsers without good MathML support can still enable
it or choose the lighter <code>mathml.css</code> stylesheet). MathJax was a bit overkill
for my blog since I'm only parsing visitor comments. To illustrate how the
<code>setSafeMode</code> and <code>filterString</code> functions can be used, I now just
have to do</p>
<pre><code>// Process TeX fragments in blog comments and comment preview.
window.addEventListener("DOMContentLoaded", function() {
TeXZilla.setSafeMode(true);
var toProcess =
document.querySelectorAll("#comments > dl > dd, #comment-form dd.comment-preview");
for (var i = 0; i < toProcess.length; i++) {
TeXZilla.filterElement(toProcess[i]);
}
});
</code></pre>
<h2>Inserting equations in a 2D/WebGL canvas</h2>
<p>The new function <a href="https://github.com/fred-wang/TeXZilla/wiki/Public-API#texzillatoimage">TeXZilla.toImage</a> has been introduced to convert a TeX fragment into
a math HTML image with a base64-encoded <code>src</code> attribute.
Contrary to other functions of the API, this one needs to do some
work to determine the image size and perform the conversion, so it is unlikely
to work as expected in a non-browser context. The goal is really only to have a
convenient function to generate image of mathematical formulas and insert them
into a canvas context to draw 2D or 3D scientific schemas.
At the moment, this works well only in Gecko. For
instance,</p>
<pre><code>var image =
TeXZilla.toImage("\\vec{F} = G \\frac{m_1 m_2}{r^2} \\mathbf{u}");
image.onload = function() {
canvas.getContext("2d").drawImage(image,
(canvas.width - image.width) / 2,
(canvas.height - image.height) / 2);
}
</code></pre>
<p>will insert a mathematical formula in the middle of a 2D <code>canvas</code>. Similarly,
you can insert a mathematical formula as a texture in a WebGL canvas. It
is recommended to pass <code>aRoundToPowerOfTwo=true</code> to <code>TeXZilla.toImage</code>,
so that the image will
<a href="https://developer.mozilla.org/en-US/docs/Web/WebGL/Using_textures_in_WebGL#Non_power-of-two_textures">have dimensions that are power of two</a>. Note that
the mathematical formula will be automatically centered in the middle of the
generated image.
See <a href="http://fred-wang.github.io/TeXZilla/examples/toImageWebGL.html">this example</a> for how to setup the formulas with <a href="http://threejs.org/">three.js</a> and make
them always oriented in the direction of the camera.</p>
<p><a href="http://fred-wang.github.io/TeXZilla/examples/toImageWebGL.html"><img src="http://www.maths-informatique-jeux.com/blog/all-blogs/public/mathml/mathml-in-webgl.png" alt="MathML in WebGL" title="" /></a></p>
<h2>Integration in Mozilla products</h2>
<ul>
<li><p>The <a href="http://ckeditor.com/addon/texzilla">CKeditor editor plugin</a> is now
integrated in MDN, so you can click on the square root logo <img src="https://developer.cdn.mozilla.net/media/js/libs/ckeditor/plugins/texzilla/icons/texzilla.png" alt="square root logo" title="" /> in the editor toolbar to insert mathematical formulas.
By the way, the <a href="http://fred-wang.github.io/mathml.css/mathml.css">mathml.css</a>
is now used for browsers without MathML support. See for example
the pages for <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh#Polyfill">acosh</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh#Polyfill">atanh</a>
or <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform#matrix">CSS transform</a>.</p></li>
<li><p>The <code>editor/</code> in comm-central now integrates a small input box to insert mathematical formulas, accessible from the Insert menu. This will be available in Thunderbird 31 and Seamonkey 2.28, so that you can write mathematics in your emails and in the WYSIWYG editors.</p></li>
<li><p>Various <a href="https://github.com/fred-wang/TeXZilla/wiki/Applications--and-Web-pages-using-TeXZilla#firefox-os-web-apps">FirefoxOS Web math apps</a> have been written and use TeXZilla. Raniere is also working on a math keyboard for FirefoxOS as a <a href="http://blog.rgaiacs.com/tags/gsoc2014.html">GSoC project</a>, which will allow to type mathematics faster on mobile devices.</p></li>
</ul>TeXZilla 0.9.4 Releasedurn:md5:537ff152e61d2f4fa291da2a05fa41ef2014-02-25T21:20:00+01:002014-03-11T11:32:07+01:00fredwarabicbisonlatexmathmlmathzillamozillaunicode <p><strong>update 2014/03/11: TeXZilla is now available as an <a href="https://www.npmjs.org/package/texzilla">npm module</a>.</strong></p>
<h2>Introduction</h2>
<p>For the past two months, the Mozilla MathML team has been working on
<a href="http://fred-wang.github.io/TeXZilla/">TeXZilla</a>, yet another
LaTeX-to-MathML converter. The idea was to rely on
<a href="http://golem.ph.utexas.edu/~distler/blog/itex2MML.html">itex2MML</a> (which dates back from the beginning of the Mozilla MathML project) to
create a LaTeX parser such that:
</p>
<ul>
<li>It is compatible with the
<a href="http://golem.ph.utexas.edu/~distler/blog/itex2MMLcommands.html">itex2MML syntax</a> and is similarly generated from a LALR(1) grammar
(the goal is only to support a restricted set of core LaTeX commands for
mathematics, for a more complete converter of LaTeX documents see
<a href="https://github.com/brucemiller/LaTeXML">LaTeXML</a>).
</li>
<li>It is available as a standalone Javascript module
usable in all the Mozilla Web applications and add-ons (of course,
it will work in non-Mozilla products too).</li>
<li>It accepts any Unicode characters and supports right-to-left
mathematical notation
(these are important for the world-wide aspect of the Mozilla
community).
</li>
</ul>
<p>The parser is generated with the help of
<a href="http://zaach.github.io/jison/">Jison</a> and relies on a
grammar based on the one of itex2MML and on the
<code>unicode.xml</code> file of the
<a href="http://www.w3.org/TR/xml-entity-names/">XML Entity Definitions
for Characters specification</a>. As suggested by the version number,
this is still
<a href="https://github.com/fred-wang/TeXZilla/issues?state=open">in development</a>. However, we have made enough progress to
present interesting features here and get more
users and developers involved.
</p>
<h2>Quick Examples</h2>
<p><code>\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1</code></p>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mfrac><msup><mi>x</mi><mn>2</mn></msup><msup><mi>a</mi><mn>2</mn></msup></mfrac><mo>+</mo><mfrac><msup><mi>y</mi><mn>2</mn></msup><msup><mi>b</mi><mn>2</mn></msup></mfrac><mo>=</mo><mn>1</mn></mrow><annotation encoding="TeX">\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1</annotation></semantics></math>
<p><code>∑_{n=1}^{+∞} \frac{1}{n^2} = \frac{π^2}{6}</code></p>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><munderover><mo>∑</mo><mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow><mrow><mo>+</mo><mn>∞</mn></mrow></munderover><mfrac><mn>1</mn><msup><mi>n</mi><mn>2</mn></msup></mfrac><mo>=</mo><mfrac><msup><mi>π</mi><mn>2</mn></msup><mn>6</mn></mfrac></mrow><annotation encoding="TeX">∑_{n=1}^{+∞} \frac{1}{n^2} = \frac{π^2}{6}</annotation></semantics></math>
<p><code>س = \frac{-ب\pm\sqrt{ب^٢-٤اج}}{٢ا}</code></p>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>س</mi><mo>=</mo><mfrac><mrow><mo>-</mo><mi>ب</mi><mo>±</mo><msqrt><mrow><msup><mi>ب</mi><mn>٢</mn></msup><mo>-</mo><mn>٤</mn><mi>ا</mi><mi>ج</mi></mrow></msqrt></mrow><mrow><mn>٢</mn><mi>ا</mi></mrow></mfrac></mrow><annotation encoding="TeX">س = \frac{-ب\pm\sqrt{ب^٢-٤اج}}{٢ا}</annotation></semantics></math>
<h2>Live Demo / FirefoxOS Web app</h2>
<p>A <a href="http://fred-wang.github.io/TeXZilla/">live demo</a> is
available to let you test the LaTeX-to-MathML converter with various
options and examples. For people willing to use the converter on their
mobiles a <a href="http://r-gaia-cs.github.io/TeXZilla-webapp/">FirefoxOS Web app</a> is also available.</p>
<h2>Using TeXZilla in a CommonJS program or Web page</h2>
<p>TeXZilla is made of a single <code>TeXZilla.js</code> file with
a <a href="https://github.com/fred-wang/TeXZilla/wiki/Public-API">public
API</a> to convert LaTeX to MathML or extract the TeX source from a
MathML element. The converter accepts some options like
inline/display mode or RTL/LTR direction of mathematics.</p>
<p>You can load it the standard way in any Javascript
program and obtain a <code>TeXZilla</code> object that exposes the public
API.
For example in a commonJS program, to convert a TeX source into a MathML
source:</p>
<pre>
var TeXZilla = require("./TeXZilla");
console.log(TeXZilla.toMathMLString("\\sqrt{\\frac{x}{2}+y}"));
</pre>
<p>or in a Web Page, to convert a TeX source into a MathML DOM element:
<pre>
<script type="text/javascript" src="http://www.maths-informatique-jeux.com/blog/frederic/?post/2014/02/25/TeXZilla.js"></script>
...
var MathMLElement = TeXZilla.toMathML("\\sqrt{\\frac{x}{2}+y}");
</pre>
<h2>Using TeXZilla in Mozilla Add-ons</h2>
<p>One of the goal of TeXZilla is to be integrated in Mozilla add-ons,
allowing people to write cool math applications (in particular, we would
like to have an <a href="https://github.com/fred-wang/Mathzilla/issues/9">add-on for Thunderbird</a>).
A simple <a href="https://addons.mozilla.org/en-US/firefox/addon/texzilla/">Firefox add-on</a> has been written and passed the AMO review, which means
that you can safely include the <code>TeXZilla.js</code> script in your
own add-ons.
</p>
<p>TeXZilla can be used as an
<a href="https://github.com/mozilla/addon-sdk/wiki/Community-developed-modules">addon-sdk module</a>. However, if you intend to use features
requiring a DOMParser instance (for example <code>toMathML</code>),
you need to initialize the DOM explicitly:
</p>
<pre>
var {Cc, Ci} = require("chrome");
TeXZilla.setDOMParser(Cc["@mozilla.org/xmlextras/domparser;1"].
createInstance(Ci.nsIDOMParser));
</pre>
<p>More generally, for traditional Mozilla add-ons, you can do</p>
<pre>
TeXZilla.setDOMParser(Components.
classes["@mozilla.org/xmlextras/domparser;1"].
createInstance(Components.interfaces.nsIDOMParser));
</pre>
<h2>Using TeXZilla from the command line</h2>
<p>TeXZilla has a basic command line interface. However, since
<a href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> is still being
standardized, this may work inconsistently between commonjs interpreters.
We have tested it on <a href="http://slimerjs.org/">slimerjs</a> (which
uses Gecko),
<a href="http://phantomjs.org/">phantomjs</a> and
<a href="http://nodejs.org/">nodejs</a>. For example you can do
</p>
<pre> $ slimerjs TeXZilla.js parser "a^2+b^2=c^2" true
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><...
</pre>
<p>or launch a Web service (see next section). We plan to implement a stream
filter too so that it can behave the same as itex2MML: looking the LaTeX
fragments from a text document and converting them into MathML.</p>
<h2>Using TeXZilla as a Web Server</h2>
<p>TeXZilla can be used as a Web Server that receives POST and GET HTTP requests
with the LaTeX input and sends JSON replies with the MathML output. The typical
use case is for people willing to perform some server-side LaTeX-to-MathML conversion.</p>
<p>For instance, to start the TeXZilla Webserver on port 7777:</p>
<pre>
$ nodejs TeXZilla.js webserver 7777
Web server started on http://localhost:7777
</pre>
<p>Then you can sent a POST request:</p>
<pre> $ curl -H "Content-Type: application/json" -X POST -d '{"tex":"x+y","display":"true"}' http://localhost:7777
{"tex":"x+y","mathml":"<math xmlns=\"http://www.w3.org/1998/Math/MathML\"...
</pre>
<p>or a GET request:</p>
<pre> $ curl "http://localhost:7777/?tex=x+y&rtl=true"
{"tex":"x+y","mathml":"<math xmlns=\"http://www.w3.org/1998/Math/MathML\"...
</pre>
<p>Note that <a href="https://github.com/fred-wang/TeXZilla/wiki/Advanced-Usages#wiki-parsing-tex-expressions-in-your-web-page">client-side</a> conversion is trivial using the public API, but see the next section.</p>
<h2>Web Components Custom Element <x-tex></h2>
<p>We used the <a href="http://www.x-tags.org/">X-Tag</a> library
to implement a simple Web Components Custom Element
<a href="https://github.com/fred-wang/x-tex"><x-tex></a>. The idea is to
have a container for LaTeX expressions like</p>
<pre> <x-tex dir="rtl">س = \frac{-ب\pm\sqrt{ب^٢-٤اج}}{٢ا}</x-tex></pre>
<p>that will be converted into MathML by TeXZilla and displayed in your
browser:
<math dir="rtl" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>س</mi><mo>=</mo><mfrac><mrow><mo>-</mo><mi>ب</mi><mo>±</mo><msqrt><mrow><msup><mi>ب</mi><mn>٢</mn></msup><mo>-</mo><mn>٤</mn><mi>ا</mi><mi>ج</mi></mrow></msqrt></mrow><mrow><mn>٢</mn><mi>ا</mi></mrow></mfrac></mrow><annotation encoding="TeX">س = \frac{-ب\pm\sqrt{ب^٢-٤اج}}{٢ا}</annotation></semantics></math>. You can
set the display/dir attributes on that <code><x-tex></code> element
and they will be applied to the <code><math></code> element. Instances of
<code><x-tex></code> elements also have a <code>source</code> property that
you can use to retrieve or set the LaTeX source. Of course, the MathML output
will automatically be updated when dynamic changes occur. You can
try <a href="http://fred-wang.github.io/x-tex/demo/">this online demo</a>.</p>
<h2>CKEditor Plugins / Integration in MDN</h2>
<p>Finally, we created a first version of a
<a href="http://ckeditor.com/addon/texzilla">TeXZilla CKEditor plugin</a>. An online demo is
<a href="http://www.ime.unicamp.br/~ra092767/ck4/plugins/texzilla/samples/index.html">available here</a>.
We already sent a <a href="https://github.com/mozilla/kuma/pull/2038">pull request to Kuma</a> and we hope it will soon enable users to put mathematical <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Basic_Transformations#Complex_transformations_with_matrix%28%29">mathematical formulas in MDN articles</a> without having to paste the MathML into the source
code view. It could be enhanced later with a
<a href="https://github.com/r-gaia-cs/CKEditor-TeXZilla/issues/6">more advanced UI</a>.
</p>New MathML Firefox add-ons on AMOurn:md5:a826b3f19e0974de4a033d453c5298102014-01-29T13:07:00+01:002014-01-29T14:18:10+01:00fredwlatexlatexmlmathmlmathzillamediawikimozillawikipediaxpcom <p>While the patches for MathML integration in MediaWiki are
<a href="https://gerrit.wikimedia.org/r/#/projects/mediawiki/extensions/Math,dashboards/default">progressively being reviewed and merged</a> and
while we are working on the
<a href="http://www.maths-informatique-jeux.com/ulule/mathml_torture_test/">support for Open Type fonts with a MATH table</a> in Gecko, I finally
found time to check the progress in Mozilla's
<a href="https://developer.mozilla.org/en-US/Add-ons/SDK">add-on
SDK</a>. In particular, since the last time I tried (some years ago)
they have introduced a cleaner interface for content scripts as well
as the possibility to use XPCOM for missing features.
Hence I have been able to update some of my experimental MathML add-ons.
I have submitted two new add-ons to Mozilla's AMO that I hope
could be useful to some people:</p>
<ul>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/mathjax-native-mathml/">MathJax Native MathML</a>, an add-on to <strong>force MathJax to
switch to Gecko's MathML support</strong>
without having to use the MathJax menu to change the output mode
and works even on Websites where that menu is disabled.
This also removes MathJax's automatic rescaling and inline-block
<code>span</code> that are currently causing random rendering bugs
with Gecko's native MathML (and will confuse possible future
line-breaking support anyway).
<div style="width: 600px; margin-left: auto; margin-right: auto;">
<img src="https://addons.cdn.mozilla.net/img/uploads/previews/full/123/123814.png?modified=1390414386" width="600" alt="MathJax Native MathML"/>
</div>
</li>
<li>
<a href="https://addons.mozilla.org/en-US/firefox/addon/mathml-copy/">MathML Copy</a> (at the moment only partially reviewed by the AMO team), an
add-on to <strong>copy MathML and TeX into the clipboard</strong>.
For MathML, two flavors are copied: the source as plain text
(to paste in your favorite text editor)
and the MathML as HTML
(to paste in Thunderbird, MDN, any Gecko-based
HTML editor etc). Copying TeX
is only possible when it is provided via the
<a href="https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics">standard MathML
annotation method</a>, which is the case in e.g.
<a href="http://dlmf.nist.gov/LaTeXML/">LaTeXML</a> and
<a href="http://golem.ph.utexas.edu/wiki/instiki/show/Sandbox">Instiki</a>
documents as well as in <a href="https://gerrit.wikimedia.org/r/#/c/109486/">Wikipedia in the future</a>.
<div style="width: 600px; margin-left: auto; margin-right: auto;">
<img src="https://addons.cdn.mozilla.net/img/uploads/previews/full/124/124088.png?modified=1390660049" width="600" alt="MathML Copy"/>
</div>
</li>
</ul>
<p>As usual, there is room for <a href="https://github.com/fred-wang/Mathzilla/issues">improvements and bug fixes</a>, but that's a start. In particular
I would be happy to get
<a href="https://github.com/fred-wang/Mathzilla/issues/1">translations for the two strings of the
MathML Copy add-on</a>: "Copy MathML Formula" and "Copy TeX Source".
Also, because I used the add-on SDK these add-ons are unfortunately
only available for Firefox at the moment...
</p>Writing mathematics in emailsurn:md5:2885206ad0af181ba11570d6641fac3f2012-11-14T20:35:00+01:002012-11-14T21:38:28+01:00fredwappleemaillatexmathjaxmathmlmicrosoftmozilla <p>People writing mathematics in emails, like researchers in mathematics or
physics, have probably encountered this difficulty to properly format complex
mathematical formulas. The most common technique is just to write text with
LaTeX-like or ASCIIMathML-like syntax and hope that the recipient will just
understand the expressions. Obviously, this is not really convenient to write
and read, some errors may happen and result in misunderstandings between the
sender and the recipient. There are other classical issues like how to write
the math (special syntax? math panel? handwriting recognition?), accessibility,
rendering quality etc Of course, these issues are well-known and expected to be
addressed by MathML. Since HTML is a common format for email and MathML is now
part of HTML5, this is clearly a good candidate to solve the problem of
mathematics in emails.</p>
<p>The idea to use MathML in emails is not new and was already suggested in <a
href="http://www-archive.mozilla.org/projects/mathml/screenshots/mathmail.gif">a
screenshot from the Mozilla MathML Project</a> more than 10 years ago.
Thunderbird has been able to render <a
href="https://developer.mozilla.org/files/2993/mail_client_blog.png">MathML in
newsfeeds</a> for a long time, provided that the author served his content as
XHTML. I may also mention Amaya, which added support for sending a document by
email in 2007, although I have never figured out how to configure it to send
emails. Two years ago, I tried without success to fix a bug to <a
href="https://bugzilla.mozilla.org/show_bug.cgi?id=235629">display XHTML
attachment inline</a> and which could be a partial solution to the problem.
Finally, one year ago Bob Mathews (from Design Science) asked me about the
status of MathML in Thunderbird, and I could unfortunately not give him a
better answer than what is in the present paragraph. But I hoped that MathML in
HTML5 will change the situation.</p>
<p>Indeed, while I was working on some MathML-in-clipboard patches, I realized
that it is now possible to paste MathML inside an email. After further
discussions with Bob Mathews, Paul Topping & David Carlisle, I've been able
to do more testing. The situation is the following:</p>
<ul>
<li>Thunderbird can send emails containing MathML and render them
correctly.</li>
<li>Apple Mail (used in Mac OS X and iOS) can receive emails containing
MathML and should render them correctly since MathML
is enabled in Apple's products.</li>
<li>Microsoft Outlook does not render MathML in emails. However the rendering
is based on Microsoft Word which has MathML support. Basically, Thunderbird
sends MathML in HTML5 and Word displays MathML after an XSLT conversion
into Microsoft's own OMML format. Hence Microsoft might be able to do
something not too complicated to make the whole stuff work.</li>
<li>Web Mail Clients like Gmail or Zimbra seem to filter the MathML in emails
and so do not render it correctly. If this filter is removed, they can
certainly let the browser do the rendering job or use MathJax to do so.</li>
</ul>
<p>Now let's consider a basic example about how to send MathML in emails, using
Thunderbird. One of the issue is that Gecko's editor has really been designed
with only HTML-editing features in mind and if you start editing MathML formulas you are
going to get some invalid markup messages or other troubles. And of course
Thunderbird does not have any math panel or other WYSIWYG tools to write
mathematics. However it might not be too difficult to write an add-on to add
MathML editing features in Thunderbird like <a
href="http://www.bluegriffon.com/index.php?pages/MathML">BlueGriffon's
add-on</a> or <a href="http://www.firemath.info/">Firemath</a> (these add-on
might even be installed without too much trouble in Thunderbird). Or one can of
course use one of the <a href="http://www.w3.org/Math/Software/">existing
tools to generate MathML</a> and just paste the code in Thunderbird. Here I'm
going to use the <code>itex2MML</code> filter. So first write your mail in a
separate text file:</p>
<pre>mail.txt
Hi Matthew, I just read your email about the behavior of the factorial function and harmonic series for large values of $n$. If you denote by $\gamma \approx 0.5772156649$ the Euler's number, by $e \approx 2.7182818284$ the Euler's constant then you have the well-known Stirling's approximation:
$$n! = \sqrt{2 \pi n} {\left( \frac{n}{e} \right)}^n \left( 1 + O \left( \frac{1}{n} \right) \right)$$
where of course I use the classical constant $\pi \approx 3.1415926535$. We also have the following asymptotic expansion:
$$\sum_{k=1}^n \frac{1}{k} = \ln(n) + \gamma + O \left( \frac{1}{n} \right)$$
I hope that this answers your question.</pre>
<p>then call <code>itex2MML</code> to replace the LaTeX code by
<code><math></code> elements:</p>
<pre>cat mail.txt | itex2MML > mail.html</pre>
<p>Write a new mail in Thunderbird and use the menu "Insert ; HTML" . David
Carlisle told me that you have to be sure that the "send as HTML" is enabled if
it does not show up. Then just copy the <code>mail.html</code> source into the
window:</p>
<p><img alt="insert MathML" src="http://www.maths-informatique-jeux.com/blog/all-blogs/public/mathml-in-emails/insertHTML-mathml.png"
style="display: block; text-align: center; margin-left: auto; margin-right: auto"
width="427" height="407" /></p>
<p>Once you click the insert button, the MathML should be automatically
rendered in Thunderbird:</p>
<p><img alt="MathML in Thunderbird" src="http://www.maths-informatique-jeux.com/blog/all-blogs/public/mathml-in-emails/mathml-thunderbird.png"
style="display: block; text-align: center; margin-left: auto; margin-right: auto"
width="683" height="619" /></p>
<p>When your email is ready, just send it as usual! Here is how it appears on
an iPod:</p>
<p><img alt="MathML in Apple Mail" src="http://www.maths-informatique-jeux.com/blog/all-blogs/public/mathml-in-emails/mathml-ipod.png"
style="display: block; text-align: center; margin-left: auto; margin-right: auto"
width="300" height="450" /> </p>
<p>Let's just hope that other mail clients will support MathML in emails!</p>Master Thesis, LaTeXML and Quantum Groups (part 1)urn:md5:e969612a6ea9961eb7cbe277ff8d2c8d2012-09-13T23:43:00+02:002012-09-14T00:38:29+02:00fredwlatexlatexmlmathjaxmathmlmozillaquantum groupswebsite updates <p>I wanted to wait for my oral defense before blogging about my master thesis
and how I manage to publish Web and paper versions of it. However, I finally met
my supervisor today and the oral defense is only likely to take
place next Wednesday. I do not want to delay too much this blog post and
thus decided to publish it today...</p>
<p>This year, I have taken the following approach to write my master thesis:
from LaTeX input files, I used XeLaTeX to generate a pdf document and LaTeXML
to generate HTML+MathML Web pages. I had to handle some small differences via
separate configuration files. However in general, these two tools are compatible
and accept more or less the same LaTeX input. I did not really have to make
graphics: I only used the <code>amscd</code> package to draw simple commutative
diagrams and did not try to draw schemas for representations of quantum groups.
Hence I did not get the opportunity to test how LaTeXML can generate
MathML inside SVG, although I saw on July something interesting for Firefox on
the LaTeXML mailing list.</p>
<p>The pdf version provides a good print layout which allows to workaround
some issues that I had two years ago when I printed
<a href="http://www.maths-informatique-jeux.com/blog/frederic/?post/2010/07/24/Using-Mozilla-to-print-a-scientific-report-based-on-Web-formats">my Master Thesis
in Computer Science</a> directly from Firefox. XeLaTeX also seems much faster
and so more convenient to use when you only want to check that your LaTeX code
is syntactically
correct and get a quick preview. It seems that XeLaTeX uses a kind of cache:
there are intermediary files that I guess are used again when you regenerate
the document. In contrast, LaTeXML seems to always regenerate one big XML file
in a first step and the Web pages in a second step. Perhaps LaTeXML has an
option to avoid that behavior or perhaps the idea of a cache system
does not work well in the case of Web pages.</p>
<p>The output of LaTeXML has the classical advantages of HTML+MathML for
publication on the Web and is much more comfortable to read on a screen.
Generally speaking, I think Firefox renders pretty well the LaTeXML output.
LaTeXML generates HTML rows to implement labelling and does not rely on
<code>mathvariant</code>, which allow to avoid issues with
<code><mlabeledtr></code> and token elements. However, I still note some
MathML's rendering imperfections which, not surprisingly, have already be
mentioned in the <a
href="http://www.maths-informatique-jeux.com/blog/frederic/?post/2012/09/01/Mozilla-MathML-Project%3A-Roadmap">MathML
project roadmap</a>:</p>
<ul>
<li>Linebreaking: bad line breaks inside some equations, apparently those
generated by some environments like <code>multline</code> or
<code>gathered</code>. Sometimes, I also see bad line breaks around
equations for example when they are inside parenthesis.</li>
<li>Spacing: the lack of support for
<code>mtable@rowspacing/columnspacing</code> seems to give wrong spacing
inside binom-like notations. For some reason LaTeXML generates
<code><mpadded></code> elements of zero width in some places and they
cause weird overlappings in some summations.</li>
<li>Operator Stretching: commutative diagrams in the definition of Hopf
algebras would look better if we support stretching operators in table
cells.</li>
</ul>
<p>This also gives me the opportunity to report various bugs and give some
suggestions to the LaTeXML team, including the use of MathJax (for
browsers without MathML support), the replacement of
<code><mfenced></code> by the equivalent <code><mrow></code>,
<code><mo></code> constructions (better rendering in Firefox),
improvement to the generation of headers in HTML5 and more.</p>
<p>The title of my master thesis is <a href="http://www.maths-informatique-jeux.com/maths/memoire_groupes_quantiques/">"Specialization of Quantum Groups at a Root of Unity and Finite Dimensional Representations"</a>. The concept of
<a href="http://en.wikipedia.org/wiki/Quantum_group">Quantum
Groups</a> is based on ideas from theoretical physics, but I studied these
structures from a purely algebraic point of view. That is not likely to be
interesting if you have never heard about Lie algebras or are not familiar with
representation theory, so I will present
<a href="http://www.maths-informatique-jeux.com/blog/frederic/?post/2012/09/13/Master-Thesis,-LaTeXML-and-Quantum-Groups-(part-2)">my contribution in a separate blog post</a>.</p>