Use LaTeX Math in your markdown

Remark+Rehype plugins to enable LaTeX math

latexremarkrehypeastro
Published 2022-05-04
Table of Contents

Intro

Use math annotations in your Markdown. Support LaTeX math.

Works on SSG, no client-side JavaScript needed.

Examples

Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following
equation.

$$
L = \frac{1}{2} \rho v^2 S C_L
$$

Lift() can be determined by Lift Coefficient () like the following equation.


is a point on the line segment from which








Install

npm i remark-math rehype-mathjax --save-dev

remark-math makes AST changes for later processing by rehype-mathjax

rehype-mathjax transforms work from remark-math into equations, etc.

Config

In your astro.config.mjs file, add the plugins

export default defineConfig({
  //integrations: [ixmageOptimize()],
  markdown: {
    //mode: 'mdx',
    remarkPlugins: [
      'remark-gfm', 'remark-smartypants',
      'remark-math' 
    ],
    rehypePlugins: [
      //'rehype-slug', < needed only prior beta.22
      'rehype-mathjax' 
    ]
  }
});

Because you are adding extra plugins, you will need to explicitly also include remark-gfm and remark-smartypants

Conclusion

Now my site supports markdown math if I ever need it.

A tableco-existingwith math-latex
1,11,21,3
2,12,22,3
3,13,23,3



Back to Post List
ok!