From c15bc253656f3b9097fa790f1207437ba8a3ace7 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Tue, 25 Jul 2023 22:40:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86mathpix=E6=B6=A6?= =?UTF-8?q?=E8=89=B2=E5=B7=A5=E5=85=B7=E7=9A=84=E5=A4=84=E7=90=86cases?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E4=B8=A4=E4=B8=AAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 5786f503..55b59817 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -1006,6 +1006,7 @@ def RefineMathpix(raw_string): # 进一步修改mathpix得到的字符串 string = re.sub(r"([CP])(_[^_\^]{,5}\^)",lambda x:r"\mathrm{"+x.group(1)+"}"+x.group(2),string) #处理排列数和组合数字母的正体 string = re.sub(r"([\^_])\{([-]{0,1})\\dfrac",lambda matchobj: matchobj.group(1) + "{" + matchobj.group(2) + "\\frac",string) string = re.sub(r"ldots",r"cdots",string) #将ldots替换为cdots + string = re.sub(r"\\text\s*\{,\s*当\s*\}",", ",string) string = re.sub(r"[\\{]*\\(begin|end)\{array\}(?:\{[rcl]*\}){0,1}",lambda matchobj: "\\" + matchobj.group(1) + "{cases}",string) #将分段函数的array环境改为cases环境 string = re.sub(r"([\u4e00-\u9fa5\$])[\s]*\n\\item",lambda matchobj: matchobj.group(1)+"\\blank{50}.\n\\item",string) #给中文或公式结尾的题目最后一行加上填空的空格. string = re.sub(r"(是|为|(?:=\$))\s*([,.;\n])",lambda matchobj: matchobj.group(1) + "\\blank{50}" + ("." if matchobj.group(2) == "\n" else "") + matchobj.group(2),string) #给行中的题目需要的地方加上空格 @@ -1130,6 +1131,7 @@ def RefineCasesEnv(string): # 美化cases环境 newcontent = re.sub(r",[\s]*&[\s]*\\",r",\\",newcontent) newcontent = re.sub(r",[\s]*&[\s]*$",",",newcontent) #给逗号添加&分栏符, 并去除无效的& string = lmatter + newcontent + rmatter + string = re.sub(r"&[,\s]&","& ",string) return string #返回处理后的字符串 def SubstringOccurence(regex,string): #生成regex在string中出现的所有位置