From 75043d52be98575480e44b62281a41c7ed1db414 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 8 Aug 2026 14:18:10 -0400 Subject: [PATCH 1/3] Use retryAfter() and handleRetriesFor() from `mathjax` so they are easier to override --- ts/core/MathDocument.ts | 7 +++---- ts/input/tex/textmacros/TextMacrosMethods.ts | 4 ++-- ts/output/common/FontData.ts | 7 +++---- ts/ui/lazy/LazyHandler.ts | 11 ++++------- ts/util/Entities.ts | 3 ++- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ts/core/MathDocument.ts b/ts/core/MathDocument.ts index ea43073ac..12994cc06 100644 --- a/ts/core/MathDocument.ts +++ b/ts/core/MathDocument.ts @@ -36,7 +36,6 @@ import { MmlFactory } from '../core/MmlTree/MmlFactory.js'; import { DOMAdaptor } from '../core/DOMAdaptor.js'; import { BitField, BitFieldClass } from '../util/BitField.js'; import { PrioritizedList } from '../util/PrioritizedList.js'; -import { handleRetriesFor } from '../util/Retries.js'; import { localize } from './__locales__/Component.js'; import { Locale } from '../util/Locale.js'; import { mathjax } from '../mathjax.js'; @@ -883,7 +882,7 @@ export abstract class AbstractMathDocument implements MathDocument< */ public renderPromise() { return this.whenReady(() => - handleRetriesFor(async () => { + mathjax.handleRetriesFor(async () => { this.render(); await this.actionPromises(); this.clearPromises(); @@ -906,7 +905,7 @@ export abstract class AbstractMathDocument implements MathDocument< */ public rerenderPromise(start: number = STATE.RERENDER) { return this.whenReady(() => - handleRetriesFor(async () => { + mathjax.handleRetriesFor(async () => { this.rerender(start); await this.actionPromises(); this.clearPromises(); @@ -962,7 +961,7 @@ export abstract class AbstractMathDocument implements MathDocument< */ public convertPromise(math: string, options: OptionList = {}) { return this.whenReady(() => - handleRetriesFor(async () => { + mathjax.handleRetriesFor(async () => { const node = this.convert(math, options); await this.actionPromises(); this.clearPromises(); diff --git a/ts/input/tex/textmacros/TextMacrosMethods.ts b/ts/input/tex/textmacros/TextMacrosMethods.ts index 102c330d4..4fdc14bb5 100644 --- a/ts/input/tex/textmacros/TextMacrosMethods.ts +++ b/ts/input/tex/textmacros/TextMacrosMethods.ts @@ -21,9 +21,9 @@ * @author dpvc@mathjax.org (Davide P. Cervone) */ +import { mathjax } from '../../../mathjax.js'; import { HandlerType } from '../HandlerTypes.js'; import TexParser from '../TexParser.js'; -import { retryAfter } from '../../../util/Retries.js'; import { TextParser } from './TextParser.js'; import BaseMethods from '../base/BaseMethods.js'; @@ -290,7 +290,7 @@ export const TextMacrosMethods = { if (!macro || (autoload && macro._func === autoload.Autoload)) { texParser.parse(HandlerType.MACRO, [texParser, name]); if (!macro) return; - retryAfter(Promise.resolve()); + mathjax.retryAfter(Promise.resolve()); } texParser.parse(HandlerType.MACRO, [parser, name]); }, diff --git a/ts/output/common/FontData.ts b/ts/output/common/FontData.ts index b1fa5529b..d8536ce81 100644 --- a/ts/output/common/FontData.ts +++ b/ts/output/common/FontData.ts @@ -26,7 +26,6 @@ import { mathjax } from '../../mathjax.js'; import { OptionList, defaultOptions, userOptions } from '../../util/Options.js'; import { StyleJson } from '../../util/StyleJson.js'; import { asyncLoad } from '../../util/AsyncLoad.js'; -import { retryAfter } from '../../util/Retries.js'; import { Locale } from '../../util/Locale.js'; import { COMPONENT, localize } from '../../core/__locales__/Component.js'; import { DIRECTION } from './Direction.js'; @@ -1314,7 +1313,7 @@ export class FontData< if (!dynamic.promise) { dynamic.promise = Promise.resolve(); try { - mathjax.asyncLoad(this.dynamicFileName(dynamic)); + asyncLoad(this.dynamicFileName(dynamic)); } catch (err) { dynamic.failed = true; console.warn(err); @@ -1343,7 +1342,7 @@ export class FontData< this.loadDynamicFileSync(delim); return this.getDelimiter(n); } - retryAfter(this.loadDynamicFile(delim)); + mathjax.retryAfter(this.loadDynamicFile(delim)); return null; } return delim as DelimiterData; @@ -1395,7 +1394,7 @@ export class FontData< this.loadDynamicFileSync(char); return this.getChar(name, n); } - retryAfter(this.loadDynamicFile(char)); + mathjax.retryAfter(this.loadDynamicFile(char)); return null; } return char as CharDataArray; diff --git a/ts/ui/lazy/LazyHandler.ts b/ts/ui/lazy/LazyHandler.ts index 73c53ea93..a48f72648 100644 --- a/ts/ui/lazy/LazyHandler.ts +++ b/ts/ui/lazy/LazyHandler.ts @@ -30,7 +30,6 @@ import { HTMLDocument } from '../../handlers/html/HTMLDocument.js'; import { HTMLHandler } from '../../handlers/html/HTMLHandler.js'; // import { EnrichedMathItem } from '../../a11y/semantic-enrich.js'; import { SpeechMathItem } from '../../a11y/speech.js'; -import { handleRetriesFor } from '../../util/Retries.js'; import { OptionList } from '../../util/Options.js'; import { StyleJson } from '../../util/StyleJson.js'; @@ -568,7 +567,7 @@ export function LazyMathDocumentMixin< // Typeset the math and put back the font cache when done. // this.reset(); - return handleRetriesFor(() => this.render()).then(() => { + return this.renderPromise().then(() => { if (fontCache) this.outputJax.options.fontCache = fontCache; }); } @@ -622,16 +621,14 @@ export function LazyMathDocumentMixin< protected lazyHandleSet() { const set = this.lazySet; this.lazySet = new Set(); - this.lazyPromise = this.lazyPromise.then(() => { + this.lazyPromise = this.lazyPromise.then(async () => { let state = this.compileEarlierItems(set) ? STATE.COMPILED : STATE.TYPESET; state = this.resetStates(set, state); this.state(state - 1, null); // reset processed bits to allow reprocessing - return handleRetriesFor(() => { - this.render(); - this.lazyIdle = false; - }); + await this.renderPromise(); + this.lazyIdle = false; }); } diff --git a/ts/util/Entities.ts b/ts/util/Entities.ts index 0532ac2a5..c79642b4e 100644 --- a/ts/util/Entities.ts +++ b/ts/util/Entities.ts @@ -22,6 +22,7 @@ */ import { mathjax } from '../mathjax.js'; +import { asyncLoad } from './AsyncLoad.js'; import { OptionList } from './Options.js'; /** @@ -507,7 +508,7 @@ function replace(match: string, entity: string): string { entity.charAt(0).toLowerCase(); if (!loaded[file]) { loaded[file] = true; - const promise = mathjax.asyncLoad(`./util/entities/${file}.js`); + const promise = asyncLoad(`./util/entities/${file}.js`); if (mathjax.asyncIsSynchronous) { return replace(match, entity); } From 331f9918a40df057ef0a7d118cde7b213a19393c Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 15 Aug 2026 00:40:48 -0400 Subject: [PATCH 2/3] Put back the mathjax.asyncLoad() calls, as per PR review. --- ts/output/common/FontData.ts | 2 +- ts/util/Entities.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ts/output/common/FontData.ts b/ts/output/common/FontData.ts index d8536ce81..2025a06c3 100644 --- a/ts/output/common/FontData.ts +++ b/ts/output/common/FontData.ts @@ -1313,7 +1313,7 @@ export class FontData< if (!dynamic.promise) { dynamic.promise = Promise.resolve(); try { - asyncLoad(this.dynamicFileName(dynamic)); + mathjax.asyncLoad(this.dynamicFileName(dynamic)); } catch (err) { dynamic.failed = true; console.warn(err); diff --git a/ts/util/Entities.ts b/ts/util/Entities.ts index c79642b4e..365aba4d1 100644 --- a/ts/util/Entities.ts +++ b/ts/util/Entities.ts @@ -508,7 +508,7 @@ function replace(match: string, entity: string): string { entity.charAt(0).toLowerCase(); if (!loaded[file]) { loaded[file] = true; - const promise = asyncLoad(`./util/entities/${file}.js`); + const promise = mathjax.asyncLoad(`./util/entities/${file}.js`); if (mathjax.asyncIsSynchronous) { return replace(match, entity); } From f9610c31419442c658f653d2df91ac46fabd8b2b Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 15 Aug 2026 10:27:05 -0400 Subject: [PATCH 3/3] Remove unneeded import --- ts/util/Entities.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ts/util/Entities.ts b/ts/util/Entities.ts index 365aba4d1..0532ac2a5 100644 --- a/ts/util/Entities.ts +++ b/ts/util/Entities.ts @@ -22,7 +22,6 @@ */ import { mathjax } from '../mathjax.js'; -import { asyncLoad } from './AsyncLoad.js'; import { OptionList } from './Options.js'; /**