Skip to content

Commit 69f7c0c

Browse files
committed
updates to mathjax plugin, incl more examples hakimel#531
1 parent 9984cb1 commit 69f7c0c

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

examples/math.html

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
1616

1717
<link rel="stylesheet" href="../css/reveal.min.css">
18-
<link rel="stylesheet" href="../css/theme/default.css" id="theme">
18+
<link rel="stylesheet" href="../css/theme/night.css" id="theme">
1919

2020
<!-- For syntax highlighting -->
2121
<link rel="stylesheet" href="../lib/css/zenburn.css">
@@ -32,11 +32,12 @@
3232
<div class="slides">
3333

3434
<section>
35-
<h1>Reveal.js Math Plugin</h1>
35+
<h2>reveal.js Math Plugin</h2>
36+
<p>A thin wrapper for MathJax</p>
3637
</section>
3738

3839
<section>
39-
<h2>The Lorenz Equations</h2>
40+
<h3>The Lorenz Equations</h3>
4041
\[\begin{aligned}
4142
\dot{x} &amp; = \sigma(y-x) \\
4243
\dot{y} &amp; = \rho x - y - xz \\
@@ -45,13 +46,13 @@ <h2>The Lorenz Equations</h2>
4546
</section>
4647

4748
<section>
48-
<h2>The Cauchy-Schwarz Inequality</h2>
49+
<h3>The Cauchy-Schwarz Inequality</h3>
4950

5051
\[ \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) \]
5152
</section>
5253

5354
<section>
54-
<h2>A Cross Product Formula</h2>
55+
<h3>A Cross Product Formula</h3>
5556

5657
\[\mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix}
5758
\mathbf{i} &amp; \mathbf{j} &amp; \mathbf{k} \\
@@ -61,13 +62,36 @@ <h2>A Cross Product Formula</h2>
6162
</section>
6263

6364
<section>
64-
<h2>An Identity of Ramanujan</h2>
65+
<h3>The probability of getting \(k\) heads when flipping \(n\) coins is</h3>
66+
67+
\[P(E) = {n \choose k} p^k (1-p)^{ n-k} \]
68+
</section>
69+
70+
<section>
71+
<h3>An Identity of Ramanujan</h3>
6572

6673
\[ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
6774
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
6875
{1+\frac{e^{-8\pi}} {1+\ldots} } } } \]
6976
</section>
7077

78+
<section>
79+
<h3>A Rogers-Ramanujan Identity</h3>
80+
81+
\[ 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots =
82+
\prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}\]
83+
</section>
84+
85+
<section>
86+
<h3>Maxwell&#8217;s Equations</h3>
87+
88+
\[ \begin{aligned}
89+
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} &amp; = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} &amp; = 4 \pi \rho \\
90+
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} &amp; = \vec{\mathbf{0}} \\
91+
\nabla \cdot \vec{\mathbf{B}} &amp; = 0 \end{aligned}
92+
\]
93+
</section>
94+
7195
</div>
7296

7397
</div>
@@ -78,6 +102,8 @@ <h2>An Identity of Ramanujan</h2>
78102
<script>
79103

80104
Reveal.initialize({
105+
transition: 'linear',
106+
81107
dependencies: [
82108
{ src: '../lib/js/classList.js', condition: function() { return !document.body.classList; } },
83109
{ src: '../plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },

plugin/math/math.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
*/
77
(function(){
88

9+
var config = Reveal.getConfig().math || {};
10+
config.mode = config.mode || 'TeX-AMS_HTML-full';
11+
912
var head = document.querySelector( 'head' );
1013
var script = document.createElement( 'script' );
1114
script.type = 'text/javascript';
12-
script.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG-full';
15+
script.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=' + config.mode;
1316

1417
// Detect when the script has loaded
1518
script.onload = onScriptLoad;
@@ -28,8 +31,16 @@
2831
tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
2932
});
3033

34+
// Process any math inside of the current slide when navigating,
35+
// this is important since it's not possible to typeset
36+
// equations within invisible elements (far future or past).
3137
Reveal.addEventListener( 'slidechanged', function( event ) {
38+
39+
// This will only typeset equations that have not yet been
40+
// processed, as well as equations that have change since
41+
// last being processed.
3242
MathJax.Hub.Update( event.currentSlide );
43+
3344
} );
3445

3546
}

0 commit comments

Comments
 (0)