diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index a942ae3d..7c21b6b0 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -870,6 +870,58 @@ def GenerateLessonPreparationDraft(notetitle, outputdir, adict, prodict, objdict else: print("编译失败") return latex_data # 返回有错误的latex源代码 + +def GenerateLessonPreparation(notetitle, outputdir, adict, prodict, objdict, lessonsdict, basicknowledgedict): #根据adict中课时与例题, 课堂练习, 作业题的题号对应生成每一课时的教案 + output = "\\tableofcontents\n\\newpage\n\n" + + outputfilepath = os.path.join(outputdir,notetitle+".tex") + + + for lid in adict: + output += "\\section{%s \ %s}\n\n"%(lid,lessonsdict[lid]["name"]) + output += "\\subsection{课时目标}\n\n" + output += "\\begin{enumerate}\n\n" + for objid in objdict: + if objid.startswith(lid): + output += "\\item %s \\ %s \n\n"%(objid,objdict[objid]["content"]) + output += "\\end{enumerate}\n\n" + + output += "\\subsection{双基梳理}\n\n" + basic_body = "" + for bnid in basicknowledgedict: + if basicknowledgedict[bnid]["obj"].startswith(lid): + basic_body += "\\item %s\n\n"%basicknowledgedict[bnid]["content"] + output += "\\begin{enumerate}\n\n %s\n\n\\end{enumerate}\n\n"%(basic_body if basic_body != "" else "\\item 暂无") + problems_list = adict[lid] + output += "\\subsection{知识体验}\n\n" + output += "\\subsubsection{必讲例题}\n\n" + output += GenerateStudentBodyString([problems_list[0]],[],prodict,consecutivenumbering=False,answered=False) + output += "\\subsubsection{选讲例题}\n\n" + output += GenerateStudentBodyString([problems_list[1]],[],prodict,consecutivenumbering=False,answered=False) + output += "\\subsection{巩固新知}\n\n" + output += GenerateStudentBodyString([problems_list[2]],[],prodict,consecutivenumbering=False,answered=False) + output += "\\subsection{课后作业}\n\n" + output += GenerateStudentBodyString([problems_list[3]],[],prodict,consecutivenumbering=False,answered=False) + output += "\\newpage" + + + latex_raw = ReadTextFile("模板文件/讲义模板.txt") + 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) + + latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,output)) #替换标题和bodystring + SaveTextFile(latex_data,outputfilepath) #保存.tex文件 + + if XeLaTeXCompile(outputdir,notetitle+".tex"): + print("编译成功") + return 0 # 返回0 + else: + print("编译失败") + return latex_data # 返回有错误的latex源代码 + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file