           abbrev: abbrev
           url: match[2][1...-1]
 
+  processCites = (tex) ->
+    tex.replace /\\cite\s*(?:\[([^\[\]]*)\]\s*)?{([^{}]*)}/g, (match, p1, p2) ->
+      '[' + (
+        for cite in p2.split ','
+          cite = cite.trim()
+          bib = bibs[cite]
+          if bib?
+            "\\href{#{bib.url}}{#{bib.abbrev}}"
+          else
+            console.warn "Missing bib url for '#{cite}'" unless bib?
+            cite
+      ).join(', ') + (if p1? then ", #{p1}" else '') + ']'
+
   ## Extract figures.
   figures = {}
   for filename, content of zip.files

      for message in messages
        attach = []
        message.body = message.body
        .replace /\\ref\s*{([^{}]*)}/, (match, p1) ->
          if p1 of labels
            labels[p1]
          else if p1 of figures

      tex = tex
      .replace /%.*$\n?/mg, ''
      .replace /\\begin\s*{(wrap)?figure}[^\0]*?\\end\s*{(wrap)?figure}\s*/g, ''
      tex = processCites tex
      depths = []
      start = null
      labels = {}
