From 1748a29ff3b7cbbe72616d82f00063ac164942f9 Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Mon, 12 Aug 2013 09:21:38 -0400
Subject: first version of mathjax plugin #531
---
plugin/math/math.js | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100755 plugin/math/math.js
(limited to 'plugin/math')
diff --git a/plugin/math/math.js b/plugin/math/math.js
new file mode 100755
index 0000000..3efe321
--- /dev/null
+++ b/plugin/math/math.js
@@ -0,0 +1,37 @@
+/**
+ * A plugin which enables rendering of math equations inside
+ * of reveal.js slides. Essentially a thin wrapper for MathJax.
+ *
+ * @author Hakim El Hattab
+ */
+(function(){
+
+ var head = document.querySelector( 'head' );
+ var script = document.createElement( 'script' );
+ script.type = 'text/javascript';
+ script.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG-full';
+
+ // Detect when the script has loaded
+ script.onload = onScriptLoad;
+ script.onreadystatechange = function() {
+ if ( this.readyState === 'loaded' ) {
+ onScriptLoad.call();
+ }
+ }
+
+ head.appendChild( script );
+
+ function onScriptLoad() {
+
+ MathJax.Hub.Config({
+ messageStyle: 'none',
+ tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
+ });
+
+ Reveal.addEventListener( 'slidechanged', function( event ) {
+ MathJax.Hub.Rerender();
+ } );
+
+ }
+
+})();
--
cgit v1.2.3
From 9984cb1f2189b489afd7b05077c319fd123365af Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Mon, 12 Aug 2013 09:27:23 -0400
Subject: limit scope of mathjax rerender #531
---
plugin/math/math.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'plugin/math')
diff --git a/plugin/math/math.js b/plugin/math/math.js
index 3efe321..30dd38c 100755
--- a/plugin/math/math.js
+++ b/plugin/math/math.js
@@ -29,7 +29,7 @@
});
Reveal.addEventListener( 'slidechanged', function( event ) {
- MathJax.Hub.Rerender();
+ MathJax.Hub.Update( event.currentSlide );
} );
}
--
cgit v1.2.3
From 69f7c0c69338a966841b3ecd4bd97df00bf28dbb Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Mon, 12 Aug 2013 22:42:14 -0400
Subject: updates to mathjax plugin, incl more examples #531
---
examples/math.html | 38 ++++++++++++++++++++++++++++++++------
plugin/math/math.js | 13 ++++++++++++-
2 files changed, 44 insertions(+), 7 deletions(-)
(limited to 'plugin/math')
diff --git a/examples/math.html b/examples/math.html
index 49d4952..67fa546 100644
--- a/examples/math.html
+++ b/examples/math.html
@@ -15,7 +15,7 @@
-
+
@@ -32,11 +32,12 @@
- Reveal.js Math Plugin
+ reveal.js Math Plugin
+ A thin wrapper for MathJax
- The Lorenz Equations
+ The Lorenz Equations
\[\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
@@ -45,13 +46,13 @@
- The Cauchy-Schwarz Inequality
+ The Cauchy-Schwarz Inequality
\[ \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) \]
- A Cross Product Formula
+ A Cross Product Formula
\[\mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
@@ -61,13 +62,36 @@
- An Identity of Ramanujan
+ The probability of getting \(k\) heads when flipping \(n\) coins is
+
+ \[P(E) = {n \choose k} p^k (1-p)^{ n-k} \]
+
+
+
+ An Identity of Ramanujan
\[ \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} } } } \]
+
+ A Rogers-Ramanujan Identity
+
+ \[ 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots =
+ \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}\]
+
+
+
+ Maxwell’s Equations
+
+ \[ \begin{aligned}
+ \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
+ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
+ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{aligned}
+ \]
+
+
@@ -78,6 +102,8 @@
@@ -185,10 +187,7 @@
},
dependencies: [
- { src: '../lib/js/classList.js', condition: function() { return !document.body.classList; } },
- { src: '../plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
- { src: '../plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
- { src: '../plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
+ { src: '../lib/js/classList.js' },
{ src: '../plugin/math/math.js', async: true }
]
});
diff --git a/plugin/math/math.js b/plugin/math/math.js
index 78856a5..d021fdc 100755
--- a/plugin/math/math.js
+++ b/plugin/math/math.js
@@ -6,37 +6,28 @@
*/
var RevealMath = window.RevealMath || (function(){
- var loaded = false;
-
var config = Reveal.getConfig().math || {};
config.host = config.host || 'http://cdn.mathjax.org/mathjax/latest/MathJax.js';
config.mode = config.mode || 'TeX-AMS_HTML-full';
loadScript( config.host + '?config=' + config.mode, function() {
- // Conditioned just in case both onload and readystate fire
- if( loaded === false ) {
- loaded = true;
-
- MathJax.Hub.Config({
- messageStyle: 'none',
- tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
- });
+ MathJax.Hub.Config({
+ messageStyle: 'none',
+ tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
+ });
- // Process any math inside of the current slide when navigating,
- // this is needed since it's not possible to typeset equations
- // within invisible elements (far future or past).
- Reveal.addEventListener( 'slidechanged', function( event ) {
+ // Process any math inside of the current slide when navigating,
+ // this is needed since it's not possible to typeset equations
+ // within invisible elements (far future or past).
+ Reveal.addEventListener( 'slidechanged', function( event ) {
- // This will only typeset equations that have not yet been
- // processed, as well as equations that have change since
- // last being processed.
- MathJax.Hub.Update( event.currentSlide, function() {
- Reveal.layout();
- } );
+ // This will only typeset equations that have not yet been
+ // processed, as well as equations that have change since
+ // last being processed.
+ MathJax.Hub.Update( event.currentSlide );
- } );
- }
+ } );
} );
--
cgit v1.2.3
From b17e285164bb17b920e8759ccb2891e147a0397e Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Tue, 13 Aug 2013 08:53:31 -0400
Subject: mathjax plugin updates #531
---
examples/math.html | 4 ++--
plugin/math/math.js | 23 ++++++++++++-----------
2 files changed, 14 insertions(+), 13 deletions(-)
(limited to 'plugin/math')
diff --git a/examples/math.html b/examples/math.html
index 7d3eba2..867c45e 100644
--- a/examples/math.html
+++ b/examples/math.html
@@ -182,8 +182,8 @@
transition: 'linear',
math: {
- // host: 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
- mode: 'TeX-AMS_HTML-full'
+ // mathjax: 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
+ dialect: 'TeX-AMS_HTML-full'
},
dependencies: [
diff --git a/plugin/math/math.js b/plugin/math/math.js
index d021fdc..104d0e5 100755
--- a/plugin/math/math.js
+++ b/plugin/math/math.js
@@ -7,25 +7,26 @@
var RevealMath = window.RevealMath || (function(){
var config = Reveal.getConfig().math || {};
- config.host = config.host || 'http://cdn.mathjax.org/mathjax/latest/MathJax.js';
- config.mode = config.mode || 'TeX-AMS_HTML-full';
+ config.mathjax = config.mathjax || 'http://cdn.mathjax.org/mathjax/latest/MathJax.js';
+ config.dialect = config.dialect || 'TeX-AMS_HTML-full';
- loadScript( config.host + '?config=' + config.mode, function() {
+ loadScript( config.mathjax + '?config=' + config.dialect, function() {
MathJax.Hub.Config({
messageStyle: 'none',
- tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
+ tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] },
+ skipStartupTypeset: true
});
- // Process any math inside of the current slide when navigating,
- // this is needed since it's not possible to typeset equations
- // within invisible elements (far future or past).
+ // Typeset followed by an immediate reveal.js layout since
+ // the typesetting process could affect slide height
+ MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] );
+ MathJax.Hub.Queue( Reveal.layout );
+
+ // Reprocess equations in slides when they turn visible
Reveal.addEventListener( 'slidechanged', function( event ) {
- // This will only typeset equations that have not yet been
- // processed, as well as equations that have change since
- // last being processed.
- MathJax.Hub.Update( event.currentSlide );
+ MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, event.currentSlide ] );
} );
--
cgit v1.2.3
From 2bed5833ca87d7f127513acabee05971277e0f94 Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Fri, 16 Aug 2013 09:30:22 -0400
Subject: remove pointless .call()
---
plugin/math/math.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'plugin/math')
diff --git a/plugin/math/math.js b/plugin/math/math.js
index 104d0e5..4e3402e 100755
--- a/plugin/math/math.js
+++ b/plugin/math/math.js
@@ -52,7 +52,7 @@ var RevealMath = window.RevealMath || (function(){
// IE
script.onreadystatechange = function() {
if ( this.readyState === 'loaded' ) {
- finish.call();
+ finish();
}
}
--
cgit v1.2.3
From c9853233ae51e84f589797991dbd69dfac103471 Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Sun, 18 Aug 2013 14:13:55 -0400
Subject: rename math plugin config option
---
examples/math.html | 2 +-
plugin/math/math.js | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
(limited to 'plugin/math')
diff --git a/examples/math.html b/examples/math.html
index 867c45e..b0f0763 100644
--- a/examples/math.html
+++ b/examples/math.html
@@ -183,7 +183,7 @@
math: {
// mathjax: 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
- dialect: 'TeX-AMS_HTML-full'
+ config: 'TeX-AMS_HTML-full'
},
dependencies: [
diff --git a/plugin/math/math.js b/plugin/math/math.js
index 4e3402e..d55d9d1 100755
--- a/plugin/math/math.js
+++ b/plugin/math/math.js
@@ -6,11 +6,11 @@
*/
var RevealMath = window.RevealMath || (function(){
- var config = Reveal.getConfig().math || {};
- config.mathjax = config.mathjax || 'http://cdn.mathjax.org/mathjax/latest/MathJax.js';
- config.dialect = config.dialect || 'TeX-AMS_HTML-full';
+ var options = Reveal.getConfig().math || {};
+ options.mathjax = options.mathjax || 'http://cdn.mathjax.org/mathjax/latest/MathJax.js';
+ options.config = options.config || 'TeX-AMS_HTML-full';
- loadScript( config.mathjax + '?config=' + config.dialect, function() {
+ loadScript( options.mathjax + '?config=' + options.config, function() {
MathJax.Hub.Config({
messageStyle: 'none',
--
cgit v1.2.3