From e6d8987647195c4e96059bd69bc4190e3bfceeba Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 11 Jan 2020 18:46:03 -0500 Subject: [PATCH 1/3] Move reset() calls to typeset() functions so page state is retained for rerender(). Save processed when menu creates a new document, and dont' actually recompile on rerender (we just need enrichment, etc.). Resolves issue mathjax/MathJax#2255. --- ts/components/startup.ts | 2 ++ ts/core/MathDocument.ts | 3 +-- ts/core/MathItem.ts | 1 - ts/input/mathml.ts | 2 +- ts/ui/menu/Menu.ts | 9 +++++---- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ts/components/startup.ts b/ts/components/startup.ts index 3776a3850..c23447b21 100644 --- a/ts/components/startup.ts +++ b/ts/components/startup.ts @@ -327,10 +327,12 @@ export namespace Startup { export function makeTypesetMethods() { MathJax.typeset = (elements: any = null) => { document.options.elements = elements; + document.reset(); document.render(); }; MathJax.typesetPromise = (elements: any = null) => { document.options.elements = elements; + document.reset(); return mathjax.handleRetriesFor(() => { document.render(); }) diff --git a/ts/core/MathDocument.ts b/ts/core/MathDocument.ts index 9f9a1376a..b3a214ad7 100644 --- a/ts/core/MathDocument.ts +++ b/ts/core/MathDocument.ts @@ -516,8 +516,7 @@ export abstract class AbstractMathDocument implements MathDocument }; diff --git a/ts/core/MathItem.ts b/ts/core/MathItem.ts index cb9974d21..b90e9b4a8 100644 --- a/ts/core/MathItem.ts +++ b/ts/core/MathItem.ts @@ -404,7 +404,6 @@ export const STATE: {[state: string]: number} = { RERENDER: 125, TYPESET: 150, INSERTED: 200, - RESET: 500, LAST: 10000 }; diff --git a/ts/input/mathml.ts b/ts/input/mathml.ts index 0df77289f..ff0525fa0 100644 --- a/ts/input/mathml.ts +++ b/ts/input/mathml.ts @@ -128,7 +128,7 @@ export class MathML extends AbstractInputJax { */ public compile(math: MathItem, document: MathDocument) { let mml = math.start.node; - if (!mml || this.options['forceReparse']) { + if (!mml || this.options['forceReparse'] || this.adaptor.kind(mml) === '#text') { let mathml = this.executeFilters(this.preFilters, math, document, math.math || ''); let doc = this.checkForErrors(this.adaptor.parse(mathml, 'text/' + this.options['parseAs'])); let body = this.adaptor.body(doc); diff --git a/ts/ui/menu/Menu.ts b/ts/ui/menu/Menu.ts index aed03cedc..a84cdfd0c 100644 --- a/ts/ui/menu/Menu.ts +++ b/ts/ui/menu/Menu.ts @@ -677,7 +677,7 @@ export class Menu { protected setExplorer(explore: boolean) { this.enableExplorerItems(explore); if (!explore || (window.MathJax._.a11y && window.MathJax._.a11y.explorer)) { - this.rerender(this.settings.collapsible ? STATE.RERENDER : STATE.COMPILED); + this.rerender(this.settings.collapsible ? STATE.RERENDER : STATE.COMPILED + 1); } else { this.loadA11y('explorer'); } @@ -688,7 +688,7 @@ export class Menu { */ protected setCollapsible(collapse: boolean) { if (!collapse || (window.MathJax._.a11y && window.MathJax._.a11y.complexity)) { - this.rerender(STATE.COMPILED); + this.rerender(STATE.COMPILED + 1); } else { this.loadA11y('complexity'); } @@ -734,7 +734,7 @@ export class Menu { } } Menu.loading--; - this.rerender(STATE.COMPILED); + this.rerender(STATE.COMPILED + 1); } /*======================================================================*/ @@ -804,8 +804,9 @@ export class Menu { this.document = startup.document = startup.getDocument(); this.document.menu = this; this.transferMathList(document); + this.document.processed = document.processed; if (!Menu._loadingPromise) { - this.rerender(component === 'complexity' || noEnrich ? STATE.COMPILED : STATE.TYPESET); + this.rerender(component === 'complexity' || noEnrich ? STATE.COMPILED + 1 : STATE.TYPESET); } }); } From c67e18fb76c813ebe17fea7db58b02ef6071cb4e Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 11 Jan 2020 18:57:05 -0500 Subject: [PATCH 2/3] Do need to recompile after all, to remove enrichment properties when toggled off. --- ts/ui/menu/Menu.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ts/ui/menu/Menu.ts b/ts/ui/menu/Menu.ts index a84cdfd0c..ffaa9750b 100644 --- a/ts/ui/menu/Menu.ts +++ b/ts/ui/menu/Menu.ts @@ -677,7 +677,7 @@ export class Menu { protected setExplorer(explore: boolean) { this.enableExplorerItems(explore); if (!explore || (window.MathJax._.a11y && window.MathJax._.a11y.explorer)) { - this.rerender(this.settings.collapsible ? STATE.RERENDER : STATE.COMPILED + 1); + this.rerender(this.settings.collapsible ? STATE.RERENDER : STATE.COMPILED); } else { this.loadA11y('explorer'); } @@ -688,7 +688,7 @@ export class Menu { */ protected setCollapsible(collapse: boolean) { if (!collapse || (window.MathJax._.a11y && window.MathJax._.a11y.complexity)) { - this.rerender(STATE.COMPILED + 1); + this.rerender(STATE.COMPILED); } else { this.loadA11y('complexity'); } @@ -734,7 +734,7 @@ export class Menu { } } Menu.loading--; - this.rerender(STATE.COMPILED + 1); + this.rerender(STATE.COMPILED); } /*======================================================================*/ From 2f8e1c75721cbfaf7ea134ca9c67c255f865c803 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 11 Jan 2020 19:02:37 -0500 Subject: [PATCH 3/3] Missed one in the previous commit. --- ts/ui/menu/Menu.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/ui/menu/Menu.ts b/ts/ui/menu/Menu.ts index ffaa9750b..186dd182c 100644 --- a/ts/ui/menu/Menu.ts +++ b/ts/ui/menu/Menu.ts @@ -806,7 +806,7 @@ export class Menu { this.transferMathList(document); this.document.processed = document.processed; if (!Menu._loadingPromise) { - this.rerender(component === 'complexity' || noEnrich ? STATE.COMPILED + 1 : STATE.TYPESET); + this.rerender(component === 'complexity' || noEnrich ? STATE.COMPILED : STATE.TYPESET); } }); }