-_ = require 'underscore'
+_ = require 'lodash'
 
 MATH_MARKER_BLOCK  = '\u200c\u200c\u200c' # zero-width non-joiner
 MATH_MARKER_INLINE = '\u200b\u200b\u200b' # zero-width space

      node.textContent = "#{MATH_MARKER_INLINE}#{formula}#{MATH_MARKER_INLINE}"
    latexNodes.push(node)

  unless _.isEmpty(latexNodes)
    windowImpl.MathJax.Hub.Typeset(latexNodes)

  mathMLNodes = _.toArray(windowImpl.document.querySelectorAll(MATH_ML_SELECTOR))
  unless _.isEmpty(mathMLNodes)
    # style the entire document because mathjax is unable to style individual math elements
    windowImpl.MathJax.Hub.Typeset( windowImpl.document )

  windowImpl.MathJax.Hub.Queue ->
    # Queue a call to mark the found nodes as rendered so are ignored if typesetting is called repeatedly
    # uses className += instead of classList because IE
    for node in latexNodes.concat(mathMLNodes)
      node.className += " #{MATH_RENDERED_CLASS}"

# Install a debounce around typesetting function so that it will only run once
# every Xms even if called multiple times in that period
typesetDocument = _.debounce( typesetDocument, 100)

# typesetMath is the main exported function.
# It's called by components like HTML after they're rendered

  # schedule a Mathjax pass if there is at least one [data-math] or <math> element present

  if windowImpl.MathJax?.Hub?.Queue? and root.querySelector(COMBINED_MATH_SELECTOR)
    getTypesetDocument(root, windowImpl)()


# The following should be called once and configures MathJax.
