-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathedraw-org-export-latex.el
73 lines (56 loc) · 2.46 KB
/
edraw-org-export-latex.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
;;; edraw-org-export-latex.el --- Export edraw link As LaTeX in Org -*- lexical-binding: t; -*-
;; Copyright (C) 2022 AKIYAMA Kouhei
;; Author: AKIYAMA Kouhei <[email protected]>
;; Keywords: Graphics, Drawing, SVG, Editor, Orgmode
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'ox-latex)
(require 'edraw-org-edit)
;;;; Customize
;;;; Export
(defun edraw-org-export-latex-link (path _description _back-end info link)
;; path is unescaped : \[ \] => [ ]
;; description is not unescaped : \[ \] => \[ \]
(require 'edraw)
(if-let ((link-props (edraw-org-link-props-parse path nil t)))
(if-let ((data (edraw-org-link-prop-data link-props)))
;; Export data=base64.
;; Create temporary file.
(edraw-org-export-latex-link-file
(edraw-org-export-latex-create-temp-data-file data)
info link)
(if-let ((file (edraw-org-link-prop-file link-props)))
;; Export file=.
(edraw-org-export-latex-link-file file info link)
""))
""))
(defun edraw-org-export-latex-create-temp-data-file (data)
(let* ((svg-str (edraw-decode-string data t))
(hash (sha1 svg-str))
(file (format "link-data-%s.edraw.svg" hash))) ;;@todo customize
(with-temp-file file
(insert svg-str)
(set-buffer-file-coding-system 'utf-8))
file))
(defun edraw-org-export-latex-link-file (file info link)
;; (concat "\\includesvg" "{" file "}\n")
(let* ((element (org-element-copy link))
(element (org-element-put-property element :path file))
(parent (org-element-property :parent link))
(element (org-element-put-property element :parent parent)))
;; Delegate to ox-latex.
;; To support caption, attributes, etc.
(org-latex--inline-image element info)))
(provide 'edraw-org-export-latex)
;;; edraw-org-export-latex.el ends here