* DONE Exporting citations in html CLOSED: [2014-05-17 Sat 14:42] :PROPERTIES: :categories: org-mode :date: 2014/05/17 14:41:43 :updated: 2014/07/15 16:52:09 :END: Now that org-ref works well for LaTeX, I want to explore a simple approach to exporting citations with a bibliography in html. This will enable me to put citations in blogposts, like this one cite:armiento-2014-high and these ones citet:daza-2014-carbon-dioxid,mehta-2014-ident-poten,suntivich-2014-estim-hybrid. We should be able to have the same citation in more than one place like this cite:armiento-2014-high, but only have one entry in the bibliography. The bibliography should be sorted if we ask for it cite:alesi-2012-evaluat-primar. I am curious to see this book citation: cite:day-1995-scien-englis. The first thing we need is a list of bibtex keys cited in this buffer. #+BEGIN_SRC emacs-lisp (defun org-ref-get-bibtex-keys () "return a list of unique keys in the buffer" (interactive) (let ((keys '())) (org-element-map (org-element-parse-buffer) 'link (lambda (link) (let ((plist (nth 1 link))) (when (-contains? org-ref-cite-types (plist-get plist ':type)) (dolist (key (org-ref-split-and-strip-string (plist-get plist ':path))) (when (not (-contains? keys key)) (setq keys (append keys (list key))))))))) keys)) (org-ref-get-bibtex-keys) #+END_SRC #+RESULTS: | armiento-2014-high | daza-2014-carbon-dioxid | mehta-2014-ident-poten | suntivich-2014-estim-hybrid | alesi-2012-evaluat-primar | day-1995-scien-englis | Good. Now, we need to create an HTML string for the bibliography. For each key, we will create an unordered list of simple citations. Each citation will be a named anchor in html. Let us start with a function that takes a key, and generates the HTML for that entry. #+BEGIN_SRC emacs-lisp (defun org-ref-get-bibtex-entry-html (key) (interactive) (let ((org-ref-bibliography-files (org-ref-find-bibliography)) (cb (current-buffer)) (file) (entry)) (setq file (catch 'result (loop for file in org-ref-bibliography-files do (message "looking for %s in %s" key file) (if (org-ref-key-in-file-p key (file-truename file)) (throw 'result file) (message "%s not found in %s" key (file-truename file)))))) (set-buffer (find-file-noselect file)) (prog1 (bibtex-search-entry key nil 0) (setq entry (org-ref-bib-citation)) (set-buffer cb)) (format "