mathpix文本优化功能中增加了对平行符号的替换, 并将平行与垂直均作为关系符进行逗号分割

This commit is contained in:
wangweiye7840 2023-07-27 08:57:26 +08:00
parent 5a9e26da4e
commit 55c2853665
1 changed files with 3 additions and 3 deletions

View File

@ -975,7 +975,7 @@ def setCopy(string): # 写入剪切板内容
def RefineMathpix(raw_string): # 进一步修改mathpix得到的字符串
puctuationsfulltosemi = {" ": " ","": ". ","": ". ","": ", ","": ": ","": "; ","": "(","": ")","": "? ","": "``","": "''", "": "[", "": "]"}
replacestrings = {r"\\overparen": r"\\overset\\frown", "eqslant": "eq", r"\\vec": r"\\overrightarrow ", r"\\bar": r"\\overline", r"\\lim": r"\\displaystyle\\lim", r"\\sum":r"\\displaystyle\\sum", r"\\prod":r"\\displaystyle\\prod", r"\\mid":"|", r"\^\{\\prime\}":"'",r"e\^":r"\\mathrm{e}^"}
replacestrings = {r"\\overparen": r"\\overset\\frown", "eqslant": "eq", r"\\vec": r"\\overrightarrow ", r"\\bar": r"\\overline", r"\\lim": r"\\displaystyle\\lim", r"\\sum":r"\\displaystyle\\sum", r"\\prod":r"\\displaystyle\\prod", r"\\mid":"|", r"\^\{\\prime\}":"'",r"e\^":r"\\mathrm{e}^",r"/\s*/":r"\\parallel "}
wrongrecog = {"":"","[粗秿]圆":"椭圆","投郑":"投掷","抛郑":"抛掷","范目":"范围","":"","末见":"未见","末成":"未成","针角":"钝角","幕函数":"幂函数","末知":"未知","阀值":"阈值"}
string = raw_string
string = re.sub(r"\\left(?:\.?)|\\right(?:\.?)","",string) #删去括号前的\left与\right标记
@ -1014,7 +1014,7 @@ def RefineMathpix(raw_string): # 进一步修改mathpix得到的字符串
string = re.sub(r"([\u4e00-\u9fa5\$])(?:\\bracket\{20\})*[\.]*[\s]*\n\\fourch",lambda matchobj: matchobj.group(1)+"\\bracket{20}.\n\\fourch",string) #给中文或公式结尾的题目最后一行加上选择题的括号.
string = re.sub(r"(%[^\n]*)\\blank\{50\}\.",lambda matchobj:matchobj.group(1),string) #注释行不加\blank{50}
string = re.sub(r"[\\\\]*\n(\(\d{1,2}\))(?:(?!\n)\s)*",lambda matchobj: "\\\\\n"+matchobj.group(1)+" ",string) #新一行的小题号回车前加上换行符
string = re.sub(r"\(([^\(\)]*(?:\\in|=|\\ge|\\le|\\ne|>|<)[^\(\)]*)\)\$",lambda matchobj: "$($" + matchobj.group(1) + "$)",string) #公式最后的范围陈述的括号放到公式环境外
string = re.sub(r"\(([^\(\)]*(?:\\in|=|\\ge|\\le|\\ne|>|<|\\parallel|\\perp)[^\(\)]*)\)\$",lambda matchobj: "$($" + matchobj.group(1) + "$)",string) #公式最后的范围陈述的括号放到公式环境外
string = re.sub(r"\$\$\(","(",string) #删去上一步造成的多余双$
string = re.sub(r"\(\s\$","($",string) #删去首个括号内公式前的空格
string = re.sub(r"\(\\begin\{cases\}",r"\\begin{pmatrix}",string) #修改错误的\begin{cases})
@ -1062,7 +1062,7 @@ def SplitMathComma(string): #判断数学环境中的","是否需要用$ $分离
if len(p1r)*len(p2r)>0:
if p1r[0]>p2r[0]:
tosplit = False
if len(SubstringOccurence(r"(?:=|\\ge|\\le|\\ne|\\in|>|<)",locallmatter))*len(SubstringOccurence(r"(?:=|\\ge|\\le|\\ne|\\in|>|<)",localrmatter)) == 0:
if len(SubstringOccurence(r"(?:=|\\ge|\\le|\\ne|\\in|>|<|\\parallel|\\perp)",locallmatter))*len(SubstringOccurence(r"(?:=|\\ge|\\le|\\ne|\\in|>|<|\\parallel|\\perp)",localrmatter)) == 0:
tosplit = False
if tosplit:
rmatter = ", $"+lmatter[pos+1:].lstrip()+rmatter.lstrip()