diff --git a/README.md b/README.md index 3cf1f1b5..b9ddbb39 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,12 @@ Vivify brings your (Markdown) files to life in the browser! support](#editor-support)) - Vivify server starts lazily and automatically shuts down when no more viewers are connected +- customize KaTeX to your needs by providing available [KaTeX + options](#KaTeX-options) + +If you need any additional features, feel free to [open an +issue](https://github.com/jannis-baum/vivify/issues/new/choose) or +[contribute](CONTRIBUTING.md)! ### Markdown @@ -25,9 +31,19 @@ Vivify brings your (Markdown) files to life in the browser! - syntax highlighting for code - graphviz/dot graphs -If you need any additional features, feel free to [open an -issue](https://github.com/jannis-baum/vivify/issues/new/choose) or -[contribute](CONTRIBUTING.md)! +### KaTeX options + +Customize KaTeX to your needs by providing an optional +`~/.vivify/katex_config.json` config file with [available KaTeX +options](https://katex.org/docs/options.html). For example: +``` +{ + "errorColor": "#cc0000", + "macros": { + "\\RR": "\\mathbb{R}" + } +} +``` ## Usage diff --git a/src/parser/parser.ts b/src/parser/parser.ts index a22955d6..a36e9a43 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -1,10 +1,17 @@ import { homedir } from 'os'; +import fs from 'fs'; import MarkdownIt from 'markdown-it'; import anchor from 'markdown-it-anchor'; import highlight from './highlight'; import graphviz from './dot'; +const katexConfigPath = `${homedir()}/.vivify/katex_config.json`; +let katexConfig = {}; +if (fs.existsSync(katexConfigPath)) { + katexConfig = JSON.parse(fs.readFileSync(katexConfigPath, 'utf8')); +} + const mdit = new MarkdownIt({ html: true, highlight: highlight, @@ -22,7 +29,7 @@ mdit.use(require('markdown-it-inject-linenumbers')); mdit.use(require('markdown-it-texmath'), { engine: require('katex'), delimiters: 'dollars', - katexOptions: { errorColor: '#cc0000', macros: { '\\RR': '\\mathbb{R}' } } + katexOptions: katexConfig }); /* eslint-enable @typescript-eslint/no-var-requires */ mdit.use(graphviz);