basant307/AI_Governance_Project
048
1# remark-math2 3[![Build][build-badge]][build]4[![Coverage][coverage-badge]][coverage]5[![Downloads][downloads-badge]][downloads]6[![Size][size-badge]][size]7[![Sponsors][sponsors-badge]][collective]8[![Backers][backers-badge]][collective]9[![Chat][chat-badge]][chat]10 11**[remark][]** plugin to support math (`$C_L$`).12 13## Contents14 15* [What is this?](#what-is-this)16* [When should I use this?](#when-should-i-use-this)17* [Install](#install)18* [Use](#use)19* [API](#api)20 * [`unified().use(remarkMath[, options])`](#unifieduseremarkmath-options)21 * [`Options`](#options)22* [Authoring](#authoring)23* [HTML](#html)24* [CSS](#css)25* [Syntax](#syntax)26* [Syntax tree](#syntax-tree)27* [Types](#types)28* [Compatibility](#compatibility)29* [Security](#security)30* [Related](#related)31* [Contribute](#contribute)32* [License](#license)33 34## What is this?35 36This package is a [unified][] ([remark][]) plugin to add support for math37syntax.38You can use this to add support for parsing and serializing this syntax39extension.40 41As there is no spec for math in markdown, this extension follows how code42(fenced and text) works in Commonmark, but uses dollars (`$`).43 44## When should I use this?45 46This project is useful when you want to support math in markdown.47Extending markdown with a syntax extension makes the markdown less portable.48LaTeX equations are also quite hard.49But this mechanism works well when you want authors, that have some LaTeX50experience, to be able to embed rich diagrams of math in scientific text.51 52If you *just* want to turn markdown into HTML (with maybe a few extensions such53as math), we recommend [`micromark`][micromark] with54[`micromark-extension-math`][micromark-extension-math] instead.55If you don’t use plugins and want to access the syntax tree, you can use56[`mdast-util-from-markdown`][mdast-util-from-markdown] with57[`mdast-util-math`][mdast-util-math].58 59This plugins adds [fields on nodes][mdast-util-to-hast-fields] so that the60plugin responsible for turning markdown (mdast) into HTML (hast),61[`remark-rehype`][remark-rehype], will turn text math (inline) into62`<code class="language-math math-inline">…</code>` and flow math (block)63into `<pre><code class="language-math math-display">…</code></pre>`.64 65## Install66 67This package is [ESM only][esm].68In Node.js (version 16+), install with [npm][]:69 70```sh71npm install remark-math72```73 74In Deno with [`esm.sh`][esmsh]:75 76```js77import remarkMath from 'https://esm.sh/remark-math@6'78```79 80In browsers with [`esm.sh`][esmsh]:81 82```html83<script type="module">84 import remarkMath from 'https://esm.sh/remark-math@6?bundle'85</script>86```87 88## Use89 90Say our document `example.md` contains:91 92```markdown93Lift($$L$$) can be determined by Lift Coefficient ($$C_L$$) like the following94equation.95 96$$97L = \frac{1}{2} \rho v^2 S C_L98$$99```100 101…and our module `example.js` contains:102 103```js104import rehypeKatex from 'rehype-katex'105import rehypeStringify from 'rehype-stringify'106import remarkMath from 'remark-math'107import remarkParse from 'remark-parse'108import remarkRehype from 'remark-rehype'109import {read} from 'to-vfile'110import {unified} from 'unified'111 112const file = await unified()113 .use(remarkParse)114 .use(remarkMath)115 .use(remarkRehype)116 .use(rehypeKatex)117 .use(rehypeStringify)118 .process(await read('example.md'))119 120console.log(String(file))121```122 123…then running `node example.js` yields:124 125```html126<p>Lift(<code class="language-math math-inline"><span class="katex">…</span></code>) like the following127equation.</p>128<pre><code class="language-math math-display"><span class="katex-display"><span class="katex">…</span></span></code></pre>129```130 131## API132 133This package exports no identifiers.134The default export is [`remarkMath`][api-remark-math].135 136### `unified().use(remarkMath[, options])`137 138Add support for math.139 140###### Parameters141 142* `options` ([`Options`][api-options], optional)143 — configuration144 145###### Returns146 147Nothing (`undefined`).148 149### `Options`150 151Configuration (TypeScript type).152 153###### Fields154 155* `singleDollarTextMath` (`boolean`, default: `true`)156 — whether to support text math (inline) with a single dollar.157 Single dollars work in Pandoc and many other places, but often interfere158 with “normal” dollars in text.159 If you turn this off, you can still use two or more dollars for text math.160 161## Authoring162 163When authoring markdown with math, keep in mind that math doesn’t work in most164places.165Notably, GitHub currently has a really weird crappy client-side regex-based166thing.167But on your own (math-heavy?) site it can be great!168 169Instead of a syntax extension to markdown, you can also use fenced code with an170info string of `math`:171 172````markdown173```math174L = \frac{1}{2} \rho v^2 S C_L175```176````177 178## HTML179 180This plugin integrates with [`remark-rehype`][remark-rehype].181When markdown (mdast) is turned into HTML (hast) the math nodes are turned182into `<code class="language-math math-inline">…</code>` and183`<pre><code class="language-math math-display">…</code></pre>` elements.184 185## CSS186 187This package does not relate to CSS.188You can choose to render the math with KaTeX, MathJax, or something else, which189might need CSS.190 191## Syntax192 193See [*Syntax* in194`micromark-extension-math`](https://github.com/micromark/micromark-extension-math#syntax).195 196## Syntax tree197 198See [*Syntax tree* in199`mdast-util-math`](https://github.com/syntax-tree/mdast-util-math#syntax-tree).200 201## Types202 203This package is fully typed with [TypeScript][].204It exports the additional type [`Options`][api-options].205 206If you’re working with the syntax tree, you can register the new node types207with `@types/mdast` by adding a reference:208 209```js210// Register math nodes in mdast:211/// <reference types="mdast-util-math" />212 213import {visit} from 'unist-util-visit'214 215function myRemarkPlugin() {216 /**217 * @param {import('mdast').Root} tree218 * Tree.219 * @returns {undefined}220 * Nothing.221 */222 return function (tree) {223 visit(tree, function (node) {224 console.log(node) // `node` can now be one of the math nodes.225 })226 }227}228```229 230## Compatibility231 232Projects maintained by the unified collective are compatible with maintained233versions of Node.js.234 235When we cut a new major release, we drop support for unmaintained versions of236Node.237This means we try to keep the current release line, `remark-math@^6`,238compatible with Node.js 16.239 240This plugin works with unified version 6+ and remark version 14+.241The previous major (version 4) worked with remark 13.242 243## Security244 245Use of `remark-math` does not involve **[rehype][]** ([hast][]) or user246content so there are no openings for [cross-site scripting (XSS)][wiki-xss]247attacks.248 249## Related250 251* [`remark-gfm`](https://github.com/remarkjs/remark-gfm)252 — support GFM (autolink literals, footnotes, strikethrough, tables,253 tasklists)254* [`remark-frontmatter`](https://github.com/remarkjs/remark-frontmatter)255 — support frontmatter (YAML, TOML, and more)256* [`remark-directive`](https://github.com/remarkjs/remark-directive)257 — support directives258* [`remark-mdx`](https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx)259 — support MDX (ESM, JSX, expressions)260 261## Contribute262 263See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways264to get started.265See [`support.md`][support] for ways to get help.266 267This project has a [code of conduct][coc].268By interacting with this repository, organization, or community you agree to269abide by its terms.270 271## License272 273[MIT][license] © [Junyoung Choi][author]274 275<!-- Definitions -->276 277[build-badge]: https://github.com/remarkjs/remark-math/workflows/main/badge.svg278 279[build]: https://github.com/remarkjs/remark-math/actions280 281[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-math.svg282 283[coverage]: https://codecov.io/github/remarkjs/remark-math284 285[downloads-badge]: https://img.shields.io/npm/dm/remark-math.svg286 287[downloads]: https://www.npmjs.com/package/remark-math288 289[size-badge]: https://img.shields.io/bundlejs/size/remark-math290 291[size]: https://bundlejs.com/?q=remark-math292 293[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg294 295[backers-badge]: https://opencollective.com/unified/backers/badge.svg296 297[collective]: https://opencollective.com/unified298 299[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg300 301[chat]: https://github.com/remarkjs/remark/discussions302 303[npm]: https://docs.npmjs.com/cli/install304 305[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c306 307[esmsh]: https://esm.sh308 309[health]: https://github.com/remarkjs/.github310 311[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md312 313[support]: https://github.com/remarkjs/.github/blob/main/support.md314 315[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md316 317[license]: https://github.com/remarkjs/remark-math/blob/main/license318 319[author]: https://rokt33r.github.io320 321[hast]: https://github.com/syntax-tree/hast322 323[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown324 325[mdast-util-math]: https://github.com/syntax-tree/mdast-util-math326 327[mdast-util-to-hast-fields]: https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes328 329[micromark]: https://github.com/micromark/micromark330 331[micromark-extension-math]: https://github.com/micromark/micromark-extension-math332 333[rehype]: https://github.com/rehypejs/rehype334 335[remark]: https://github.com/remarkjs/remark336 337[remark-rehype]: https://github.com/remarkjs/remark-rehype338 339[typescript]: https://www.typescriptlang.org340 341[unified]: https://github.com/unifiedjs/unified342 343[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting344 345[api-options]: #options346 347[api-remark-math]: #unifieduseremarkmath-options348 