/* * @Author: LiZhiWei * @Date: 2025-05-14 15:52:16 * @LastEditors: LiZhiWei * @LastEditTime: 2025-05-14 15:52:19 * @Description: */ // 创建数学公式元素 export function createMathElement (element) { const el = document.createElement('div') el.style.position = 'absolute' el.style.top = element.top + 'px' el.style.left = element.left + 'px' el.style.width = element.width + 'px' el.style.height = element.height + 'px' // 如果有公式图片,优先使用图片显示 if (element.picBase64) { const img = document.createElement('img') img.src = element.picBase64 img.style.width = '100%' img.style.height = '100%' img.style.objectFit = 'contain' el.appendChild(img) return el } // 如果有 LaTeX 表达式,使用 MathJax 渲染 if (element.latex) { // 创建公式容器 const mathContainer = document.createElement('div') mathContainer.style.width = '100%' mathContainer.style.height = '100%' mathContainer.style.display = 'flex' mathContainer.style.alignItems = 'center' mathContainer.style.justifyContent = 'center' // 添加 LaTeX 公式 mathContainer.innerHTML = `\\[${element.latex}\\]` // 如果 MathJax 不可用,显示原始 LaTeX mathContainer.style.fontFamily = 'monospace' mathContainer.style.whiteSpace = 'pre-wrap' mathContainer.style.padding = '10px' mathContainer.textContent = element.latex el.appendChild(mathContainer) } return el }