数学

¥Math

Math 插件可让你在幻灯片中包含排版精美的数学公式。首先,请确保 reveal.js 已初始化并启用了数学插件。

¥The Math plugin lets you include beautifully typeset math formulas in your slides. To get started, make sure that reveal.js is initialized with the math plugin enabled.

<script src="plugin/math/math.js"></script>
<script>
  Reveal.initialize({ plugins: [RevealMath.KaTeX] });
</script>

在本例中,我们使用 KaTeX 排版工具,但你也可以选择 MathJax 23

¥We're using the KaTeX typesetter in this example but you can also choose from MathJax 2 or 3.

现在插件已注册,我们可以开始将 LaTeX 公式添加到幻灯片中。

¥Now that the plugin is registered we can start adding LaTeX formulas to our slides.

<section>
  <h2>The Lorenz Equations</h2>
  \[\begin{aligned} \dot{x} &amp; = \sigma(y-x) \\ \dot{y} &amp; = \rho x - y -
  xz \\ \dot{z} &amp; = -\beta z + xy \end{aligned} \]
</section>

洛伦兹方程

\[\begin{aligned} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x - y - xz \\ \dot{z} & = -\beta z + xy \end{aligned} \]

Markdown

要在用 Markdown 编写的演示文稿中包含数学公式,请使用可用的数学的分隔符(例如 $$)包裹公式:

¥To include math inside of a presentation written in Markdown, wrap the equation using one the available math delimiters like $$:

<section data-markdown>$$ J(\theta_0,\theta_1) = \sum_{i=0} $$</section>

排版库

¥Typesetting Libraries

数学插件提供了三种数学排版库供你选择,可用于渲染数学公式。每个变体都是一个独立的插件,可以通过 RevealMath.<Variant> 访问。如果你没有偏好设置,我们建议你使用 KaTeX。

¥The math plugin offers three choices of math typesetting libraries that you can use to render your math. Each variant is its own plugin that can be accessed via RevealMath.<Variant>. If you don't have a preference, we recommend going with KaTeX.

图库插件名称配置属性
KaTeXRevealMath.KaTeXkatex
MathJax 2RevealMath.MathJax2mathjax2
MathJax 3RevealMath.MathJax3mathjax3

KaTeX 4.2.0

¥KaTeX 4.2.0

通过 katex 配置对象调整选项。以下是该插件的默认配置。如果你不打算更改这些值,则根本不需要包含 katex 配置选项。

¥Adjust options through the katex configuration object. Below is how the plugin is configured by default. If you don't intend to change these values you do not need to include the katex config option at all.

Reveal.initialize({
  katex: {
    version: 'latest',
    delimiters: [
      { left: '$$', right: '$$', display: true },
      { left: '$', right: '$', display: false },
      { left: '\\(', right: '\\)', display: false },
      { left: '\\[', right: '\\]', display: true },
    ],
    ignoredTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
  },
  plugins: [RevealMath.KaTeX],
});

请注意,默认情况下,最新的 KaTeX 是从远程服务器 (https://cdn.jsdelivr.net/npm/katex) 加载的。要使用固定版本,请将 version 设置为例如 0.13.18

¥Note that by default the latest KaTeX is loaded from a remote server (https://cdn.jsdelivr.net/npm/katex). To use a fixed version set version to, for example, 0.13.18.

如果你想离线使用 KaTeX,你需要下载库的副本(例如,使用 npm)并使用 local 配置选项(version 选项将被忽略),例如:

¥If you want to use KaTeX offline you'll need to download a copy of the library (e.g. with npm) and use the local configuration option (the version option will then be ignored), for example:

Reveal.initialize({
  katex: {
    local: 'node_modules/katex',
  },
  plugins: [RevealMath.KaTeX],
});

MathJax 2

通过 mathjax2 配置对象调整选项。以下是该插件的默认配置。如果你不打算更改这些值,则根本不需要包含 mathjax2 配置选项。

¥Adjust options through the mathjax2 configuration object. Below is how the plugin is configured by default. If you don't intend to change these values you do not need to include the mathjax2 config option at all.

Reveal.initialize({
  mathjax2: {
    mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js',
    config: 'TeX-AMS_HTML-full',
    // pass other options into `MathJax.Hub.Config()`
    tex2jax: {
      inlineMath: [
        ['$', '$'],
        ['\\(', '\\)'],
      ],
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
    },
  },
  plugins: [RevealMath.MathJax2],
});

请注意,最新的 MathJax 2 是从远程服务器加载的。要使用固定版本,请将 mathjax 设置为例如 https://cdn.jsdelivr.net/npm/mathjax@2.7.8/MathJax.js

¥Note that the latest MathJax 2 is loaded from a remote server. To use a fixed version set mathjax to, for example, https://cdn.jsdelivr.net/npm/mathjax@2.7.8/MathJax.js.

如果你想离线使用 MathJax,你需要下载库的副本(例如,使用 npm)并将 mathjax 指向本地副本。

¥If you want to use MathJax offline you'll need to download a copy of the library (e.g. with npm) and point mathjax to the local copy.

MathJax 3 4.2.0

¥MathJax 3 4.2.0

通过 mathjax3 配置对象调整选项。以下是该插件的默认配置。如果你不打算更改这些值,则根本不需要包含 mathjax3 配置选项。

¥Adjust options through the mathjax3 configuration object. Below is how the plugin is configured by default. If you don't intend to change these values you do not need to include the mathjax3 config option at all.

Reveal.initialize({
  mathjax3: {
    mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js',
    tex: {
      inlineMath: [
        ['$', '$'],
        ['\\(', '\\)'],
      ],
    },
    options: {
      skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
    },
  },
  plugins: [RevealMath.MathJax3],
});

请注意,最新的 MathJax 3 是从远程服务器加载的。要使用固定版本,请将 mathjax 设置为例如 https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-mml-chtml.js。此外,配置现在是 URL 的一部分,默认情况下会加载 tex-mml-chtml,它可以识别 TeX 和 MathML 符号中的数学符号,并使用带有 CSS(CommonHTML 输出格式)的 HTML 生成输出。这是最通用的配置之一,但也是最大的配置之一,因此你可能需要考虑一个更适合你需求的较小配置,例如 tex-svg

¥Note that the latest MathJax 3 is loaded from a remote server. To use a fixed version set mathjax to, for example, https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-mml-chtml.js. Additionally, the config is now part of of the url, by default tex-mml-chtml is loaded which recognizes mathematics in both TeX and MathML notation, and generates output using HTML with CSS (the CommonHTML output format). This is one of the most general configurations, but it is also one of the largest, so you might want to consider a smaller one that is more tailored to your needs, e.g. tex-svg.

如果你想离线使用 MathJax,你需要下载库的副本(例如,使用 npm)并相应地调整 mathjax

¥If you want to use MathJax offline you'll need to download a copy of the library (e.g. with npm) and adjust mathjax accordingly.