latex编辑题目后在汇入题库前进行编译测试

This commit is contained in:
weiye.wang 2024-02-06 12:03:36 +08:00
parent 4766ab185a
commit c0a5963e50
3 changed files with 44 additions and 2 deletions

View File

@ -888,6 +888,20 @@ def XeLaTeXCompile(filedir,filename): #在filedir目录中用XeLaTeX编译filena
return flagsuc # 若第二次编译成功则返回True, 否则返回False return flagsuc # 若第二次编译成功则返回True, 否则返回False
def XeLaTeXTest(editedid,adict,objdict,misc,templatepath,outdir,outfile): #对adict中的题号字符串editedid进行编译测试, 返回成功True或失败False
latex_raw = ReadTextFile(templatepath)
if misc["教师版"] == True:
latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学")
bodystring = "\\begin{enumerate}\n\n"
idlist = generate_number_set(editedid)
for id in idlist:
bodystring += generateLaTeXBodyContent(id,adict,objdict,misc)
bodystring += "\n\n\\end{enumerate}\n\n"
latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,("测试",bodystring)) #替换标题和bodystring
SaveTextFile(latex_data,os.path.join(outdir,outfile))
succ = XeLaTeXCompile(outdir,outfile)
return succ
def GenerateSectionBodyString2024(problems,sectiontitles,pro_dict,obj_dict,bk_dict,misc,consecutivenumbering= True): #生成学生版的.tex文件的主体内容 def GenerateSectionBodyString2024(problems,sectiontitles,pro_dict,obj_dict,bk_dict,misc,consecutivenumbering= True): #生成学生版的.tex文件的主体内容
bodystring = "" bodystring = ""
count = 0 count = 0

View File

@ -1,11 +1,23 @@
id_string = "20478" id_string = "24488:24499"
editor = "王伟叶" editor = "王伟叶"
from database_tools import * from database_tools import *
pro_dict = load_dict("../题库0.3/problems.json") pro_dict = load_dict("../题库0.3/problems.json")
obj_dict = load_dict("../题库0.3/LessonObj.json")
tempfilepath = "临时文件/problem_edit.tex" tempfilepath = "临时文件/problem_edit.tex"
pro_dict_raw_string = ReadTextFile("../题库0.3/Problems.json")
configjson = load_dict("文本文件/config.json")["默认完整编译题目模式"]
edited = ModifyProblembyTeX(id_string,pro_dict,tempfilepath,editor) edited = ModifyProblembyTeX(id_string,pro_dict,tempfilepath,editor)
print("编辑过的题号: %s"%edited) print("编辑过的题号: %s"%edited)
if not XeLaTeXTest(edited,pro_dict,obj_dict,configjson,templatepath="模板文件/讲义模板.txt",outdir = "临时文件",outfile = "problems_test.tex"):
SaveTextFile(pro_dict_raw_string,"../题库0.3/Problems.json")
print("编译失败, 题库文件退回原状")
else:
print("编译成功, 已汇入题库")

View File

@ -51,5 +51,21 @@
}, },
"编译单个文件": false, "编译单个文件": false,
"编译合集": true "编译合集": true
},
"默认完整编译题目模式": {
"输出路径": "临时文件",
"教师版": true,
"字段显示设置": {
"题后空间": true,
"课时目标": true,
"题目标签": true,
"答案": true,
"解答与提示": true,
"使用记录": [3,-1],
"使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
"来源": true,
"备注": true,
"届别": []
}
} }
} }