ox-koma-letter.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. ;;; ox-koma-letter.el --- KOMA Scrlttr2 Back-End for Org Export Engine
  2. ;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou AT gmail DOT com>
  4. ;; Alan Schmitt <alan.schmitt AT polytechnique DOT org>
  5. ;; Viktor Rosenfeld <listuser36 AT gmail DOT com>
  6. ;; Rasmus Pank Roulund <emacs AT pank DOT eu>
  7. ;; Keywords: org, wp, tex
  8. ;; This program is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; This program is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;;
  20. ;; This library implements a KOMA Scrlttr2 back-end, derived from the
  21. ;; LaTeX one.
  22. ;;
  23. ;; Depending on the desired output format, three commands are provided
  24. ;; for export: `org-koma-letter-export-as-latex' (temporary buffer),
  25. ;; `org-koma-letter-export-to-latex' ("tex" file) and
  26. ;; `org-koma-letter-export-to-pdf' ("pdf" file).
  27. ;;
  28. ;; On top of buffer keywords supported by `latex' back-end (see
  29. ;; `org-latex-options-alist'), this back-end introduces the following
  30. ;; keywords: "CLOSING" (see `org-koma-letter-closing'), "FROM_ADDRESS"
  31. ;; (see `org-koma-letter-from-address'), "LCO" (see
  32. ;; `org-koma-letter-class-option-file'), "OPENING" (see
  33. ;; `org-koma-letter-opening'), "PHONE_NUMBER" (see
  34. ;; `org-koma-letter-phone-number'), "SIGNATURE" (see
  35. ;; `org-koma-letter-signature') and "TO_ADDRESS".
  36. ;;
  37. ;; You will need to add an appropriate association in
  38. ;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. For
  39. ;; example, you can use the following code:
  40. ;;
  41. ;; (add-to-list 'org-latex-classes
  42. ;; '("my-letter"
  43. ;; "\\documentclass\[%
  44. ;; DIV=14,
  45. ;; fontsize=12pt,
  46. ;; parskip=half,
  47. ;; subject=titled,
  48. ;; backaddress=false,
  49. ;; fromalign=left,
  50. ;; fromemail=true,
  51. ;; fromphone=true\]\{scrlttr2\}
  52. ;; \[DEFAULT-PACKAGES]
  53. ;; \[PACKAGES]
  54. ;; \[EXTRA]"))
  55. ;;
  56. ;; Then, in your Org document, be sure to require the proper class
  57. ;; with :
  58. ;;
  59. ;; #+LATEX_CLASS: my-letter
  60. ;;; Code:
  61. (require 'ox-latex)
  62. ;;; User-Configurable Variables
  63. (defgroup org-export-koma-letter nil
  64. "Options for exporting to KOMA scrlttr2 class in LaTeX export."
  65. :tag "Org Koma-Letter"
  66. :group 'org-export)
  67. (defcustom org-koma-letter-class-option-file "NF"
  68. "Letter Class Option File."
  69. :group 'org-export-koma-letter
  70. :type 'string)
  71. (defcustom org-koma-letter-author 'user-full-name
  72. "The sender's name.
  73. This variable defaults to calling the function `user-full-name'
  74. which just returns the current `user-full-name'. Alternatively a
  75. string, nil or a function may be given. Functions must return a
  76. string."
  77. :group 'org-export-koma-letter
  78. :type '(radio (function-item user-full-name)
  79. (string)
  80. (function)
  81. (const nil)))
  82. (defcustom org-koma-letter-email 'org-koma-letter-email
  83. "The sender's email address.
  84. This variable defaults to the value `org-koma-letter-email' which
  85. returns `user-mail-address'. Alternatively a string, nil or a
  86. function may be given. Functions must return a string."
  87. :group 'org-export-koma-letter
  88. :type '(radio (function-item org-koma-letter-email)
  89. (string)
  90. (function)
  91. (const nil)))
  92. (defcustom org-koma-letter-from-address nil
  93. "Sender's address, as a string."
  94. :group 'org-export-koma-letter
  95. :type 'string)
  96. (defcustom org-koma-letter-phone-number nil
  97. "Sender's phone number, as a string."
  98. :group 'org-export-koma-letter
  99. :type 'string)
  100. (defcustom org-koma-letter-place nil
  101. "Place from which the letter is sent."
  102. :group 'org-export-koma-letter
  103. :type 'string)
  104. (defcustom org-koma-letter-opening nil
  105. "Letter's opening, as a string."
  106. :group 'org-export-koma-letter
  107. :type 'string)
  108. (defcustom org-koma-letter-closing nil
  109. "Koma-Letter's closing, as a string."
  110. :group 'org-export-koma-letter
  111. :type 'string)
  112. (defcustom org-koma-letter-signature nil
  113. "String used as the signature."
  114. :group 'org-export-koma-letter
  115. :type 'string)
  116. (defcustom org-koma-letter-subject-format t
  117. "Use the title as the subject of the letter. At the time of
  118. writing the following values are allowed:
  119. - afteropening: subject after opening
  120. - beforeopening: subject before opening
  121. - centered: subject centered
  122. - left:subject left-justified
  123. - right: subject right-justified
  124. - titled: add title/description to subject
  125. - underlined: set subject underlined (see note in text please)
  126. - untitled: do not add title/description to subject.
  127. - No-export: do no insert a subject even if present.
  128. Please refer to the KOMA-script manual (Table 4.16. in the
  129. English manual of 2012-07-22)"
  130. :type '(set (const "afteropening")
  131. (const "beforeopening")
  132. (const "centered")
  133. (const "left")
  134. (const "right")
  135. (const "underlined")
  136. (const "titled")
  137. (const "untitled")
  138. (const :tag "No export" nil)
  139. (const :tag "Default options" t)
  140. (string))
  141. :group 'org-export-koma-letter)
  142. (defcustom org-koma-letter-use-backaddress t
  143. "Print return address in small line above to address."
  144. :group 'org-export-koma-letter
  145. :type 'boolean)
  146. (defcustom org-koma-letter-use-foldmarks "true"
  147. "Configure appearence of fold marks.
  148. Accepts any valid value for the KOMA-Script `foldmarks' option.
  149. Use `foldmarks:true' to activate default fold marks or
  150. `foldmarks:nil' to deactivate fold marks."
  151. :group 'org-export-koma-letter
  152. :type 'string)
  153. (defcustom org-koma-letter-use-phone t
  154. "Print sender's phone number."
  155. :group 'org-export-koma-letter
  156. :type 'boolean)
  157. (defcustom org-koma-letter-use-email t
  158. "Print sender's email address."
  159. :group 'org-export-koma-letter
  160. :type 'boolean)
  161. (defcustom org-koma-letter-use-place t
  162. "Print the letter's place next to the date."
  163. :group 'org-export-koma-letter
  164. :type 'boolean)
  165. (defconst org-koma-letter-special-tags-after-closing
  166. '("ps" "encl" "cc")
  167. "Header tags to be inserted after closing")
  168. (defconst org-koma-letter-special-tags-after-letter '("after_letter")
  169. "Header tags to be inserted after closing")
  170. (defvar org-koma-letter-special-contents nil "holds special
  171. content temporarily.")
  172. ;;; Define Back-End
  173. (org-export-define-derived-backend 'koma-letter 'latex
  174. :options-alist
  175. '((:lco "LCO" nil org-koma-letter-class-option-file)
  176. (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t)
  177. (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline)
  178. (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number)
  179. (:email "EMAIL" nil (org-koma-letter--get-custom org-koma-letter-email) t)
  180. (:to-address "TO_ADDRESS" nil nil newline)
  181. (:place "PLACE" nil org-koma-letter-place)
  182. (:opening "OPENING" nil org-koma-letter-opening)
  183. (:closing "CLOSING" nil org-koma-letter-closing)
  184. (:signature "SIGNATURE" nil org-koma-letter-signature newline)
  185. (:special-tags nil nil
  186. (append org-koma-letter-special-tags-after-closing
  187. org-koma-letter-special-tags-after-letter))
  188. (:with-after-closing nil "after-closing-order"
  189. org-koma-letter-special-tags-after-closing)
  190. (:with-after-letter nil "after-letter-order"
  191. org-koma-letter-special-tags-after-letter)
  192. (:with-backaddress nil "backaddress" org-koma-letter-use-backaddress)
  193. (:with-foldmarks nil "foldmarks" org-koma-letter-use-foldmarks)
  194. (:with-phone nil "phone" org-koma-letter-use-phone)
  195. (:with-email nil "email" org-koma-letter-use-email)
  196. (:with-place nil "place" org-koma-letter-use-place)
  197. (:with-subject nil "subject" org-koma-letter-subject-format))
  198. :translate-alist '((export-block . org-koma-letter-export-block)
  199. (export-snippet . org-koma-letter-export-snippet)
  200. (headline . org-koma-letter-headline)
  201. (keyword . org-koma-letter-keyword)
  202. (template . org-koma-letter-template))
  203. :menu-entry
  204. '(?k "Export with KOMA Scrlttr2"
  205. ((?L "As LaTeX buffer" org-koma-letter-export-as-latex)
  206. (?l "As LaTeX file" org-koma-letter-export-to-latex)
  207. (?p "As PDF file" org-koma-letter-export-to-pdf)
  208. (?o "As PDF file and open"
  209. (lambda (a s v b)
  210. (if a (org-koma-letter-export-to-pdf t s v b)
  211. (org-open-file (org-koma-letter-export-to-pdf nil s v b))))))))
  212. ;;; Helper functions
  213. (defun org-koma-letter-email ()
  214. "Return the current `user-mail-address'"
  215. user-mail-address)
  216. ;; The following is taken from/inspired by ox-grof.el
  217. ;; Thanks, Luis!
  218. (defun org-koma-letter--get-tagged-contents (tag)
  219. "Get tagged content from `org-koma-letter-special-contents'"
  220. (cdr (assoc tag org-koma-letter-special-contents)))
  221. (defun org-koma-letter--get-custom (value)
  222. "Determines whether a value is nil, a string or a
  223. function (a symobl). If it is a function it it evaluates it."
  224. (when value
  225. (cond ((stringp value) value)
  226. ((functionp value) (funcall value))
  227. ((symbolp value) (symbol-name value)))))
  228. (defun org-koma-letter--prepare-special-contents-as-macro (a-list &optional keep-newlines no-tag)
  229. "Finds all the components of `org-koma-letter-special-contents'
  230. corresponding to members of the `a-list' and return them as a
  231. string to be formatted. The function is used for inserting
  232. content of speciall headings such as PS.
  233. If keep-newlines is t newlines will not be removed. If no-tag is
  234. is t the content in `org-koma-letter-special-contents' will not
  235. be wrapped in a macro named whatever the members of a-list are called.
  236. "
  237. (let (output)
  238. (dolist (ac a-list output)
  239. (let
  240. ((x (org-koma-letter--get-tagged-contents ac))
  241. (regexp (if keep-newlines "" "\\`\n+\\|\n*\\'")))
  242. (when x
  243. (setq output
  244. (concat
  245. output "\n"
  246. ;; sometimes LaTeX complains about newlines
  247. ;; at the end or beginning of macros. Remove them.
  248. (org-koma-letter--format-string-as-macro
  249. (format "%s" (replace-regexp-in-string regexp "" x))
  250. (unless no-tag ac)))))))))
  251. (defun org-koma-letter--format-string-as-macro (string &optional macro)
  252. "If a macro is given format as string as \"\\macro{string}\" else as \"string\""
  253. (if macro
  254. (format "\\%s{%s}" macro string)
  255. (format "%s" string)))
  256. ;;; Transcode Functions
  257. ;;;; Export Block
  258. (defun org-koma-letter-export-block (export-block contents info)
  259. "Transcode an EXPORT-BLOCK element into KOMA Scrlttr2 code.
  260. CONTENTS is nil. INFO is a plist used as a communication
  261. channel."
  262. (when (member (org-element-property :type export-block) '("KOMA-LETTER" "LATEX"))
  263. (org-remove-indentation (org-element-property :value export-block))))
  264. ;;;; Export Snippet
  265. (defun org-koma-letter-export-snippet (export-snippet contents info)
  266. "Transcode an EXPORT-SNIPPET object into KOMA Scrlttr2 code.
  267. CONTENTS is nil. INFO is a plist used as a communication
  268. channel."
  269. (when (memq (org-export-snippet-backend export-snippet) '(latex koma-letter))
  270. (org-element-property :value export-snippet)))
  271. ;;;; Keyword
  272. (defun org-koma-letter-keyword (keyword contents info)
  273. "Transcode a KEYWORD element into KOMA Scrlttr2 code.
  274. CONTENTS is nil. INFO is a plist used as a communication
  275. channel."
  276. (let ((key (org-element-property :key keyword))
  277. (value (org-element-property :value keyword)))
  278. ;; Handle specifically BEAMER and TOC (headlines only) keywords.
  279. ;; Otherwise, fallback to `latex' back-end.
  280. (if (equal key "KOMA-LETTER") value
  281. (org-export-with-backend 'latex keyword contents info))))
  282. ;; Headline
  283. (defun org-koma-letter-headline (headline contents info)
  284. "Transcode a HEADLINE element from Org to LaTeX.
  285. CONTENTS holds the contents of the headline. INFO is a plist
  286. holding contextual information.
  287. Note that if a headline is tagged with a tag from
  288. `org-koma-letter-special-tags' it will not be exported, but
  289. stored in `org-koma-letter-special-contents' and included at the
  290. appropriate place."
  291. (let*
  292. ((tags (and (plist-get info :with-tags)
  293. (org-export-get-tags headline info)))
  294. (tag (downcase (car tags))))
  295. (if (member tag (plist-get info :special-tags))
  296. (progn
  297. (push (cons tag contents)
  298. org-koma-letter-special-contents)
  299. nil)
  300. contents)))
  301. ;;;; Template
  302. (defun org-koma-letter-template (contents info)
  303. "Return complete document string after KOMA Scrlttr2 conversion.
  304. CONTENTS is the transcoded contents string. INFO is a plist
  305. holding export options."
  306. ;; FIXME: instead of setq'ing org-koma-letter-special-contents and
  307. ;; callying varioues stuff it might be nice to put a big let* around the templace
  308. ;; as in org-groff...
  309. (concat
  310. ;; Time-stamp.
  311. (and (plist-get info :time-stamp-file)
  312. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  313. ;; Document class and packages.
  314. (let ((class (plist-get info :latex-class))
  315. (class-options (plist-get info :latex-class-options)))
  316. (org-element-normalize-string
  317. (let* ((header (nth 1 (assoc class org-latex-classes)))
  318. (document-class-string
  319. (and (stringp header)
  320. (if (not class-options) header
  321. (replace-regexp-in-string
  322. "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
  323. class-options header t nil 1)))))
  324. (if (not document-class-string)
  325. (user-error "Unknown LaTeX class `%s'")
  326. (org-latex-guess-babel-language
  327. (org-latex-guess-inputenc
  328. (org-splice-latex-header
  329. document-class-string
  330. org-latex-default-packages-alist ; defined in org.el
  331. org-latex-packages-alist nil ; defined in org.el
  332. (concat (plist-get info :latex-header)
  333. (plist-get info :latex-header-extra))))
  334. info)))))
  335. (let ((lco (plist-get info :lco))
  336. (author (plist-get info :author))
  337. (from-address (plist-get info :from-address))
  338. (phone-number (plist-get info :phone-number))
  339. (email (plist-get info :email))
  340. (signature (plist-get info :signature)))
  341. (concat
  342. ;; Letter Class Option File
  343. (when lco
  344. (let ((lco-files (split-string lco " "))
  345. (lco-def ""))
  346. (dolist (lco-file lco-files lco-def)
  347. (setq lco-def (format "%s\\LoadLetterOption{%s}\n" lco-def lco-file)))
  348. lco-def))
  349. ;; Define "From" data.
  350. (when author (format "\\setkomavar{fromname}{%s}\n"
  351. (org-export-data author info)))
  352. (when from-address (format "\\setkomavar{fromaddress}{%s}\n" from-address))
  353. (when phone-number (format "\\setkomavar{fromphone}{%s}\n" phone-number))
  354. (when email (format "\\setkomavar{fromemail}{%s}\n" email))
  355. (when signature (format "\\setkomavar{signature}{%s}\n" signature))))
  356. ;; Date.
  357. (format "\\date{%s}\n" (org-export-data (org-export-get-date info) info))
  358. ;; Place
  359. (let ((with-place (plist-get info :with-place))
  360. (place (plist-get info :place)))
  361. (when (or place (not with-place))
  362. (format "\\setkomavar{place}{%s}\n" (if with-place place ""))))
  363. ;; KOMA options
  364. (let ((with-backaddress (plist-get info :with-backaddress))
  365. (with-foldmarks (plist-get info :with-foldmarks))
  366. (with-phone (plist-get info :with-phone))
  367. (with-email (plist-get info :with-email)))
  368. (concat
  369. (format "\\KOMAoption{backaddress}{%s}\n" (if with-backaddress "true" "false"))
  370. (format "\\KOMAoption{foldmarks}{%s}\n" (if with-foldmarks with-foldmarks "false"))
  371. (format "\\KOMAoption{fromphone}{%s}\n" (if with-phone "true" "false"))
  372. (format "\\KOMAoption{fromemail}{%s}\n" (if with-email "true" "false"))))
  373. ;; Document start
  374. "\\begin{document}\n\n"
  375. ;; Subject
  376. (let* ((with-subject (plist-get info :with-subject))
  377. (subject-format (cond ((member with-subject '("true" "t" t)) nil)
  378. ((stringp with-subject) (list with-subject))
  379. ((symbolp with-subject)
  380. (list (symbol-name with-subject)))
  381. (t with-subject)))
  382. (subject (org-export-data (plist-get info :title) info))
  383. (l (length subject-format))
  384. (y ""))
  385. (concat
  386. (when (and with-subject subject-format)
  387. (concat
  388. "\\KOMAoption{subject}{"
  389. (apply 'format
  390. (dotimes (x l y)
  391. (setq y (concat (if (> x 0) "%s," "%s") y)))
  392. subject-format) "}\n"))
  393. (when (and subject with-subject)
  394. (format "\\setkomavar{subject}{%s}\n\n" subject))))
  395. ;; Letter start
  396. (format "\\begin{letter}{%%\n%s}\n\n"
  397. (or (plist-get info :to-address) "no address given"))
  398. ;; Opening.
  399. (format "\\opening{%s}\n\n" (plist-get info :opening))
  400. ;; Letter body.
  401. contents
  402. ;; Closing.
  403. (format "\n\\closing{%s}\n" (plist-get info :closing))
  404. (org-koma-letter--prepare-special-contents-as-macro
  405. (plist-get info :with-after-closing))
  406. ;; Letter end.
  407. "\n\\end{letter}\n"
  408. (org-koma-letter--prepare-special-contents-as-macro
  409. (plist-get info :with-after-letter) t t)
  410. ;; Document end.
  411. "\n\\end{document}"
  412. ))
  413. ;;; Commands
  414. ;;;###autoload
  415. (defun org-koma-letter-export-as-latex
  416. (&optional async subtreep visible-only body-only ext-plist)
  417. "Export current buffer as a KOMA Scrlttr2 letter.
  418. If narrowing is active in the current buffer, only export its
  419. narrowed part.
  420. If a region is active, export that region.
  421. A non-nil optional argument ASYNC means the process should happen
  422. asynchronously. The resulting buffer should be accessible
  423. through the `org-export-stack' interface.
  424. When optional argument SUBTREEP is non-nil, export the sub-tree
  425. at point, extracting information from the headline properties
  426. first.
  427. When optional argument VISIBLE-ONLY is non-nil, don't export
  428. contents of hidden elements.
  429. When optional argument BODY-ONLY is non-nil, only write code
  430. between \"\\begin{letter}\" and \"\\end{letter}\".
  431. EXT-PLIST, when provided, is a proeprty list with external
  432. parameters overriding Org default settings, but still inferior to
  433. file-local settings.
  434. Export is done in a buffer named \"*Org KOMA-LETTER Export*\". It
  435. will be displayed if `org-export-show-temporary-export-buffer' is
  436. non-nil."
  437. (interactive)
  438. (let (org-koma-letter-special-contents)
  439. (if async
  440. (org-export-async-start
  441. (lambda (output)
  442. (with-current-buffer (get-buffer-create "*Org KOMA-LETTER Export*")
  443. (erase-buffer)
  444. (insert output)
  445. (goto-char (point-min))
  446. (LaTeX-mode)
  447. (org-export-add-to-stack (current-buffer) 'koma-letter)))
  448. `(org-export-as 'koma-letter ,subtreep ,visible-only ,body-only
  449. ',ext-plist))
  450. (let ((outbuf (org-export-to-buffer
  451. 'koma-letter "*Org KOMA-LETTER Export*"
  452. subtreep visible-only body-only ext-plist)))
  453. (with-current-buffer outbuf (LaTeX-mode))
  454. (when org-export-show-temporary-export-buffer
  455. (switch-to-buffer-other-window outbuf))))))
  456. ;;;###autoload
  457. (defun org-koma-letter-export-to-latex
  458. (&optional async subtreep visible-only body-only ext-plist)
  459. "Export current buffer as a KOMA Scrlttr2 letter (tex).
  460. If narrowing is active in the current buffer, only export its
  461. narrowed part.
  462. If a region is active, export that region.
  463. A non-nil optional argument ASYNC means the process should happen
  464. asynchronously. The resulting file should be accessible through
  465. the `org-export-stack' interface.
  466. When optional argument SUBTREEP is non-nil, export the sub-tree
  467. at point, extracting information from the headline properties
  468. first.
  469. When optional argument VISIBLE-ONLY is non-nil, don't export
  470. contents of hidden elements.
  471. When optional argument BODY-ONLY is non-nil, only write code
  472. between \"\\begin{letter}\" and \"\\end{letter}\".
  473. EXT-PLIST, when provided, is a property list with external
  474. parameters overriding Org default settings, but still inferior to
  475. file-local settings.
  476. When optional argument PUB-DIR is set, use it as the publishing
  477. directory.
  478. Return output file's name."
  479. (interactive)
  480. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  481. (if async
  482. (org-export-async-start
  483. (lambda (f) (org-export-add-to-stack f 'koma-letter))
  484. `(expand-file-name
  485. (org-export-to-file
  486. 'koma-letter ,outfile ,subtreep ,visible-only ,body-only
  487. ',ext-plist)))
  488. (org-export-to-file
  489. 'koma-letter outfile subtreep visible-only body-only ext-plist))))
  490. ;;;###autoload
  491. (defun org-koma-letter-export-to-pdf
  492. (&optional async subtreep visible-only body-only ext-plist)
  493. "Export current buffer as a KOMA Scrlttr2 letter (pdf).
  494. If narrowing is active in the current buffer, only export its
  495. narrowed part.
  496. If a region is active, export that region.
  497. A non-nil optional argument ASYNC means the process should happen
  498. asynchronously. The resulting file should be accessible through
  499. the `org-export-stack' interface.
  500. When optional argument SUBTREEP is non-nil, export the sub-tree
  501. at point, extracting information from the headline properties
  502. first.
  503. When optional argument VISIBLE-ONLY is non-nil, don't export
  504. contents of hidden elements.
  505. When optional argument BODY-ONLY is non-nil, only write code
  506. between \"\\begin{letter}\" and \"\\end{letter}\".
  507. EXT-PLIST, when provided, is a property list with external
  508. parameters overriding Org default settings, but still inferior to
  509. file-local settings.
  510. Return PDF file's name."
  511. (interactive)
  512. (if async
  513. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  514. (org-export-async-start
  515. (lambda (f) (org-export-add-to-stack f 'koma-letter))
  516. `(expand-file-name
  517. (org-latex-compile
  518. (org-export-to-file
  519. 'koma-letter ,outfile ,subtreep ,visible-only ,body-only
  520. ',ext-plist)))))
  521. (org-latex-compile
  522. (org-koma-letter-export-to-latex
  523. nil subtreep visible-only body-only ext-plist))))
  524. (provide 'ox-koma-letter)
  525. ;;; ox-koma-letter.el ends here