Modern Apps git

← Modern-Apps.git

library: fix markdown arrows mangled by left/right stripping

Commit
1a1c3fb4f6c6e64d2a15a06a0ff7625e7d702fc8
Author
Vayun Mathur <[email protected]>
When
2026-11-07 14:06 UTC (28 days ago)
Parents
3249da1
formatMathContent stripped the substrings \left and \right before
replacing LaTeX commands, so \rightarrow rendered as the literal
text "arrow" and \leftarrow lost its command too.

Only strip \left/\right when not followed by a letter, so the arrow
commands survive to the command-replacement step (which maps them to
unicode arrows).

Verified by LibraryMarkdown2Test#latexCommandSweepAndHeaderLevel6
(\rightarrow/\leftarrow assertions failed before, pass after) and
the full :library:testDebugUnitTest suite.

Diff

library/src/main/java/com/vayunmathur/library/util/Markdown.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/Markdown.kt b/library/src/main/java/com/vayunmathur/library/util/Markdown.ktindex 541e1fca50..d383ea33b8 100644--- a/library/src/main/java/com/vayunmathur/library/util/Markdown.kt+++ b/library/src/main/java/com/vayunmathur/library/util/Markdown.kt@@ -577,8 +577,11 @@ private val latexCommands = mapOf( private fun formatMathContent(content: String): String {     var result = content -    // 1. Strip \left and \right-    result = result.replace("\\left", "").replace("\\right", "")+    // 1. Strip \left and \right (but not \leftarrow / \rightarrow, which are+    // commands of their own and are replaced below).+    result = result+        .replace(Regex("\\\\left(?![A-Za-z])"), "")+        .replace(Regex("\\\\right(?![A-Za-z])"), "")      // 2. Handle \frac{a}{b} -> ((a)/(b))     repeat(FRAC_REPLACE_PASSES) {