better-react-mathjax 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{MathJax.d.ts → MathJax/MathJax.d.ts} +2 -2
- package/MathJax/MathJax.js +1 -0
- package/MathJax/index.d.ts +1 -0
- package/MathJax/index.js +1 -0
- package/MathJax/package.json +5 -0
- package/MathJax2.d.ts +555 -0
- package/MathJax3.d.ts +5 -0
- package/{MathJaxContext.d.ts → MathJaxContext/MathJaxContext.d.ts} +10 -14
- package/MathJaxContext/MathJaxContext.js +1 -0
- package/MathJaxContext/index.d.ts +1 -0
- package/MathJaxContext/index.js +1 -0
- package/MathJaxContext/package.json +5 -0
- package/README.md +225 -88
- package/esm/MathJax/MathJax.js +1 -0
- package/esm/MathJax/index.js +1 -0
- package/esm/MathJaxContext/MathJaxContext.js +1 -0
- package/esm/MathJaxContext/index.js +1 -0
- package/esm/index.js +1 -0
- package/index.d.ts +3 -1
- package/index.js +1 -1
- package/package.json +6 -1
- package/MathJax.js +0 -1
- package/MathJaxContext.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, FC } from "react";
|
|
2
|
-
import { MathJaxOverrideableProps } from "
|
|
2
|
+
import { MathJaxOverrideableProps } from "../MathJaxContext";
|
|
3
3
|
export interface MathJaxProps extends MathJaxOverrideableProps {
|
|
4
4
|
inline?: boolean;
|
|
5
5
|
onInitTypeset?: () => void;
|
|
@@ -7,5 +7,5 @@ export interface MathJaxProps extends MathJaxOverrideableProps {
|
|
|
7
7
|
text?: string;
|
|
8
8
|
dynamic?: boolean;
|
|
9
9
|
}
|
|
10
|
-
declare const MathJax: FC<MathJaxProps & ComponentPropsWithoutRef<"
|
|
10
|
+
declare const MathJax: FC<MathJaxProps & ComponentPropsWithoutRef<"span">>;
|
|
11
11
|
export default MathJax;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&__createBinding(t,e,n);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var n={};for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]]);return n},react_1=(Object.defineProperty(exports,"__esModule",{value:!0}),__importStar(require("react"))),MathJaxContext_1=require("../MathJaxContext"),typesettingFailed=function(e){return"Typesetting failed: ".concat(void 0!==e.message?e.message:e.toString())},MathJax=function(e){function r(){var e;"every"===h&&g&&"post"===_&&null!==f.current&&(f.current.style.visibility=null!=(e=null==(e=p.style)?void 0:e.visibility)?e:"visible"),b.current||("first"===h&&null!==f.current&&(f.current.style.visibility="visible"),n&&n(),b.current=!0),o&&o(),m.current=!1}var t=e.inline,i=void 0!==t&&t,t=e.hideUntilTypeset,n=e.onInitTypeset,o=e.onTypeset,s=e.text,u=e.dynamic,a=e.typesettingOptions,l=e.renderMode,c=e.children,p=__rest(e,["inline","hideUntilTypeset","onInitTypeset","onTypeset","text","dynamic","typesettingOptions","renderMode","children"]),d=(0,react_1.useRef)(""),f=(0,react_1.useRef)(null),y=(0,react_1.useContext)(MathJaxContext_1.MathJaxBaseContext),h=null!=t?t:null==y?void 0:y.hideUntilTypeset,_=null!=l?l:null==y?void 0:y.renderMode,v=null!=a?a:null==y?void 0:y.typesettingOptions,g=!1!==u&&(u||"production"!==process.env.NODE_ENV),b=(0,react_1.useRef)(!1),m=(0,react_1.useRef)(!1);return!m.current&&null!==f.current&&g&&"every"===h&&"post"===_&&(f.current.style.visibility="hidden"),("undefined"!=typeof window?react_1.useLayoutEffect:react_1.useEffect)(function(){if((g||!b.current)&&null!==f.current){if(!y)throw Error("MathJax was not loaded, did you use the MathJax component outside of a MathJaxContext?");if("pre"===_){if(!("string"==typeof(e=s)&&0<e.length))throw Error("Render mode 'pre' requires text prop to be set and non-empty, which was currently \"".concat(s,'"'));if(!a||!a.fn)throw Error("Render mode 'pre' requires 'typesettingOptions' prop with 'fn' property to be set on MathJax element or in the MathJaxContext");if(2===y.version)throw Error("Render mode 'pre' only available with MathJax 3, and version 2 is currently in use")}"post"!==_&&s===d.current||m.current||(m.current=!0,3===y.version?y.promise.then(function(t){var n;"pre"===_?(n=function(e){d.current=s,t.startup.document.clear(),t.startup.document.updateDocument(),null!==f.current&&(f.current.innerHTML=e.outerHTML),r()},a.fn.endsWith("Promise")?t.startup.promise.then(function(){return t[v.fn](s,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}))}).then(n).catch(function(e){throw r(),Error(typesettingFailed(e))}):t.startup.promise.then(function(){var e=t[v.fn](s,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}));n(e)}).catch(function(e){throw r(),Error(typesettingFailed(e))})):t.startup.promise.then(function(){return t.typesetClear([f.current]),t.typesetPromise([f.current])}).then(r).catch(function(e){throw r(),Error(typesettingFailed(e))})}).catch(function(e){throw r(),Error(typesettingFailed(e))}):y.promise.then(function(e){e.Hub.Queue(["Typeset",e.Hub,f.current]),e.Hub.Queue(r)}).catch(function(e){throw r(),Error(typesettingFailed(e))}))}var e}),react_1.default.createElement("span",__assign({},p,{style:__assign(__assign({display:i?"inline":"block"},p.style),{visibility:h?"hidden":null==(e=p.style)?void 0:e.visibility}),ref:f}),c)};exports.default=MathJax;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MathJax, default, MathJaxProps } from "./MathJax";
|
package/MathJax/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},MathJax_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.MathJax=void 0,require("./MathJax"));Object.defineProperty(exports,"MathJax",{enumerable:!0,get:function(){return __importDefault(MathJax_1).default}}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return __importDefault(MathJax_1).default}});
|
package/MathJax2.d.ts
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
// Type definitions for MathJax 2.7.9
|
|
2
|
+
// Project: https://github.com/mathjax/MathJax
|
|
3
|
+
// Definitions by: Roland Zwaga <https://github.com/rolandzwaga>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
// Refactored and updated by: Elias Lousseief <https://github.com/fast-reflexes>
|
|
6
|
+
|
|
7
|
+
/* to take care of use of Function in the original types which is advised against by lint rules,
|
|
8
|
+
typing it to a function type that matches almost any function */
|
|
9
|
+
type GeneralFunction = (...args: any[]) => void
|
|
10
|
+
|
|
11
|
+
export interface MathJax2Object {
|
|
12
|
+
Hub: Hub
|
|
13
|
+
Ajax: Ajax
|
|
14
|
+
Message: Message
|
|
15
|
+
HTML: HTML
|
|
16
|
+
Callback: Callback
|
|
17
|
+
Localization: Localization
|
|
18
|
+
InputJax: InputJax
|
|
19
|
+
OutputJax: OutputJax
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Callback {
|
|
23
|
+
(arg: GeneralFunction | GeneralFunction[] | any[] | any | string): CallbackObject
|
|
24
|
+
Delay(time: number, callback: any): CallbackObject
|
|
25
|
+
Queue(...args: any[]): Queue
|
|
26
|
+
Signal(name: string): Signal
|
|
27
|
+
ExecuteHooks(hooks: any[], data: any[], reset: boolean): CallbackObject
|
|
28
|
+
Hooks(reset: boolean): Hooks
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Hooks {
|
|
32
|
+
Add(hook: any, priority: number): CallbackObject
|
|
33
|
+
Remove(hook: CallbackObject): void
|
|
34
|
+
Execute(): CallbackObject
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Queue {
|
|
38
|
+
pending: number
|
|
39
|
+
running: number
|
|
40
|
+
queue: any[]
|
|
41
|
+
Push(specs: any[]): CallbackObject
|
|
42
|
+
Process(): void
|
|
43
|
+
Suspend(): void
|
|
44
|
+
Resume(): void
|
|
45
|
+
wait(callback: GeneralFunction): GeneralFunction
|
|
46
|
+
call(): void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface Signal {
|
|
50
|
+
name: string
|
|
51
|
+
posted: any[]
|
|
52
|
+
listeners: CallbackObject[]
|
|
53
|
+
Post(message: string, callback?: CallbackObject): CallbackObject
|
|
54
|
+
Clear(callback?: CallbackObject): CallbackObject
|
|
55
|
+
Interest(callback: CallbackObject, ignorePast?: boolean): CallbackObject
|
|
56
|
+
NoInterest(callback: CallbackObject): void
|
|
57
|
+
MessageHook(message: string, callback: CallbackObject): CallbackObject
|
|
58
|
+
ExecuteHook(message: string): void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface CallbackObject {
|
|
62
|
+
hook: number
|
|
63
|
+
data: any[]
|
|
64
|
+
object: any
|
|
65
|
+
called: boolean
|
|
66
|
+
autoReset: boolean
|
|
67
|
+
reset(): void
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface Hub {
|
|
71
|
+
config?: MathJax2Config
|
|
72
|
+
processSectionDelay?: number
|
|
73
|
+
processUpdateTime?: number
|
|
74
|
+
processUpdateDelay?: number
|
|
75
|
+
signal?: Signal
|
|
76
|
+
queue?: any
|
|
77
|
+
Browser?: BrowserInfo
|
|
78
|
+
inputJax?: any
|
|
79
|
+
outputJax?: any
|
|
80
|
+
Register?: Register
|
|
81
|
+
Config(config: MathJax2Config): void
|
|
82
|
+
Configured(): void
|
|
83
|
+
Queue(callBack: any): any
|
|
84
|
+
Typeset(element: any, callBack: any): any
|
|
85
|
+
PreProcess(element: any, callBack: any): any
|
|
86
|
+
Process(element: any, callBack: any): any
|
|
87
|
+
Update(element: any, callBack: any): any
|
|
88
|
+
Reprocess(element: any, callBack: any): any
|
|
89
|
+
Rerender(element: any, callBack: any): any
|
|
90
|
+
getAllJax(element: any): any[]
|
|
91
|
+
getJaxByType(type: string, element: any): void
|
|
92
|
+
getJaxByInputType(type: string, element: any): void
|
|
93
|
+
getJaxFor(element: any): any
|
|
94
|
+
isJax(element: any): number
|
|
95
|
+
setRenderer(renderer: string, type: string): void
|
|
96
|
+
Insert(dst: any, src: any): any
|
|
97
|
+
formatError(script: any, error: any): void
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface Register {
|
|
101
|
+
PreProcessor(callBack: any): void
|
|
102
|
+
MessageHook(type: string, callBack: any): void
|
|
103
|
+
StartupHook(type: string, callBack: any): void
|
|
104
|
+
LoadHook(file: string, callBack: GeneralFunction): void
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface BrowserInfo {
|
|
108
|
+
version: string
|
|
109
|
+
isMac?: boolean
|
|
110
|
+
isPC?: boolean
|
|
111
|
+
isMobile?: boolean
|
|
112
|
+
isFirefox?: boolean
|
|
113
|
+
isSafari?: boolean
|
|
114
|
+
isChrome?: boolean
|
|
115
|
+
isOpera?: boolean
|
|
116
|
+
isMSIE?: boolean
|
|
117
|
+
isKonqueror?: boolean
|
|
118
|
+
versionAtLeast(version: string): void
|
|
119
|
+
Select(choices: any): void
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface Ajax {
|
|
123
|
+
timeout?: number
|
|
124
|
+
STATUS: STATUS
|
|
125
|
+
loaded: any
|
|
126
|
+
loading: boolean
|
|
127
|
+
loadHooks: any
|
|
128
|
+
Require(file: string, callBack: any): any
|
|
129
|
+
Load(file: string, callBack: any): any
|
|
130
|
+
loadComplete(file: string): void
|
|
131
|
+
loadTimeout(file: string): void
|
|
132
|
+
loadError(file: string): void
|
|
133
|
+
LoadHook(file: string, callBack: any): any
|
|
134
|
+
Preloading(...args: any[]): void
|
|
135
|
+
Styles(styles: any, callback: any): any
|
|
136
|
+
fileURL(file: string): string
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface STATUS {
|
|
140
|
+
OK: string
|
|
141
|
+
ERROR: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface Message {
|
|
145
|
+
Set(message: string, n: number, delay: number): number
|
|
146
|
+
Clear(n: number, delay: number): void
|
|
147
|
+
Remove(): void
|
|
148
|
+
File(file: string): number
|
|
149
|
+
filterText(text: string, n: number): string
|
|
150
|
+
Log(): string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface HTML {
|
|
154
|
+
Cookie?: Cookie
|
|
155
|
+
Element(type: string, attributes: any, contents: any): any
|
|
156
|
+
addElement(parent: any, type: string, attributes: any, content: any): any
|
|
157
|
+
TextNode(text: string): any
|
|
158
|
+
addText(parent: any, text: string): any
|
|
159
|
+
setScript(script: string, text: string): void
|
|
160
|
+
getScript(script: string): string
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface Cookie {
|
|
164
|
+
prefix?: string
|
|
165
|
+
expires?: number
|
|
166
|
+
Set(name: string, data: any): void
|
|
167
|
+
Get(name: string, obj?: any): any
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface MenuSettings {
|
|
171
|
+
zoom?: "None" | "Hover" | "Click" | "Double-Click"
|
|
172
|
+
CTRL?: boolean
|
|
173
|
+
ALT?: boolean
|
|
174
|
+
CMD?: boolean
|
|
175
|
+
Shift?: boolean
|
|
176
|
+
zscale?: string
|
|
177
|
+
context?: "MathJax" | "Browser"
|
|
178
|
+
texHints?: boolean
|
|
179
|
+
mpContext?: boolean
|
|
180
|
+
mpMouse?: boolean
|
|
181
|
+
inTabOrder?: boolean
|
|
182
|
+
semantics?: boolean
|
|
183
|
+
readonly renderer?: "HTML-CSS" | "CommonHTML" | "PreviewHTML" | "NativeMML" | "SVG" | "PlainSource"
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface ErrorSettings {
|
|
187
|
+
message?: string[]
|
|
188
|
+
style?: any
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface MathJax2Config {
|
|
192
|
+
MathZoom?: MathZoom
|
|
193
|
+
MathMenu?: MathMenu
|
|
194
|
+
MathEvents?: MathEvents
|
|
195
|
+
FontWarnings?: FontWarnings
|
|
196
|
+
Safe?: Safe
|
|
197
|
+
MatchWebFonts?: MatchWebFonts
|
|
198
|
+
SVG?: SVGOutputProcessor
|
|
199
|
+
MMLorHTML?: MMLorHTMLConfiguration
|
|
200
|
+
NativeMML?: NativeMMLOutputProcessor
|
|
201
|
+
"HTML-CSS"?: HTMLCSSOutputProcessor
|
|
202
|
+
CommonHTML?: CommonHTMLOutputProcessor
|
|
203
|
+
AsciiMath?: AsciiMathInputProcessor
|
|
204
|
+
MathML?: MathMLInputProcessor
|
|
205
|
+
TeX?: TeXInputProcessor
|
|
206
|
+
jsMath2jax?: JSMath2jaxPreprocessor
|
|
207
|
+
asciimath2jax?: Asciimath2jaxPreprocessor
|
|
208
|
+
mml2jax?: MML2jaxPreprocessor
|
|
209
|
+
tex2jax?: TEX2jaxPreprocessor
|
|
210
|
+
jax?: string[]
|
|
211
|
+
extensions?: string[]
|
|
212
|
+
config?: string[]
|
|
213
|
+
styleSheets?: string[]
|
|
214
|
+
styles?: any
|
|
215
|
+
preJax?: any
|
|
216
|
+
postJax?: any
|
|
217
|
+
preRemoveClass?: string
|
|
218
|
+
showProcessingMessages?: boolean
|
|
219
|
+
messageStyle?: string
|
|
220
|
+
displayAlign?: string
|
|
221
|
+
displayIndent?: string
|
|
222
|
+
delayStartupUntil?: string
|
|
223
|
+
skipStartupTypeset?: boolean
|
|
224
|
+
elements?: string[]
|
|
225
|
+
positionToHash?: boolean
|
|
226
|
+
showMathMenu?: boolean
|
|
227
|
+
showMathMenuMSIE?: boolean
|
|
228
|
+
menuSettings?: MenuSettings
|
|
229
|
+
errorSettings?: ErrorSettings
|
|
230
|
+
"v1.0-compatible"?: boolean
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface MathZoom {
|
|
234
|
+
styles: any
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface MathMenu {
|
|
238
|
+
delay?: number
|
|
239
|
+
helpURL?: string
|
|
240
|
+
showRenderer?: boolean
|
|
241
|
+
showFontMenu?: boolean
|
|
242
|
+
showLocale?: boolean
|
|
243
|
+
showMathPlayer?: boolean
|
|
244
|
+
showContext?: boolean
|
|
245
|
+
semanticsAnnotations?: any
|
|
246
|
+
windowSettings?: any
|
|
247
|
+
styles?: any
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface MathEvents {
|
|
251
|
+
hover?: number
|
|
252
|
+
styles?: any
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface FontWarnings {
|
|
256
|
+
messageStyle?: any
|
|
257
|
+
Message?: HTMLMessages
|
|
258
|
+
HTML?: HTMLSnippets
|
|
259
|
+
removeAfter?: number
|
|
260
|
+
fadeoutSteps?: number
|
|
261
|
+
fadeoutTime?: number
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface HTMLMessages {
|
|
265
|
+
webFont?: any[]
|
|
266
|
+
imageFonts?: any[]
|
|
267
|
+
noFonts?: any[]
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface HTMLSnippets {
|
|
271
|
+
closeBox?: string
|
|
272
|
+
webfonts?: string
|
|
273
|
+
fonts?: string
|
|
274
|
+
STIXfonts?: string
|
|
275
|
+
TeXfonts?: string
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface Safe {
|
|
279
|
+
allow?: SafeAllow
|
|
280
|
+
sizeMin?: number
|
|
281
|
+
sizeMax?: number
|
|
282
|
+
safeProtocols?: SafeProtocols
|
|
283
|
+
safeStyles?: SafeStyles
|
|
284
|
+
safeRequire?: SafeRequire
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface SafeAllow {
|
|
288
|
+
URLs?: string
|
|
289
|
+
classes?: string
|
|
290
|
+
cssIDs?: string
|
|
291
|
+
styles?: string
|
|
292
|
+
require?: string
|
|
293
|
+
fontsize?: string
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface SafeProtocols {
|
|
297
|
+
http?: boolean
|
|
298
|
+
https?: boolean
|
|
299
|
+
file?: boolean
|
|
300
|
+
javascript?: boolean
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface SafeStyles {
|
|
304
|
+
color?: boolean
|
|
305
|
+
backgroundColor?: boolean
|
|
306
|
+
border?: boolean
|
|
307
|
+
cursor?: boolean
|
|
308
|
+
margin?: boolean
|
|
309
|
+
padding?: boolean
|
|
310
|
+
textShadow?: boolean
|
|
311
|
+
fontFamily?: boolean
|
|
312
|
+
fontSize?: boolean
|
|
313
|
+
fontStyle?: boolean
|
|
314
|
+
fontWeight?: boolean
|
|
315
|
+
opacity?: boolean
|
|
316
|
+
outline?: boolean
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface SafeRequire {
|
|
320
|
+
action?: boolean
|
|
321
|
+
amscd?: boolean
|
|
322
|
+
amsmath?: boolean
|
|
323
|
+
amssymbols?: boolean
|
|
324
|
+
autobold?: boolean
|
|
325
|
+
"autoload-all"?: boolean
|
|
326
|
+
bbox?: boolean
|
|
327
|
+
begingroup?: boolean
|
|
328
|
+
boldsymbol?: boolean
|
|
329
|
+
cancel?: boolean
|
|
330
|
+
color?: boolean
|
|
331
|
+
enclose?: boolean
|
|
332
|
+
extpfeil?: boolean
|
|
333
|
+
HTML?: boolean
|
|
334
|
+
mathchoice?: boolean
|
|
335
|
+
mhchem?: boolean
|
|
336
|
+
newcommand?: boolean
|
|
337
|
+
noErrors?: boolean
|
|
338
|
+
noUndefined?: boolean
|
|
339
|
+
unicode?: boolean
|
|
340
|
+
verb?: boolean
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface MatchWebFonts {
|
|
344
|
+
matchFor?: MatchFor
|
|
345
|
+
fontCheckDelay?: number
|
|
346
|
+
fontCheckTimeout?: number
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export interface MatchFor {
|
|
350
|
+
"HTML-CSS"?: boolean
|
|
351
|
+
NativeMML?: boolean
|
|
352
|
+
SVG?: boolean
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface SVGOutputProcessor {
|
|
356
|
+
scale?: number
|
|
357
|
+
minScaleAdjust?: number
|
|
358
|
+
font?: string
|
|
359
|
+
blacker?: number
|
|
360
|
+
undefinedFamily?: string
|
|
361
|
+
mtextFontInherit?: boolean
|
|
362
|
+
addMMLclasses?: boolean
|
|
363
|
+
useFontCache?: boolean
|
|
364
|
+
useGlobalCache?: boolean
|
|
365
|
+
EqnChunk?: number
|
|
366
|
+
EqnChunkFactor?: number
|
|
367
|
+
EqnChunkDelay?: number
|
|
368
|
+
matchFontHeight?: boolean
|
|
369
|
+
linebreaks?: LineBreaks
|
|
370
|
+
styles?: any
|
|
371
|
+
tooltip?: ToolTip
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export interface LineBreaks {
|
|
375
|
+
automatic?: boolean
|
|
376
|
+
width?: string
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface ToolTip {
|
|
380
|
+
delayPost: number
|
|
381
|
+
delayClear: number
|
|
382
|
+
offsetX: number
|
|
383
|
+
offsetY: number
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface MMLorHTMLConfiguration {
|
|
387
|
+
prefer?: BrowserPreference
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export interface BrowserPreference {
|
|
391
|
+
MSIE?: string
|
|
392
|
+
Firefox?: string
|
|
393
|
+
Safari?: string
|
|
394
|
+
Chrome?: string
|
|
395
|
+
Opera?: string
|
|
396
|
+
other?: string
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export interface NativeMMLOutputProcessor {
|
|
400
|
+
scale?: number
|
|
401
|
+
minScaleAdjust?: number
|
|
402
|
+
matchFontHeight?: boolean
|
|
403
|
+
styles?: any
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface HTMLCSSOutputProcessor {
|
|
407
|
+
scale?: number
|
|
408
|
+
minScaleAdjust?: number
|
|
409
|
+
availableFonts?: string[]
|
|
410
|
+
preferredFont?: string
|
|
411
|
+
webFont?: string
|
|
412
|
+
imageFont?: string
|
|
413
|
+
undefinedFamily?: string[]
|
|
414
|
+
mtextFontInherit?: boolean
|
|
415
|
+
EqnChunk?: number
|
|
416
|
+
EqnChunkFactor?: number
|
|
417
|
+
EqnChunkDelay?: number
|
|
418
|
+
matchFontHeight?: boolean
|
|
419
|
+
linebreaks?: LineBreaks
|
|
420
|
+
styles?: any
|
|
421
|
+
showMathMenu?: boolean
|
|
422
|
+
tooltip?: ToolTip
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export interface CommonHTMLOutputProcessor {
|
|
426
|
+
scale?: number
|
|
427
|
+
minScaleAdjust?: number
|
|
428
|
+
mtextFontInherit?: boolean
|
|
429
|
+
linebreaks?: LineBreaks
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export interface AsciiMathInputProcessor {
|
|
433
|
+
displaystyle?: boolean
|
|
434
|
+
decimal?: string
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export interface MathMLInputProcessor {
|
|
438
|
+
useMathMLspacing?: boolean
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export interface TeXInputProcessor {
|
|
442
|
+
TagSide?: string
|
|
443
|
+
TagIndent?: string
|
|
444
|
+
MultLineWidth?: string
|
|
445
|
+
equationNumbers?: EquationNumbers
|
|
446
|
+
Macros?: any
|
|
447
|
+
MAXMACROS?: number
|
|
448
|
+
MAXBUFFER?: number
|
|
449
|
+
extensions?: string[]
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export interface EquationNumbers {
|
|
453
|
+
autoNumber?: string
|
|
454
|
+
formatNumber?: (n: number) => string
|
|
455
|
+
formatTag?: (n: number) => string
|
|
456
|
+
formatID?: () => string
|
|
457
|
+
formatURL?: (id: string) => string
|
|
458
|
+
useLabelIds?: boolean
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export interface JSMath2jaxPreprocessor {
|
|
462
|
+
preview: any
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export interface Asciimath2jaxPreprocessor {
|
|
466
|
+
delimiters?: any
|
|
467
|
+
preview?: any
|
|
468
|
+
skipTags?: string[]
|
|
469
|
+
ignoreClass?: string
|
|
470
|
+
processClass?: string
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
export interface MML2jaxPreprocessor {
|
|
474
|
+
preview?: any
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export interface TEX2jaxPreprocessor {
|
|
478
|
+
inlineMath?: any
|
|
479
|
+
displayMath?: any
|
|
480
|
+
balanceBraces?: boolean
|
|
481
|
+
processEscapes?: boolean
|
|
482
|
+
processEnvironments?: boolean
|
|
483
|
+
preview?: any
|
|
484
|
+
skipTags?: string[]
|
|
485
|
+
ignoreClass?: string
|
|
486
|
+
processClass?: string
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export interface Localization {
|
|
490
|
+
locale: string
|
|
491
|
+
directory: string
|
|
492
|
+
strings: any
|
|
493
|
+
_(id: number, message: string, ...args: any[]): void
|
|
494
|
+
setLocale(locale: string): void
|
|
495
|
+
addTranslation(locale: string, domain: string, def: any): void
|
|
496
|
+
setCSS(div: any): any
|
|
497
|
+
fontFamily(): string
|
|
498
|
+
fontDirection(): string
|
|
499
|
+
plural(value: any): number
|
|
500
|
+
number(value: number): string
|
|
501
|
+
loadDomain(domain: string, callback?: CallbackObject): CallbackObject
|
|
502
|
+
Try(spec: any): void
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export interface InputJax {
|
|
506
|
+
id: string
|
|
507
|
+
version: string
|
|
508
|
+
directory: string
|
|
509
|
+
elementJax: string
|
|
510
|
+
Process(script: any, state: any): any
|
|
511
|
+
Translate(script: any, state: any): ElementJax
|
|
512
|
+
Register(mimetype: string): void
|
|
513
|
+
needsUpdate(element: any): boolean
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export interface OutputJax {
|
|
517
|
+
id: string
|
|
518
|
+
version: string
|
|
519
|
+
directory: string
|
|
520
|
+
fontDir: string
|
|
521
|
+
imageDir: string
|
|
522
|
+
preProcess(state: any): void
|
|
523
|
+
preTranslate(state: any): void
|
|
524
|
+
Translate(script: any, state: any): ElementJax
|
|
525
|
+
postTranslate(state: any): void
|
|
526
|
+
Register(mimetype: string): void
|
|
527
|
+
Remove(jax: any): void
|
|
528
|
+
getJaxFromMath(math: any): ElementJax
|
|
529
|
+
Zoom(jax: any, span: any, math: any, Mw: number, Mh: number): ZoomStruct
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export interface ZoomStruct {
|
|
533
|
+
Y: number
|
|
534
|
+
mW: number
|
|
535
|
+
mH: number
|
|
536
|
+
zW: number
|
|
537
|
+
zH: number
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export interface ElementJax {
|
|
541
|
+
id: string
|
|
542
|
+
version: string
|
|
543
|
+
directory: string
|
|
544
|
+
inputJax: string
|
|
545
|
+
outputJax: string
|
|
546
|
+
inputID: string
|
|
547
|
+
originalText: string
|
|
548
|
+
mimeType: string
|
|
549
|
+
Text(text: string, callback?: any): CallbackObject
|
|
550
|
+
Rerender(callback: any): CallbackObject
|
|
551
|
+
Reprocess(callback: any): CallbackObject
|
|
552
|
+
Remove(): void
|
|
553
|
+
SourceElement(): any
|
|
554
|
+
needsUpdate(): boolean
|
|
555
|
+
}
|
package/MathJax3.d.ts
ADDED
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
import React, { FC } from "react";
|
|
2
|
+
import type { MathJax2Config, MathJax2Object } from "../MathJax2";
|
|
3
|
+
import type { MathJax3Config, MathJax3Object, OptionList } from "../MathJax3";
|
|
2
4
|
export declare type TypesettingFunction = "tex2chtml" | "tex2chtmlPromise" | "tex2svg" | "tex2svgPromise" | "tex2mml" | "tex2mmlPromise" | "mathml2chtml" | "mathml2chtmlPromise" | "mathml2svg" | "mathml2svgPromise" | "mathml2mml" | "mathml2mmlPromise" | "asciimath2chtml" | "asciimath2chtmlPromise" | "asciimath2svg" | "asciimath2svgPromise" | "asciimath2mml" | "asciimath2mmlPromise";
|
|
3
5
|
export interface MathJaxOverrideableProps {
|
|
4
6
|
hideUntilTypeset?: "first" | "every";
|
|
5
7
|
typesettingOptions?: {
|
|
6
8
|
fn: TypesettingFunction;
|
|
7
|
-
options?:
|
|
9
|
+
options?: OptionList;
|
|
8
10
|
};
|
|
9
11
|
renderMode?: "pre" | "post";
|
|
10
12
|
}
|
|
11
13
|
export declare type MathJaxSubscriberProps = ({
|
|
12
14
|
version: 2;
|
|
13
|
-
promise: Promise<
|
|
15
|
+
promise: Promise<MathJax2Object>;
|
|
14
16
|
} | {
|
|
15
17
|
version: 3;
|
|
16
|
-
promise: Promise<
|
|
18
|
+
promise: Promise<MathJax3Object>;
|
|
17
19
|
}) & MathJaxOverrideableProps;
|
|
18
|
-
export declare const MathJaxBaseContext: React.Context<
|
|
19
|
-
version: 2;
|
|
20
|
-
promise: Promise<any>;
|
|
21
|
-
} & MathJaxOverrideableProps) | ({
|
|
22
|
-
version: 3;
|
|
23
|
-
promise: Promise<any>;
|
|
24
|
-
} & MathJaxOverrideableProps) | undefined>;
|
|
20
|
+
export declare const MathJaxBaseContext: React.Context<MathJaxSubscriberProps | undefined>;
|
|
25
21
|
interface MathJaxContextStaticProps extends MathJaxOverrideableProps {
|
|
26
22
|
src?: string;
|
|
27
23
|
onLoad?: () => void;
|
|
28
24
|
onError?: (error: any) => void;
|
|
29
25
|
}
|
|
30
26
|
export declare type MathJaxContextProps = ({
|
|
31
|
-
config?:
|
|
27
|
+
config?: MathJax2Config;
|
|
32
28
|
version: 2;
|
|
33
|
-
onStartup?: (mathJax:
|
|
29
|
+
onStartup?: (mathJax: MathJax2Object) => void;
|
|
34
30
|
} | {
|
|
35
|
-
config?:
|
|
31
|
+
config?: MathJax3Config;
|
|
36
32
|
version?: 3;
|
|
37
|
-
onStartup?: (mathJax:
|
|
33
|
+
onStartup?: (mathJax: MathJax3Object) => void;
|
|
38
34
|
}) & MathJaxContextStaticProps;
|
|
39
35
|
declare const MathJaxContext: FC<MathJaxContextProps>;
|
|
40
36
|
export default MathJaxContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var v2Promise,v3Promise,__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&("get"in r?t.__esModule:!r.writable&&!r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){e[o=void 0===o?n:o]=t[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&__createBinding(t,e,n);return __setModuleDefault(t,e),t},react_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MathJaxBaseContext=void 0,__importStar(require("react"))),DEFAULT_V2_SRC=(exports.MathJaxBaseContext=(0,react_1.createContext)(void 0),"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-MML-AM_CHTML"),DEFAULT_V3_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.js",MathJaxContext=function(e){var o=e.config,t=e.version,t=void 0===t?3:t,n=e.src,n=void 0===n?2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC:n,r=e.onStartup,a=e.onLoad,i=e.onError,s=e.typesettingOptions,u=e.renderMode,u=void 0===u?"post":u,c=e.hideUntilTypeset,e=e.children,d=(0,react_1.useContext)(exports.MathJaxBaseContext);if(void 0!==(null==d?void 0:d.version)&&(null==d?void 0:d.version)!==t)throw Error("Cannot nest MathJaxContexts with different versions. MathJaxContexts should not be nested at all but if they are, they cannot have different versions. Stick with one version of MathJax in your app and avoid using more than one MathJaxContext.");if(2===t&&void 0!==v3Promise||3===t&&void 0!==v2Promise)throw Error("Cannot use MathJax versions 2 and 3 simultaneously in the same app due to how MathJax is set up in the browser; either you have multiple MathJaxContexts with different versions or you have mounted and unmounted MathJaxContexts with different versions. Please stick with one version of MathJax in your app. File an issue in the project Github page if you need this feature.");var h=(0,react_1.useRef)(d),d=(0,react_1.useRef)((null==d?void 0:d.version)||null);if(null===d.current)d.current=t;else if(d.current!==t)throw Error("Cannot change version of MathJax in a MathJaxContext after component has mounted. Either reload the page with a new setting when this should happen or use multiple, non-nested, MathJaxContexts in your app.");var l=n||(2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC);function f(t,n){o&&(window.MathJax=o);var e=document.createElement("script");e.type="text/javascript",e.src=l,e.async=!1,e.addEventListener("load",function(){var e=window.MathJax;r&&r(e),t(e),a&&a()}),e.addEventListener("error",function(e){return n(e)}),document.getElementsByTagName("head")[0].appendChild(e)}return void 0===h.current&&(d={typesettingOptions:s,renderMode:u,hideUntilTypeset:c},2===t?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(f)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 2 from '".concat(l,"' due to: ").concat(e));i(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(f)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 3 from '".concat(l,"' due to: ").concat(e));i(e)}):(v3Promise=Promise.reject()).catch(function(e){})),h.current=__assign(__assign({},d),2===t?{version:2,promise:v2Promise}:{version:3,promise:v3Promise})),react_1.default.createElement(exports.MathJaxBaseContext.Provider,{value:h.current},e)};exports.default=MathJaxContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, default as MathJaxContext, MathJaxOverrideableProps, MathJaxContextProps, MathJaxBaseContext, MathJaxSubscriberProps } from "./MathJaxContext";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},MathJaxContext_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MathJaxBaseContext=exports.MathJaxContext=exports.default=void 0,require("./MathJaxContext"));Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return __importDefault(MathJaxContext_1).default}}),Object.defineProperty(exports,"MathJaxContext",{enumerable:!0,get:function(){return __importDefault(MathJaxContext_1).default}}),Object.defineProperty(exports,"MathJaxBaseContext",{enumerable:!0,get:function(){return MathJaxContext_1.MathJaxBaseContext}});
|
package/README.md
CHANGED
|
@@ -1,34 +1,101 @@
|
|
|
1
1
|
|
|
2
|
-
<!-- prettier-ignore-start -->
|
|
3
|
-
|
|
4
2
|
# A simple React component for MathJax #
|
|
5
3
|
|
|
6
|
-
#### Note: The full documentation is available at https://github.com/fast-reflexes/better-react-mathjax
|
|
4
|
+
#### Note: The full documentation is available at https://github.com/fast-reflexes/better-react-mathjax ####
|
|
7
5
|
|
|
8
6
|
Up-to-date component for using MathJax in latest React (using functional components and hooks API). Focuses on being versatile and making the use of MathJax in
|
|
9
7
|
React a pleasant experience without flashes of non-typeset content, both with respect to initial rendering as
|
|
10
8
|
well as dynamic updates. Simple to use but with many configuration options.
|
|
11
9
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
`better-react-mathjax` introduces two React components - `MathJaxContext` and `MathJax`. For MathJax to work with React,
|
|
15
|
-
wrap the outermost component containing math (or the entire app) in a `MathJaxContext` component. Then simply use `MathJax` components at
|
|
16
|
-
different levels for the actual math. In the typical case, the content of a `MathJax` component can be everything from a
|
|
17
|
-
subtree of the DOM to a portion of text in a long paragraph. The `MathJaxContext` is responsible for downloading MathJax
|
|
18
|
-
and providing it to all wrapped `MathJax` components that typeset math.
|
|
19
|
-
|
|
20
|
-
### Features ###
|
|
10
|
+
## Features
|
|
21
11
|
|
|
22
12
|
* Supports both MathJax version 2 and 3.
|
|
23
13
|
* Supports local copy of MathJax or copy supplied via CDN.
|
|
14
|
+
* Small imprint on production bundle with dependencies only for types (image shows a size of 6.18 KB and 2.3 KB gzipped in a NextJS project analyzed with their bundle analyzer).
|
|
15
|
+
|
|
16
|
+
<br/>
|
|
17
|
+
<p align="center" width="100%">
|
|
18
|
+
<img align="center" src="https://github.com/fast-reflexes/better-react-mathjax/blob/master/images/bundle_imprint.png" width="75%">
|
|
19
|
+
</p>
|
|
20
|
+
<br/>
|
|
21
|
+
|
|
24
22
|
* Built in a modular fashion on top of MathJax with direct access to MathJax via the MathJax configuration.
|
|
25
23
|
* Use MathJax functionality either through the `MathJax` component or by yourself through the `MathJaxBaseContext`.
|
|
26
24
|
* Either put your math into the DOM with React first and let MathJax typeset afterwards (v. 2 and 3), or typeset with MathJax
|
|
27
25
|
first and add it to the DOM afterwards (v. 3 only).
|
|
28
26
|
* Hide your components before they are typeset to avoid flashes of non-typeset content and make the use of MathJax a
|
|
29
27
|
pleasant experience.
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
* Complete - no other dependencies related to MathJax are needed to enable the use of MathJax in your React app.
|
|
29
|
+
|
|
30
|
+
## Basic workflow
|
|
31
|
+
|
|
32
|
+
### Installation
|
|
33
|
+
|
|
34
|
+
Add this library manually as a dependency to `package.json`...
|
|
35
|
+
```
|
|
36
|
+
dependencies: {
|
|
37
|
+
"better-react-mathjax": "^2.0.0"
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
... and then run `npm install` **or** let `npm` or `yarn` do it for you, depending on which package manager you have
|
|
41
|
+
chosen to use:
|
|
42
|
+
```shell
|
|
43
|
+
# npm
|
|
44
|
+
npm install better-react-mathjax
|
|
45
|
+
|
|
46
|
+
# yarn
|
|
47
|
+
yarn add better-react-mathjax
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Usage
|
|
51
|
+
|
|
52
|
+
`better-react-mathjax` introduces two React components - `MathJaxContext` and `MathJax`. For MathJax to work with React:
|
|
53
|
+
|
|
54
|
+
1. Wrap your entire app in a `MathJaxContext` component (***only use one in your app***).
|
|
55
|
+
```js
|
|
56
|
+
const App = () => {
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<MathJaxContext>
|
|
60
|
+
<!-- APP CONTENT -->
|
|
61
|
+
</MathJaxContext>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
2. Then simply use `MathJax` components at different levels for the actual math.
|
|
66
|
+
```js
|
|
67
|
+
const Component = () => {
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div>
|
|
71
|
+
<MathJax>{ /* math content */ }</MathJax>
|
|
72
|
+
<h3>This is a header</h3>
|
|
73
|
+
<MathJax>
|
|
74
|
+
<div>
|
|
75
|
+
<h4>This is a subheader</h4>
|
|
76
|
+
<span>{ /* math content */ }</span>
|
|
77
|
+
<h4>This is a second subheader</h4>
|
|
78
|
+
<span>{ /* math content */ }</span>
|
|
79
|
+
...
|
|
80
|
+
</div>
|
|
81
|
+
</MathJax>
|
|
82
|
+
<p>
|
|
83
|
+
This is text which involves math <MathJax>{ /* math content */ }</MathJax> inside the paragraph.
|
|
84
|
+
</p>
|
|
85
|
+
</div>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
In the typical case, the content of a `MathJax` component can be everything from a subtree of the DOM to a portion of
|
|
90
|
+
text in a long paragraph. If you have a lot of math, try to wrap as much as possible in the same `MathJax` component.
|
|
91
|
+
The `MathJaxContext` is responsible for downloading MathJax and providing it to all wrapped `MathJax` components that
|
|
92
|
+
typeset math. By default, `MathJaxContext` imports MathJax from a CDN which allows for use of Latex, AsciiMath and MathML
|
|
93
|
+
with [MathJax version 2](https://docs.mathjax.org/en/v2.7-latest/config-files.html#the-tex-mml-am-chtml-configuration-file) and
|
|
94
|
+
Latex and MathML with the default [MathJax version 3](https://docs.mathjax.org/en/latest/web/components/combined.html#tex-mml-chtml) with
|
|
95
|
+
HTML output for both. If you need something else or want to host your own copy of MathJax, read more about the `src`
|
|
96
|
+
attribute of the `MathJaxContext` below.
|
|
97
|
+
|
|
98
|
+
## Examples
|
|
32
99
|
|
|
33
100
|
The first 3 are basic examples with zero configuration standard setup using MathJax version 3 with default MathJax config
|
|
34
101
|
and no extra options. Note that sandboxes tend to be slower than use in a real environment.
|
|
@@ -36,36 +103,39 @@ and no extra options. Note that sandboxes tend to be slower than use in a real e
|
|
|
36
103
|
### Example 1: Basic example with Latex ####
|
|
37
104
|
|
|
38
105
|
Standard setup using MathJax version 3 with default MathJax config and no extra options.
|
|
39
|
-
|
|
40
|
-
|
|
106
|
+
```js
|
|
107
|
+
export default function App() {
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<MathJaxContext>
|
|
111
|
+
<h2>Basic MathJax example with Latex</h2>
|
|
112
|
+
<MathJax>{"\\(\\frac{10}{4x} \\approx 2^{12}\\)"}</MathJax>
|
|
113
|
+
</MathJaxContext>
|
|
114
|
+
);
|
|
41
115
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<h2>Basic MathJax example with Latex</h2>
|
|
45
|
-
<MathJax>{"\\(\\frac{10}{4x} \\approx 2^{12}\\)"}</MathJax>
|
|
46
|
-
</MathJaxContext>
|
|
47
|
-
);
|
|
48
|
-
|
|
116
|
+
}
|
|
117
|
+
```
|
|
49
118
|
Sandbox: https://codesandbox.io/s/better-react-mathjax-basic-example-latex-bj8gd
|
|
50
119
|
|
|
51
120
|
### Example 2: Basic example with AsciiMath ####
|
|
52
121
|
|
|
53
|
-
Using AsciiMath requires
|
|
54
|
-
AsciiMath uses the same display mode on the entire page, which is math
|
|
55
|
-
adding `asciimath: { displaystyle: false }` to the input config.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
122
|
+
Using AsciiMath with the default version 3 import requires adding an extra loader (see the [MathJax documentation](http://docs.mathjax.org/en/latest/input/asciimath.html)
|
|
123
|
+
for further information). AsciiMath uses the same display mode on the entire page, which is display math by default.
|
|
124
|
+
It can be changed to inline math by adding `asciimath: { displaystyle: false }` to the input config.
|
|
125
|
+
```js
|
|
126
|
+
export default function App() {
|
|
127
|
+
const config = {
|
|
128
|
+
loader: { load: ["input/asciimath"] }
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<MathJaxContext config={config}>
|
|
133
|
+
<h2>Basic MathJax example with AsciiMath</h2>
|
|
134
|
+
<MathJax>{"`frac(10)(4x) approx 2^(12)`"}</MathJax>
|
|
135
|
+
</MathJaxContext>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
69
139
|
|
|
70
140
|
Sandbox: https://codesandbox.io/s/better-react-mathjax-basic-example-asciimath-ddy4r
|
|
71
141
|
|
|
@@ -73,34 +143,34 @@ Sandbox: https://codesandbox.io/s/better-react-mathjax-basic-example-asciimath-d
|
|
|
73
143
|
|
|
74
144
|
MathML is supported natively by a few but far from all browsers. It might be problematic to use with Typescript (no types for
|
|
75
145
|
MathML included in this package).
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
146
|
+
```js
|
|
147
|
+
export default function App() {
|
|
148
|
+
return (
|
|
149
|
+
<MathJaxContext>
|
|
150
|
+
<h2>Basic MathJax example with MathML</h2>
|
|
151
|
+
<MathJax>
|
|
152
|
+
<math>
|
|
153
|
+
<mrow>
|
|
83
154
|
<mrow>
|
|
84
|
-
<
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</mfrac>
|
|
89
|
-
</mrow>
|
|
90
|
-
<mo>≈</mo>
|
|
91
|
-
<mrow>
|
|
92
|
-
<msup>
|
|
93
|
-
<mn>2</mn>
|
|
94
|
-
<mn>12</mn>
|
|
95
|
-
</msup>
|
|
96
|
-
</mrow>
|
|
155
|
+
<mfrac>
|
|
156
|
+
<mn>10</mn>
|
|
157
|
+
<mi>4x</mi>
|
|
158
|
+
</mfrac>
|
|
97
159
|
</mrow>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
160
|
+
<mo>≈</mo>
|
|
161
|
+
<mrow>
|
|
162
|
+
<msup>
|
|
163
|
+
<mn>2</mn>
|
|
164
|
+
<mn>12</mn>
|
|
165
|
+
</msup>
|
|
166
|
+
</mrow>
|
|
167
|
+
</mrow>
|
|
168
|
+
</math>
|
|
169
|
+
</MathJax>
|
|
170
|
+
</MathJaxContext>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
104
174
|
Sandbox: https://codesandbox.io/s/better-react-mathjax-basic-example-mathml-20vv6
|
|
105
175
|
|
|
106
176
|
### Example 4: Elaborate example with Latex ###
|
|
@@ -110,18 +180,28 @@ Sandbox: https://codesandbox.io/s/better-react-mathjax-example-latex-3vsr5
|
|
|
110
180
|
Sandbox: https://codesandbox.io/s/better-react-mathjax-example-asciimath-p0uf1
|
|
111
181
|
|
|
112
182
|
### Example 6: Elaborate example with MathML ###
|
|
113
|
-
Sandbox link: https://codesandbox.io/s/better-react-mathjax-example-mathml-nprxz
|
|
114
183
|
|
|
115
184
|
Make sure to study the comments in this file as MathML processing is a little bit different from Latex and AsciiMath.
|
|
116
185
|
|
|
186
|
+
Sandbox link: https://codesandbox.io/s/better-react-mathjax-example-mathml-nprxz
|
|
187
|
+
|
|
117
188
|
### Example 7: Elaborate example with optimal settings for dynamic updates with Latex ###
|
|
118
|
-
Sandbox link: https://codesandbox.io/s/better-react-mathjax-example-latex-optimal-8nn9n
|
|
119
189
|
|
|
120
|
-
|
|
190
|
+
This example shows a configuration that in some particular cases has proven to result in a very smooth experience with
|
|
191
|
+
no flashes of non-typeset content. **It is by no means recommended as a first attempt and can be tried if you
|
|
192
|
+
experience problems with flashes of non-typeset content, long waiting times or other undesired behaviour**. Especially for
|
|
193
|
+
those using MathJax version 2, some of the configuration options can be used as an inspiration.
|
|
121
194
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
195
|
+
Sandbox link: https://codesandbox.io/s/better-react-mathjax-example-latex-optimal-8nn9n
|
|
196
|
+
|
|
197
|
+
# TypeScript types #
|
|
198
|
+
This project has both its own types and MathJax types included in the package. For MathJax version 2, a refactored and updated
|
|
199
|
+
version of [`@types/mathjax`](https://www.npmjs.com/package/@types/mathjax) is used whereas for MathJax version 3, this package
|
|
200
|
+
depends on the types from [`mathjax-full`](https://www.npmjs.com/package/mathjax-full). Nonetheless, none of the logic from
|
|
201
|
+
these are used in this project so after building production code and tree-shaking, these dependencies will not affect the
|
|
202
|
+
size of the final bundle. If you would prefer a separate `@types` package for this project, please make a suggestion about this in an issue on the
|
|
203
|
+
project Github page. Note also that issues with the MathJax 2 types can be addressed and updated within this project whereas
|
|
204
|
+
the types from `mathjax-full` are used unaltered.
|
|
125
205
|
|
|
126
206
|
# API #
|
|
127
207
|
|
|
@@ -129,6 +209,9 @@ The following three properties can be set on **both** the `MathJaxContext` and `
|
|
|
129
209
|
`MathJaxContext` component, they apply to all wrapped `MathJax` components except those on which the property in
|
|
130
210
|
question is set on the individual `MathJax` component, which then takes precedence.
|
|
131
211
|
|
|
212
|
+
**Note**: `MathJax3Object` and `MathJax3Config` are aliases for `MathJaxObject` and `MathJaxConfig`
|
|
213
|
+
as exported by `mathjax-full`.
|
|
214
|
+
|
|
132
215
|
---
|
|
133
216
|
|
|
134
217
|
### `hideUntilTypeset: "first" | "every" | undefined` ###
|
|
@@ -144,7 +227,7 @@ it might be desirable to use `pre` for performance reasons or to handle very spe
|
|
|
144
227
|
|
|
145
228
|
**Default**: `post`
|
|
146
229
|
|
|
147
|
-
### `typesettingOptions: { fn: TypesettingFunction, options:
|
|
230
|
+
### `typesettingOptions: { fn: TypesettingFunction, options: OptionList | undefined } | undefined` ###
|
|
148
231
|
|
|
149
232
|
Used to control typesetting when `renderMode` is set to `pre`. Controls which typesetting function to use and an optional
|
|
150
233
|
object with typesetting details.
|
|
@@ -154,7 +237,7 @@ object with typesetting details.
|
|
|
154
237
|
## `MathJaxContext` component ##
|
|
155
238
|
|
|
156
239
|
---
|
|
157
|
-
### `config:
|
|
240
|
+
### `config: MathJax2Config | MathJax3Config | undefined` ###
|
|
158
241
|
|
|
159
242
|
Controls MathJax and is passed to MathJax as its config.
|
|
160
243
|
|
|
@@ -167,11 +250,23 @@ MathJax configuration object. Make sure it corresponds to the version used. More
|
|
|
167
250
|
|
|
168
251
|
The location of MathJax.
|
|
169
252
|
|
|
170
|
-
|
|
171
253
|
**Default**: `undefined` (default CDN `https://cdnjs.cloudflare.com` is used)
|
|
172
254
|
|
|
173
255
|
Local or remote url to fetch MathJax from. More information about hosting your own copy of MathJax can be found
|
|
174
|
-
[
|
|
256
|
+
[in the MathJax documentation](http://docs.mathjax.org/en/latest/web/hosting.html) and more in particular on
|
|
257
|
+
[the `better-react-mathjax` Github page](https://github.com/fast-reflexes/better-react-mathjax/issues/1#issuecomment-873537018).
|
|
258
|
+
|
|
259
|
+
A source url may contain both some specific file and some query parameters corresponding to a configuration which, in turn, governs
|
|
260
|
+
which additional assets MathJax fetches. The default sources used when this property is omitted are the same as those
|
|
261
|
+
listed in the [MathJax instruction](https://www.mathjax.org/#gettingstarted) (however from a different CDN). This means
|
|
262
|
+
that for version 2, the fetched resource (`MathJax.js?config=TeX-MML-AM_CHTML`) includes support for Latex, MML
|
|
263
|
+
and AsciiMath with HTML output by default, and for version 3, the fetched resource (`tex-mml-chtml.js`) supports
|
|
264
|
+
MML and Latex with HTML output. These correspond to some typical and broad use of MathJax in the browser. If you have a
|
|
265
|
+
use case where you, using standalone MathJax, would have to use a different source url, then you have to manually supply
|
|
266
|
+
such a url (local or remote) here. This, in analogy to how you would modify the script import to adjust to your needs in
|
|
267
|
+
a plain HTML environment with direct use of MathJax. Read more about different configurations
|
|
268
|
+
[here](https://docs.mathjax.org/en/latest/web/components/combined.html) (for MathJax 3) and
|
|
269
|
+
[here](https://docs.mathjax.org/en/v2.7-latest/config-files.html#common-configurations) (for MathJax 2).
|
|
175
270
|
|
|
176
271
|
### `version: 2 | 3 | undefined` ###
|
|
177
272
|
|
|
@@ -180,9 +275,9 @@ MathJax version to use. Must be synced with any `config` passed.
|
|
|
180
275
|
**Default**: `3`
|
|
181
276
|
|
|
182
277
|
Version of MathJax to use. If set, make sure that any configuration and url to MathJax uses the same version. If `src`
|
|
183
|
-
is not specified, setting `
|
|
278
|
+
is not specified, setting `version`to `2` currently makes use of version 2.7.9 and setting it to `3` uses 3.2.0.
|
|
184
279
|
|
|
185
|
-
### `onStartUp((mathJax:
|
|
280
|
+
### `onStartUp((mathJax: MathJax2Object | MathJax3Object) => void) | undefined` ###
|
|
186
281
|
|
|
187
282
|
Callback to be called when MathJax has loaded successfully but before the MathJax object has been made available
|
|
188
283
|
to wrapped `MathJax` components. The MathJax object is handed as an argument to this callback which is a good place
|
|
@@ -251,20 +346,20 @@ as this functionality is used by the `MathJax` component itself.***
|
|
|
251
346
|
## Custom use of MathJax directly ##
|
|
252
347
|
You can use the underlying MathJax object directly (not through the `MathJax` component) if you want as well. The
|
|
253
348
|
following snippet illustrates how to use `MathJaxBaseContext` to accomplish this.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
349
|
+
```js
|
|
350
|
+
// undefined or MathJaxSubscriberProps with properties version, hideUntilTypeset, renderMode, typesettingOptions and promise
|
|
351
|
+
const mjContext = useContext(MathJaxBaseContext)
|
|
352
|
+
if(mjContext)
|
|
353
|
+
mjContext.promise.then(mathJaxObject => { /* do work with the MathJax object here */ })
|
|
354
|
+
```
|
|
260
355
|
This requires only a `MathJaxContext`, supplying the `MathJaxBaseContext`, to be in the hierarchy. The object passed from the `promise` property is the MathJax
|
|
261
356
|
object for the version in use.
|
|
262
357
|
|
|
263
358
|
Sandbox example: https://codesandbox.io/s/better-react-mathjax-custom-example-latex-e5kym
|
|
264
359
|
|
|
265
360
|
## MathJax documentation ##
|
|
266
|
-
* Version 3: https://docs.mathjax.org/en/latest/
|
|
267
361
|
|
|
362
|
+
* Version 3: https://docs.mathjax.org/en/latest/
|
|
268
363
|
* Version 2: https://docs.mathjax.org/en/v2.7-latest/
|
|
269
364
|
|
|
270
365
|
## Github ##
|
|
@@ -272,11 +367,53 @@ Sandbox example: https://codesandbox.io/s/better-react-mathjax-custom-example-la
|
|
|
272
367
|
Read full documentation, file problems or contribute on Github: https://github.com/fast-reflexes/better-react-mathjax
|
|
273
368
|
|
|
274
369
|
## Changelog ##
|
|
275
|
-
v. 1.0.0
|
|
370
|
+
* v. 1.0.0
|
|
371
|
+
* Initial Release
|
|
372
|
+
* v. 1.0.1
|
|
373
|
+
* Removed types imported from `@types/mathjax` and `mathjax-full` due to several reasons. Custom type declarations will be supplied instead.
|
|
374
|
+
* v. 1.0.2
|
|
375
|
+
* Readded types with custom types for MathJax2 based on `@types/mathjax` and types from `mathjax-full` for MathJax3.
|
|
376
|
+
* v. 1.0.3
|
|
377
|
+
* Fixed missing license.
|
|
378
|
+
* Corrected function signature on `MathJax` component.
|
|
379
|
+
* Updated default MathJax 3 version provided by CDN to using v. 3.2.0.
|
|
380
|
+
* Updated MathJax 3 types used to v. 3.2.0.
|
|
381
|
+
* Added content to API documentation on property `src`.
|
|
382
|
+
* Added installation instructions.
|
|
383
|
+
* Added information about AsciiMath display mode.
|
|
384
|
+
* Corrected typo in API documentation on `version` property.
|
|
385
|
+
* v. 2.0.0
|
|
386
|
+
* **Breaking change**: can no longer use MathJax versions 2 and 3 side by side in different
|
|
387
|
+
`MathJaxContext`s. This did typically not work as intended before either and even though this change is
|
|
388
|
+
breaking, it should not affect many users, if any. Docs have been updated and `MathJaxContext` now throws an error
|
|
389
|
+
if it has been initialized with one version and another `MathJaxContext` (later or simultaneous) has a different
|
|
390
|
+
value on the `version` prop.
|
|
391
|
+
* Added support for hot reload by always setting `dynamic` to `true` when `dynamic` is not explicitly set to `false`
|
|
392
|
+
and `process.env.NODE_ENV` is not `production`.
|
|
393
|
+
* Honoring possible style settings of `style.visibility` in `MathJax` component when visibility is not controlled
|
|
394
|
+
by the component itself.
|
|
395
|
+
* Corrected sandbox example with AsciiMath where Latex default delimiter was used instead of AsciiMath delimiter
|
|
396
|
+
(still worked because Latex is loaded by default as well).
|
|
397
|
+
* Improved documentation with clarifications:
|
|
398
|
+
* The entire app should be wrapped in the only `MathJaxContext` that should exist in a project.
|
|
399
|
+
* How to deal with the situation when you have a lot of math on your page.
|
|
400
|
+
* The features available with the default imports from CDN.
|
|
401
|
+
* Difference between inline and display math.
|
|
402
|
+
* Added Q & A section to documentation.
|
|
403
|
+
* Changed all checks for undefined to use `typeof X === "undefined"` instead of `X === undefined`.
|
|
404
|
+
* Added support for esm modules as well as the previous cjs modules.
|
|
405
|
+
* Added language tags on code samples
|
|
406
|
+
|
|
407
|
+
## Migration guides
|
|
408
|
+
|
|
409
|
+
* v1 to v2:
|
|
410
|
+
* Remove all simultaneous use of MathJax version 2 and 3 in the same app and use only one version of MathJax
|
|
411
|
+
per loaded page. This means that even if you unmount the `MathJaxContext` and then remount it, it must have the
|
|
412
|
+
same version both times. If you load a new page context (e.g. not just change page in a SPA (single-page application))
|
|
413
|
+
the version can be determined anew. If you need to use both versions side by side, file an issue on the project
|
|
414
|
+
Github page.
|
|
276
415
|
|
|
277
416
|
## License
|
|
278
417
|
|
|
279
418
|
This project is licensed under the terms of the
|
|
280
|
-
[MIT license](/LICENSE).
|
|
281
|
-
|
|
282
|
-
<!-- prettier-ignore-end -->
|
|
419
|
+
[MIT license](https://github.com/fast-reflexes/better-react-mathjax/blob/master/LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},__rest=this&&this.__rest||function(t,e){var n={};for(i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]]);return n};import React,{useContext,useEffect,useLayoutEffect,useRef}from"react";import{MathJaxBaseContext}from"../MathJaxContext";var typesettingFailed=function(t){return"Typesetting failed: ".concat(void 0!==t.message?t.message:t.toString())},MathJax=function(t){function r(){var t;"every"===h&&m&&"post"===v&&null!==f.current&&(f.current.style.visibility=null!=(t=null==(t=p.style)?void 0:t.visibility)?t:"visible"),_.current||("first"===h&&null!==f.current&&(f.current.style.visibility="visible"),n&&n(),_.current=!0),o&&o(),b.current=!1}var e=t.inline,i=void 0!==e&&e,e=t.hideUntilTypeset,n=t.onInitTypeset,o=t.onTypeset,s=t.text,u=t.dynamic,a=t.typesettingOptions,l=t.renderMode,c=t.children,p=__rest(t,["inline","hideUntilTypeset","onInitTypeset","onTypeset","text","dynamic","typesettingOptions","renderMode","children"]),y=useRef(""),f=useRef(null),d=useContext(MathJaxBaseContext),h=null!=e?e:null==d?void 0:d.hideUntilTypeset,v=null!=l?l:null==d?void 0:d.renderMode,g=null!=a?a:null==d?void 0:d.typesettingOptions,m=!1!==u&&(u||"production"!==process.env.NODE_ENV),_=useRef(!1),b=useRef(!1);return!b.current&&null!==f.current&&m&&"every"===h&&"post"===v&&(f.current.style.visibility="hidden"),("undefined"!=typeof window?useLayoutEffect:useEffect)(function(){if((m||!_.current)&&null!==f.current){if(!d)throw Error("MathJax was not loaded, did you use the MathJax component outside of a MathJaxContext?");if("pre"===v){if(!("string"==typeof(t=s)&&0<t.length))throw Error("Render mode 'pre' requires text prop to be set and non-empty, which was currently \"".concat(s,'"'));if(!a||!a.fn)throw Error("Render mode 'pre' requires 'typesettingOptions' prop with 'fn' property to be set on MathJax element or in the MathJaxContext");if(2===d.version)throw Error("Render mode 'pre' only available with MathJax 3, and version 2 is currently in use")}"post"!==v&&s===y.current||b.current||(b.current=!0,3===d.version?d.promise.then(function(e){var n;"pre"===v?(n=function(t){y.current=s,e.startup.document.clear(),e.startup.document.updateDocument(),null!==f.current&&(f.current.innerHTML=t.outerHTML),r()},a.fn.endsWith("Promise")?e.startup.promise.then(function(){return e[g.fn](s,__assign(__assign({},(null==g?void 0:g.options)||{}),{display:!i}))}).then(n).catch(function(t){throw r(),Error(typesettingFailed(t))}):e.startup.promise.then(function(){var t=e[g.fn](s,__assign(__assign({},(null==g?void 0:g.options)||{}),{display:!i}));n(t)}).catch(function(t){throw r(),Error(typesettingFailed(t))})):e.startup.promise.then(function(){return e.typesetClear([f.current]),e.typesetPromise([f.current])}).then(r).catch(function(t){throw r(),Error(typesettingFailed(t))})}).catch(function(t){throw r(),Error(typesettingFailed(t))}):d.promise.then(function(t){t.Hub.Queue(["Typeset",t.Hub,f.current]),t.Hub.Queue(r)}).catch(function(t){throw r(),Error(typesettingFailed(t))}))}var t}),React.createElement("span",__assign({},p,{style:__assign(__assign({display:i?"inline":"block"},p.style),{visibility:h?"hidden":null==(t=p.style)?void 0:t.visibility}),ref:f}),c)};export default MathJax;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{default as MathJax,default}from"./MathJax";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var a in t=arguments[o])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};import React,{createContext,useContext,useRef}from"react";var v2Promise,v3Promise,MathJaxBaseContext=createContext(void 0),DEFAULT_V2_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-MML-AM_CHTML",DEFAULT_V3_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.js",MathJaxContext=function(e){var n=e.config,t=e.version,t=void 0===t?3:t,o=e.src,o=void 0===o?2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC:o,a=e.onStartup,r=e.onLoad,i=e.onError,s=e.typesettingOptions,h=e.renderMode,h=void 0===h?"post":h,d=e.hideUntilTypeset,e=e.children,c=useContext(MathJaxBaseContext);if(void 0!==(null==c?void 0:c.version)&&(null==c?void 0:c.version)!==t)throw Error("Cannot nest MathJaxContexts with different versions. MathJaxContexts should not be nested at all but if they are, they cannot have different versions. Stick with one version of MathJax in your app and avoid using more than one MathJaxContext.");if(2===t&&void 0!==v3Promise||3===t&&void 0!==v2Promise)throw Error("Cannot use MathJax versions 2 and 3 simultaneously in the same app due to how MathJax is set up in the browser; either you have multiple MathJaxContexts with different versions or you have mounted and unmounted MathJaxContexts with different versions. Please stick with one version of MathJax in your app. File an issue in the project Github page if you need this feature.");var u=useRef(c),c=useRef((null==c?void 0:c.version)||null);if(null===c.current)c.current=t;else if(c.current!==t)throw Error("Cannot change version of MathJax in a MathJaxContext after component has mounted. Either reload the page with a new setting when this should happen or use multiple, non-nested, MathJaxContexts in your app.");var v=o||(2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC);function l(t,o){n&&(window.MathJax=n);var e=document.createElement("script");e.type="text/javascript",e.src=v,e.async=!1,e.addEventListener("load",function(){var e=window.MathJax;a&&a(e),t(e),r&&r()}),e.addEventListener("error",function(e){return o(e)}),document.getElementsByTagName("head")[0].appendChild(e)}return void 0===u.current&&(c={typesettingOptions:s,renderMode:h,hideUntilTypeset:d},2===t?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(l)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 2 from '".concat(v,"' due to: ").concat(e));i(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(l)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 3 from '".concat(v,"' due to: ").concat(e));i(e)}):(v3Promise=Promise.reject()).catch(function(e){})),u.current=__assign(__assign({},c),2===t?{version:2,promise:v2Promise}:{version:3,promise:v3Promise})),React.createElement(MathJaxBaseContext.Provider,{value:u.current},e)};export default MathJaxContext;export{MathJaxBaseContext};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{default,default as MathJaxContext,MathJaxBaseContext}from"./MathJaxContext";
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{default as MathJax}from"./MathJax";export{default as MathJaxContext,MathJaxBaseContext}from"./MathJaxContext";
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { default as MathJax, MathJaxProps } from "./MathJax";
|
|
2
|
-
export { default as MathJaxContext, MathJaxContextProps, MathJaxBaseContext } from "./MathJaxContext";
|
|
2
|
+
export { default as MathJaxContext, MathJaxContextProps, MathJaxBaseContext, MathJaxSubscriberProps } from "./MathJaxContext";
|
|
3
|
+
export { MathJax2Config, MathJax2Object } from "./MathJax2";
|
|
4
|
+
export { MathJax3Object, MathJax3Config, OptionList } from "./MathJax3";
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}}
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},MathJax_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MathJaxBaseContext=exports.MathJaxContext=exports.MathJax=void 0,require("./MathJax")),MathJaxContext_1=(Object.defineProperty(exports,"MathJax",{enumerable:!0,get:function(){return __importDefault(MathJax_1).default}}),require("./MathJaxContext"));Object.defineProperty(exports,"MathJaxContext",{enumerable:!0,get:function(){return __importDefault(MathJaxContext_1).default}}),Object.defineProperty(exports,"MathJaxBaseContext",{enumerable:!0,get:function(){return MathJaxContext_1.MathJaxBaseContext}});
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-react-mathjax",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Up-to-date component for using MathJax in latest React (using functional components and hooks API). Focuses on being versatile and making the use of MathJax in React a pleasant experience without flashes of non-typeset content, both with respect to initial rendering as well as dynamic updates. Simple to use but with many configuration options.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"module": "esm/index.js",
|
|
6
7
|
"types": "index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
7
9
|
"repository": {
|
|
8
10
|
"type": "git",
|
|
9
11
|
"url": "git+https://github.com/fast-reflexes/better-react-mathjax.git"
|
|
@@ -23,5 +25,8 @@
|
|
|
23
25
|
"homepage": "https://github.com/fast-reflexes/better-react-mathjax#readme",
|
|
24
26
|
"peerDependencies": {
|
|
25
27
|
"react": ">=16.8"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"mathjax-full": "^3.2.0"
|
|
26
31
|
}
|
|
27
32
|
}
|
package/MathJax.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){e[n=void 0===n?r:n]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var r={};for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(r[i[n]]=e[i[n]]);return r};Object.defineProperty(exports,"__esModule",{value:!0});var react_1=__importStar(require("react")),MathJaxContext_1=require("./MathJaxContext"),MathJax=function(e){function n(){"every"===y&&u&&"post"===_&&null!==f.current&&(f.current.style.visibility="visible"),g.current||("first"===y&&null!==f.current&&(f.current.style.visibility="visible"),o&&o(),g.current=!0),s&&s(),m.current=!1}var t=e.inline,i=void 0!==t&&t,r=e.hideUntilTypeset,o=e.onInitTypeset,s=e.onTypeset,a=e.text,u=e.dynamic,c=e.typesettingOptions,l=e.renderMode,p=e.children,t=e.id,e=__rest(e,["inline","hideUntilTypeset","onInitTypeset","onTypeset","text","dynamic","typesettingOptions","renderMode","children","id"]),d=react_1.useRef(""),f=react_1.useRef(null),h=react_1.useContext(MathJaxContext_1.MathJaxBaseContext),y=void 0===r?null==h?void 0:h.hideUntilTypeset:r,_=void 0===l?null==h?void 0:h.renderMode:l,v=void 0===c?null==h?void 0:h.typesettingOptions:c,g=react_1.useRef(!1),m=react_1.useRef(!1);return!m.current&&null!==f.current&&u&&"every"===y&&"post"===_&&(f.current.style.visibility="hidden"),("undefined"!=typeof window?react_1.useLayoutEffect:react_1.useEffect)(function(){if((u||!g.current)&&null!==f.current){if(!h)throw Error("MathJax was not loaded, did you use the MathJax component outside of a MathJaxContext?");if("pre"===_){if(!("string"==typeof(e=a)&&0<e.length))throw Error("Render mode 'pre' requires text prop to be set and non-empty, which was currently \""+a+'"');if(!c||!c.fn)throw Error("Render mode 'pre' requires 'typesettingOptions' prop with 'fn' property to be set on MathJax element or in the MathJaxContext");if(2===h.version)throw Error("Render mode 'pre' only available with MathJax 3, and version 2 is currently in use")}"post"!==_&&a===d.current||m.current||(m.current=!0,3===h.version?h.promise.then(function(t){var r;"pre"===_?(r=function(e){d.current=a,t.startup.document.clear(),t.startup.document.updateDocument(),null!==f.current&&(f.current.innerHTML=e.outerHTML),n()},c.fn.endsWith("Promise")?t.startup.promise.then(function(){return t[v.fn](a,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}))}).then(r).catch(function(e){throw n(),Error("Typesetting failed: "+e.message)}):t.startup.promise.then(function(){var e=t[v.fn](a,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}));r(e)}).catch(function(e){throw n(),Error("Typesetting failed: "+e.message)})):t.startup.promise.then(function(){return t.typesetClear([f.current]),t.typesetPromise([f.current])}).then(n).catch(function(e){throw n(),Error("Typesetting failed: "+e.message)})}).catch(function(e){throw Error("Typesetting failed: "+e.message)}):h.promise.then(function(e){e.Hub.Queue(["Typeset",e.Hub,f.current]),e.Hub.Queue(n)}).catch(function(e){throw Error("Typesetting failed: "+e.message)}))}var e}),react_1.default.createElement("span",__assign({},e,{id:t,style:__assign(__assign({display:i?"inline":"block"},e.style),{visibility:y?"hidden":void 0}),ref:f}),p)};exports.default=MathJax;
|
package/MathJaxContext.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&__createBinding(t,e,n);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MathJaxBaseContext=void 0;var react_1=__importStar(require("react"));exports.MathJaxBaseContext=react_1.createContext(void 0);var v2Promise,v3Promise,DEFAULT_V2_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-MML-AM_CHTML",DEFAULT_V3_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.1.2/es5/tex-mml-chtml.min.js",MathJaxContext=function(e){var r=e.config,t=e.version,o=void 0===t?3:t,n=e.src,i=void 0===n?2===o?DEFAULT_V2_SRC:DEFAULT_V3_SRC:n,a=e.onStartup,s=e.onLoad,d=e.onError,u=e.typesettingOptions,c=e.renderMode,l=void 0===c?"post":c,t=e.hideUntilTypeset,n=e.children,c=react_1.useContext(exports.MathJaxBaseContext);if(void 0!==(null==c?void 0:c.version)&&(null==c?void 0:c.version)!==o)throw Error("Cannot nest MathJaxContexts with different versions. MathJaxContexts should not be nested at all but if they are, they inherit several properties. If you need different versions, then use multiple, non-nested, MathJaxContexts in your app.");e=react_1.useRef(c),c=react_1.useRef((null==c?void 0:c.version)||null);if(null===c.current)c.current=o;else if(c.current!==o)throw Error("Cannot change version of MathJax in a MathJaxContext after component has mounted. Either reload the page with a new setting when this should happen or use multiple, non-nested, MathJaxContexts in your app.");var h=i||(2===o?DEFAULT_V2_SRC:DEFAULT_V3_SRC);function f(t,n){r&&(window.MathJax=r);var e=document.createElement("script");e.type="text/javascript",e.src=i||(2===o?DEFAULT_V2_SRC:DEFAULT_V3_SRC),e.async=!1,e.addEventListener("load",function(){var e=window.MathJax;a&&a(e),t(e),s&&s()}),e.addEventListener("error",function(e){return n(e)}),document.getElementsByTagName("head")[0].appendChild(e)}return void 0===e.current&&(t={typesettingOptions:u,renderMode:l,hideUntilTypeset:t},2===o?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(f)).catch(function(e){if(!d)throw Error("Failed to download MathJax version 2 from '"+h+"' due to: "+e);d(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(f)).catch(function(e){if(!d)throw Error("Failed to download MathJax version 3 from '"+h+"' due to: "+e);d(e)}):(v3Promise=Promise.reject()).catch(function(e){})),e.current=__assign(__assign({},t),2===o?{version:2,promise:v2Promise}:{version:3,promise:v3Promise})),react_1.default.createElement(exports.MathJaxBaseContext.Provider,{value:e.current},n)};exports.default=MathJaxContext;
|