     #text = replaceMathBlocks text, (block) ->
     #  block.replace /[\\`*{}\[\]()#+\-.!_]/g, '\\$&'
     #marked.Lexer.rules = {text: /^[^\n]+/} if title
+    ## First extract Markdown verbatim environments (backticks) to prevent
+    ## LaTeX processing on them (especially math mode, so $ is inert in code).
+    [text, ticks] = preprocessMarkdownTicks text
     ## Support what we can of LaTeX before doing Markdown conversion.
     [text, math] = latex2htmlLight text
+    ## Put Markdown verbatims back in.
+    text = putTicksBack text, ticks
     if title  ## use "single-line" version of Markdown
       text = markdownInline text
     else

  tex.replace /MATH(\d+)ENDMATH/g, (match, id) -> math[id].all

postprocessKaTeX = (text, math, initialBold) ->
  macros = {}  ## shared across multiple math expressions within same body
  if initialBold
    weights = [boldWeight]

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

putMathBack = (tex, math) ->
