1.0.0 • Published 5 years ago
@mathssyfy/markdown-it-katex v1.0.0
@mathssyfy/markdown-it-katex
Plugin markdown-it for katex rendering with ability to add global \newcommand
Installation
yarn add @mathssyfy/markdown-it-katex
# or
npm install @mathssyfy/markdown-it-katex --save
Add CSS:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" crossorigin="anonymous">
Basic
const md = require('markdown-it')();
const mkn = require('@mathssyfy/markdown-it-katex');
md.use(mkn);
Add newcommands
Example:
const md = require('markdown-it')();
const mynewcommands = '\\displaystyle'
+'\\newcommand{\\vect}[1]{\\overrightarrow{#1}}'
+'\\newcommand{\\Oij}{\\left(O;\\vect{i};\\vect{j}\\right)}';
const mkn = require('@mathssyfy/markdown-it-katex');
md.use(mkn, {
"newcommands": mynewcommands
});
Katex
The native katex syntax also is supported:
const mymacroskatex = {
"\\f": "f(#1)"
};
const mynewcommands = '\\newcommand{\\g}[1]{g\\left(#1\\right)}';
const mkn = require('@mathssyfy/markdown-it-katex');
md.use(mkn, {
"macros": mymacroskatex,
"newcommands": mynewcommands
})