md icon indicating copy to clipboard operation
md copied to clipboard

能够解析['\(', '\)'], ['\[', '\]']包围的公式吗

Open jiabochao opened this issue 1 year ago • 6 comments

哈喽,想请教一下,如果公式使用小括号和中括号样式的可以支持解析吗,目前发现设置了配置后不生效

MathJax = {
        loader: { load: ['[tex]/ams'] },
        tex: {
          packages: { '[+]': ['ams'] },
          tags: 'ams',
          inlineMath: [
            ['$', '$'],
            ['\$', '\$'],
            ['\(', '\)'],
            ['\\(', '\\)'],
          ], // ["$","$"],["\$","\$"],["\(","\)"],["\\(","\\)"]
          displayMath: [
            ['$$', '$$'],
            ['\[', '\]'],
          ],
        },
        svg: { fontCache: 'none' },
      }

https://github.com/doocs/md/blob/876a31356a9c8e2a72afaba31d61a35b001616d8/index.html#L89

jiabochao avatar Oct 15 '24 18:10 jiabochao

需要补充描述,提供示例。

YangFong avatar Oct 16 '24 05:10 YangFong

这种不是以$$包围的,而是使用\[ \]包围的公式,可以支持配置公式的起始符号来支持解析吗

\[f'(x_0) = \lim_{\Delta x \to 0} \frac{f(x_0 + \Delta x) - f(x_0)}{\Delta x}\]

jiabochao avatar Oct 16 '24 06:10 jiabochao

我不大了解 Latex,你这段公式,不能够将前后的 \[\] 去掉吗,像下面这样:

$$
f'(x_0) = \lim_{\Delta x \to 0} \frac{f(x_0 + \Delta x) - f(x_0)}{\Delta x}
$$

$$ f'(x_0) = \lim_{\Delta x \to 0} \frac{f(x_0 + \Delta x) - f(x_0)}{\Delta x} $$

我看后者的渲染效果也还可以。

YangFong avatar Oct 16 '24 06:10 YangFong

目的是支持多种,类似这个配置:https://docs.mathjax.org/en/latest/input/tex/delimiters.html

image

jiabochao avatar Oct 16 '24 06:10 jiabochao

那你得看这个文件:https://github.com/doocs/md/blob/main/src/utils/MDKatex.js

我们是先匹配 Markdown 语法,生成标记,再由 MathJax 做渲染,前者匹配规则没有变,那么后者也没法生效。

YangFong avatar Oct 16 '24 06:10 YangFong

那你得看这个文件:https://github.com/doocs/md/blob/main/src/utils/MDKatex.js

我们是先匹配 Markdown 语法,生成标记,再由 MathJax 做渲染,前者匹配规则没有变,那么后者也没法生效。

@YangFong 好的,感谢,我看一下

jiabochao avatar Oct 16 '24 07:10 jiabochao