This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具v2/新题比对.py

46 lines
1.6 KiB
Python

outputpath = "临时文件/新题比对.tex"
from database_tools import *
colors = ["green","orange","blue"]
templatepath = ".\模板文件\讲义模板.txt"
pro_dict = load_dict("../题库0.3/problems.json")
treated_dict = treat_dict(pro_dict)
data = getCopy()
problems = [(d.strip()) for d in data.split("\\item") if not d.strip() == ""]
output = "使用说明: repxxxxxx表示使用已有题号xxxxxx, sxxxxxx,yyyyyy,...表示和xxxxxx,yyyyyy,...相同, rxxxxxx,yyyyyy,...表示和xxxxxx,yyyyyy,...相关\n\n\\begin{enumerate}\n\n"
for p in problems:
p_treated = pre_treating(p)
t = stringmaxsim(p_treated,treated_dict,3)
psrstring = ""
for id,simrate in t:
if simrate == 1:
psrstring = "rep"+id
break
else:
psrstring += id + ","
if psrstring[-1] == ",":
psrstring = psrstring[:-1]
output += f"\\item [{psrstring}] {p}\n\n"
count = 0
for id,simrate in t:
output += "\n\\begin{tcolorbox}"+f"[colback = {colors[count]}!10!white, colframe = orange!10!white, breakable]\n"
output += f"{simrate:.3f} \\ {id}\n\n"
content = pro_dict[id]["content"]
output += f"{content}\n"
output += "\\end{tcolorbox}\n"
count += 1
output += "\n\n"
output += "\n\\end{enumerate}\n\n"
texraw = ReadTextFile(templatepath)
texdata = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",texraw,("新题比对"+f"{GetDate()}",output))
texfilepath = os.path.join(os.getcwd(),outputpath)
SaveTextFile(texdata,texfilepath)
os.system(f"code {texfilepath}")
# dir,filename = os.path.split(texfilepath)
# XeLaTeXCompile(dir,filename)