From 01d8266e0af0860e006eaa8efdce41806fc17246 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 19 Mar 2023 17:09:32 +0800 Subject: [PATCH] 20230319 afternoon --- 工具/模板文件/日常选题讲义模板.txt | 1 - 工具/试卷答案生成.ipynb | 86 ++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 工具/试卷答案生成.ipynb diff --git a/工具/模板文件/日常选题讲义模板.txt b/工具/模板文件/日常选题讲义模板.txt index a680b271..e89cb531 100644 --- a/工具/模板文件/日常选题讲义模板.txt +++ b/工具/模板文件/日常选题讲义模板.txt @@ -65,7 +65,6 @@ A.~#1 &B.~#2& C.~#3& D.~#4 \end{center} -%\section{课前练习} \begin{enumerate}[1.] 待替换1 diff --git a/工具/试卷答案生成.ipynb b/工具/试卷答案生成.ipynb new file mode 100644 index 00000000..3d7aab92 --- /dev/null +++ b/工具/试卷答案生成.ipynb @@ -0,0 +1,86 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "import os,re,json\n", + "\n", + "filename = r\"C:\\Users\\weiye\\Documents\\wwy sync\\23届\\第二轮复习讲义\\09_立体几何综合.tex\"\n", + "outfilename = \"立体几何综合答案\"\n", + "pdf_dir = \"临时文件\"\n", + "\n", + "with open(filename,\"r\",encoding = \"u8\") as f:\n", + " data = f.read()\n", + "with open(\"../题库0.3/Problems.json\",\"r\",encoding = \"u8\") as f:\n", + " pro_dict = json.loads(f.read())\n", + "\n", + "ids = re.findall(r\"\\((\\d{6})\\)\",data)\n", + "\n", + "output_data = \"\"\n", + "for id in ids:\n", + " problemset = pro_dict[id]\n", + " content = problemset[\"content\"]\n", + " solution = problemset[\"solution\"]\n", + " answer = \"\\\\textcolor{red}{\" + (problemset[\"ans\"] if problemset[\"ans\"] != \"\" else \"\\\\textcolor{blue}{暂无答案\") + \"}\"\n", + " output_data += \"\\\\item \" + \"(\"+id+\") \" + content + \"\\n\\n\" + \"答案: \" + answer + \"\\n\\n\" + (\"\" if solution == \"\" else (\"解答或提示: \" + solution)) + \"\\n\\n\"\n", + "\n", + "with open(\"模板文件/日常选题讲义模板.txt\",\"r\",encoding = \"u8\") as f:\n", + " outlatex = f.read()\n", + "\n", + "outlatex = outlatex.replace(\"待替换1\",output_data)\n", + "outlatex = outlatex.replace(\"标题文字待处理\",outfilename)\n", + "\n", + "outfile = os.path.join(\"临时文件\",outfilename+\".tex\")\n", + "with open(outfile,\"w\",encoding=\"u8\") as f:\n", + " f.write(outlatex)\n", + "\n", + "outfile = outfile.replace(\"\\\\\",\"/\")\n", + "\n", + "os.system(\"xelatex -interaction=batchmode -output-directory=\" + pdf_dir + \" \"+ outfile)\n", + "print(os.system(\"xelatex -interaction=batchmode -output-directory=\" + pdf_dir + \" \"+ outfile))\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "mathdept", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.15" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +}