@tal-paas/open-mathgpt-render
v0.1.3
Published
LaTeX/HTML 公式修复。
Readme
@tal-paas/open-mathgpt-render
LaTeX/HTML 公式修复。
安装
pnpm add @tal-paas/open-mathgpt-renderlatexFix:LaTeX 异常公式修复
类型与参数(摘要)
| 参数 | 类型 | 说明 | 备注/默认值 |
| ------- | ----------------------------- | -------------------- | ------------- |
| input | string \| null \| undefined | 待修复的批改答案文本 | 空值返回 '' |
| options | LatexFixOptions | 修复选项,字段见下表 | 可选,{} |
| 返回值 | string | 修复后的文本 | |
LatexFixOptions 字段说明:
| 字段 | 类型 | 说明 | 默认值 |
| ---- | ------- | ------------------------------------------------------------ | ------ |
| div | boolean | 是否将合适的 a/b 表达式转换为 \\frac{a}{b} | false |
不同环境下的使用方法
1. ESM(Vite / Webpack / Node type: module 等)
import { latexFix } from '@tal-paas/open-mathgpt-render'
const fixed = latexFix('答案为 1/2,角度为 30^\\circ', { div: true })
// "答案为$$ \\frac{1}{2}$$,角度为$$ 30^\\circ$$"按需同时引入类型:
import type { LatexFixOptions } from '@tal-paas/open-mathgpt-render/latex-fix'也可以使用子路径入口:
import latexFix from '@tal-paas/open-mathgpt-render/latex-fix'
import type { LatexFixOptions } from '@tal-paas/open-mathgpt-render/latex-fix'
const options: LatexFixOptions = { div: true }
const fixed = latexFix('<img src="a.png"> -xy+\\frac{1}{2}', options)2. CommonJS
const latexFix = require('@tal-paas/open-mathgpt-render/latex-fix').default
const fixed = latexFix('价格是$123')