From bfb603929c4e610540628499257681081201eb62 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Thu, 28 Dec 2023 16:11:05 +0800 Subject: [PATCH 1/2] support `\boldsymbol`, `\bm` and other 'mathtools' commands --- src/preview/math/mathjax.ts | 8 ++++++-- types/mathjax-full/index.d.ts | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/preview/math/mathjax.ts b/src/preview/math/mathjax.ts index ce780bee6..b7cefc0f2 100644 --- a/src/preview/math/mathjax.ts +++ b/src/preview/math/mathjax.ts @@ -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' @@ -15,11 +15,15 @@ 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[]) { + 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(baseTexOption) diff --git a/types/mathjax-full/index.d.ts b/types/mathjax-full/index.d.ts index da229986b..1231c1c26 100644 --- a/types/mathjax-full/index.d.ts +++ b/types/mathjax-full/index.d.ts @@ -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][], @@ -56,6 +60,7 @@ export type TexOption = { maxMacros?: number, maxBuffer?: number, baseURL?: string, + macros?: MacrosOption, formatError?: (jax: TeX, message: TexError) => unknown } From d16397af860cff8fab6d92cda7230eb1175261c6 Mon Sep 17 00:00:00 2001 From: James Yu Date: Fri, 29 Dec 2023 16:10:16 +0000 Subject: [PATCH 2/2] Add a MathJax bm package reference [skip ci] --- src/preview/math/mathjax.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/preview/math/mathjax.ts b/src/preview/math/mathjax.ts index b7cefc0f2..3008d47dd 100644 --- a/src/preview/math/mathjax.ts +++ b/src/preview/math/mathjax.ts @@ -18,6 +18,7 @@ RegisterHTMLHandler(adaptor) 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], }