A remark plugin for subscript and superscript syntax using _{...} and ^{...}.
LaTeX-style syntax that:
- No GFM conflict —
~text~stays as strikethrough - Familiar — billions of documents use
_{}and^{}for sub/sup - Unambiguous — braces clearly delimit content
npm install remark-sub-supimport { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkSubSup from 'remark-sub-sup'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
const html = await unified()
.use(remarkParse)
.use(remarkSubSup)
.use(remarkRehype)
.use(rehypeStringify)
.process('H_{2}O and x^{2}')
// Output: <p>H<sub>2</sub>O and x<sup>2</sup></p>H_{2}O → H<sub>2</sub>O
x^{2} → x<sup>2</sup>
a_{i}^{j} → a<sub>i</sub><sup>j</sup>Braces inside content are preserved:
f_{g(x)} → f<sub>g(x)</sub>
_{a{b}c} → <sub>a{b}c</sub>Note: Content inside _{...} and ^{...} is treated as plain text, not parsed as Markdown.
\_{not sub} → _{not sub}
_{a\}b} → <sub>a}b</sub>This monorepo contains:
| Package | Purpose |
|---|---|
micromark-extension-sub-sup |
Tokenizer |
mdast-util-sub-sup |
AST utilities |
remark-sub-sup |
Remark plugin |
MIT