简体   繁体   English

如何在 Sublime 文本中启用 MathJax 渲染 Markdown 预览

[英]How to Enable MathJax Rendering in Sublime Text Markdown Preview

Using Sublime Text 3, I'm writing a Markdown document that includes math.使用 Sublime Text 3,我正在编写包含数学的 Markdown 文档。 The Markdown Preview package enables real-time rendering of the document in the browser (Chrome). Markdown Preview package 支持在浏览器 (Chrome) 中实时呈现文档。 So as I write, the changes are visible.所以在我写的时候,变化是可见的。 The following is my markdown text.以下是我的 markdown 文字。

$a = \sin^{2}(\Delta \phi/2) + \cos(\phi_{1})\cos(\phi_{2})\sin^{2}(\Delta \lambda/2)$
$c = 2 \arcsin(\sqrt{a})$
$d = rc$

MarkdownPreview manual says something like "When enable_mathjax is true ", but I cannot figure it out where it is. MarkdownPreview 手册说“当enable_mathjaxtrue时”,但我无法弄清楚它在哪里。 For completeness, The Sublime console does not display any error message.为了完整起见,Sublime 控制台不显示任何错误消息。 I'm using Windows 7 and the lastest MathJax fetched from Git.我正在使用 Windows 7 和从 Git 获取的最新 MathJax。 MathJax itself works fine when I displayed some sample test html.当我显示一些示例测试 html 时,MathJax 本身工作正常。

Providing MarkdownPreview is installed correctly, one can find option enable_mathjax this way:如果 MarkdownPreview 安装正确,可以通过这种方式找到选项enable_mathjax

在此处输入图片说明

Hope this helps.希望这可以帮助。

The MarkDown Preview 2.x branch won't work with the method in @VividD answer. MarkDown Preview 2.x 分支不适用于@VividD 答案中的方法。

My User Settings, which enables MathJaX is as following:启用 MathJaX 的我的用户设置如下:

{
    "enable_mathjax": true,
    "js": [
    "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js",
            "res://MarkdownPreview/js/math_config.js",
    ],
}

Also, using Package​Resource​Viewer I edited the math_config.js in the js folder of MarkDown Preview to make the Display Math aligned to center:此外,使用包资源浏览器我编辑的math_config.jsjs文件夹降价预览,使对准中心显示数学:

MathJax.Hub.Config({
  config: ["MMLorHTML.js"],
  extensions: ["tex2jax.js"],
  jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
  tex2jax: {
    inlineMath: [ ['$','$'], ["\\(","\\)"] ],
    displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
    processEscapes: true
  },
  TeX: {
    extensions: ["AMSmath.js", "AMSsymbols.js"],
    TagSide: "right",
    TagIndent: ".8em",
    MultLineWidth: "85%",
    equationNumbers: {
      autoNumber: "AMS",
    },
    unicode: {
      fonts: "STIXGeneral,'Arial Unicode MS'"
    }
  },
  displayAlign: "center",
  showProcessingMessages: false,
  messageStyle: 'none'
});

Pay attention to displayAlign .注意displayAlign At default it is displayAlign: "left" .默认情况下它是displayAlign: "left"
You can customize MathJaX farther according to MathJaX Options .您可以根据MathJaX Options进一步自定义 MathJaX。

As of now, neither of the above answers is working anymore.截至目前,上述答案都不再有效。 I finally found a solution in a Github issue which provides an updated version of the code snippet that needs to be added to the MarkdownPreview user settings:我终于在Github 问题中找到了一个解决方案,它提供了需要添加到 MarkdownPreview 用户设置的代码片段的更新版本:

"js": [
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js",
        "res://MarkdownPreview/js/math_config.js",
],
"markdown_extensions": {
    "pymdownx.arithmatex": {
        "generic": true
    }
}

In order to give a more precise answer, open the User Settings of Markdown Preview, now located here :为了给出更准确的答案,请打开 Markdown Preview 的用户设置,现在位于此处:

在此处输入图片说明

And add this to the settings :并将其添加到设置中:

{
    "enable_mathjax": true,
    "js": [
        "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",
        "res://MarkdownPreview/js/math_config.js",
    ],
    "markdown_extensions": [
        "markdown.extensions.extra",
        {
            "pymdownx.arithmatex": {
                "generic": true
            }
        },
        {
            "markdown.extensions.toc": {
                "permalink": "\ue157"
            }
        }
        //---- etc.
    ]
}

This allows to keep other extensions active (here Table of Contents), which you can specify in the place of //etc.这允许保持其他扩展处于活动状态(此处为目录),您可以在//etc.的位置指定它们//etc. . .

In more recent versions (today is September 2022) the configuration of this Sublime extension has slightly changed.在最近的版本中(今天是 2022 年 9 月),这个 Sublime 扩展的配置略有变化。

But first, note that MathJax support works only in plain "markdown" mode, not "GitHub" nor "GitLab".但首先,请注意,MathJax 支持仅适用于普通的“markdown”模式,而不是“GitHub”或“GitLab”。

Extras - Markdown Preview Documentation : 附加功能 - Markdown 预览文档

GitHub and GitLab is not supported with MathJax. MathJax 不支持 GitHub 和 GitLab。 You will have to come up with a MathJax config that works for it and escape problematic syntax that GitHub may try to convert.您必须想出一个适用于它的 MathJax 配置,并避开 GitHub 可能尝试转换的有问题的语法。

This said, head to the configuration of the extension (in the menu bar look for "Preferences", then "Package Settings", then "MarkDownPreview").这就是说,转到扩展的配置(在菜单栏中查找“首选项”,然后是“包设置”,然后是“MarkDownPreview”)。

Then add the following json snippet.然后添加以下 json 片段。 Note that a new "markdown" json node has been added halfway, which I believe wasn't there in previous releases:请注意,新的“降价” json 节点已添加到一半,我相信以前的版本中没有:

"enable_mathjax": true,
"js": {
        "markdown": [
            "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js",
            "res://MarkdownPreview/js/math_config.js"
        ]
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM