     @doc.activate()
 
 Zotero.BetterBibTeX.CAYW.Formatter = {
+  latex: (citations, config) ->
+    config.command ||= 'cite'
+
+    return '' if citations.length == 0
+
+    state = {
+      prefix: 0
+      suffix: 0
+      'suppress-author': 0
+      locator: 0
+      label: 0
+    }
+    if citations.length > 1
+      for citation in citations
+        for own k of citation
+          state[k] ?= 0
+          state[k]++
+
+    if state.suffix == 0 && state.prefix == 0 && state.locator == 0 && state['suppress-author'] in [0, citations.length]
+      # simple case where everything can be put in a single cite
+      return "\\#{if citations[0]['suppress-author'] then 'citeyear' else config.command}{#{(citation.citekey for citation in citations).join(',')}}"
+
+    formatted = ''
+    for citation in citations
+      formatted += ' ' + citation.prefix + ' ' if citation.prefix
+      formatted += "\\"
+      formatted += if citation['suppress-author'] then 'citeyear' else config.command
+
+      switch
+        when citation.locator && citation.suffix
+          formatted += '[' + Zotero.BetterBibTeX.CAYW.shortLocator[citation.label] + ' ' + citation.locator + ', ' + citation.suffix + ']'
+        when citation.locator
+          formatted += '[' + Zotero.BetterBibTeX.CAYW.shortLocator[citation.label] + ' ' + citation.locator + ']'
+        when citation.suffix
+          formatted += '[' + citation.suffix + ']'
+      formatted += '{' + citation.citekey + '}'
+
+    return formatted.trim()
+
   mmd: (citations) ->
     formatted = []
     for citation in citations

Zotero.BetterBibTeX.CAYW = {}

class Zotero.BetterBibTeX.CAYW.Document
  constructor: ->

        when item.libraryID then "zg:#{item.libraryID}:#{item.key}"
        when Zotero.userID then "zu:#{Zotero.userID}:#{item.key}"
        else "zu:0:#{item.key}"
      locator = if citation.locator then "#{Zotero.BetterBibTeX.CAYW.shortLocator[citation.label]} #{citation.locator}" else ''
      citation.prefix ?= ''
      citation.suffix ?= ''

