-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
org-ref-publish.el
107 lines (88 loc) · 3.94 KB
/
org-ref-publish.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
;;; org-ref-publish.el --- org-publish with org-ref -*- lexical-binding: t; -*-
;;; Commentary:
;; First draft proposed by madhu 230826 (Madhu <[email protected]>)
;; This code provides publishing capability that leverages
;;; Code:
;; modified from org-publish-org-to to call org-ref-process-buffer before
;; calling org-export-to-file
(defun org-ref-publish-org-to (backend filename extension plist &optional pub-dir)
"Publish an Org file to a specified backend using org-ref.
BACKEND is a symbol representing the backend used for
transcoding. FILENAME is the filename of the Org file to be
published. EXTENSION is the extension used for the output
string, with the leading dot. PLIST is the property list for the
given project.
Optional argument PUB-DIR, when non-nil is the publishing
directory.
Return output file name."
(unless (or (not pub-dir) (file-exists-p pub-dir))
(make-directory pub-dir t))
;; Check if a buffer visiting FILENAME is already open.
(let* ((org-inhibit-startup t)
(visiting (find-buffer-visiting filename))
(work-buffer (or visiting (find-file-noselect filename))))
(unwind-protect
(with-current-buffer work-buffer
(let* ((output (org-export-output-file-name extension nil pub-dir)))
(org-export-with-buffer-copy
(org-export-expand-include-keyword)
(goto-char (point-min))
(org-ref-process-buffer backend nil) ;no subtreep
(goto-char (point-min))
(org-export-to-file backend output
nil nil nil (plist-get plist :body-only)
;; Add `org-publish--store-crossrefs' and
;; `org-publish-collect-index' to final output filters.
;; The latter isn't dependent on `:makeindex', since we
;; want to keep it up-to-date in cache anyway.
(org-combine-plists
plist
`(:crossrefs
,(org-publish-cache-get-file-property
;; Normalize file names in cache.
(file-truename filename) :crossrefs nil t)
:filter-final-output
(org-publish--store-crossrefs
org-publish-collect-index
,@(plist-get plist :filter-final-output))))))))
;; Remove opened buffer in the process.
(unless visiting (kill-buffer work-buffer)))))
;; modified from org-html-publish-to-html to call org-ref-publish-org-to instead
;; of org-publish-org-to
(defun org-ref-publish-to-html (plist filename pub-dir)
"Publish an org file to HTML through org-ref.
FILENAME is the filename of the Org file to be published. PLIST
is the property list for the given project. PUB-DIR is the
publishing directory.
Return output file name."
(org-ref-publish-org-to 'html filename
(concat (when (> (length org-html-extension) 0) ".")
(or (plist-get plist :html-extension)
org-html-extension
"html"))
plist pub-dir))
;; modified from org-latex-publish-to-latex to call org-ref-publish-org-to
;; instead of org-publish-org-to
(defun org-ref-publish-to-latex (plist filename pub-dir)
"Publish an Org file to LaTeX using org-ref.
FILENAME is the filename of the Org file to be published. PLIST
is the property list for the given project. PUB-DIR is the
publishing directory.
Return output file name."
(org-ref-publish-org-to 'latex filename ".tex" plist pub-dir))
;; modified from org-latex-publish-to-pdf to call org-ref-publish-org-to instead of org-publish-org-to
(defun org-ref-publish-to-pdf (plist filename pub-dir)
"Publish an Org file to PDF (via LaTeX) using org-ref.
FILENAME is the filename of the Org file to be published. PLIST
is the property list for the given project. PUB-DIR is the
publishing directory.
Return output file name."
(org-publish-attachment
plist
(let ((default-directory (file-name-directory filename)))
(org-latex-compile
(org-ref-publish-org-to
'latex filename ".tex" plist (file-name-directory filename))))
pub-dir))
(provide 'org-ref-publish)
;;; org-ref-publish.el ends here