1. markdown-it-katex-gpt
是markdown-it
的插件,直接使用方法:
const renderMarkdown = new MarkdownIt();
renderMarkdown.use(markdownItKatexGpt, {
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
]
});
但默认使用方法会导致公式的字体不是katex.css
内置的公式专用字体,问题根源在于markdown-it-katex-gpt
的代码:
// 如果不是静默模式,将 LaTeX 公式转换为 MathML
if (!silent) {
const content = state.src.slice(start + left.length, pos)
try {
const renderedContent = katex.renderToString(content, {
throwOnError: false,
output: 'htmlAndMathml',
displayMode: display
})
const token = state.push('html_inline', '', 0)
token.content = renderedContent
} catch (e) {
console.error(e)
}
}
output处,原参数为Mathml
,这会导致字体渲染失败,改为htmlAndMathml
恢复正常