60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
from database_tools import *
|
|
import time
|
|
|
|
|
|
configjson = load_dict("文本文件/config.json")["多种题目生成.py"]
|
|
|
|
|
|
prodictpath = "../题库0.3/Problems.json"
|
|
objdictpath = "../题库0.3/LessonObj.json"
|
|
raw_pro_dict = load_dict(prodictpath)
|
|
|
|
grades = configjson["字段显示设置"]["届别"]
|
|
pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades)
|
|
obj_dict = load_dict(objdictpath)
|
|
|
|
notetitle = configjson["pdf标题"]
|
|
outputdir = "临时文件" #输出文件的目录
|
|
outputfilepath = os.path.join(outputdir,notetitle+".tex")
|
|
print("输出文件目录: %s\n输出文件名: %s"%(os.path.join(os.getcwd(),outputdir),notetitle+".tex"))
|
|
|
|
latex_raw = ReadTextFile("模板文件/讲义模板.txt")
|
|
if configjson["教师版"] == True:
|
|
latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学")
|
|
|
|
if sys.platform != "win32": #非win系统用默认字体
|
|
latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw)
|
|
latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw)
|
|
|
|
bodystring = "\\tableofcontents\n\n\\newpage\n\n"
|
|
bodylist = []
|
|
|
|
|
|
problems_dict = configjson["标题与题号"]
|
|
|
|
starttime = time.time()
|
|
|
|
for p in problems_dict:
|
|
currentbodystring = f"\\section{{{p}}}\n\\begin{{enumerate}}\n\n"
|
|
for id in generate_number_set(problems_dict[p]):
|
|
if id in pro_dict:
|
|
currentbodystring += generateLaTeXBodyContent(id,pro_dict,obj_dict,configjson)
|
|
currentbodystring += "\\end{enumerate}"
|
|
bodylist.append(currentbodystring)
|
|
bodystring += "\n\n\\newpage\n\n".join(bodylist)
|
|
|
|
midtime = time.time()
|
|
print(f"生成LaTeX文件所花时间: {midtime-starttime:.3f}秒")
|
|
|
|
latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,bodystring)) #替换标题和bodystring
|
|
SaveTextFile(latex_data,outputfilepath) #保存.tex文件
|
|
|
|
if XeLaTeXCompile(outputdir,notetitle+".tex"):
|
|
print("编译成功")
|
|
else:
|
|
print("编译失败")
|
|
|
|
endtime = time.time()
|
|
print(f"生成pdf文件所花时间: {endtime-midtime:.3f}秒")
|
|
|