Latex support in Parsedown
Note
Does not yet include the lasted changes in ParsedownExtended v1.2.0
- Works with both Parsedown and ParsedownExtra
- Tested in php 7.0 to 8.0
- 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
Inline:
\( ... \)
$ ... $
if enabled
Block:
\[ ... \]
$$ ... $$
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
\]
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
]
]);