LaTex ecuations
Some checks failed
build_docker / essential (push) Successful in 1s
build_docker / build_paddle_ocr (push) Has started running
build_docker / build_doctr_gpu (push) Has been cancelled
build_docker / build_easyocr (push) Has been cancelled
build_docker / build_easyocr_gpu (push) Has been cancelled
build_docker / build_doctr (push) Has been cancelled
build_docker / build_raytune (push) Has been cancelled
build_docker / build_paddle_ocr_gpu (push) Has been cancelled

This commit is contained in:
2026-02-04 21:07:27 +01:00
parent e9c937a042
commit b91e31e173
9 changed files with 157 additions and 108 deletions

View File

@@ -92,25 +92,23 @@ def md_to_html_para(text):
def convert_latex_formulas(text):
"""Convert LaTeX formulas to MathML for Word compatibility."""
# Block formulas $$...$$
"""Convert LaTeX formulas to styled text for easy copy-paste into Word equation editor.
Word's equation editor accepts LaTeX directly, so we preserve the LaTeX code
in a visually distinct format that users can copy and paste.
"""
# Block formulas $$...$$ - center and style as equation placeholder
def convert_block(match):
latex = match.group(1)
try:
mathml = latex_to_mathml(latex, display="block")
return f'<p class=MsoNormal style="text-align:center">{mathml}</p>'
except:
return match.group(0) # Keep original if conversion fails
latex = match.group(1).strip()
# Style as centered, monospace text that's easy to identify and copy
return f'<p class=MsoNormal style="text-align:center;background:#f5f5f5;padding:8pt;margin:6pt 40pt;font-family:Consolas;font-size:10pt"><span lang=ES>{latex}</span></p>'
text = re.sub(r'\$\$([^$]+)\$\$', convert_block, text)
# Inline formulas $...$
# Inline formulas $...$ - style as inline code
def convert_inline(match):
latex = match.group(1)
try:
return latex_to_mathml(latex, display="inline")
except:
return match.group(0)
latex = match.group(1).strip()
return f'<span style="font-family:Consolas;font-size:10pt;background:#f5f5f5;padding:1pt 3pt">{latex}</span>'
text = re.sub(r'\$([^$]+)\$', convert_inline, text)
return text