xcatliu / pagic

A static site generator powered by Deno + React
https://pagic.org
MIT License
1.64k stars 104 forks source link

Markdown katex macro #89

Closed ziqiq closed 3 years ago

ziqiq commented 3 years ago

This patch enables users to define page level and global katex macro, so that they don't have to type long but frequent math expression over and over again.

Example:

Global macros in pagic.config.ts

export default {
  md: {
    katexMacros: {
      "\\Z": "\\mathbb{Z}",
      "\\Null": "\\mathit{Null}",
      "\\cycl": "\\langle #1 \\rangle"
    },
  },
};

Some additional macros in index.md

$$
\gdef \greetings#1{\text{Welcome to my site, #1!}}
\gdef \degree{^\circ}
$$

$$\greetings{World}$$

A $90 \degree$ counter-clockwise rotation.

The null space of a matrix is $\Null(A) = \{\vec{x}\in \R^n : A\vec{x}=\vec{0}\}$

A cyclic subgroup is $\cycl{g} = \{ g^k | k \in \Z \}$.

result:

Screen Shot 2021-08-10 at 5 43 07 PM