MathJax: Difference between revisions

From miki
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
__TOC__

'''[http://www.mathjax.org/ MathJax]''' is a client-side javascript that allows for very nice rendering of formula written in LaTeX, much like [[jsMath]].
'''[http://www.mathjax.org/ MathJax]''' is a client-side javascript that allows for very nice rendering of formula written in LaTeX, much like [[jsMath]].


Line 7: Line 9:
* Better LaTeX support
* Better LaTeX support


On MediaWiki, MathJax is available either in the [http://www.mediawiki.org/wiki/Extension:Math Math extension] (as an optional renderer) or in the [http://www.mediawiki.org/wiki/Extension:MathJax MathJax extension]. The later option is better since it allows for the more natural and lighter notation <code>$ ... $</code>.
On MediaWiki, MathJax is available either in the [http://www.mediawiki.org/wiki/Extension:Math Math extension] (as an optional renderer) or in the [http://www.mediawiki.org/wiki/Extension:MathJax MathJax extension]. The later option provides more functionality (like support for \begin...\end tags). However, this version does not work anymore on recent Mediawiki version, and I use a forked version of [http://www.mediawiki.org/wiki/Extension:SimpleMathJax SimpleMathJax extension].



== Links ==
Note that '''[[KaTeX]]''' seems a superior alternative to MathJax.
* [https://github.com/susam/texme#texme TeXMe] ([https://susam.github.io/texme/examples/demo.html demo]) &mdash; A self-rendering Markdown + MathJax documents
* '''[[KaTeX]]''' &mdash; seems a superior alternative to MathJax.


== Configuration ==
== Configuration ==
Line 30: Line 33:
<!---__M&#65;THJ&#65;X_DOLLAR__ --->
<!---__M&#65;THJ&#65;X_DOLLAR__ --->
</pre>
</pre>
<!---__MATHJAX_DOLLAR__ --->


== Examples ==
== Examples ==
Line 67: Line 71:
$$
$$
We consider, for various values of $s$, the $n$-dimensional integral
We consider, for various values of $$s$$, the $$n$$-dimensional integral
\begin{align}
\begin{align}
\label{def:Wns}
\label{def:Wns}
Line 77: Line 81:
which occurs in the theory of uniform random walk integrals in the plane,
which occurs in the theory of uniform random walk integrals in the plane,
where at each step a unit-step is taken in a random direction. As such,
where at each step a unit-step is taken in a random direction. As such,
the integral \eqref{def:Wns} expresses the $s$-th moment of the distance
the integral \eqref{def:Wns} expresses the $$s$$-th moment of the distance
to the origin after $n$ steps.
to the origin after $$n$$ steps.
By experimentation and some sketchy arguments we quickly conjectured and
By experimentation and some sketchy arguments we quickly conjectured and
strongly believed that, for $k$ a nonnegative integer
strongly believed that, for $$k$$ a nonnegative integer
\begin{align}
\begin{align}
\label{eq:W3k}
\label{eq:W3k}
W_3(k) &= \Re \, \pFq32{\frac12, -\frac k2, -\frac k2}{1, 1}{4}.
W_3(k) &= \Re \, \pFq32{\frac12, -\frac k2, -\frac k2}{1, 1}{4}.
\end{align}
\end{align}
Appropriately defined, \eqref{eq:W3k} also holds for negative odd integers.
Appropriately defined, $$\eqref{eq:W3k}$$ also holds for negative odd integers.
The reason for \eqref{eq:W3k} was long a mystery, but it will be explained
The reason for $$\eqref{eq:W3k}$$ was long a mystery, but it will be explained
at the end of the paper.
at the end of the paper.



Latest revision as of 07:08, 1 February 2022

MathJax is a client-side javascript that allows for very nice rendering of formula written in LaTeX, much like jsMath.

The advantages of MathJax over jsMath:

  • MathJax seems actively developed for now
  • MathJax uses server-side fonts, and so does not require any configuration on the client side to get better results
  • MathJax supports LaTeX macros
  • Better LaTeX support

On MediaWiki, MathJax is available either in the Math extension (as an optional renderer) or in the MathJax extension. The later option provides more functionality (like support for \begin...\end tags). However, this version does not work anymore on recent Mediawiki version, and I use a forked version of SimpleMathJax extension.

Links

  • TeXMe (demo) — A self-rendering Markdown + MathJax documents
  • KaTeX — seems a superior alternative to MathJax.

Configuration

  • Single dollar notation breaks too many things. We disable it permanently, and use double-dollar instead.
--- a/mwMathJaxConfig.js
+++ b/mwMathJaxConfig.js
-                  inlineMath: [ ['$','$'], ["\\(","\\)"] ],
+                  inlineMath: [ ['$$','$$'], ["\\(","\\)"] ],
-                  displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
+                  displayMath: [ ["\\[","\\]"] ],

Enable dollar notation

MathJax supports inline style math with a single dollar ($...$), but this breaks many pages that contain sample code (like bash scripts). So by default, this notation is disabled. To enable it, insert in the page the following keyword (typically in an html comment) __MATHJAX_DOLLAR__. For instance:

<!---__MATHJAX_DOLLAR__ --->

Examples

Some simple examples.

formula Textstyle (<math>...</math> , $$...$$ or \(...\)) Displaystyle (:<math>...</math> or \[...\])
\frac{x}{1+\frac{x}{1+y}}
$$\frac{x}{1+\frac{x}{1+y}}$$ :<math>\frac{x}{1+\frac{x}{1+y}}</math>
\newcommand{\ud}{\,\mathrm{d}}
\int_a^b f(x)\ud x

$$\newcommand{\ud}{\,\mathrm{d}}$$

\(\int_0^\infty f(x)\ud x\) \[\int_0^\infty f(x)\ud x\]
An Identity of Ramanujan <math>\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } }</math> :<math>\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =

1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } }</math>

