From 5e7240e2d0bbd7eecaf2c7f67a10bb98103598e7 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 4 Dec 2025 20:50:48 +0000 Subject: [PATCH] fix: Convert inline `align` environments to display math Co-authored-by: aider (gemini/gemini-2.5-pro) --- webclient/src/Article.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/webclient/src/Article.js b/webclient/src/Article.js index 08261bb..0761dca 100644 --- a/webclient/src/Article.js +++ b/webclient/src/Article.js @@ -149,8 +149,25 @@ function Article({ cache }) { } if (isMath) { - console.log(v, isMath); - return {v.textContent}; + let mathContent = v.textContent; + // align environment requires display math mode + if (mathContent.includes('\\begin{align')) { + const trimmed = mathContent.trim(); + if (trimmed.startsWith('\\(')) { + // Replace \( and \) with \[ and \] to switch to display mode + const firstParen = mathContent.indexOf('\\('); + const lastParen = mathContent.lastIndexOf('\\)'); + mathContent = mathContent.substring(0, firstParen) + '\\[' + mathContent.substring(firstParen + 2, lastParen) + '\\]' + mathContent.substring(lastParen + 2); + } else if (trimmed.startsWith('$') && !trimmed.startsWith('$$')) { + // Replace $ with $$ + const firstDollar = mathContent.indexOf('$'); + const lastDollar = mathContent.lastIndexOf('$'); + if (firstDollar !== lastDollar) { + mathContent = mathContent.substring(0, firstDollar) + '$$' + mathContent.substring(firstDollar + 1, lastDollar) + '$$' + mathContent.substring(lastDollar + 1); + } + } + } + return {mathContent}; } if (VOID_ELEMENTS.includes(Tag)) {