Skip to content

Commit

Permalink
Merge pull request #4114 from huangyxi/patch-1
Browse files Browse the repository at this point in the history
Support `\boldsymbol`, `\bm` and other `'mathtools'` commands in equations preview
  • Loading branch information
James-Yu authored Dec 29, 2023
2 parents bea3b67 + d16397a commit ab3cf7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/preview/math/mathjax.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as workerpool from 'workerpool'
import type {ConvertOption, SupportedExtension, SvgOption, TexOption} from 'mathjax-full'
import type {ConvertOption, MacrosOption, SupportedExtension, SvgOption, TexOption} from 'mathjax-full'
import { mathjax } from 'mathjax-full/js/mathjax.js'
import { TeX } from 'mathjax-full/js/input/tex.js'
import { SVG } from 'mathjax-full/js/output/svg.js'
Expand All @@ -15,11 +15,16 @@ import 'mathjax-full/js/input/tex/AllPackages.js'
const adaptor = liteAdaptor()
RegisterHTMLHandler(adaptor)

const baseExtensions: SupportedExtension[] = ['ams', 'base', 'color', 'newcommand', 'noerrors', 'noundefined']
const baseExtensions: SupportedExtension[] = ['ams', 'base', 'boldsymbol', 'color', 'configmacros', 'mathtools', 'newcommand', 'noerrors', 'noundefined']

function createHtmlConverter(extensions: SupportedExtension[]) {
// https://github.com/mathjax/MathJax/issues/1219
const macrosOption: MacrosOption = {
bm: ['\\boldsymbol{#1}', 1],
}
const baseTexOption: TexOption = {
packages: extensions,
macros: macrosOption,
formatError: (_jax, error) => { throw new Error(error.message) }
}
const texInput = new TeX<LiteElement, LiteText, LiteDocument>(baseTexOption)
Expand Down
5 changes: 5 additions & 0 deletions types/mathjax-full/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export type SupportedExtension =
'upgreek' |
'verb'

export type MacrosOption = {
[name: string]: object;
}

export type TexOption = {
packages?: readonly SupportedExtension[],
inlineMath?: readonly [string, string][],
Expand All @@ -56,6 +60,7 @@ export type TexOption = {
maxMacros?: number,
maxBuffer?: number,
baseURL?: string,
macros?: MacrosOption,
formatError?: (jax: TeX<LiteElement, LiteText, LiteDocument>, message: TexError) => unknown
}

Expand Down

0 comments on commit ab3cf7d

Please sign in to comment.