benjaminhoegh/parsedown-math

An extension of Parsedown that adds support for LaTeX.

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

This package is auto-updated.

Last update: 2024-11-26 23:03:58 UTC


README

ParsedownMath

ParsedownMath

GitHub release GitHub

Latex support in Parsedown

Note

Does not yet include the lasted changes in ParsedownExtended v1.2.0

Features

  • Works with both Parsedown and ParsedownExtra
  • Tested in php 7.0 to 8.0

Get started

  1. Make sure you have downloaded and included Parsedown or ParsedownExtra
  2. Download the latest release and include ParsedownMath.php
  3. Download and include Katex.js and auto-render.js your HTML

How to write a match section

Inline:

  • \( ... \)
  • $ ... $ if enabled

Block:

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

Examples:

Inline

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

<!-- Or -->

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

Block

$$
    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
\]

Options

You can toggle math by doing the following:

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

Or if you only want inline or block you can use:

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

To enable single dollar sign for inline match:

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