From 4a7a5cb703da037c5b4df05104dcc78262e9df96 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Fri, 30 Jun 2023 16:08:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7v2=E4=B8=AD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20=E6=89=B9=E9=87=8F=E8=AE=B2=E4=B9=89=E7=94=9F=E6=88=90=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/批量讲义生成.py | 36 ++++++++++++++++++++++++++++++++++++ 工具v2/模板文件/讲义模板.txt | 1 + 2 files changed, 37 insertions(+) create mode 100644 工具v2/批量讲义生成.py diff --git a/工具v2/批量讲义生成.py b/工具v2/批量讲义生成.py new file mode 100644 index 00000000..156d735b --- /dev/null +++ b/工具v2/批量讲义生成.py @@ -0,0 +1,36 @@ +problems_dict = { + "第一讲": "1:20", + "第二讲": "50:60,70:80" +} #题号字典, 每一项的key表示标题, 内容字符串表示题号 +notetitle = "测试批量讲义" #讲义标题, 也是文件标题 +answered = True #是否展示答案, True表示展示答案, False表示不展示答案 + + +from database_tools import * + +prodictpath = "../题库0.3/problems.json" +pro_dict = load_dict(prodictpath) + +outputdir = "临时文件" #输出文件的目录 +outputfilepath = os.path.join(outputdir,notetitle+".tex") +print("输出文件目录: %s\n输出文件名: %s"%(os.path.join(os.getcwd(),outputdir),notetitle+".tex")) + +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) + +bodystring = "\\tableofcontents\n\n\\newpage\n\n" + +for p in problems_dict: + bodystring += GenerateStudentBodyString([problems_dict[p]],[p],pro_dict,True,answered,False) + "\n\n\\newpage\n\n" #生成.tex中的内容主体字符串, 用于替换模板中的相应部分 + +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("编译失败") diff --git a/工具v2/模板文件/讲义模板.txt b/工具v2/模板文件/讲义模板.txt index ec00ffb1..500d4ea1 100644 --- a/工具v2/模板文件/讲义模板.txt +++ b/工具v2/模板文件/讲义模板.txt @@ -9,6 +9,7 @@ \usepackage{makecell} \usepackage{longtable} \usepackage{diagbox} +\usepackage{hyperref} \usepackage[top=1in, bottom=1in,left=0.8in,right=0.8in]{geometry} \usepackage{fancyhdr} \fancyhf{}