From a39c43a2a98ecce64036fd43d2a7e74422b82a96 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 29 Oct 2025 13:08:47 -0400 Subject: [PATCH 1/2] Use a default font size when it can't be computed directly (e.g., the element is not in an active DOM). (mathjax/MathJax#3458) --- ts/adaptors/HTMLAdaptor.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ts/adaptors/HTMLAdaptor.ts b/ts/adaptors/HTMLAdaptor.ts index b5d4799df..41c2b497b 100644 --- a/ts/adaptors/HTMLAdaptor.ts +++ b/ts/adaptors/HTMLAdaptor.ts @@ -199,6 +199,13 @@ export class HTMLAdaptor< extends AbstractDOMAdaptor implements MinHTMLAdaptor { + + /** + * The font size to use when it can't be measured (e.g., the element + * isn't in the DOM). + */ + public static DEFAULT_FONT_SIZE = 16; + /** * The HTML adaptor can measure DOM node sizes */ @@ -588,7 +595,10 @@ export class HTMLAdaptor< */ public fontSize(node: N) { const style = this.window.getComputedStyle(node); - return parseFloat(style.fontSize); + return parseFloat( + style.fontSize || + String((this.constructor as typeof HTMLAdaptor).DEFAULT_FONT_SIZE) + ); } /** From 85d8430c7868c607f4297b29797ef21d672d2fb7 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Tue, 4 Nov 2025 08:57:39 -0500 Subject: [PATCH 2/2] Make prettier happy --- ts/adaptors/HTMLAdaptor.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ts/adaptors/HTMLAdaptor.ts b/ts/adaptors/HTMLAdaptor.ts index 41c2b497b..1a385a545 100644 --- a/ts/adaptors/HTMLAdaptor.ts +++ b/ts/adaptors/HTMLAdaptor.ts @@ -199,7 +199,6 @@ export class HTMLAdaptor< extends AbstractDOMAdaptor implements MinHTMLAdaptor { - /** * The font size to use when it can't be measured (e.g., the element * isn't in the DOM). @@ -597,7 +596,7 @@ export class HTMLAdaptor< const style = this.window.getComputedStyle(node); return parseFloat( style.fontSize || - String((this.constructor as typeof HTMLAdaptor).DEFAULT_FONT_SIZE) + String((this.constructor as typeof HTMLAdaptor).DEFAULT_FONT_SIZE) ); }