diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 3b988fea..82d9acf2 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -888,6 +888,20 @@ def XeLaTeXCompile(filedir,filename): #在filedir目录中用XeLaTeX编译filena 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文件的主体内容 bodystring = "" count = 0 diff --git a/工具v2/latex编辑题目答案及提示.py b/工具v2/latex编辑题目答案及提示.py index 1ede5751..d8252427 100644 --- a/工具v2/latex编辑题目答案及提示.py +++ b/工具v2/latex编辑题目答案及提示.py @@ -1,11 +1,23 @@ -id_string = "20478" +id_string = "24488:24499" editor = "王伟叶" from database_tools import * pro_dict = load_dict("../题库0.3/problems.json") +obj_dict = load_dict("../题库0.3/LessonObj.json") 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) -print("编辑过的题号: %s"%edited) \ No newline at end of file +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("编译成功, 已汇入题库") \ No newline at end of file diff --git a/工具v2/文本文件/config.json b/工具v2/文本文件/config.json index b249b131..da319cd6 100644 --- a/工具v2/文本文件/config.json +++ b/工具v2/文本文件/config.json @@ -51,5 +51,21 @@ }, "编译单个文件": false, "编译合集": true + }, + "默认完整编译题目模式": { + "输出路径": "临时文件", + "教师版": true, + "字段显示设置": { + "题后空间": true, + "课时目标": true, + "题目标签": true, + "答案": true, + "解答与提示": true, + "使用记录": [3,-1], + "使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示", + "来源": true, + "备注": true, + "届别": [] + } } } \ No newline at end of file