fix: fragmented-function 前缀匹配,修复 sinx 误输出为 'sinx' 而非 '\sin x' #2
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题现象
当函数名被 Word 拆成多个 run 且紧贴变量时(如
<mi>s</mi><mi>i</mi><mi>n</mi><mi>x</mi>),输出sinx而非\sin x。根因
visitors/mrow_visitor.py的_check_fragmented_function_at_position把所有连续单字母拼成整串"sinx",然后只查整串是否在MATH_FUNCTIONS中,不做前缀匹配,导致"sinx"匹配失败、函数名未被识别。(注:
compat/legacy_adapter.py的_check_fragmented_function_at_level早已是前缀匹配,仅 mrow_visitor 这一处遗漏。)修复
改为前缀匹配(从最长 6 字母到最短 2 字母),只消耗函数名对应的字母,其余字母留给调用方继续转换。
验证
sinx/cosx/tanx→\sin x/\cos x/\tan xsin/log→\sin/\log(不回归)log_2(msub)→\log_{2}(不回归)BC = 2拼接 → 仍正确(不回归)test_mixed.docx130 个 OMML 公式输出与上一轮修复相比零变化(纯增量)关联 commit:
93d0709