myst-to-tex
myst-to-tex
is a library for converting MyST documents into LaTeX.
Goals
- Convert from
myst-spec
AST documents into markup - Work with jtex to template documents
- Work as a
unifiedjs
plugin and in themystjs
ecosystem
Not Goals
- Read LaTeX, this package is for serialization only
Installation¶
Install the package into your virtual environment using npm:
npm install myst-to-tex
Simple example¶
Below we construct a AST tree using unist-builder
, use the mystToTex
plugin in a unified
pipeline and stringify
the document into a file.
import { unified } from 'unified';
import { u } from 'unist-builder';
import mystToTex from 'myst-to-tex';
// Create a AST document, or parse using mystjs
const tree = u(
'root',
u('paragraph', [
u('text', { value: 'This is a unicode “fraction”: ' }),
u('inlineMath', { value: '½' }),
]),
);
// Use the plugin, and stringify the tree
const file = unified().use(mystToTex).stringify(tree);
// Log the results
console.log(file.result.value);
The document that we fed in was quite simple, and the ½
unicode characters as well as the quotes are nicely transformed into the appropriate :
This is a unicode ``fraction'': $\frac{1}{2}$
Overview¶
The myst-to-tex
library aims to translate all standard MyST syntax to sensible syntax, as well as be extensible to other plugins.