Plugins

Math

This plugins adds support for KaTeX expressions.

Installation

npm i @cartamd/plugin-math

Setup

Styles

You need to get access to the katex stylesheet, to do so, you can either install katex using:

npm i katex

and then adding this import to your app:

import 'katex/dist/katex.css';

or by using a content delivery network:

<link
	rel="stylesheet"
	href="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/katex.min.css"
	integrity="sha384-3UiQGuEI4TTMaFmGIZumfRPtfKQ3trwQE2JgosJxCnGmQpL/lJdjpcHkaaFwHlcI"
	crossorigin="anonymous"
/>

Extension

<script>
	import { Carta, MarkdownEditor } from 'carta-md';
	import { math } from '@cartamd/plugin-math';

	const carta = new Carta({
		extensions: [math()]
	});
</script>

<MarkdownEditor {carta} />

Usage

Inline:

Pythagorean theorem: $a^2+b^2=c^2$

a2+b2=c2a^2+b^2=c^2


Block:

$$
  \mathcal{L}\{f\}(s) = \int_0^{\infty} {f(t)e^{-st}dt}
$$
L{f}(s)=0f(t)estdt\mathcal{L}\{f\}(s) = \int_0^{\infty} {f(t)e^{-st}dt}

Options

Here are the options you can pass to math():

interface MathExtensionOptions {
	/**
	 * Options for inline katex, eg: $a^2+b^2=c^2$
	 */
	inline?: {
		/**
		 * @default control+m
		 */
		shortcut?: Set<string>;
	};
	/**
	 * Option for block katex, eg:
	 * $$
	 * a^2+b^2=c^2
	 * $$
	 */
	block?: {
		/**
		 * @default ctrl+shift+m
		 */
		shortcut?: Set<string>;
	};
	/**
	 * Options for remark-math
	 */
	remarkMath?: RemarkMathOptions;
	/**
	 * Options for rehype-katex
	 */
	rehypeKatex?: RehypeKatexOptions;
}
Handmade by Davide