From 82db2ae624c82872d52f21b633304e7c2acc4ce6 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 14 Jul 2025 07:29:57 -0400 Subject: [PATCH] Place the hidden svg/defs elements at the beginning of the document, not the end --- ts/handlers/html/HTMLDocument.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ts/handlers/html/HTMLDocument.ts b/ts/handlers/html/HTMLDocument.ts index 2e9b04bd3..e5d0ff9cc 100644 --- a/ts/handlers/html/HTMLDocument.ts +++ b/ts/handlers/html/HTMLDocument.ts @@ -278,10 +278,16 @@ export class HTMLDocument extends AbstractMathDocument { * Add any elements needed for the document */ protected addPageElements() { - const body = this.adaptor.body(this.document); + const adaptor = this.adaptor; + const body = adaptor.body(this.document); const node = this.documentPageElements(); if (node) { - this.adaptor.append(body, node); + const child = adaptor.firstChild(body); + if (child) { + adaptor.insert(node, child); + } else { + adaptor.append(body, node); + } } }