This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具v2/参考答案生成.py

25 lines
1.3 KiB
Python

answeringfilepath = r"C:\Users\weiye\Documents\wwy sync\23届" # 要生成答案的路径
outputfilepath = "临时文件/23届" # 输出文件路径
from database_tools import *
texfiles, texpaths = GetValidTexFiles(answeringfilepath)
pro_dict = load_dict("../题库0.3/Problems.json")
for path in texpaths:
pathname = os.path.split(path)[1]
mainbody = "\n\n\\tableofcontents\n\n\\newpage\n\n"
sections = []
for f in texfiles:
if f.startswith(path) and len(re.findall("答案",ReadTextFile(f)))<10:
sectionname = os.path.split(f)[1].replace("_","-")[:-4]
idlist = re.findall(r"\((\d{6})\)",ReadTextFile(f))
sections = sections + [GenerateStudentBodyString([",".join(idlist)],[sectionname],pro_dict,consecutivenumbering=True,answered=True,spaceflag=False)]
mainbody += "\n\n\\newpage\n\n".join(sections)
latex_raw = ReadTextFile("模板文件/讲义模板.txt")
latexstr = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(pathname+" 参考答案",mainbody))
SaveTextFile(latexstr,os.path.join(outputfilepath,pathname+"参考答案.tex"))
print("正在编译 %s 文件"%os.path.join(outputfilepath,pathname+"参考答案.tex"))
XeLaTeXCompile(outputfilepath,pathname+"参考答案.tex") # 在指定目录中生成相应的答案文件