fix(omml2latex): 修复多字母标识符被拆开的问题

OMML2MML 会把 Word 里连写的多字母标识符(线段名 BC、三角形 △ABC、
角度 45° 等)拆成相邻的 <mi>/<mn> 元素,原转换器用空格 join 导致
'BC' 被渲染成 'B C'(B×C),'45°' 变成 '4 5°'。

三处修复:
- mrow_visitor: 连续单字母 <mi> 拼接
- legacy_adapter: <math> 根节点多子元素时连续单字母 <mi> 拼接
- math_strategy: Unicode+字母混合内容按'LaTeX命令后跟字母才加空格'规则 join

回归验证:test_mixed.docx 130 个 OMML 公式,16 个发生变化且全部为
正确改善(线段名/角度/三角形/隐式乘法拼接),零误伤。
This commit is contained in:
2026-10-15 01:01:10 +08:00
parent b00f8d7f46
commit d4c2fd1fca
4 changed files with 75 additions and 1 deletions

View File

@@ -141,7 +141,19 @@ class MathStrategy(Strategy):
converted_parts.append(' ')
else:
converted_parts.append(char)
return ' '.join(converted_parts)
# Join with intelligent spacing: a LaTeX command followed by a
# letter/digit needs a space (otherwise "\triangleA" becomes an
# undefined command), but plain letters stay adjacent so that a
# multi-letter identifier like "△ABC" becomes "\triangle ABC",
# not "\triangle A B C".
result_parts = []
for idx, part in enumerate(converted_parts):
result_parts.append(part)
if idx < len(converted_parts) - 1:
nxt = converted_parts[idx + 1]
if part.startswith('\\') and nxt and (nxt[0].isalpha() or nxt[0].isdigit()):
result_parts.append(' ')
return ''.join(result_parts)
# USER REQUIREMENT: "use the mathvariant to determine whether it's mathrm"
# REMOVED: Chemistry detection heuristics (lines 139-162)