LaTeX environments can be easily started with \begin{...}...\end{...}. For instance (from [1]):

$$

 \newcommand{\Re}{\mathrm{Re}\,}
 \newcommand{\pFq}[5]{{}_{#1}\mathrm{F}_{#2} \left( \genfrac{}{}{0pt}{}{#3}{#4} \bigg| {#5} \right)}

$$

We consider, for various values of $$s$$, the $$n$$-dimensional integral \begin{align}

 \label{def:Wns}
 W_n (s)
 &:= 
 \int_{[0, 1]^n} 
   \left| \sum_{k = 1}^n \mathrm{e}^{2 \pi \mathrm{i} \, x_k} \right|^s \mathrm{d}\boldsymbol{x}

\end{align} which occurs in the theory of uniform random walk integrals in the plane, where at each step a unit-step is taken in a random direction. As such, the integral \eqref{def:Wns} expresses the $$s$$-th moment of the distance to the origin after $$n$$ steps.

By experimentation and some sketchy arguments we quickly conjectured and strongly believed that, for $$k$$ a nonnegative integer \begin{align}

 \label{eq:W3k}
 W_3(k) &= \Re \, \pFq32{\frac12, -\frac k2, -\frac k2}{1, 1}{4}.

\end{align} Appropriately defined, $$\eqref{eq:W3k}$$ also holds for negative odd integers. The reason for $$\eqref{eq:W3k}$$ was long a mystery, but it will be explained at the end of the paper.

Troubleshooting

Conflict with other extensions

Conflicts with:

  • footnote (from Debian repository)
  • semantic wiki

This might be related to the bug:

The fix for footnote is to use recursiveTagParse:

diff --git a/footnote.php b/footnote.php
index 4d5c052..17c7fab 100644
--- a/footnote.php
+++ b/footnote.php
@@ -77,7 +77,7 @@ function insert_endnotes( &$parser, &$text ) {
     return true;
 }
 
-function parse_footnote( $text, $params, $parser ) {
+function parse_footnote( $text, array $params, Parser $parser, PPFrame $frame ) {
     $ret = "" ;
 
     global $footnoteNotes , $footnoteCount, $footnoteRecursionGuard ;
@@ -88,8 +88,7 @@ function parse_footnote( $text, $params, $parser ) {
     }
 
     $footnoteRecursionGuard = true;
-    $ret = $footnoteParserObj->parse( $text , $parser->getTitle() , $parser->getOptions(), false ) ;
-    $ret = $ret->getText();
+    $ret = $parser->recursiveTagParse( $text, $frame );
     $footnoteRecursionGuard = false;
 
     $footnoteNotes[$footnoteCount] = $ret;

MathJax not loading on HTTPS

When loading a page from https, make sure to fetch MathJax javascript from https as well. For instance, in mediawiki, use the URL:

# Must use https CDN since the wiki is served through https
MathJax_Parser::$MathJaxJS = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';