feat: katex chemical equations support

This commit is contained in:
NGPixel 2020-03-29 17:06:32 -04:00
parent c69a92a02a
commit 44a0f69a78
3 changed files with 1692 additions and 0 deletions

View File

@ -216,6 +216,7 @@ import mdMark from 'markdown-it-mark'
import mdFootnote from 'markdown-it-footnote'
import mdImsize from 'markdown-it-imsize'
import katex from 'katex'
import 'katex/dist/contrib/mhchem'
import twemoji from 'twemoji'
// Prism (Syntax Highlighting)

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
const katex = require('katex')
const chemParse = require('./mhchem')
/* global WIKI */
@ -8,6 +9,19 @@ const katex = require('katex')
//
// Includes code from https://github.com/liradb2000/markdown-it-katex
// Add \ce, \pu, and \tripledash to the KaTeX macros.
katex.__defineMacro('\\ce', function(context) {
return chemParse(context.consumeArgs(1)[0], 'ce')
})
katex.__defineMacro('\\pu', function(context) {
return chemParse(context.consumeArgs(1)[0], 'pu')
})
// Needed for \bond for the ~ forms
// Raise by 2.56mu, not 2mu. We're raising a hyphen-minus, U+002D, not
// a mathematical minus, U+2212. So we need that extra 0.56.
katex.__defineMacro('\\tripledash', '{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2mu' + '\\tiny\\text{-}\\mkern1mu\\text{-}\\mkern1mu\\text{-}\\mkern2mu$}}')
module.exports = {
init (mdinst, conf) {
if (conf.useInline) {