window.MathJax={tex:{inlineMath:[['$','$'],['\\(','\\)']],displayMath:[['$$','$$'],['\\[','\\]']],processEscapes:true,processEnvironments:true,packages:{'[+]':['ams','newcommand','configmacros']},tags:'ams'},options:{skipHtmlTags:['script','noscript','style','textarea','pre','code'],ignoreHtmlClass:'tex2jax_ignore',processHtmlClass:'tex2jax_process'},startup:{ready:()=>{console.log('MathJax 已加载完成')
MathJax.startup.defaultReady()
if(window._mathJaxPendingElements){window._mathJaxPendingElements.forEach(el=>{MathJax.typesetPromise([el]).catch(err=>console.warn('MathJax 渲染失败:',err))})
window._mathJaxPendingElements=[]}}}}
window._mathJaxLoading=false
window._mathJaxLoaded=false
window._mathJaxPendingElements=[]
window.hasMathContent=function(text){if(!text)return false
const mathPatterns=[/\$[^$]+\$/,/\$\$[^$]+\$\$/,/\\\([^)]+\\\)/,/\\\[[^\]]+\\\]/]
return mathPatterns.some(pattern=>pattern.test(text))}
window.loadMathJaxIfNeeded=function(element,text){if(!window.hasMathContent(text)){return}
if(window._mathJaxLoaded&&window.MathJax&&window.MathJax.typesetPromise){MathJax.typesetPromise([element]).catch(err=>console.warn('MathJax 渲染失败:',err))
return}
window._mathJaxPendingElements.push(element)
if(window._mathJaxLoading){return}
window._mathJaxLoading=true
console.log('📐 检测到数学公式,开始加载 MathJax (1.17MB)...')
const script=document.createElement('script')
script.id='MathJax-script'
script.async=true
script.src='/static/js/tex-mml-chtml.js'
script.onload=function(){window._mathJaxLoaded=true
console.log('✅ MathJax 加载完成')}
script.onerror=function(){console.error('❌ MathJax 加载失败')
window._mathJaxLoading=false}
document.head.appendChild(script)}