工具v2中新增 参考答案生成 工具
This commit is contained in:
parent
311db87ad6
commit
a4fc1f9328
|
|
@ -0,0 +1,25 @@
|
||||||
|
answeringfilepath = r"C:\Users\weiye\Documents\wwy sync\23届" # 要生成答案的路径
|
||||||
|
outputfilepath = "临时文件" # 输出文件路径
|
||||||
|
|
||||||
|
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") # 在指定目录中生成相应的答案文件
|
||||||
Reference in New Issue