     ## Escape all characters that can be (in particular, _s) that appear
     ## inside math mode, to prevent Marked from processing them.
     ## The Regex is exactly marked.js's inline.escape.
-    text = replaceMathBlocks text, (block) ->
-      block.replace /[\\`*{}\[\]()#+\-.!_]/g, '\\$&'
+    #text = replaceMathBlocks text, (block) ->
+    #  block.replace /[\\`*{}\[\]()#+\-.!_]/g, '\\$&'
     #marked.Lexer.rules = {text: /^[^\n]+/} if title
     if title  ## use "single-line" version of Markdown
       text = markdownInline text

  title = title
  .replace /^\s*<P>\s*/i, ''
  .replace /\s*<\/P>\s*$/i, ''
  sanitize postprocess title, leaveTeX

@stripHTMLTags = (html) ->
  html.replace /<[^>]*>/gm, ''


katex = require 'katex'

preprocessKaTeX = (text) ->
  math = []
  i = 0
  text = replaceMathBlocks text, (block) ->
    i += 1
    math[i] = block
    "MATH#{i}ENDMATH"
  [text, math]

postprocessKaTeX = (text, math) ->
  #replaceMathBlocks text, (block) ->
  text.replace /MATH(\d+)ENDMATH/g, (match, p1) ->
    block = math[p1]
    start$ = /^\$+/.exec block
    end$ = /\$+$/.exec block
    display = start$[0].length >= 2
    block = block[start$[0].length...end$.index]
    #.replace /&lt;/g, '<'
    #.replace /&gt;/g, '>'
    #.replace /’/g, "'"
    #.replace /‘/g, "`"  ## remove bad Marked automatic behavior
    try
      katex.renderToString block,
        displayMode: display
