-
Notifications
You must be signed in to change notification settings - Fork 3
/
mathjaxknowl.js
110 lines (95 loc) · 3.16 KB
/
mathjaxknowl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/****************************************************
*
* mathjaxknowl.js
*
* Implements \knowl{url}{math} macro for MathJax. Knowls are
* described at
*
* http://www.aimath.org/knowlepedia/
*
* Be sure to change the loadComplete() address to the URL
* of the location of this file on your server.
*
* You can load it via the config=file parameter on the script
* tag that loads MathJax.js, or by including it in the extensions
* array in your configuration.
*
* Based on an approach developed by Tom Leathrum. See
*
* http://groups.google.com/group/mathjax-users/browse_thread/thread/d8a8d081b8e63242
*
* for details.
*/
MathJax.Extension.Knowl = {
version: "1.0",
//
// Reveal or hide a MathJax knowl
//
Show: function (url,id) {
var oid = "MathJax-knowl-output-"+id,
uid = "MathJax-kuid-"+id;
if ($("#"+oid).length) {
$("#"+uid).slideToggle("fast");
} else {
var the_content = "<div class='knowl-output' id='"+uid+"'>" +
"<div class='knowl'>" +
"<div class='knowl-content' id='"+oid+"'>" +
"loading '"+url+"'" +
"</div>" +
"<div class='knowl-footer'>" + url + "</div>" +
"</div>" +
"</div>";
var the_parent = $("#MathJax-knowl-"+id).closest("p, article, .displaymath");
if(the_parent.length == 0) {
the_parent = $("#MathJax-knowl-"+id).closest(".MJXc-display").next();
if(the_parent.length == 0) {
the_parent = $("#MathJax-knowl-"+id).parent().parent().parent().parent();
}
}
the_parent.after(the_content);
$("#"+oid).load(url,function () {
MathJax.Hub.Queue(["Typeset",MathJax.Hub,uid]);
});
$("#"+uid).slideDown("slow");
}
},
//
// Get a unique ID for the knowl
//
id: 0,
GetID: function () {return this.id++}
};
MathJax.Callback.Queue(
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
var TEX = MathJax.InputJax.TeX,
TEXDEF = TEX.Definitions,
KNOWL = MathJax.Extension.Knowl;
TEXDEF.macros.knowl = "Knowl";
TEX.Parse.Augment({
//
// Implements \knowl{url}{math}
//
Knowl: function (name) {
var url = this.GetArgument(name), math = this.ParseArg(name);
if (math.inferred && math.data.length == 1)
{math = math.data[0]} else {delete math.inferred}
var id = KNOWL.GetID();
this.Push(math.With({
"class": "MathJax_knowl",
href: "javascript:MathJax.Extension.Knowl.Show('"+url+"','"+id+"')",
id: "MathJax-knowl-"+id,
// border and padding will only work properly if given explicitly on the element
style: "color:blue; border-bottom: 1px dotted #00A; padding-bottom: 1px"
}));
}
});
}),
MathJax.Hub.Register.StartupHook("onLoad",function () {
MathJax.Ajax.Styles({
".MathJax_knowl:hover": {"background-color": "#DDF"}
});
}),
["Post",MathJax.Hub.Startup.signal,"TeX knowl ready"]
);
MathJax.Ajax.loadComplete("http://pretextbook.org/js/lib/mathjaxknowl.js");
MathJax.Ajax.loadComplete("https://pretextbook.org/js/lib/mathjaxknowl.js");