在工具面板上增加了 在LaTeX界面修改题目内容 的菜单项, 同时可设置编辑者

This commit is contained in:
weiye.wang 2023-04-08 20:40:40 +08:00
parent e5bf2adcee
commit 3e01d7b137
5 changed files with 124 additions and 4 deletions

View File

@ -0,0 +1,40 @@
import os,re,json
"""这里编辑题号(列表)后将在vscode中打开窗口, 编辑后保存关闭"""
problems = "1:10"
editor = "王伟叶"
def generate_number_set(string,dict):
string = re.sub(r"[\n\s]","",string)
string_list = string.split(",")
numbers_list = []
for s in string_list:
if not ":" in s:
numbers_list.append(s.zfill(6))
else:
start,end = s.split(":")
for ind in range(int(start),int(end)+1):
numbers_list.append(str(ind).zfill(6))
return numbers_list
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
database = f.read()
pro_dict = json.loads(database)
idlist = generate_number_set(problems,pro_dict)
output = "编辑者: " + editor + "\n\n\\begin{enumerate}\n\n"
for id in idlist:
output += "\\item (%s) "%str(id).zfill(6) + pro_dict[id]["content"] + "\n\n"
output += "\\end{enumerate}"
with open("模板文件/题目编辑.txt","r",encoding="u8") as f:
texdata = f.read()
newtexdata = texdata.replace("待替换",output)
with open("临时文件/problems_edit.tex","w",encoding="u8") as f:
f.write(newtexdata)
os.system(r"code -g 临时文件/problems_edit.tex")

View File

@ -0,0 +1,25 @@
import json,re,time
with open("临时文件/problems_edit.tex","r",encoding="u8") as f:
data = f.read()
problems_string = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate}",data)[0].replace("\\item","<enditem><item>")+"<enditem>"
problems= re.findall("<item>[\s]*\((\d{6})\)([\s\S]*?)<enditem>",problems_string)
editor = re.findall(r"编辑者:[\s]*([^\n]*)",data)[0].strip()
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
database = f.read()
pro_dict = json.loads(database)
for item in problems:
id = item[0]
content = item[1].strip()
if pro_dict[id]["content"] == content:
print("题号%s内容未改变."%id)
else:
pro_dict[id]["content"] = content
pro_dict[id]["edit"].append("%s%s%s\t%s"%(str(time.localtime().tm_year).zfill(4),str(time.localtime().tm_mon).zfill(2),str(time.localtime().tm_mday).zfill(2),editor))
with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
f.write(json.dumps(pro_dict,indent = 4, ensure_ascii= False))

View File

@ -97,6 +97,8 @@ def run_command1():
call(["python","局部相似题目检测.py"])
elif selectedtool == "相同相似题目标注":
call(["python","相同相似题目标注.py"])
elif selectedtool == "latex修改题目":
call(["python","latex界面修改题目内容.py"])
LabelTool.config(text = selectedtool+"STEP1命令执行完毕")
button1.place_forget()
@ -108,6 +110,8 @@ def run_command2():
call(["python","导入关联题目.py"])
elif selectedtool == "修改题目数据库":
call(["python","修改结果汇入.py"])
elif selectedtool == "latex修改题目":
call(["python","导入latex界面修改的题目内容.py"])
LabelTool.config(text = selectedtool+ "STEP2命令执行完毕")
button2.place_forget()
@ -138,7 +142,8 @@ menubar.add_cascade(label = "维护", menu = MaintainenceMenu)
MaintainenceMenu.add_command(label = "批量添加字段数据", command = lambda: SetButton("批量添加字段数据",1,["文本文件/metadata.txt","批量添加字段数据.py"]))
MaintainenceMenu.add_command(label = "手动统计结果转换", command = lambda: SetButton("手动统计结果转换",1,["文本文件/metadata.txt","文本文件/手动统计结果.txt"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "修改题目", command = lambda: SetButton("修改题目数据库",2,["修改题目数据库.py"]))
MaintainenceMenu.add_command(label = "LaTeX界面修改题目内容", command = lambda: SetButton("latex修改题目",2,["latex界面修改题目内容.py"]))
MaintainenceMenu.add_command(label = "修改题目综合信息", command = lambda: SetButton("修改题目数据库",2,["修改题目数据库.py"]))
MaintainenceMenu.add_command(label = "识别题目类型", command = lambda: SetButton("识别题目类型",1,[]))

View File

@ -0,0 +1,50 @@
\documentclass[10pt,a4paper]{article}
\usepackage[UTF8,fontset = none]{ctex}
\setCJKmainfont[BoldFont=黑体,ItalicFont=楷体]{华文中宋}
\usepackage{amssymb,amsmath,amsfonts,amsthm,mathrsfs,dsfont,graphicx}
\usepackage{ifthen,indentfirst,enumerate,color,titletoc}
\usepackage{tikz}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{longtable}
\usepackage{diagbox}
\usetikzlibrary{arrows,calc,intersections,patterns,decorations.pathreplacing,3d,angles,quotes,positioning,shapes.geometric}
\usepackage[bf,small,indentafter,pagestyles]{titlesec}
\usepackage[top=1in, bottom=1in,left=0.8in,right=0.8in]{geometry}
\renewcommand{\baselinestretch}{1.65}
\newtheorem{defi}{定义~}
\newtheorem{eg}{例~}
\newtheorem{ex}{~}
\newtheorem{rem}{注~}
\newtheorem{thm}{定理~}
\newtheorem{coro}{推论~}
\newtheorem{axiom}{公理~}
\newtheorem{prop}{性质~}
\newcommand{\blank}[1]{\underline{\hbox to #1pt{}}}
\newcommand{\bracket}[1]{(\hbox to #1pt{})}
\newcommand{\onech}[4]{\par\begin{tabular}{p{.9\linewidth}}
A.~#1\\
B.~#2\\
C.~#3\\
D.~#4
\end{tabular}}
\newcommand{\twoch}[4]{\par\begin{tabular}{p{.46\linewidth}p{.46\linewidth}}
A.~#1& B.~#2\\
C.~#3& D.~#4
\end{tabular}}
\newcommand{\vartwoch}[4]{\par\begin{tabular}{p{.46\linewidth}p{.46\linewidth}}
(1)~#1& (2)~#2\\
(3)~#3& (4)~#4
\end{tabular}}
\newcommand{\fourch}[4]{\par\begin{tabular}{p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}}
A.~#1 &B.~#2& C.~#3& D.~#4
\end{tabular}}
\newcommand{\varfourch}[4]{\par\begin{tabular}{p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}}
(1)~#1 &(2)~#2& (3)~#3& (4)~#4
\end{tabular}}
\begin{document}
待替换
\end{document}

View File

@ -1,6 +1,6 @@
file_dir = r"C:\Users\weiye\Documents\wwy sync\23届\下学期测验卷"
file_dir = r"C:\Users\weiye\Documents\wwy sync\23届\四月错题重做"
filelist = [] #列表为空默认处理所有讲义
output_gloss_filename = "23届下学期测验卷参考答案"
output_gloss_filename = "错题重做参考答案"
import os,re,json