重写根据题库获得各种LaTeX源文件的内容的函数, 新增"多种题目生成.py"功能
This commit is contained in:
parent
9edacdab7c
commit
803ec588cf
|
|
@ -967,6 +967,62 @@ def GenerateUsageTexCode(id,prodict,topandbottomusagestuple): #根据topandbotto
|
|||
usagecode = re.sub("\\t([\d]\.[\d]{0,10})",GenerateValueColorCode,"\n\n".join(usages))
|
||||
return usagecode #返回缩减后的使用记录列表
|
||||
|
||||
def generateLaTeXBodyContent(id,adict,objdict,misc): #根据id,读取的json内容adict,和字典misc来生成讲义
|
||||
#misc 样例
|
||||
#{
|
||||
# "教师版": True, #如果设置为True则除了 题后空间 之外都进行判断并处理, 否则只处理 题后空间 和 答案
|
||||
# "字段显示设置": {
|
||||
# "题后空间": True,
|
||||
# "课时目标": True,
|
||||
# "题目标签": True,
|
||||
# "答案": True,
|
||||
# "解答与提示": True,
|
||||
# "使用记录": (3,-1),
|
||||
# "使用记录说明": "(a,b)表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
|
||||
# "来源": True,
|
||||
# "备注": True,
|
||||
# "届别": []
|
||||
# }
|
||||
# }
|
||||
id = str(id).zfill(6)
|
||||
if misc["教师版"] == False:
|
||||
output = f"\n\\item {{\\tiny ({id})}} {adict[id]['content']}"
|
||||
if "答案" in misc["字段显示设置"] and misc["字段显示设置"]["答案"] == True:
|
||||
ans = adict[id]["ans"] if len(adict[id]["ans"]) > 0 else "暂无答案"
|
||||
output += f"\n\n答案: \\textcolor{{red}}{{{ans}}}\n\n"
|
||||
if "题后空间" in misc["字段显示设置"] and misc["字段显示设置"]["题后空间"] == True:
|
||||
space = f"\n\n\\vspace*{{{adict[id]['space']}}}\n\n" if len(adict[id]["space"]) > 0 else ""
|
||||
output += space
|
||||
else:
|
||||
output = f"\n\\item ({id}) {adict[id]['content']}"
|
||||
if "备注" in misc["字段显示设置"] and misc["字段显示设置"]["备注"] == True:
|
||||
remark = adict[id]["remark"] if len(adict[id]["remark"]) > 0 else "暂无备注"
|
||||
output += f"\n\n备注: \\textcolor[rgb]{{0,0.5,0.2}}{{{remark}}}\n\n"
|
||||
if "课时目标" in misc["字段显示设置"] and misc["字段显示设置"]["课时目标"] == True:
|
||||
objs = f"\n\n目标:\n\n{GenerateObjTexCode(id,adict,objdict)}\n\n"
|
||||
output += objs
|
||||
if "题目标签" in misc["字段显示设置"] and misc["字段显示设置"]["题目标签"] == True:
|
||||
tags_raw = adict[id]['tags']
|
||||
if len(tags_raw) == 0:
|
||||
tags = "暂无标签"
|
||||
else:
|
||||
tags = '; '.join(adict[id]['tags'])
|
||||
output += f"\n\n标签: \\textcolor[rgb]{{0.5,0.6,0.8}}{{{tags}}}\n\n"
|
||||
if "答案" in misc["字段显示设置"] and misc["字段显示设置"]["答案"] == True:
|
||||
ans = adict[id]["ans"] if len(adict[id]["ans"]) > 0 else "暂无答案"
|
||||
output += f"\n\n答案: \\textcolor{{red}}{{{ans}}}\n\n"
|
||||
if "解答与提示" in misc["字段显示设置"] and misc["字段显示设置"]["解答与提示"] == True:
|
||||
solution = adict[id]["solution"] if len(adict[id]["solution"]) > 0 else "暂无解答或提示"
|
||||
output += f"\n\n解答或提示: \\textcolor{{magenta}}{{{solution}}}\n\n"
|
||||
if "使用记录" in misc["字段显示设置"] and type(misc["字段显示设置"]["使用记录"]) in (list,tuple) and not -2 in misc["字段显示设置"]["使用记录"]:
|
||||
usages = f"\n\n使用记录:\n\n{GenerateUsageTexCode(id,adict,misc['字段显示设置']['使用记录'])}\n\n"
|
||||
output += usages
|
||||
if "来源" in misc["字段显示设置"] and misc["字段显示设置"]["来源"] == True:
|
||||
origin = adict[id]["origin"] if len(adict[id]["origin"]) > 0 else "未记录来源"
|
||||
output += f"\n\n来源: {origin}\n\n"
|
||||
return output
|
||||
|
||||
|
||||
def GenerateTeacherBodyString(problems,sectiontitles,prodict,objdict,consecutivenumbering = True,topandbottomusagestuple = (3,3),sectionname = "section", showobjs = True, showtags = True, showans = True, showsolution = True, showusages = True, showorigin = True, showremark = True, colored = False): #生成教师版的.tex文件的主体内容, 各项是否显示为可选
|
||||
bodystring = ""
|
||||
GetAfterContent = TeachersGetAfterContentPlain if not colored else TeachersGetAfterContentColored
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
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}秒")
|
||||
|
||||
pass
|
||||
|
|
@ -12,5 +12,25 @@
|
|||
"讲义标题格式": "V202503\\d{2}",
|
||||
"输出路径": "临时文件",
|
||||
"提供答案": true
|
||||
},
|
||||
"多种题目生成.py": {
|
||||
"标题与题号": {
|
||||
"第一讲": "5:25",
|
||||
"第二讲": "20001:20030,70:80"
|
||||
},
|
||||
"pdf标题": "测试题库",
|
||||
"教师版": true,
|
||||
"字段显示设置": {
|
||||
"题后空间": true,
|
||||
"课时目标": true,
|
||||
"题目标签": true,
|
||||
"答案": true,
|
||||
"解答与提示": true,
|
||||
"使用记录": [3,2],
|
||||
"使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
|
||||
"来源": true,
|
||||
"备注": true,
|
||||
"届别": []
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue