math()

Mengaktifkan ekspresi matematika dengan sintaks inline dan display.

import { math } from "@unifast/node";

Signature

function math(): UnifastPlugin

Parameter

Tidak ada.

Penggunaan

import { compile, math } from "@unifast/node";

const md = `
Einstein's famous equation: $E = mc^2$

The sum of integers from 1 to n:

$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$$
`;

const result = compile(md, { plugins: [math()] });

Contoh

Ekspresi matematika

Math inline

Gunakan delimiter $ tunggal untuk ekspresi matematika inline.

import { compile, math } from "@unifast/node";

const md = `
The quadratic formula is $x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$ and is used to solve quadratic equations.
`;

const result = compile(md, { plugins: [math()] });

Math display

Gunakan delimiter $$ atau code block dengan bahasa math untuk math display.

import { compile, math } from "@unifast/node";

const md = `
$$
\\int_{0}^{\\infty} e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}
$$
`;

const result = compile(md, { plugins: [math()] });

Menyertakan KaTeX CSS

Plugin mengonversi sintaks math menjadi struktur HTML yang sesuai, namun Anda perlu menyertakan KaTeX CSS secara terpisah agar dirender dengan benar di peramban.

<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"
  crossorigin="anonymous"
/>