import os import re sections = ["section_1.md", "section_2.md", "section_3.md", "section_4.md", "section_5.md"] draft_content = "" for sec in sections: if os.path.exists(sec): with open(sec, "r") as f: draft_content += f.read() + "\n\n" with open("draft.md", "w") as f: f.write(draft_content) # Basic Markdown to LaTeX conversion tex_content = draft_content tex_content = re.sub(r'^# (.*?)$', r'\\section{\1}', tex_content, flags=re.MULTILINE) tex_content = re.sub(r'^## (.*?)$', r'\\subsection{\1}', tex_content, flags=re.MULTILINE) tex_content = re.sub(r'^### (.*?)$', r'\\subsubsection{\1}', tex_content, flags=re.MULTILINE) tex_content = re.sub(r'\*\*(.*?)\*\*', r'\\textbf{\1}', tex_content) # A simplified regex for italics to avoid messing up LaTeX commands or math too much # tex_content = re.sub(r'(?