# markdown-it-amsmath

> A markdown-it plugin for amsmath LaTeX environments.

Latest version **0.4.0** (published 2023-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install markdown-it-amsmath
pnpm add markdown-it-amsmath
yarn add markdown-it-amsmath
bun add markdown-it-amsmath
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2023-09-26 |
| First published | 2021-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 60.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chris Sewell |
| Maintainers | rowanc1, chrisjsewell, ebp-bot |
| Keywords | markdown, markdown-it, markdown-it-plugin, amsmath, latex |

## Links

- npm: https://www.npmjs.com/package/markdown-it-amsmath
- Homepage: https://github.com/executablebooks/markdown-it-amsmath
- npm.io page: https://npm.io/package/markdown-it-amsmath

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.4.0 (latest) — 2023-09-26
- 0.3.1 — 2022-02-15
- 0.3.0 — 2022-02-15
- 0.2.0 — 2021-12-02
- 0.1.2 — 2021-06-29
- 0.1.1 — 2021-06-29
- 0.1.0 — 2021-06-29

## README

# markdown-it-amsmath

[![ci-badge]][ci-link]
[![npm-badge]][npm-link]

A [markdown-it](https://github.com/markdown-it/markdown-it) plugin for [amsmath](https://ctan.org/pkg/amsmath) LaTeX environments.

The following "top-level" environments are parsed, with or without (ending `*`) numbering:
`equation`, `multline`, `gather`, `align`, `alignat`, `flalign`, `matrix`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`, `Vmatrix`, `eqnarray`.

(these environments are taken from [amsmath version 2.1](http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/required/amsmath/amsldoc.pdf))

Note the `split`, `gathered`, `aligned`, `alignedat` are not parsed, since they should be used within a parent environment.

See <https://executablebooks.github.io/markdown-it-amsmath/> for a demonstration!

## Usage

You should "bring your own" math render, provided as an option to the plugin.
This function should take the string plus (optional) options, and return a string.
For example, below the [KaTeX](https://github.com/Khan/KaTeX) render is used.

As a Node module:

```javascript
import { renderToString } from "katex"
import MarkdownIt from "markdown-it"
import amsmathPlugin from "markdown-it-amsmath"

const katexOptions = { throwOnError: false, displayMode: true }
const renderer = math => renderToString(math, katexOptions)
const mdit = MarkdownIt().use(amsmathPlugin, { renderer })
const text = mdit.render("\\begin{equation}a = 1\\end{equation}")
```

In the browser:

```html
<!DOCTYPE html>
<html>
  <head>
    <title>Example Page</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css"
    />
    <script src="https://cdn.jsdelivr.net/npm/markdown-it@12/dist/markdown-it.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js"></script>
    <script src="https://unpkg.com/markdown-it-amsmath"></script>
  </head>
  <body>
    <div id="demo"></div>
    <script>
      const katexOptions = { throwOnError: false, displayMode: true }
      const renderer = math => katex.renderToString(math, katexOptions)
      const mdit = window.markdownit().use(window.markdownitAmsmath, { renderer })
      const text = mdit.render("\\begin{equation}a = 1\\end{equation}")
      document.getElementById("demo").innerHTML = text
    </script>
  </body>
</html>
```

## Development

### Features

- TypeScript
- Code Formatting ([prettier])
- Code Linting ([eslint])
- Testing and coverage ([vitest])
- Continuous Integration ([GitHub Actions])
- Bundled as both UMD and ESM ([rollup])
- Upload as [NPM] package and [unpkg] CDN
- Simple demonstration website ([GitHub Pages])

### Getting Started

1. Create a GitHub repository [from the template](https://docs.github.com/en/github-ae@latest/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/creating-a-repository-from-a-template).
2. Replace package details in the following files:
   - `package.json`
   - `LICENSE`
   - `README.md`
   - `rollup.config.js`
3. Install the `node_module` dependencies: `npm install` or `npm ci` (see [Install a project with a clean slate](https://docs.npmjs.com/cli/v7/commands/npm-ci)).
4. Run code formatting; `npm run format`, and linting: `npm run lint:fix`.
5. Run the unit tests; `npm test`, or with coverage; `npm test -- --coverage`.

Now you can start to adapt the code in `src/index.ts` for your plugin, starting with the [markdown-it development recommendations](https://github.com/markdown-it/markdown-it/blob/master/docs/development.md).

Modify the test in `tests/fixtures.spec.ts`, to load your plugin, then the "fixtures" in `tests/fixtures`, to provide a set of potential Markdown inputs and expected HTML outputs.

On commits/PRs to the `master` branch, the GH actions will trigger, running the linting, unit tests, and build tests.
Additionally setup and uncomment the [codecov](https://about.codecov.io/) action in `.github/workflows/ci.yml`, to provide automated CI coverage.

Finally, you can update the version of your package, e.g.: `npm version patch -m "🚀 RELEASE: v%s"`, push to GitHub; `git push --follow-tags`, build; `npm run build`, and publish; `npm publish`.

Finally, you can adapt the HTML document in `docs/`, to load both markdown-it and the plugin (from [unpkg]), then render text from an input area.
This can be deployed by [GitHub Pages].

[ci-badge]: https://github.com/executablebooks/markdown-it-amsmath/workflows/CI/badge.svg
[ci-link]: https://github.com/executablebooks/markdown-it--plugin-template/actions
[npm-badge]: https://img.shields.io/npm/v/markdown-it-amsmath.svg
[npm-link]: https://www.npmjs.com/package/markdown-it-amsmath
[github actions]: https://docs.github.com/en/actions
[github pages]: https://docs.github.com/en/pages
[prettier]: https://prettier.io/
[eslint]: https://eslint.org/
[vitest]: https://vitest.dev/
[rollup]: https://rollupjs.org
[npm]: https://www.npmjs.com
[unpkg]: https://unpkg.com/

---
_Source: https://npm.io/package/markdown-it-amsmath · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
