-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-letter-gbrief.el
69 lines (59 loc) · 3.14 KB
/
org-letter-gbrief.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
;; load this file with `load'
;; letter export
(setq org-export-kill-product-buffer-when-displayed t)
(add-to-list 'org-export-latex-classes
'("brief"
"\\documentclass[11pt,ngerman]{g-brief2}
[DEFAULT-PACKAGES]
[NO-PACKAGES]
[EXTRA]"
("%%" . "%%")
("\\begin{g-brief}" . "\\end{g-brief}")))
(defun org-letter-option-get (option)
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(let (results)
(while (re-search-forward (concat "^#\\+" option ":[ \t]*\\(.*?\\)[ \t]*$") nil t)
(add-to-list 'results (concat (org-match-string-no-properties 1 nil))))
results))))
(setq org-letter-options-format-alist '(("Anrede" . "{%s}")
("Unterschrift" . "{%s}")
("Gruss" . "{%s}{1cm}")
("Betreff" . "{%s}")
("Datum" . "{%s}")
("Adresse" . "{%s}")
("IhrZeichen" . "{%s}")
("IhrSchreiben" . "{%s}")
("MeinZeichen" . "{%s}")))
(defun org-letter-buffer-brief-p ()
(string= "brief" (plist-get (org-infile-export-plist) :latex-class)))
(defun org-letter-add-options-to-latex-headers ()
(when (org-letter-buffer-brief-p)
(let* ((current-headers (plist-get org-export-latex-options-plist
:latex-header-extra))
(new-headers (mapconcat '(lambda (x)
(when (org-letter-option-get (car x))
(let ((lst (org-letter-option-get (car x))))
(concat "\n" "\\" (car x) " "
(format (cdr x)
(if (> (length lst) 1)
(mapconcat 'identity (reverse lst) "\\\\")
(car lst)))))))
org-letter-options-format-alist "")))
(plist-put org-export-latex-options-plist
:latex-header-extra (concat current-headers new-headers)))))
(add-hook 'org-export-latex-after-initial-vars-hook 'org-letter-add-options-to-latex-headers)
(defun org-letter-add-gbrief-end-section ()
(let ((gbrief-p (string-match "\\\\documentclass\\(\\[[^][]*?\\]\\)?{g-brief2}"
org-export-latex-header)))
(when gbrief-p
(goto-char (point-max))
(forward-line -1)
(insert "\\end{g-brief}"))))
(add-hook 'org-export-latex-final-hook 'org-letter-add-gbrief-end-section)
; hack because `org-export-latex-title-command' is not allowed to be set via file local variables (**)
(add-hook 'org-export-first-hook '(lambda ()
(when (org-letter-buffer-brief-p)
(set (make-local-variable 'org-export-latex-title-command) ""))))