parent
e8f730b593
commit
964cb6bb7f
@ -1,37 +0,0 @@
|
|||||||
import win32com.client
|
|
||||||
import re
|
|
||||||
|
|
||||||
def convert_to_latex(formula_xml):
|
|
||||||
# 简单转换规则 - 实际应用中可能需要更复杂的处理
|
|
||||||
latex = formula_xml
|
|
||||||
latex = re.sub(r'<[^>]+>', '', latex) # 移除XML标签
|
|
||||||
latex = latex.replace('<', '<').replace('>', '>')
|
|
||||||
return f"${latex}$"
|
|
||||||
|
|
||||||
def convert_math_type_to_word_formula(doc_path):
|
|
||||||
word = win32com.client.Dispatch("Word.Application")
|
|
||||||
doc = word.Documents.Open(doc_path)
|
|
||||||
|
|
||||||
formula_count = 0
|
|
||||||
latex_formulas = []
|
|
||||||
|
|
||||||
for omath in doc.OMaths:
|
|
||||||
formula_count += 1
|
|
||||||
try:
|
|
||||||
formula_xml = omath.Range.WordOpenXML
|
|
||||||
if formula_xml:
|
|
||||||
latex = convert_to_latex(formula_xml)
|
|
||||||
latex_formulas.append(latex)
|
|
||||||
print(f"公式{formula_count} LaTeX: {latex[:100]}...")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"公式{formula_count}转换错误: {str(e)}")
|
|
||||||
|
|
||||||
print(f"\n最终LaTeX输出:")
|
|
||||||
for i, latex in enumerate(latex_formulas, 1):
|
|
||||||
print(f"公式{i}: {latex}")
|
|
||||||
|
|
||||||
doc.Close(False)
|
|
||||||
word.Quit()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
convert_math_type_to_word_formula(r'D:\dsWork\dsProject\dsRag\Test\化学方程式_CHEMISTRY_1.docx')
|
|
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
pandoc input.md -o output.docx --resource-path=static --from=markdown+hard_line_breaks --to=docx --standalone --verbose
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue