benjaminhoegh / parsedown-math
An extension of Parsedown that adds support for LaTeX.
Fund package maintenance!
paypal.me/BenjaminHoegh
www.buymeacoffee.com/BenjaminHoegh
Requires
- php: ^7.1||^8.0
- ext-mbstring: *
- erusev/parsedown: ^2.0.0|2.0.x@dev
This package is auto-updated.
Last update: 2024-10-26 22:49:41 UTC
README
ParsedownMath
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
- Make sure you have downloaded and included Parsedown or ParsedownExtra
- Download the latest release and include ParsedownMath.php
- 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 ] ]);