-
Notifications
You must be signed in to change notification settings - Fork 107
/
v2-compatibility.html
123 lines (117 loc) · 4.38 KB
/
v2-compatibility.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width">
<title>MathJax v3 with v2-compatibility</title>
<script>
MathJax = {
startup: {
//
// Mapping of old extension names to new ones
//
requireMap: {
AMSmath: 'ams',
AMSsymbols: 'ams',
AMScd: 'amscd',
HTML: 'html',
noErrors: 'noerrors',
noUndefined: 'noundefined'
},
ready: function () {
//
// Replace the require command map with a new one that checks for
// renamed extensions and converts them to the new names.
//
var CommandMap = MathJax._.input.tex.SymbolMap.CommandMap;
var requireMap = MathJax.config.startup.requireMap;
var RequireLoad = MathJax._.input.tex.require.RequireConfiguration.RequireLoad;
var RequireMethods = {
Require: function (parser, name) {
var required = parser.GetArgument(name);
if (required.match(/[^_a-zA-Z0-9]/) || required === '') {
throw new TexError('BadPackageName', 'Argument for %1 is not a valid package name', name);
}
if (requireMap.hasOwnProperty(required)) {
required = requireMap[required];
}
RequireLoad(parser, required);
}
};
new CommandMap('require', {require: 'Require'}, RequireMethods);
//
// Add a replacement for MathJax.Callback command
//
MathJax.Callback = function (args) {
if (Array.isArray(args)) {
if (args.length === 1 && typeof(args[0]) === 'function') {
return args[0];
} else if (typeof(args[0]) === 'string' && args[1] instanceof Object &&
typeof(args[1][args[0]]) === 'function') {
return Function.bind.apply(args[1][args[0]], args.slice(1));
} else if (typeof(args[0]) === 'function') {
return Function.bind.apply(args[0], [window].concat(args.slice(1)));
} else if (typeof(args[1]) === 'function') {
return Function.bind.apply(args[1], [args[0]].concat(args.slice(2)));
}
} else if (typeof(args) === 'function') {
return args;
}
throw Error("Can't make callback from given data");
};
//
// Add a replacement for MathJax.Hub commands
//
MathJax.Hub = {
Queue: function () {
for (var i = 0, m = arguments.length; i < m; i++) {
var fn = MathJax.Callback(arguments[i]);
MathJax.startup.promise = MathJax.startup.promise.then(fn);
}
return MathJax.startup.promise;
},
Typeset: function (elements, callback) {
var promise = MathJax.typesetPromise(elements);
if (callback) {
promise = promise.then(callback);
}
return promise;
},
Register: {
MessageHook: function () {console.log('MessageHooks are not supported in version 3')},
StartupHook: function () {console.log('StartupHooks are not supported in version 3')},
LoadHook: function () {console.log('LoadHooks are not supported in version 3')}
},
Config: function () {console.log('MathJax configurations should be converted for version 3')}
};
//
// Warn about x-mathjax-config scripts
//
if (document.querySelector('script[type="text/x-mathjax-config"]')) {
throw Error('x-mathjax-config scripts should be converted to MathJax global variable');
}
//
// Do the usual startup
//
return MathJax.startup.defaultReady();
}
},
tex: {
autoload: {
color: [], // don't autoload the color extension
colorv2: ['color'], // do autoload the colorv2 extension
}
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
</head>
<body>
<h1>Color</h1>
Testing color: \(\color{red}{x} + y\)
<h1>Require</h1>
Testing AMScd \(\require{amsCd} \begin{CD} a @>>> b\end{CD}\)
Testing HTML \(\require{HTML} \href{http://www.mathjax.org/}{x}\)
</body>
</html>