* better latex support (changed delimiter from /( to regular $)

This commit is contained in:
Crizomb 2024-04-19 03:01:54 +02:00
parent 3a2878496a
commit 426c030c36
10 changed files with 402 additions and 173 deletions

View file

@ -1,4 +1,6 @@
import subprocess
from pathlib import Path
import time
def pdf_to_mmd(path_input: str):
@ -11,6 +13,18 @@ def pdf_to_mmd(path_input: str):
output_dir = "../documents/mmds"
command = ['nougat', path_input, "-o", output_dir]
subprocess.run(command)
time.sleep(1)
# Change the math delimiter to the common delimiter used in MMD
with open(f"{output_dir}/{str(Path(path_input).stem)}.mmd", "r+") as doc:
content = doc.read()
print(content)
content = content.replace(r"\[", "$$").replace(r"\]", "$$")
content = content.replace(r"\(", "$").replace(r"\)", "$")
# delete the content of the file
doc.seek(0)
doc.truncate()
doc.write(content)