   sanitized
 
 @formatBody = (format, body, leaveTeX = false) ->
-  [body, math] = preprocessKaTeX body unless leaveTeX
+  [body, math] = preprocessKaTeX body unless leaveTeX or format == 'latex'
   if format of formats
     body = formats[format] body, false
   else

      .replace /</g, '&lt;'
      .replace />/g, '&gt;'
      "<SPAN CLASS='katex-error' TITLE='#{title}'>#{latex}</SPAN>"

jsdiff = require 'diff'


latex2html = (tex) ->
  defs = {}
  tex = tex.replace /%.*$\n?/mg, ''
  tex = tex.replace /\\def\s*\\([a-zA-Z]+)\s*{((?:[^{}]|{(?:[^{}]|{[^{}]*})*})*)}/g, (match, p1, p2) ->
    defs[p1] = p2
    ''
  for def, val of defs
    #console.log "\\#{def} = #{val}"
    tex = tex.replace ///\\#{def}\s*///g, val
  tex = '<p>' + tex
  .replace /\\\\/g, '[DOUBLEBACKSLASH]'
  .replace /\\(BY|YEAR)\s*{([^{}]*)}/g, '<span style="border: thin solid; margin-left: 0.5em; padding: 0px 4px; font-variant:small-caps">$2</span>'
