Skip to content

Commit

Permalink
Correction du rendu des maths dans l'API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Dec 28, 2023
1 parent 534b7bd commit f81f6ab
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions modules/nuxt-content-latex/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,21 @@ const renderMath = (root: HTMLElement) => {
const mathElements = root.querySelectorAll('eq')
for (const mathElement of mathElements) {
// Get the trimmed text content.
const text = mathElement.text.trim()

const latex = mathElement.text.trim()
// Determine if it's a display math environment.
const displayMode = mathElement.getAttribute('env') === 'displaymath'
// Replace the math element with the rendered KaTeX HTML.
mathElement.replaceWith(
katex.renderToString(text, {
displayMode: mathElement.getAttribute('env') === 'displaymath', // Determine if it's a display math environment.
output: 'html',
trust: true,
strict: (errorCode: any) => errorCode === 'htmlExtension' ? 'ignore' : 'warn',
macros: {
'\\parallelslant': '\\mathbin{\\!/\\mkern-5mu/\\!}',
'\\ensuremath': '#1'
}
})
)
const renderedMath = katex.renderToString(latex, {
displayMode,
output: 'html',
trust: true,
strict: (errorCode: any) => errorCode === 'htmlExtension' ? 'ignore' : 'warn',
macros: {
'\\parallelslant': '\\mathbin{\\!/\\mkern-5mu/\\!}',
'\\ensuremath': '#1'
}
})
mathElement.replaceWith(`<span class="math-rendered" data-latex="${latex}" data-latex-display="${displayMode}">${renderedMath}</span>`)
}
}

Expand Down

0 comments on commit f81f6ab

Please sign in to comment.