benjaminhoegh/parsedown-math

Parsedown 的扩展,增加了对 LaTeX 的支持。

v2.0-beta1 2021-12-11 17:50 UTC

This package is auto-updated.

Last update: 2024-08-26 22:26:22 UTC


README

ParsedownMath

ParsedownMath

GitHub release GitHub

Parsedown 中添加 LaTeX 支持

注意

尚未包含 ParsedownExtended v1.2.0 的最新更改

功能

  • 与 Parsedown 和 ParsedownExtra 都兼容
  • 在 php 7.0 到 8.0 上进行过测试

开始使用

  1. 确保您已下载并包含 ParsedownParsedownExtra
  2. 下载最新版本 latest release 并包含 ParsedownMath.php
  3. 下载并包含 Katex.jsauto-render.js 到您的 HTML 中

如何编写匹配部分

行内

  • \( ... \)
  • $ ... $ 如果启用

  • \[ ... \]
  • $$ ... $$

示例

行内

Inline \(tag{E=mc^2}\) math

<!-- Or -->

Inline $tag{E=mc^2}$ math

$$
    f(x) = \int_{-\infty}^\infty
    \hat f(\xi)\,e^{2 \pi i \xi x}
    \,d\xi
$$

<!-- Or -->

\[
    f(x) = \int_{-\infty}^\infty
    \hat f(\xi)\,e^{2 \pi i \xi x}
    \,d\xi
\]

选项

您可以通过以下方式切换数学公式

$Parsedown = new ParsedownMath([
    'math' => [
        'enabled' => true // Write true to enable the module
    ]
]);

或者,如果您只想使用行内或块,可以使用

'math' => [
    ['inline'] => [
        'enabled' => false // false disable the module
    ],
    // Or
    ['block'] => [
        'enabled' => false
    ]
]

启用单美元符号进行行内匹配

$Parsedown = new ParsedownMath([
    'math' => [
        'matchSingleDollar' => true // default false
    ]
]);