Skip to content

Commit 6f2a7ff

Browse files
committed
Inject MathJax into iframe used by fixed pagination. Use a second configuration file since for some reason the xlinks use by MathJax to access the character templates don't seem to work in the iframe (for reasons I can't figure out), so we need to use the paths directly. This is accomplished by a small patch to MathJax.
1 parent 2765b99 commit 6f2a7ff

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

lib/mathjax/config/readium-iframe.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*************************************************************
2+
*
3+
* MathJax/config/readium.js
4+
*
5+
* Configuration file for Readium project
6+
*
7+
* ---------------------------------------------------------------------
8+
*
9+
* Copyright (c) 2012 Design Science, Inc.
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
24+
MathJax.Hub.Config({
25+
jax: ["input/TeX","input/MathML","output/SVG"],
26+
extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],
27+
TeX: {
28+
extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]
29+
},
30+
SVG: {
31+
linebreaks: { automatic: true }
32+
},
33+
MathMenu: {
34+
showRenderer: false
35+
},
36+
menuSettings: {
37+
zoom: "Click"
38+
},
39+
messageStyle: "none"
40+
});
41+
42+
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
43+
var SVG = MathJax.OutputJax.SVG, GLYPH = SVG.BBOX.GLYPH;
44+
GLYPH.Augment({
45+
Init: function (scale,id,h,d,w,l,r,p) {
46+
var t = SVG.config.blacker,
47+
def = {"stroke-width":t};
48+
if (p !== "") {def.d = "M"+p+"Z"}
49+
if (scale !== 1) {def.transform = "scale("+scale+")"}
50+
this.SUPER(arguments).Init.call(this,def);
51+
this.h = (h+t) * scale; this.d = (d+t) * scale; this.w = (w+t/2) *scale;
52+
this.l = (l+t/2) * scale; this.r = (r+t/2) * scale;
53+
this.H = Math.max(0,this.h); this.D = Math.max(0,this.d);
54+
this.x = this.y = 0; this.scale = scale;
55+
}
56+
});
57+
});
58+
59+
MathJax.Ajax.loadComplete("[MathJax]/config/readium-iframe.js");

scripts/views/ebook_view.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,14 @@ Readium.Views.PaginationViewBase = Backbone.View.extend({
147147
this.renderPages();
148148
},
149149

150-
150+
injectMathJax: function (iframe) {
151+
var doc = iframe.contentDocument;
152+
var script = doc.createElement("script");
153+
script.type = "text/javascript";
154+
script.src = MathJax.Hub.config.root+"/MathJax.js?config=readium-iframe";
155+
doc.getElementsByTagName("head")[0].appendChild(script);
156+
}
157+
151158
});
152159

153160

@@ -167,6 +174,7 @@ Readium.Views.ScrollingPaginationView = Readium.Views.PaginationViewBase.extend(
167174
this.$('.content-sandbox').on("load", function(e) {
168175
// not sure why, on("load", this.applyBindings, this) was not working
169176
that.applyBindings( $(e.srcElement).contents() );
177+
that.injectMathJax(e.srcElement);
170178
});
171179
return this;
172180
},

0 commit comments

Comments
 (0)