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:
@@ -1633,6 +1633,18 @@ class MrowVisitor(Visitor):
|
||||
# Found a fragmented function - add it to parts
|
||||
parts.append(function_name)
|
||||
i += consumed_count
|
||||
elif self._is_plain_single_letter_mi(children[i]):
|
||||
# Consecutive single-letter identifiers are joined without spaces:
|
||||
# Word often splits a multi-letter identifier (e.g. line segment "BC")
|
||||
# into several runs, which OMML2MML turns into adjacent <mi> elements.
|
||||
# Re-merge them so "BC" stays "BC" instead of "B C" (which renders as B×C).
|
||||
merged = self._convert_child(children[i])
|
||||
j = i + 1
|
||||
while j < len(children) and self._is_plain_single_letter_mi(children[j]):
|
||||
merged += self._convert_child(children[j])
|
||||
j += 1
|
||||
parts.append(merged)
|
||||
i = j
|
||||
else:
|
||||
# No fragmented function - convert child normally
|
||||
part = self._convert_child(children[i])
|
||||
@@ -1642,6 +1654,21 @@ class MrowVisitor(Visitor):
|
||||
|
||||
return ' '.join(parts).strip()
|
||||
|
||||
def _is_plain_single_letter_mi(self, node: ET.Element) -> bool:
|
||||
"""Return True if node is a single plain-letter <mi> identifier.
|
||||
|
||||
Used to re-merge multi-letter identifiers (e.g. line segment "BC") that
|
||||
Word split into adjacent <mi> runs. Only plain italic identifiers are
|
||||
merged; elements carrying an explicit mathvariant (e.g. normal for
|
||||
chemical formulas, double-struck, etc.) are left untouched.
|
||||
"""
|
||||
if _local(node.tag) != 'mi':
|
||||
return False
|
||||
if node.get('mathvariant') is not None:
|
||||
return False
|
||||
content = _text_content(node).strip()
|
||||
return len(content) == 1 and content.isalpha()
|
||||
|
||||
def _convert_children_no_space(self, node: ET.Element) -> str:
|
||||
"""Convert all children and join without spaces."""
|
||||
parts = []
|
||||
|
||||
Reference in New Issue
Block a user