Files
Quentin 3271fee5cc init: WordFileParse docx→HTML 解析服务(含 Word EQ 域公式修复)
服务:Spring Boot 3.2 + docx4j 8.3.9,POST /api/v3/server_office_file/file/parse
      接受 .docx,返回 HTML(公式 → LaTeX,图片 → RustFS 外链)

公式支持三类来源:
- OMML(Word 2007+ 公式)      → Python omml_mathml2latex
- MathType OLE 对象            → Ruby mathtype2mathml → MathML → LaTeX
- Word EQ 域(老教辅主力)      → EqToLatexUtil(本次新增)

本次改动:
1. 新增 java-svc/.../core/EqToLatexUtil.java:
   移植自 jby backend-services office-core,EQ 语法 → LaTeX
   (\f→\dfrac、\r→\sqrt、\i→\int/\sum/\prod、\s→^{}/_{}、\b→\left\right、
     \a→array、\x→\boxed/\overline、\o\al 堆叠、圈码、化学符号、极限、连等式)
   品牌标记 JBYU* → WPU*,与采集端一致
2. CtoMathFinder:接上 EQ 分支(原为 not-ported 桩),域代码经
   EqToLatexUtil.convert 转 LaTeX 写入 eqLatexMap(WPEQNUM 占位符)
3. WordParseUtil.dealPlaceholder:EQ 的 LaTeX 同样加 \( \) 包裹
   (原先因 WPEQNUM 例外不加包裹,前端/MathJax 不渲染)

修前症状:教辅 Word 里分式/方程组/上下标整段丢失(如 {−1/3, 1} 变成 {-,1})
修后实测:46 份教辅 2908 处 EQ 域全部还原,公式总数 2954 处、零未包裹残留

安全:application.yml(含 RustFS 密钥)不入库,提供 application.yml.example;
      OssService 的 @Value 默认密钥已清空
2026-09-29 09:43:13 +08:00

72 lines
2.5 KiB
Python

"""
Mathematical functions and chemical elements definitions.
Contains:
- MATH_FUNCTIONS: Set of 60+ recognized mathematical functions
- CHEMICAL_ELEMENTS: Set of 118 chemical elements
"""
# Comprehensive function database
MATH_FUNCTIONS = {
# Trigonometric functions
'sin', 'cos', 'tan', 'sec', 'csc', 'cot',
'sinh', 'cosh', 'tanh', 'sech', 'csch', 'coth',
'arcsin', 'arccos', 'arctan', 'arcsec', 'arccsc', 'arccot',
'asin', 'acos', 'atan', 'asec', 'acsc', 'acot',
'arcsinh', 'arccosh', 'arctanh', 'arcsech', 'arccsch', 'arccoth',
'asinh', 'acosh', 'atanh', 'asech', 'acsch', 'acoth',
# Logarithmic and exponential
'log', 'ln', 'lg', 'exp', 'log2', 'log10',
# Limits and supremum/infimum
'lim', 'limsup', 'liminf', 'sup', 'inf', 'max', 'min',
# Linear algebra
'det', 'dim', 'ker', 'rank', 'trace', 'tr', 'span', 'null',
'col', 'row', 'diag', 'adj',
# Number theory
'gcd', 'lcm', 'mod', 'rem',
# Probability and statistics
'Pr', 'Var', 'Cov', 'Corr', 'Std', 'Med',
# Calculus and analysis
'grad', 'div', 'curl', 'rot', 'arg', 'Im', 'Re',
'sgn', 'sign', 'abs', 'floor', 'ceil', 'round',
# Special functions
'erf', 'erfc', 'gamma', 'Gamma', 'zeta', 'beta', 'Beta',
'sinc', 'jinc',
# Hyperbolic and inverse hyperbolic
'arsinh', 'arcosh', 'artanh', 'arsech', 'arcsch', 'arcoth',
# Other common functions
'deg', 'rad', 'hom', 'end', 'aut', 'id',
}
# Chemical elements for special handling
CHEMICAL_ELEMENTS = {
'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne',
'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca',
'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn',
'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr',
'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn',
'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd',
'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb',
'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg',
'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th',
'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm',
'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds',
'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og'
}
# Mathematical set notation symbols that should be wrapped in \mathrm{}
MATHEMATICAL_SETS = {
'N', 'Z', 'Q', 'R', 'C', # Number sets (Natural, Integer, Rational, Real, Complex)
'A', 'B', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'O', 'P', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', # Generic sets
}