代码拉取完成,页面将自动刷新
同步操作将从 healthy/chatgpt_academic 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# This program is written by: https://github.com/polarwinkel/mdtex2html
from latex2mathml.converter import convert as tex2mathml
import re
incomplete = '<font style="color:orange;" class="tooltip">⚠<span class="tooltiptext">formula incomplete</span></font>'
convError = '<font style="color:red" class="tooltip">⚠<span class="tooltiptext">LaTeX-convert-error</span></font>'
def convert(mdtex, extensions=[], splitParagraphs=True):
''' converts recursively the Markdown-LaTeX-mixture to HTML with MathML '''
found = False
# handle all paragraphs separately (prevents aftereffects)
if splitParagraphs:
parts = re.split("\n\n", mdtex)
result = ''
for part in parts:
result += convert(part, extensions, splitParagraphs=False)
return result
# find first $$-formula:
parts = re.split('\${2}', mdtex, 2)
if len(parts)>1:
found = True
result = convert(parts[0], extensions, splitParagraphs=False)+'\n'
try:
result += '<div class="blockformula">'+tex2mathml(parts[1])+'</div>\n'
except:
result += '<div class="blockformula">'+convError+'</div>'
if len(parts)==3:
result += convert(parts[2], extensions, splitParagraphs=False)
else:
result += '<div class="blockformula">'+incomplete+'</div>'
# else find first $-formulas:
else:
parts = re.split('\${1}', mdtex, 2)
if len(parts)>1 and not found:
found = True
try:
mathml = tex2mathml(parts[1])
except:
mathml = convError
if parts[0].endswith('\n\n') or parts[0]=='': # make sure textblock starts before formula!
parts[0]=parts[0]+'​'
if len(parts)==3:
result = convert(parts[0]+mathml+parts[2], extensions, splitParagraphs=False)
else:
result = convert(parts[0]+mathml+incomplete, extensions, splitParagraphs=False)
# else find first \[..\]-equation:
else:
parts = re.split(r'\\\[', mdtex, 1)
if len(parts)>1 and not found:
found = True
result = convert(parts[0], extensions, splitParagraphs=False)+'\n'
parts = re.split(r'\\\]', parts[1], 1)
try:
result += '<div class="blockformula">'+tex2mathml(parts[0])+'</div>\n'
except:
result += '<div class="blockformula">'+convError+'</div>'
if len(parts)==2:
result += convert(parts[1], extensions, splitParagraphs=False)
else:
result += '<div class="blockformula">'+incomplete+'</div>'
# else find first \(..\)-equation:
else:
parts = re.split(r'\\\(', mdtex, 1)
if len(parts)>1 and not found:
found = True
subp = re.split(r'\\\)', parts[1], 1)
try:
mathml = tex2mathml(subp[0])
except:
mathml = convError
if parts[0].endswith('\n\n') or parts[0]=='': # make sure textblock starts before formula!
parts[0]=parts[0]+'​'
if len(subp)==2:
result = convert(parts[0]+mathml+subp[1], extensions, splitParagraphs=False)
else:
result = convert(parts[0]+mathml+incomplete, extensions, splitParagraphs=False)
if not found:
result = mdtex
return result
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。