org-odt.el 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512
  1. ;;; org-odt.el --- OpenDocumentText export for Org-mode
  2. ;; Copyright (C) 2010-2011 Free Software Foundation, Inc.
  3. ;; Author: Jambunathan K <kjambunathan at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is not (yet) part of GNU Emacs.
  8. ;; However, it is distributed under the same license.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;;; Code:
  23. (eval-when-compile
  24. (require 'cl)
  25. ;; htmlfontify.el was introduce in Emacs 23.2
  26. (when (>= (string-to-number emacs-version) 23.2)
  27. (require 'htmlfontify)))
  28. (require 'org-lparse)
  29. (defgroup org-export-odt nil
  30. "Options specific for ODT export of Org-mode files."
  31. :tag "Org Export ODT"
  32. :group 'org-export)
  33. (defun org-odt-end-export ()
  34. (org-odt-fixup-label-references)
  35. ;; remove empty paragraphs
  36. (goto-char (point-min))
  37. (while (re-search-forward
  38. "<text:p\\( text:style-name=\"Text_20_body\"\\)?>[ \r\n\t]*</text:p>"
  39. nil t)
  40. (replace-match ""))
  41. (goto-char (point-min))
  42. ;; Convert whitespace place holders
  43. (goto-char (point-min))
  44. (let (beg end n)
  45. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  46. (setq n (get-text-property beg 'org-whitespace)
  47. end (next-single-property-change beg 'org-whitespace))
  48. (goto-char beg)
  49. (delete-region beg end)
  50. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  51. (make-string n ?x)))))
  52. ;; Remove empty lines at the beginning of the file.
  53. (goto-char (point-min))
  54. (when (looking-at "\\s-+\n") (replace-match ""))
  55. ;; Remove display properties
  56. (remove-text-properties (point-min) (point-max) '(display t)))
  57. (defvar org-odt-suppress-xref nil)
  58. (defconst org-export-odt-special-string-regexps
  59. '(("\\\\-" . "&#x00ad;\\1") ; shy
  60. ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
  61. ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
  62. ("\\.\\.\\." . "&#x2026;")) ; hellip
  63. "Regular expressions for special string conversion.")
  64. (defconst org-odt-lib-dir (file-name-directory load-file-name))
  65. (defconst org-odt-styles-dir
  66. (let* ((styles-dir1 (expand-file-name "../etc/styles/" org-odt-lib-dir))
  67. (styles-dir2 (expand-file-name "./etc/styles/" org-odt-lib-dir))
  68. (styles-dir
  69. (catch 'styles-dir
  70. (mapc (lambda (styles-dir)
  71. (when (and (file-readable-p
  72. (expand-file-name
  73. "OrgOdtContentTemplate.xml" styles-dir))
  74. (file-readable-p
  75. (expand-file-name
  76. "OrgOdtStyles.xml" styles-dir)))
  77. (throw 'styles-dir styles-dir)))
  78. (list styles-dir1 styles-dir2))
  79. nil)))
  80. (unless styles-dir
  81. (error "Cannot find factory styles file. Check package dir layout"))
  82. styles-dir)
  83. "Directory that holds auxiliary XML files used by the ODT exporter.
  84. This directory contains the following XML files -
  85. \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
  86. XML files are used as the default values of
  87. `org-export-odt-styles-file' and
  88. `org-export-odt-content-template-file'.")
  89. (defcustom org-export-odt-schema-dir
  90. (let ((schema-dir (expand-file-name
  91. "../contrib/odt/etc/schema/" org-odt-lib-dir)))
  92. (if (and (file-readable-p
  93. (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir))
  94. (file-readable-p
  95. (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir))
  96. (file-readable-p
  97. (expand-file-name "schemas.xml" schema-dir)))
  98. schema-dir
  99. (prog1 nil (message "Unable to locate OpenDocument schema files."))))
  100. "Directory that contains OpenDocument schema files.
  101. This directory contains rnc files for OpenDocument schema. It
  102. also contains a \"schemas.xml\" that can be added to
  103. `rng-schema-locating-files' for auto validation of OpenDocument
  104. XML files. See also `rng-nxml-auto-validate-flag'."
  105. :type '(choice
  106. (const :tag "Not set" nil)
  107. (directory :tag "Schema directory"))
  108. :group 'org-export-odt
  109. :set
  110. (lambda (var value)
  111. "Set `org-export-odt-schema-dir'.
  112. Also add it to `rng-schema-locating-files'."
  113. (let ((schema-dir value))
  114. (set var
  115. (if (and
  116. (file-readable-p
  117. (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir))
  118. (file-readable-p
  119. (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir))
  120. (file-readable-p
  121. (expand-file-name "schemas.xml" schema-dir)))
  122. schema-dir
  123. (prog1 nil
  124. (message "Warning (org-odt): Unable to locate OpenDocument schema files.")))))
  125. (when org-export-odt-schema-dir
  126. (eval-after-load 'rng-loc
  127. '(add-to-list 'rng-schema-locating-files
  128. (expand-file-name "schemas.xml"
  129. org-export-odt-schema-dir))))))
  130. (defvar org-odt-file-extensions
  131. '(("odt" . "OpenDocument Text")
  132. ("ott" . "OpenDocument Text Template")
  133. ("odm" . "OpenDocument Master Document")
  134. ("ods" . "OpenDocument Spreadsheet")
  135. ("ots" . "OpenDocument Spreadsheet Template")
  136. ("odg" . "OpenDocument Drawing (Graphics)")
  137. ("otg" . "OpenDocument Drawing Template")
  138. ("odp" . "OpenDocument Presentation")
  139. ("otp" . "OpenDocument Presentation Template")
  140. ("odi" . "OpenDocument Image")
  141. ("odf" . "OpenDocument Formula")
  142. ("odc" . "OpenDocument Chart")))
  143. (mapc
  144. (lambda (desc)
  145. ;; Let Org open all OpenDocument files using system-registered app
  146. (add-to-list 'org-file-apps
  147. (cons (concat "\\." (car desc) "\\'") 'system))
  148. ;; Let Emacs open all OpenDocument files in archive mode
  149. (add-to-list 'auto-mode-alist
  150. (cons (concat "\\." (car desc) "\\'") 'archive-mode)))
  151. org-odt-file-extensions)
  152. ;; register the odt exporter with the pre-processor
  153. (add-to-list 'org-export-backends 'odt)
  154. ;; register the odt exporter with org-lparse library
  155. (org-lparse-register-backend 'odt)
  156. (defun org-odt-unload-function ()
  157. (org-lparse-unregister-backend 'odt)
  158. (remove-hook 'org-export-preprocess-after-blockquote-hook
  159. 'org-export-odt-preprocess-latex-fragments)
  160. nil)
  161. (defcustom org-export-odt-content-template-file nil
  162. "Template file for \"content.xml\".
  163. The exporter embeds the exported content just before
  164. \"</office:text>\" element.
  165. If unspecified, the file named \"OrgOdtContentTemplate.xml\"
  166. under `org-odt-styles-dir' is used."
  167. :type 'file
  168. :group 'org-export-odt)
  169. (defcustom org-export-odt-styles-file nil
  170. "Default styles file for use with ODT export.
  171. Valid values are one of:
  172. 1. nil
  173. 2. path to a styles.xml file
  174. 3. path to a *.odt or a *.ott file
  175. 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
  176. ...))
  177. In case of option 1, an in-built styles.xml is used. See
  178. `org-odt-styles-dir' for more information.
  179. In case of option 3, the specified file is unzipped and the
  180. styles.xml embedded therein is used.
  181. In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
  182. and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
  183. generated odt file. Use relative path for specifying the
  184. FILE-MEMBERS. styles.xml must be specified as one of the
  185. FILE-MEMBERS.
  186. Use options 1, 2 or 3 only if styles.xml alone suffices for
  187. achieving the desired formatting. Use option 4, if the styles.xml
  188. references additional files like header and footer images for
  189. achieving the desired formattting.
  190. Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
  191. a per-file basis. For example,
  192. #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
  193. #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
  194. :group 'org-export-odt
  195. :type
  196. '(choice
  197. (const :tag "Factory settings" nil)
  198. (file :must-match t :tag "styles.xml")
  199. (file :must-match t :tag "ODT or OTT file")
  200. (list :tag "ODT or OTT file + Members"
  201. (file :must-match t :tag "ODF Text or Text Template file")
  202. (cons :tag "Members"
  203. (file :tag " Member" "styles.xml")
  204. (repeat (file :tag "Member"))))))
  205. (eval-after-load 'org-exp
  206. '(add-to-list 'org-export-inbuffer-options-extra
  207. '("ODT_STYLES_FILE" :odt-styles-file)))
  208. (defconst org-export-odt-tmpdir-prefix "%s-")
  209. (defconst org-export-odt-bookmark-prefix "OrgXref.")
  210. (defvar org-export-odt-embed-images t
  211. "Should the images be copied in to the odt file or just linked?")
  212. (defvar org-export-odt-inline-images 'maybe) ; counterpart of
  213. ; `org-export-html-inline-images'
  214. (defcustom org-export-odt-inline-image-extensions
  215. '("png" "jpeg" "jpg" "gif")
  216. "Extensions of image files that can be inlined into HTML."
  217. :type '(repeat (string :tag "Extension"))
  218. :group 'org-export-odt)
  219. (defcustom org-export-odt-pixels-per-inch display-pixels-per-inch
  220. ;; FIXME add docstring
  221. ""
  222. :type 'float
  223. :group 'org-export-odt)
  224. (defcustom org-export-odt-create-custom-styles-for-srcblocks t
  225. "Whether custom styles for colorized source blocks be automatically created.
  226. When this option is turned on, the exporter creates custom styles
  227. for source blocks based on the advice of `htmlfontify'. Creation
  228. of custom styles happen as part of `org-odt-hfy-face-to-css'.
  229. When this option is turned off exporter does not create such
  230. styles.
  231. Use the latter option if you do not want the custom styles to be
  232. based on your current display settings. It is necessary that the
  233. styles.xml already contains needed styles for colorizing to work.
  234. This variable is effective only if
  235. `org-export-odt-fontify-srcblocks' is turned on."
  236. :group 'org-export-odt
  237. :type 'boolean)
  238. (defvar org-export-odt-default-org-styles-alist
  239. '((paragraph . ((default . "Text_20_body")
  240. (fixedwidth . "OrgFixedWidthBlock")
  241. (verse . "OrgVerse")
  242. (quote . "Quotations")
  243. (blockquote . "Quotations")
  244. (center . "OrgCenter")
  245. (left . "OrgLeft")
  246. (right . "OrgRight")
  247. (title . "OrgTitle")
  248. (subtitle . "OrgSubtitle")
  249. (footnote . "Footnote")
  250. (src . "OrgSrcBlock")
  251. (illustration . "Illustration")
  252. (table . "Table")
  253. (definition-term . "Text_20_body_20_bold")
  254. (horizontal-line . "Horizontal_20_Line")))
  255. (character . ((bold . "Bold")
  256. (emphasis . "Emphasis")
  257. (code . "OrgCode")
  258. (verbatim . "OrgCode")
  259. (strike . "Strikethrough")
  260. (underline . "Underline")
  261. (subscript . "OrgSubscript")
  262. (superscript . "OrgSuperscript")))
  263. (list . ((ordered . "OrgNumberedList")
  264. (unordered . "OrgBulletedList")
  265. (description . "OrgDescriptionList"))))
  266. "Default styles for various entities.")
  267. (defvar org-export-odt-org-styles-alist org-export-odt-default-org-styles-alist)
  268. (defun org-odt-get-style-name-for-entity (category &optional entity)
  269. (let ((entity (or entity 'default)))
  270. (or
  271. (cdr (assoc entity (cdr (assoc category
  272. org-export-odt-org-styles-alist))))
  273. (cdr (assoc entity (cdr (assoc category
  274. org-export-odt-default-org-styles-alist))))
  275. (error "Cannot determine style name for entity %s of type %s"
  276. entity category))))
  277. (defcustom org-export-odt-preferred-output-format nil
  278. "Automatically post-process to this format after exporting to \"odt\".
  279. Interactive commands `org-export-as-odt' and
  280. `org-export-as-odt-and-open' export first to \"odt\" format and
  281. then use `org-export-odt-convert-process' to convert the
  282. resulting document to this format. During customization of this
  283. variable, the list of valid values are populated based on
  284. `org-export-odt-convert-capabilities'."
  285. :group 'org-export-odt
  286. :type '(choice :convert-widget
  287. (lambda (w)
  288. (apply 'widget-convert (widget-type w)
  289. (eval (car (widget-get w :args)))))
  290. `((const :tag "None" nil)
  291. ,@(mapcar (lambda (c)
  292. `(const :tag ,c ,c))
  293. (org-lparse-reachable-formats "odt")))))
  294. ;;;###autoload
  295. (defun org-export-as-odt-and-open (arg)
  296. "Export the outline as ODT and immediately open it with a browser.
  297. If there is an active region, export only the region.
  298. The prefix ARG specifies how many levels of the outline should become
  299. headlines. The default is 3. Lower levels will become bulleted lists."
  300. (interactive "P")
  301. (org-lparse-and-open
  302. (or org-export-odt-preferred-output-format "odt") "odt" arg))
  303. ;;;###autoload
  304. (defun org-export-as-odt-batch ()
  305. "Call the function `org-lparse-batch'.
  306. This function can be used in batch processing as:
  307. emacs --batch
  308. --load=$HOME/lib/emacs/org.el
  309. --eval \"(setq org-export-headline-levels 2)\"
  310. --visit=MyFile --funcall org-export-as-odt-batch"
  311. (org-lparse-batch "odt"))
  312. ;;;###autoload
  313. (defun org-export-as-odt-to-buffer (arg)
  314. "Call `org-lparse-odt` with output to a temporary buffer.
  315. No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
  316. (interactive "P")
  317. (org-lparse-to-buffer "odt" arg))
  318. ;;;###autoload
  319. (defun org-replace-region-by-odt (beg end)
  320. "Assume the current region has org-mode syntax, and convert it to ODT.
  321. This can be used in any buffer. For example, you could write an
  322. itemized list in org-mode syntax in an ODT buffer and then use this
  323. command to convert it."
  324. (interactive "r")
  325. (org-replace-region-by "odt" beg end))
  326. ;;;###autoload
  327. (defun org-export-region-as-odt (beg end &optional body-only buffer)
  328. "Convert region from BEG to END in org-mode buffer to ODT.
  329. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  330. contents, and only produce the region of converted text, useful for
  331. cut-and-paste operations.
  332. If BUFFER is a buffer or a string, use/create that buffer as a target
  333. of the converted ODT. If BUFFER is the symbol `string', return the
  334. produced ODT as a string and leave not buffer behind. For example,
  335. a Lisp program could call this function in the following way:
  336. (setq odt (org-export-region-as-odt beg end t 'string))
  337. When called interactively, the output buffer is selected, and shown
  338. in a window. A non-interactive call will only return the buffer."
  339. (interactive "r\nP")
  340. (org-lparse-region "odt" beg end body-only buffer))
  341. ;;; org-export-as-odt
  342. ;;;###autoload
  343. (defun org-export-as-odt (arg &optional hidden ext-plist
  344. to-buffer body-only pub-dir)
  345. "Export the outline as a OpenDocumentText file.
  346. If there is an active region, export only the region. The prefix
  347. ARG specifies how many levels of the outline should become
  348. headlines. The default is 3. Lower levels will become bulleted
  349. lists. HIDDEN is obsolete and does nothing.
  350. EXT-PLIST is a property list with external parameters overriding
  351. org-mode's default settings, but still inferior to file-local
  352. settings. When TO-BUFFER is non-nil, create a buffer with that
  353. name and export to that buffer. If TO-BUFFER is the symbol
  354. `string', don't leave any buffer behind but just return the
  355. resulting XML as a string. When BODY-ONLY is set, don't produce
  356. the file header and footer, simply return the content of
  357. <body>...</body>, without even the body tags themselves. When
  358. PUB-DIR is set, use this as the publishing directory."
  359. (interactive "P")
  360. (org-lparse (or org-export-odt-preferred-output-format "odt")
  361. "odt" arg hidden ext-plist to-buffer body-only pub-dir))
  362. (defvar org-odt-entity-control-callbacks-alist
  363. `((EXPORT
  364. . (org-odt-begin-export org-odt-end-export))
  365. (DOCUMENT-CONTENT
  366. . (org-odt-begin-document-content org-odt-end-document-content))
  367. (DOCUMENT-BODY
  368. . (org-odt-begin-document-body org-odt-end-document-body))
  369. (TOC
  370. . (org-odt-begin-toc org-odt-end-toc))
  371. (ENVIRONMENT
  372. . (org-odt-begin-environment org-odt-end-environment))
  373. (FOOTNOTE-DEFINITION
  374. . (org-odt-begin-footnote-definition org-odt-end-footnote-definition))
  375. (TABLE
  376. . (org-odt-begin-table org-odt-end-table))
  377. (TABLE-ROWGROUP
  378. . (org-odt-begin-table-rowgroup org-odt-end-table-rowgroup))
  379. (LIST
  380. . (org-odt-begin-list org-odt-end-list))
  381. (LIST-ITEM
  382. . (org-odt-begin-list-item org-odt-end-list-item))
  383. (OUTLINE
  384. . (org-odt-begin-outline org-odt-end-outline))
  385. (OUTLINE-TEXT
  386. . (org-odt-begin-outline-text org-odt-end-outline-text))
  387. (PARAGRAPH
  388. . (org-odt-begin-paragraph org-odt-end-paragraph)))
  389. "")
  390. (defvar org-odt-entity-format-callbacks-alist
  391. `((EXTRA-TARGETS . org-lparse-format-extra-targets)
  392. (ORG-TAGS . org-lparse-format-org-tags)
  393. (SECTION-NUMBER . org-lparse-format-section-number)
  394. (HEADLINE . org-odt-format-headline)
  395. (TOC-ENTRY . org-odt-format-toc-entry)
  396. (TOC-ITEM . org-odt-format-toc-item)
  397. (TAGS . org-odt-format-tags)
  398. (SPACES . org-odt-format-spaces)
  399. (TABS . org-odt-format-tabs)
  400. (LINE-BREAK . org-odt-format-line-break)
  401. (FONTIFY . org-odt-format-fontify)
  402. (TODO . org-lparse-format-todo)
  403. (LINK . org-odt-format-link)
  404. (INLINE-IMAGE . org-odt-format-inline-image)
  405. (ORG-LINK . org-odt-format-org-link)
  406. (HEADING . org-odt-format-heading)
  407. (ANCHOR . org-odt-format-anchor)
  408. (TABLE . org-lparse-format-table)
  409. (TABLE-ROW . org-odt-format-table-row)
  410. (TABLE-CELL . org-odt-format-table-cell)
  411. (FOOTNOTES-SECTION . ignore)
  412. (FOOTNOTE-REFERENCE . org-odt-format-footnote-reference)
  413. (HORIZONTAL-LINE . org-odt-format-horizontal-line)
  414. (COMMENT . org-odt-format-comment)
  415. (LINE . org-odt-format-line)
  416. (ORG-ENTITY . org-odt-format-org-entity))
  417. "")
  418. ;;;_. callbacks
  419. ;;;_. control callbacks
  420. ;;;_ , document body
  421. (defun org-odt-begin-office-body ()
  422. ;; automatic styles
  423. (insert-file-contents
  424. (or org-export-odt-content-template-file
  425. (expand-file-name "OrgOdtContentTemplate.xml"
  426. org-odt-styles-dir)))
  427. (goto-char (point-min))
  428. (re-search-forward "</office:text>" nil nil)
  429. (delete-region (match-beginning 0) (point-max)))
  430. ;; Following variable is let bound when `org-do-lparse' is in
  431. ;; progress. See org-html.el.
  432. (defvar org-lparse-toc)
  433. (defun org-odt-format-toc ()
  434. (if (not org-lparse-toc) "" (concat "\n" org-lparse-toc "\n")))
  435. (defun org-odt-format-preamble (opt-plist)
  436. (let* ((title (plist-get opt-plist :title))
  437. (author (plist-get opt-plist :author))
  438. (date (plist-get opt-plist :date))
  439. (iso-date (org-odt-format-date date))
  440. (date (org-odt-format-date date "%d %b %Y"))
  441. (email (plist-get opt-plist :email)))
  442. (concat
  443. ;; title
  444. (when title
  445. (concat
  446. (org-odt-format-stylized-paragraph
  447. 'title (org-odt-format-tags
  448. '("<text:title>" . "</text:title>") title))
  449. ;; separator
  450. "<text:p text:style-name=\"OrgTitle\"/>"))
  451. (cond
  452. ((and author (not email))
  453. ;; author only
  454. (concat
  455. (org-odt-format-stylized-paragraph
  456. 'subtitle
  457. (org-odt-format-tags
  458. '("<text:initial-creator>" . "</text:initial-creator>")
  459. author))
  460. ;; separator
  461. "<text:p text:style-name=\"OrgSubtitle\"/>"))
  462. ((and author email)
  463. ;; author and email
  464. (concat
  465. (org-odt-format-stylized-paragraph
  466. 'subtitle
  467. (org-odt-format-link
  468. (org-odt-format-tags
  469. '("<text:initial-creator>" . "</text:initial-creator>")
  470. author) (concat "mailto:" email)))
  471. ;; separator
  472. "<text:p text:style-name=\"OrgSubtitle\"/>")))
  473. ;; date
  474. (when date
  475. (concat
  476. (org-odt-format-stylized-paragraph
  477. 'subtitle
  478. (org-odt-format-tags
  479. '("<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">"
  480. . "</text:date>") date "N75" iso-date))
  481. ;; separator
  482. "<text:p text:style-name=\"OrgSubtitle\"/>"))
  483. ;; toc
  484. (org-odt-format-toc))))
  485. (defun org-odt-begin-document-body (opt-plist)
  486. (org-odt-begin-office-body)
  487. (insert (org-odt-format-preamble opt-plist)))
  488. (defvar org-lparse-body-only) ; let bound during org-do-lparse
  489. (defvar org-lparse-to-buffer) ; let bound during org-do-lparse
  490. (defun org-odt-end-document-body (opt-plist)
  491. (unless org-lparse-body-only
  492. (org-lparse-insert-tag "</office:text>")
  493. (org-lparse-insert-tag "</office:body>")))
  494. (defun org-odt-begin-document-content (opt-plist)
  495. (ignore))
  496. (defun org-odt-end-document-content ()
  497. (org-lparse-insert-tag "</office:document-content>"))
  498. (defun org-odt-begin-outline (level1 snumber title tags
  499. target extra-targets class)
  500. (org-lparse-insert
  501. 'HEADING (org-lparse-format
  502. 'HEADLINE title extra-targets tags snumber level1)
  503. level1 target))
  504. (defun org-odt-end-outline ()
  505. (ignore))
  506. (defun org-odt-begin-outline-text (level1 snumber class)
  507. (ignore))
  508. (defun org-odt-end-outline-text ()
  509. (ignore))
  510. (defun org-odt-begin-paragraph (&optional style)
  511. (org-lparse-insert-tag
  512. "<text:p%s>" (org-odt-get-extra-attrs-for-paragraph-style style)))
  513. (defun org-odt-end-paragraph ()
  514. (org-lparse-insert-tag "</text:p>"))
  515. (defun org-odt-get-extra-attrs-for-paragraph-style (style)
  516. (let (style-name)
  517. (setq style-name
  518. (cond
  519. ((stringp style) style)
  520. ((symbolp style) (org-odt-get-style-name-for-entity
  521. 'paragraph style))))
  522. (unless style-name
  523. (error "Don't know how to handle paragraph style %s" style))
  524. (format " text:style-name=\"%s\"" style-name)))
  525. (defun org-odt-format-stylized-paragraph (style text)
  526. (org-odt-format-tags
  527. '("<text:p%s>" . "</text:p>") text
  528. (org-odt-get-extra-attrs-for-paragraph-style style)))
  529. (defvar org-lparse-opt-plist) ; bound during org-do-lparse
  530. (defun org-odt-format-author (&optional author)
  531. (when (setq author (or author (plist-get org-lparse-opt-plist :author)))
  532. (org-odt-format-tags '("<dc:creator>" . "</dc:creator>") author)))
  533. (defun org-odt-format-date (&optional org-ts fmt)
  534. (save-match-data
  535. (let* ((time
  536. (and (stringp org-ts)
  537. (string-match org-ts-regexp0 org-ts)
  538. (apply 'encode-time
  539. (org-fix-decoded-time
  540. (org-parse-time-string (match-string 0 org-ts) t)))))
  541. date)
  542. (cond
  543. (fmt (format-time-string fmt time))
  544. (t (setq date (format-time-string "%Y-%m-%dT%H:%M:%S%z" time))
  545. (format "%s:%s" (substring date 0 -2) (substring date -2)))))))
  546. (defun org-odt-begin-annotation (&optional author date)
  547. (org-lparse-insert-tag "<office:annotation>")
  548. (when (setq author (org-odt-format-author author))
  549. (insert author))
  550. (insert (org-odt-format-tags
  551. '("<dc:date>" . "</dc:date>")
  552. (org-odt-format-date
  553. (or date (plist-get org-lparse-opt-plist :date)))))
  554. (org-lparse-begin-paragraph))
  555. (defun org-odt-end-annotation ()
  556. (org-lparse-insert-tag "</office:annotation>"))
  557. (defun org-odt-begin-environment (style env-options-plist)
  558. (case style
  559. (annotation
  560. (org-lparse-stash-save-paragraph-state)
  561. (org-odt-begin-annotation (plist-get env-options-plist 'author)
  562. (plist-get env-options-plist 'date)))
  563. ((blockquote verse center quote)
  564. (org-lparse-begin-paragraph style)
  565. (list))
  566. ((fixedwidth native)
  567. (org-lparse-end-paragraph)
  568. (list))
  569. (t (error "Unknown environment %s" style))))
  570. (defun org-odt-end-environment (style env-options-plist)
  571. (case style
  572. (annotation
  573. (org-lparse-end-paragraph)
  574. (org-odt-end-annotation)
  575. (org-lparse-stash-pop-paragraph-state))
  576. ((blockquote verse center quote)
  577. (org-lparse-end-paragraph)
  578. (list))
  579. ((fixedwidth native)
  580. (org-lparse-begin-paragraph)
  581. (list))
  582. (t (error "Unknown environment %s" style))))
  583. (defvar org-lparse-list-level) ; dynamically bound in org-do-lparse
  584. (defun org-odt-begin-list (ltype)
  585. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  586. ltype))
  587. (let* ((style-name (org-odt-get-style-name-for-entity 'list ltype))
  588. (extra (concat (when (= org-lparse-list-level 1)
  589. " text:continue-numbering=\"false\"")
  590. (when style-name
  591. (format " text:style-name=\"%s\"" style-name)))))
  592. (case ltype
  593. ((ordered unordered description)
  594. (org-lparse-end-paragraph)
  595. (org-lparse-insert-tag "<text:list%s>" extra))
  596. (t (error "Unknown list type: %s" ltype)))))
  597. (defun org-odt-end-list (ltype)
  598. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  599. ltype))
  600. (if ltype
  601. (org-lparse-insert-tag "</text:list>")
  602. (error "Unknown list type: %s" ltype)))
  603. (defun org-odt-begin-list-item (ltype &optional arg headline)
  604. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  605. ltype))
  606. (case ltype
  607. (ordered
  608. (assert (not headline) t)
  609. (let* ((counter arg) (extra ""))
  610. (org-lparse-insert-tag "<text:list-item>")
  611. (org-lparse-begin-paragraph)))
  612. (unordered
  613. (let* ((id arg) (extra ""))
  614. (org-lparse-insert-tag "<text:list-item>")
  615. (org-lparse-begin-paragraph)
  616. (insert (if headline (org-odt-format-target headline id)
  617. (org-odt-format-bookmark "" id)))))
  618. (description
  619. (assert (not headline) t)
  620. (let ((term (or arg "(no term)")))
  621. (insert
  622. (org-odt-format-tags
  623. '("<text:list-item>" . "</text:list-item>")
  624. (org-odt-format-stylized-paragraph 'definition-term term)))
  625. (org-lparse-begin-list-item 'unordered)
  626. (org-lparse-begin-list 'description)
  627. (org-lparse-begin-list-item 'unordered)))
  628. (t (error "Unknown list type"))))
  629. (defun org-odt-end-list-item (ltype)
  630. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  631. ltype))
  632. (case ltype
  633. ((ordered unordered)
  634. (org-lparse-insert-tag "</text:list-item>"))
  635. (description
  636. (org-lparse-end-list-item-1)
  637. (org-lparse-end-list 'description)
  638. (org-lparse-end-list-item-1))
  639. (t (error "Unknown list type"))))
  640. ;; Following variables are let bound when table emission is in
  641. ;; progress. See org-lparse.el.
  642. (defvar org-lparse-table-begin-marker)
  643. (defvar org-lparse-table-ncols)
  644. (defvar org-lparse-table-rowgrp-open)
  645. (defvar org-lparse-table-rownum)
  646. (defvar org-lparse-table-cur-rowgrp-is-hdr)
  647. (defvar org-lparse-table-is-styled)
  648. (defvar org-lparse-table-rowgrp-info)
  649. (defvar org-lparse-table-colalign-vector)
  650. (defvar org-odt-table-style nil
  651. "Table style specified by \"#+ATTR_ODT: <style-name>\" line.
  652. This is set during `org-odt-begin-table'.")
  653. (defvar org-odt-table-style-spec nil
  654. "Entry for `org-odt-table-style' in `org-export-odt-table-styles'.")
  655. (defcustom org-export-odt-table-styles
  656. '(("OrgEquation" "OrgEquation"
  657. ((use-first-column-styles . t)
  658. (use-last-column-styles . t))))
  659. "Specify how Table Styles should be derived from a Table Template.
  660. This is a list where each element is of the
  661. form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
  662. TABLE-STYLE-NAME is the style associated with the table through
  663. `org-odt-table-style'.
  664. TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
  665. TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
  666. below) that is included in
  667. `org-export-odt-content-template-file'.
  668. TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
  669. \"TableCell\"
  670. PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
  671. \"TableParagraph\"
  672. TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
  673. \"FirstRow\" | \"LastRow\" |
  674. \"EvenRow\" | \"OddRow\" |
  675. \"EvenColumn\" | \"OddColumn\" | \"\"
  676. where \"+\" above denotes string concatenation.
  677. TABLE-CELL-OPTIONS is an alist where each element is of the
  678. form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
  679. TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
  680. `use-last-row-styles' |
  681. `use-first-column-styles' |
  682. `use-last-column-styles' |
  683. `use-banding-rows-styles' |
  684. `use-banding-columns-styles' |
  685. `use-first-row-styles'
  686. ON-OR-OFF := `t' | `nil'
  687. For example, with the following configuration
  688. \(setq org-export-odt-table-styles
  689. '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
  690. \(\(use-first-row-styles . t\)
  691. \(use-first-column-styles . t\)\)\)
  692. \(\"TableWithHeaderColumns\" \"Custom\"
  693. \(\(use-first-column-styles . t\)\)\)\)\)
  694. 1. A table associated with \"TableWithHeaderRowsAndColumns\"
  695. style will use the following table-cell styles -
  696. \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
  697. \"CustomTableCell\" and the following paragraph styles
  698. \"CustomFirstRowTableParagraph\",
  699. \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
  700. as appropriate.
  701. 2. A table associated with \"TableWithHeaderColumns\" style will
  702. use the following table-cell styles -
  703. \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
  704. following paragraph styles
  705. \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
  706. as appropriate..
  707. Note that TABLE-TEMPLATE-NAME corresponds to the
  708. \"<table:table-template>\" elements contained within
  709. \"<office:styles>\". The entries (TABLE-STYLE-NAME
  710. TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
  711. \"table:template-name\" and \"table:use-first-row-styles\" etc
  712. attributes of \"<table:table>\" element. Refer ODF-1.2
  713. specification for more information. Also consult the
  714. implementation filed under `org-odt-get-table-cell-styles'.
  715. The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
  716. formatting of numbered display equations. Do not delete this
  717. style from the list."
  718. :group 'org-export-odt
  719. :type '(choice
  720. (const :tag "None" nil)
  721. (repeat :tag "Table Styles"
  722. (list :tag "Table Style Specification"
  723. (string :tag "Table Style Name")
  724. (string :tag "Table Template Name")
  725. (alist :options (use-first-row-styles
  726. use-last-row-styles
  727. use-first-column-styles
  728. use-last-column-styles
  729. use-banding-rows-styles
  730. use-banding-columns-styles)
  731. :key-type symbol
  732. :value-type (const :tag "True" t))))))
  733. (defun org-odt-begin-table (caption label attributes)
  734. (setq org-odt-table-style attributes)
  735. (setq org-odt-table-style-spec
  736. (assoc org-odt-table-style org-export-odt-table-styles))
  737. (when label
  738. (insert
  739. (org-odt-format-stylized-paragraph
  740. 'table (org-odt-format-entity-caption label caption "__Table__"))))
  741. (org-lparse-insert-tag
  742. "<table:table table:name=\"%s\" table:style-name=\"%s\">"
  743. (or label "") (or (nth 1 org-odt-table-style-spec) "OrgTable"))
  744. (setq org-lparse-table-begin-marker (point)))
  745. (defvar org-lparse-table-colalign-info)
  746. (defun org-odt-end-table ()
  747. (goto-char org-lparse-table-begin-marker)
  748. (loop for level from 0 below org-lparse-table-ncols
  749. do (let* ((col-cookie (and org-lparse-table-is-styled
  750. (cdr (assoc (1+ level)
  751. org-lparse-table-colalign-info))))
  752. (extra-columns (or (nth 1 col-cookie) 0)))
  753. (dotimes (i (1+ extra-columns))
  754. (insert
  755. (org-odt-format-tags
  756. "<table:table-column table:style-name=\"%sColumn\"/>"
  757. "" (or (nth 1 org-odt-table-style-spec) "OrgTable"))))
  758. (insert "\n")))
  759. ;; fill style attributes for table cells
  760. (when org-lparse-table-is-styled
  761. (while (re-search-forward "@@\\(table-cell:p\\|table-cell:style-name\\)@@\\([0-9]+\\)@@\\([0-9]+\\)@@" nil t)
  762. (let* ((spec (match-string 1))
  763. (r (string-to-number (match-string 2)))
  764. (c (string-to-number (match-string 3)))
  765. (cell-styles (org-odt-get-table-cell-styles
  766. r c org-odt-table-style-spec))
  767. (table-cell-style (car cell-styles))
  768. (table-cell-paragraph-style (cdr cell-styles)))
  769. (cond
  770. ((equal spec "table-cell:p")
  771. (replace-match table-cell-paragraph-style t t))
  772. ((equal spec "table-cell:style-name")
  773. (replace-match table-cell-style t t))))))
  774. (goto-char (point-max))
  775. (org-lparse-insert-tag "</table:table>"))
  776. (defun org-odt-begin-table-rowgroup (&optional is-header-row)
  777. (when org-lparse-table-rowgrp-open
  778. (org-lparse-end 'TABLE-ROWGROUP))
  779. (org-lparse-insert-tag (if is-header-row
  780. "<table:table-header-rows>"
  781. "<table:table-rows>"))
  782. (setq org-lparse-table-rowgrp-open t)
  783. (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row))
  784. (defun org-odt-end-table-rowgroup ()
  785. (when org-lparse-table-rowgrp-open
  786. (setq org-lparse-table-rowgrp-open nil)
  787. (org-lparse-insert-tag
  788. (if org-lparse-table-cur-rowgrp-is-hdr
  789. "</table:table-header-rows>" "</table:table-rows>"))))
  790. (defun org-odt-format-table-row (row)
  791. (org-odt-format-tags
  792. '("<table:table-row>" . "</table:table-row>") row))
  793. (defun org-odt-get-table-cell-styles (r c &optional style-spec)
  794. "Retrieve styles applicable to a table cell.
  795. R and C are (zero-based) row and column numbers of the table
  796. cell. STYLE-SPEC is an entry in `org-export-odt-table-styles'
  797. applicable to the current table. It is `nil' if the table is not
  798. associated with any style attributes.
  799. Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
  800. When STYLE-SPEC is nil, style the table cell the conventional way
  801. - choose cell borders based on row and column groupings and
  802. choose paragraph alignment based on `org-col-cookies' text
  803. property. See also
  804. `org-odt-get-paragraph-style-cookie-for-table-cell'.
  805. When STYLE-SPEC is non-nil, ignore the above cookie and return
  806. styles congruent with the ODF-1.2 specification."
  807. (cond
  808. (style-spec
  809. ;; LibreOffice - particularly the Writer - honors neither table
  810. ;; templates nor custom table-cell styles. Inorder to retain
  811. ;; inter-operability with LibreOffice, only automatic styles are
  812. ;; used for styling of table-cells. The current implementation is
  813. ;; congruent with ODF-1.2 specification and hence is
  814. ;; future-compatible.
  815. ;; Additional Note: LibreOffice's AutoFormat facility for tables -
  816. ;; which recognizes as many as 16 different cell types - is much
  817. ;; richer. Unfortunately it is NOT amenable to easy configuration
  818. ;; by hand.
  819. (let* ((template-name (nth 1 style-spec))
  820. (cell-style-selectors (nth 2 style-spec))
  821. (cell-type
  822. (cond
  823. ((and (cdr (assoc 'use-first-column-styles cell-style-selectors))
  824. (= c 0)) "FirstColumn")
  825. ((and (cdr (assoc 'use-last-column-styles cell-style-selectors))
  826. (= c (1- org-lparse-table-ncols))) "LastColumn")
  827. ((and (cdr (assoc 'use-first-row-styles cell-style-selectors))
  828. (= r 0)) "FirstRow")
  829. ((and (cdr (assoc 'use-last-row-styles cell-style-selectors))
  830. (= r org-lparse-table-rownum))
  831. "LastRow")
  832. ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors))
  833. (= (% r 2) 1)) "EvenRow")
  834. ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors))
  835. (= (% r 2) 0)) "OddRow")
  836. ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors))
  837. (= (% c 2) 1)) "EvenColumn")
  838. ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors))
  839. (= (% c 2) 0)) "OddColumn")
  840. (t ""))))
  841. (cons
  842. (concat template-name cell-type "TableCell")
  843. (concat template-name cell-type "TableParagraph"))))
  844. (t
  845. (cons
  846. (concat
  847. "OrgTblCell"
  848. (cond
  849. ((= r 0) "T")
  850. ((eq (cdr (assoc r org-lparse-table-rowgrp-info)) :start) "T")
  851. (t ""))
  852. (when (= r org-lparse-table-rownum) "B")
  853. (cond
  854. ((= c 0) "")
  855. ((or (memq (nth c org-table-colgroup-info) '(:start :startend))
  856. (memq (nth (1- c) org-table-colgroup-info) '(:end :startend))) "L")
  857. (t "")))
  858. (capitalize (aref org-lparse-table-colalign-vector c))))))
  859. (defun org-odt-get-paragraph-style-cookie-for-table-cell (r c)
  860. (concat
  861. (and (not org-odt-table-style-spec)
  862. (cond
  863. (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
  864. ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
  865. "OrgTableHeading")
  866. (t "OrgTableContents")))
  867. (and org-lparse-table-is-styled
  868. (format "@@table-cell:p@@%03d@@%03d@@" r c))))
  869. (defun org-odt-get-style-name-cookie-for-table-cell (r c)
  870. (when org-lparse-table-is-styled
  871. (format "@@table-cell:style-name@@%03d@@%03d@@" r c)))
  872. (defun org-odt-format-table-cell (data r c horiz-span)
  873. (concat
  874. (let* ((paragraph-style-cookie
  875. (org-odt-get-paragraph-style-cookie-for-table-cell r c))
  876. (style-name-cookie
  877. (org-odt-get-style-name-cookie-for-table-cell r c))
  878. (extra (and style-name-cookie
  879. (format " table:style-name=\"%s\"" style-name-cookie)))
  880. (extra (concat extra
  881. (and (> horiz-span 0)
  882. (format " table:number-columns-spanned=\"%d\""
  883. (1+ horiz-span))))))
  884. (org-odt-format-tags
  885. '("<table:table-cell%s>" . "</table:table-cell>")
  886. (if org-lparse-list-table-p data
  887. (org-odt-format-stylized-paragraph paragraph-style-cookie data)) extra))
  888. (let (s)
  889. (dotimes (i horiz-span)
  890. (setq s (concat s "\n<table:covered-table-cell/>"))) s)
  891. "\n"))
  892. (defun org-odt-begin-footnote-definition (n)
  893. (org-lparse-begin-paragraph 'footnote))
  894. (defun org-odt-end-footnote-definition (n)
  895. (org-lparse-end-paragraph))
  896. (defun org-odt-begin-toc (lang-specific-heading max-level)
  897. (insert
  898. (format "
  899. <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
  900. <text:table-of-content-source text:outline-level=\"%d\">
  901. <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
  902. " max-level lang-specific-heading))
  903. (loop for level from 1 upto 10
  904. do (insert (format
  905. "
  906. <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
  907. <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
  908. <text:index-entry-chapter/>
  909. <text:index-entry-text/>
  910. <text:index-entry-link-end/>
  911. </text:table-of-content-entry-template>
  912. " level level)))
  913. (insert
  914. (format "
  915. </text:table-of-content-source>
  916. <text:index-body>
  917. <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
  918. <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
  919. </text:index-title>
  920. " lang-specific-heading)))
  921. (defun org-odt-end-toc ()
  922. (insert "
  923. </text:index-body>
  924. </text:table-of-content>
  925. "))
  926. (defun org-odt-format-toc-entry (snumber todo headline tags href)
  927. (setq headline (concat
  928. (and org-export-with-section-numbers
  929. (concat snumber ". "))
  930. headline
  931. (and tags
  932. (concat
  933. (org-lparse-format 'SPACES 3)
  934. (org-lparse-format 'FONTIFY tags "tag")))))
  935. (when todo
  936. (setq headline (org-lparse-format 'FONTIFY headline "todo")))
  937. (let ((org-odt-suppress-xref t))
  938. (org-odt-format-link headline (concat "#" href))))
  939. (defun org-odt-format-toc-item (toc-entry level org-last-level)
  940. (let ((style (format "Contents_20_%d"
  941. (+ level (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1) -1))))
  942. (insert "\n" (org-odt-format-stylized-paragraph style toc-entry) "\n")))
  943. ;; Following variable is let bound during 'ORG-LINK callback. See
  944. ;; org-html.el
  945. (defvar org-lparse-link-description-is-image nil)
  946. (defun org-odt-format-link (desc href &optional attr)
  947. (cond
  948. ((and (= (string-to-char href) ?#) (not org-odt-suppress-xref))
  949. (setq href (concat org-export-odt-bookmark-prefix (substring href 1)))
  950. (let ((xref-format "text"))
  951. (when (numberp desc)
  952. (setq desc (format "%d" desc) xref-format "number"))
  953. (org-odt-format-tags
  954. '("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
  955. "</text:bookmark-ref>")
  956. desc xref-format href)))
  957. (org-lparse-link-description-is-image
  958. (org-odt-format-tags
  959. '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" . "</draw:a>")
  960. desc href (or attr "")))
  961. (t
  962. (org-odt-format-tags
  963. '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" . "</text:a>")
  964. desc href (or attr "")))))
  965. (defun org-odt-format-spaces (n)
  966. (cond
  967. ((= n 1) " ")
  968. ((> n 1) (concat
  969. " " (org-odt-format-tags "<text:s text:c=\"%d\"/>" "" (1- n))))
  970. (t "")))
  971. (defun org-odt-format-tabs (&optional n)
  972. (let ((tab "<text:tab/>")
  973. (n (or n 1)))
  974. (insert tab)))
  975. (defun org-odt-format-line-break ()
  976. (org-odt-format-tags "<text:line-break/>" ""))
  977. (defun org-odt-format-horizontal-line ()
  978. (org-odt-format-stylized-paragraph 'horizontal-line ""))
  979. (defun org-odt-encode-plain-text (line &optional no-whitespace-filling)
  980. (setq line (org-xml-encode-plain-text line))
  981. (if no-whitespace-filling line
  982. (org-odt-fill-tabs-and-spaces line)))
  983. (defun org-odt-format-line (line)
  984. (case org-lparse-dyn-current-environment
  985. (fixedwidth (concat
  986. (org-odt-format-stylized-paragraph
  987. 'fixedwidth (org-odt-encode-plain-text line)) "\n"))
  988. (t (concat line "\n"))))
  989. (defun org-odt-format-comment (fmt &rest args)
  990. (let ((comment (apply 'format fmt args)))
  991. (format "\n<!-- %s -->\n" comment)))
  992. (defun org-odt-format-org-entity (wd)
  993. (org-entity-get-representation wd 'utf8))
  994. (defun org-odt-fill-tabs-and-spaces (line)
  995. (replace-regexp-in-string
  996. "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
  997. (cond
  998. ((string= s "\t") (org-odt-format-tabs))
  999. (t (org-odt-format-spaces (length s))))) line))
  1000. (defcustom org-export-odt-fontify-srcblocks t
  1001. "Specify whether or not source blocks need to be fontified.
  1002. Turn this option on if you want to colorize the source code
  1003. blocks in the exported file. For colorization to work, you need
  1004. to make available an enhanced version of `htmlfontify' library."
  1005. :type 'boolean
  1006. :group 'org-export-odt)
  1007. (defun org-odt-format-source-line-with-line-number-and-label
  1008. (line rpllbl num fontifier par-style)
  1009. (let ((keep-label (not (numberp rpllbl)))
  1010. (ref (org-find-text-property-in-string 'org-coderef line)))
  1011. (setq line (concat line (and keep-label ref (format "(%s)" ref))))
  1012. (setq line (funcall fontifier line))
  1013. (when ref
  1014. (setq line (org-odt-format-target line (concat "coderef-" ref))))
  1015. (setq line (org-odt-format-stylized-paragraph par-style line))
  1016. (if (not num) line
  1017. (org-odt-format-tags '("<text:list-item>" . "</text:list-item>") line))))
  1018. (defun org-odt-format-source-code-or-example-plain
  1019. (lines lang caption textareap cols rows num cont rpllbl fmt)
  1020. "Format source or example blocks much like fixedwidth blocks.
  1021. Use this when `org-export-odt-fontify-srcblocks' option is turned
  1022. off."
  1023. (let* ((lines (org-split-string lines "[\r\n]"))
  1024. (line-count (length lines))
  1025. (i 0))
  1026. (mapconcat
  1027. (lambda (line)
  1028. (incf i)
  1029. (org-odt-format-source-line-with-line-number-and-label
  1030. line rpllbl num 'org-odt-encode-plain-text
  1031. (if (= i line-count) "OrgFixedWidthBlockLastLine"
  1032. "OrgFixedWidthBlock")))
  1033. lines "\n")))
  1034. (defvar org-src-block-paragraph-format
  1035. "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
  1036. <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
  1037. <style:background-image/>
  1038. </style:paragraph-properties>
  1039. <style:text-properties fo:color=\"%s\"/>
  1040. </style:style>"
  1041. "Custom paragraph style for colorized source and example blocks.
  1042. This style is much the same as that of \"OrgFixedWidthBlock\"
  1043. except that the foreground and background colors are set
  1044. according to the default face identified by the `htmlfontify'.")
  1045. (defun org-odt-hfy-face-to-css (fn)
  1046. "Create custom style for face FN.
  1047. When FN is the default face, use it's foreground and background
  1048. properties to create \"OrgSrcBlock\" paragraph style. Otherwise
  1049. use it's color attribute to create a character style whose name
  1050. is obtained from FN. Currently all attributes of FN other than
  1051. color are ignored.
  1052. The style name for a face FN is derived using the following
  1053. operations on the face name in that order - de-dash, CamelCase
  1054. and prefix with \"OrgSrc\". For example,
  1055. `font-lock-function-name-face' is associated with
  1056. \"OrgSrcFontLockFunctionNameFace\"."
  1057. (let* ((css-list (hfy-face-to-style fn))
  1058. (style-name ((lambda (fn)
  1059. (concat "OrgSrc"
  1060. (mapconcat
  1061. 'capitalize (split-string
  1062. (hfy-face-or-def-to-name fn) "-")
  1063. ""))) fn))
  1064. (color-val (cdr (assoc "color" css-list)))
  1065. (background-color-val (cdr (assoc "background" css-list)))
  1066. (style (and org-export-odt-create-custom-styles-for-srcblocks
  1067. (cond
  1068. ((eq fn 'default)
  1069. (format org-src-block-paragraph-format
  1070. background-color-val color-val))
  1071. (t
  1072. (format
  1073. "
  1074. <style:style style:name=\"%s\" style:family=\"text\">
  1075. <style:text-properties fo:color=\"%s\"/>
  1076. </style:style>" style-name color-val))))))
  1077. (cons style-name style)))
  1078. (defun org-odt-insert-custom-styles-for-srcblocks (styles)
  1079. "Save STYLES used for colorizing of source blocks.
  1080. Update styles.xml with styles that were collected as part of
  1081. `org-odt-hfy-face-to-css' callbacks."
  1082. (when styles
  1083. (with-current-buffer
  1084. (find-file-noselect (expand-file-name "styles.xml") t)
  1085. (goto-char (point-min))
  1086. (when (re-search-forward "</office:styles>" nil t)
  1087. (goto-char (match-beginning 0))
  1088. (insert "\n<!-- Org Htmlfontify Styles -->\n" styles "\n")))))
  1089. (defun org-odt-format-source-code-or-example-colored
  1090. (lines lang caption textareap cols rows num cont rpllbl fmt)
  1091. "Format source or example blocks using `htmlfontify-string'.
  1092. Use this routine when `org-export-odt-fontify-srcblocks' option
  1093. is turned on."
  1094. (let* ((lang-m (and lang (or (cdr (assoc lang org-src-lang-modes)) lang)))
  1095. (mode (and lang-m (intern (concat (if (symbolp lang-m)
  1096. (symbol-name lang-m)
  1097. lang-m) "-mode"))))
  1098. (org-inhibit-startup t)
  1099. (org-startup-folded nil)
  1100. (lines (with-temp-buffer
  1101. (insert lines)
  1102. (if (functionp mode) (funcall mode) (fundamental-mode))
  1103. (font-lock-fontify-buffer)
  1104. (buffer-string)))
  1105. (hfy-html-quote-regex "\\([<\"&> ]\\)")
  1106. (hfy-html-quote-map '(("\"" "&quot;")
  1107. ("<" "&lt;")
  1108. ("&" "&amp;")
  1109. (">" "&gt;")
  1110. (" " "<text:s/>")
  1111. (" " "<text:tab/>")))
  1112. (hfy-face-to-css 'org-odt-hfy-face-to-css)
  1113. (hfy-optimisations-1 (copy-seq hfy-optimisations))
  1114. (hfy-optimisations (add-to-list 'hfy-optimisations-1
  1115. 'body-text-only))
  1116. (hfy-begin-span-handler
  1117. (lambda (style text-block text-id text-begins-block-p)
  1118. (insert (format "<text:span text:style-name=\"%s\">" style))))
  1119. (hfy-end-span-handler (lambda nil (insert "</text:span>"))))
  1120. (when (fboundp 'htmlfontify-string)
  1121. (let* ((lines (org-split-string lines "[\r\n]"))
  1122. (line-count (length lines))
  1123. (i 0))
  1124. (mapconcat
  1125. (lambda (line)
  1126. (incf i)
  1127. (org-odt-format-source-line-with-line-number-and-label
  1128. line rpllbl num 'htmlfontify-string
  1129. (if (= i line-count) "OrgSrcBlockLastLine" "OrgSrcBlock")))
  1130. lines "\n")))))
  1131. (defun org-odt-format-source-code-or-example (lines lang caption textareap
  1132. cols rows num cont
  1133. rpllbl fmt)
  1134. "Format source or example blocks for export.
  1135. Use `org-odt-format-source-code-or-example-plain' or
  1136. `org-odt-format-source-code-or-example-colored' depending on the
  1137. value of `org-export-odt-fontify-srcblocks."
  1138. (setq lines (org-export-number-lines
  1139. lines 0 0 num cont rpllbl fmt 'preprocess)
  1140. lines (funcall
  1141. (or (and org-export-odt-fontify-srcblocks
  1142. (or (featurep 'htmlfontify)
  1143. (require 'htmlfontify nil t))
  1144. (fboundp 'htmlfontify-string)
  1145. 'org-odt-format-source-code-or-example-colored)
  1146. 'org-odt-format-source-code-or-example-plain)
  1147. lines lang caption textareap cols rows num cont rpllbl fmt))
  1148. (if (not num) lines
  1149. (let ((extra (format " text:continue-numbering=\"%s\""
  1150. (if cont "true" "false"))))
  1151. (org-odt-format-tags
  1152. '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
  1153. . "</text:list>") lines extra))))
  1154. (defun org-odt-remap-stylenames (style-name)
  1155. (or
  1156. (cdr (assoc style-name '(("timestamp-wrapper" . "OrgTimestampWrapper")
  1157. ("timestamp" . "OrgTimestamp")
  1158. ("timestamp-kwd" . "OrgTimestampKeyword")
  1159. ("tag" . "OrgTag")
  1160. ("todo" . "OrgTodo")
  1161. ("done" . "OrgDone")
  1162. ("target" . "OrgTarget"))))
  1163. style-name))
  1164. (defun org-odt-format-fontify (text style &optional id)
  1165. (let* ((style-name
  1166. (cond
  1167. ((stringp style)
  1168. (org-odt-remap-stylenames style))
  1169. ((symbolp style)
  1170. (org-odt-get-style-name-for-entity 'character style))
  1171. ((listp style)
  1172. (assert (< 1 (length style)))
  1173. (let ((parent-style (pop style)))
  1174. (mapconcat (lambda (s)
  1175. ;; (assert (stringp s) t)
  1176. (org-odt-remap-stylenames s)) style "")
  1177. (org-odt-remap-stylenames parent-style)))
  1178. (t (error "Don't how to handle style %s" style)))))
  1179. (org-odt-format-tags
  1180. '("<text:span text:style-name=\"%s\">" . "</text:span>")
  1181. text style-name)))
  1182. (defun org-odt-relocate-relative-path (path dir)
  1183. (if (file-name-absolute-p path) path
  1184. (file-relative-name (expand-file-name path dir)
  1185. (expand-file-name "eyecandy" dir))))
  1186. (defun org-odt-format-inline-image (thefile)
  1187. (let* ((thelink (if (file-name-absolute-p thefile) thefile
  1188. (org-xml-format-href
  1189. (org-odt-relocate-relative-path
  1190. thefile org-current-export-file))))
  1191. (href
  1192. (org-odt-format-tags
  1193. "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
  1194. (if org-export-odt-embed-images
  1195. (org-odt-copy-image-file thefile) thelink))))
  1196. (org-export-odt-format-image thefile href)))
  1197. (defun org-export-odt-format-formula (src href &optional embed-as)
  1198. "Create image tag with source and attributes."
  1199. (save-match-data
  1200. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  1201. (caption (and caption (org-xml-format-desc caption)))
  1202. (label (org-find-text-property-in-string 'org-label src))
  1203. (latex-frag (org-find-text-property-in-string 'org-latex-src src))
  1204. (embed-as (or embed-as
  1205. (and latex-frag
  1206. (org-find-text-property-in-string
  1207. 'org-latex-src-embed-type src))
  1208. (if (or caption label) 'paragraph 'character)))
  1209. width height)
  1210. (when latex-frag
  1211. (setq href (org-propertize href :title "LaTeX Fragment"
  1212. :description latex-frag)))
  1213. (cond
  1214. ((eq embed-as 'character)
  1215. (org-odt-format-entity "InlineFormula" href width height))
  1216. (t
  1217. (org-lparse-end-paragraph)
  1218. (org-lparse-insert-list-table
  1219. `((,(org-odt-format-entity
  1220. (if caption "CaptionedDisplayFormula" "DisplayFormula")
  1221. href width height caption nil)
  1222. ,(if (not label) ""
  1223. (org-odt-format-entity-caption label nil "__MathFormula__"))))
  1224. nil nil nil "OrgEquation" nil '((1 "c" 8) (2 "c" 1)))
  1225. (throw 'nextline nil))))))
  1226. (defvar org-odt-embedded-formulas-count 0)
  1227. (defun org-odt-copy-formula-file (path)
  1228. "Returns the internal name of the file"
  1229. (let* ((src-file (expand-file-name
  1230. path (file-name-directory org-current-export-file)))
  1231. (target-dir (format "Formula-%04d/"
  1232. (incf org-odt-embedded-formulas-count)))
  1233. (target-file (concat target-dir "content.xml")))
  1234. (when (not org-lparse-to-buffer)
  1235. (message "Embedding %s as %s ..."
  1236. (substring-no-properties path) target-file)
  1237. (make-directory target-dir)
  1238. (org-odt-create-manifest-file-entry
  1239. "application/vnd.oasis.opendocument.formula" target-dir "1.2")
  1240. (case (org-odt-is-formula-link-p src-file)
  1241. (mathml
  1242. (copy-file src-file target-file 'overwrite))
  1243. (odf
  1244. (org-odt-zip-extract-one src-file "content.xml" target-dir))
  1245. (t
  1246. (error "%s is not a formula file" src-file)))
  1247. (org-odt-create-manifest-file-entry "text/xml" target-file))
  1248. target-file))
  1249. (defun org-odt-format-inline-formula (thefile)
  1250. (let* ((thelink (if (file-name-absolute-p thefile) thefile
  1251. (org-xml-format-href
  1252. (org-odt-relocate-relative-path
  1253. thefile org-current-export-file))))
  1254. (href
  1255. (org-odt-format-tags
  1256. "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
  1257. (file-name-directory (org-odt-copy-formula-file thefile)))))
  1258. (org-export-odt-format-formula thefile href)))
  1259. (defun org-odt-is-formula-link-p (file)
  1260. (let ((case-fold-search nil))
  1261. (cond
  1262. ((string-match "\\.\\(mathml\\|mml\\)\\'" file)
  1263. 'mathml)
  1264. ((string-match "\\.odf\\'" file)
  1265. 'odf))))
  1266. (defun org-odt-format-org-link (opt-plist type-1 path fragment desc attr
  1267. descp)
  1268. "Make a OpenDocument link.
  1269. OPT-PLIST is an options list.
  1270. TYPE-1 is the device-type of the link (THIS://foo.html).
  1271. PATH is the path of the link (http://THIS#location).
  1272. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  1273. DESC is the link description, if any.
  1274. ATTR is a string of other attributes of the a element."
  1275. (declare (special org-lparse-par-open))
  1276. (save-match-data
  1277. (let* ((may-inline-p
  1278. (and (member type-1 '("http" "https" "file"))
  1279. (org-lparse-should-inline-p path descp)
  1280. (not fragment)))
  1281. (type (if (equal type-1 "id") "file" type-1))
  1282. (filename path)
  1283. (thefile path))
  1284. (cond
  1285. ;; check for inlined images
  1286. ((and (member type '("file"))
  1287. (not fragment)
  1288. (org-file-image-p
  1289. filename org-export-odt-inline-image-extensions)
  1290. (or (eq t org-export-odt-inline-images)
  1291. (and org-export-odt-inline-images (not descp))))
  1292. (org-odt-format-inline-image thefile))
  1293. ;; check for embedded formulas
  1294. ((and (member type '("file"))
  1295. (not fragment)
  1296. (org-odt-is-formula-link-p filename)
  1297. (or (not descp)))
  1298. (org-odt-format-inline-formula thefile))
  1299. ((string= type "coderef")
  1300. (let* ((ref fragment)
  1301. (lineno-or-ref (cdr (assoc ref org-export-code-refs)))
  1302. (desc (and descp desc))
  1303. (org-odt-suppress-xref nil)
  1304. (href (org-xml-format-href (concat "#coderef-" ref))))
  1305. (cond
  1306. ((and (numberp lineno-or-ref) (not desc))
  1307. (org-odt-format-link lineno-or-ref href))
  1308. ((and (numberp lineno-or-ref) desc
  1309. (string-match (regexp-quote (concat "(" ref ")")) desc))
  1310. (format (replace-match "%s" t t desc)
  1311. (org-odt-format-link lineno-or-ref href)))
  1312. (t
  1313. (setq desc (format
  1314. (if (and desc (string-match
  1315. (regexp-quote (concat "(" ref ")"))
  1316. desc))
  1317. (replace-match "%s" t t desc)
  1318. (or desc "%s"))
  1319. lineno-or-ref))
  1320. (org-odt-format-link (org-xml-format-desc desc) href)))))
  1321. (t
  1322. (when (string= type "file")
  1323. (setq thefile
  1324. (cond
  1325. ((file-name-absolute-p path)
  1326. (concat "file://" (expand-file-name path)))
  1327. (t (org-odt-relocate-relative-path
  1328. thefile org-current-export-file)))))
  1329. (when (and (member type '("" "http" "https" "file")) fragment)
  1330. (setq thefile (concat thefile "#" fragment)))
  1331. (setq thefile (org-xml-format-href thefile))
  1332. (when (not (member type '("" "file")))
  1333. (setq thefile (concat type ":" thefile)))
  1334. (let ((org-odt-suppress-xref nil))
  1335. (org-odt-format-link
  1336. (org-xml-format-desc desc) thefile attr)))))))
  1337. (defun org-odt-format-heading (text level &optional id)
  1338. (let* ((text (if id (org-odt-format-target text id) text)))
  1339. (org-odt-format-tags
  1340. '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
  1341. "</text:h>") text level level)))
  1342. (defun org-odt-format-headline (title extra-targets tags
  1343. &optional snumber level)
  1344. (concat
  1345. (org-lparse-format 'EXTRA-TARGETS extra-targets)
  1346. ;; No need to generate section numbers. They are auto-generated by
  1347. ;; the application
  1348. ;; (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
  1349. title
  1350. (and tags (concat (org-lparse-format 'SPACES 3)
  1351. (org-lparse-format 'ORG-TAGS tags)))))
  1352. (defun org-odt-format-anchor (text name &optional class)
  1353. (org-odt-format-target text name))
  1354. (defun org-odt-format-bookmark (text id)
  1355. (if id
  1356. (org-odt-format-tags "<text:bookmark text:name=\"%s\"/>" text id)
  1357. text))
  1358. (defun org-odt-format-target (text id)
  1359. (let ((name (concat org-export-odt-bookmark-prefix id)))
  1360. (concat
  1361. (and id (org-odt-format-tags
  1362. "<text:bookmark-start text:name=\"%s\"/>" "" name))
  1363. (org-odt-format-bookmark text id)
  1364. (and id (org-odt-format-tags
  1365. "<text:bookmark-end text:name=\"%s\"/>" "" name)))))
  1366. (defun org-odt-format-footnote (n def)
  1367. (let ((id (concat "fn" n))
  1368. (note-class "footnote")
  1369. (par-style "Footnote"))
  1370. (org-odt-format-tags
  1371. '("<text:note text:id=\"%s\" text:note-class=\"%s\">" .
  1372. "</text:note>")
  1373. (concat
  1374. (org-odt-format-tags
  1375. '("<text:note-citation>" . "</text:note-citation>")
  1376. n)
  1377. (org-odt-format-tags
  1378. '("<text:note-body>" . "</text:note-body>")
  1379. def))
  1380. id note-class)))
  1381. (defun org-odt-format-footnote-reference (n def refcnt)
  1382. (if (= refcnt 1)
  1383. (org-odt-format-footnote n def)
  1384. (org-odt-format-footnote-ref n)))
  1385. (defun org-odt-format-footnote-ref (n)
  1386. (let ((note-class "footnote")
  1387. (ref-format "text")
  1388. (ref-name (concat "fn" n)))
  1389. (org-odt-format-tags
  1390. '("<text:span text:style-name=\"%s\">" . "</text:span>")
  1391. (org-odt-format-tags
  1392. '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" . "</text:note-ref>")
  1393. n note-class ref-format ref-name)
  1394. "OrgSuperscript")))
  1395. (defun org-odt-get-image-name (file-name)
  1396. (require 'sha1)
  1397. (file-relative-name
  1398. (expand-file-name
  1399. (concat (sha1 file-name) "." (file-name-extension file-name)) "Pictures")))
  1400. (defun org-export-odt-format-image (src href &optional embed-as)
  1401. "Create image tag with source and attributes."
  1402. (save-match-data
  1403. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  1404. (caption (and caption (org-xml-format-desc caption)))
  1405. (attr (org-find-text-property-in-string 'org-attributes src))
  1406. (label (org-find-text-property-in-string 'org-label src))
  1407. (latex-frag (org-find-text-property-in-string
  1408. 'org-latex-src src))
  1409. (category (and latex-frag "__DvipngImage__"))
  1410. (embed-as (or embed-as
  1411. (if latex-frag
  1412. (or (org-find-text-property-in-string
  1413. 'org-latex-src-embed-type src) 'character)
  1414. 'paragraph)))
  1415. (attr-plist (org-lparse-get-block-params attr))
  1416. (size (org-odt-image-size-from-file
  1417. src (plist-get attr-plist :width)
  1418. (plist-get attr-plist :height)
  1419. (plist-get attr-plist :scale) nil embed-as))
  1420. (width (car size)) (height (cdr size)))
  1421. (when latex-frag
  1422. (setq href (org-propertize href :title "LaTeX Fragment"
  1423. :description latex-frag)))
  1424. (cond
  1425. ((not (or caption label))
  1426. (case embed-as
  1427. (paragraph (org-odt-format-entity "DisplayImage" href width height))
  1428. (character (org-odt-format-entity "InlineImage" href width height))
  1429. (t (error "Unknown value for embed-as %S" embed-as))))
  1430. (t
  1431. (org-odt-format-entity
  1432. "CaptionedDisplayImage" href width height caption label category))))))
  1433. (defun org-odt-format-object-description (title description)
  1434. (concat (and title (org-odt-format-tags
  1435. '("<svg:title>" . "</svg:title>")
  1436. (org-odt-encode-plain-text title t)))
  1437. (and description (org-odt-format-tags
  1438. '("<svg:desc>" . "</svg:desc>")
  1439. (org-odt-encode-plain-text description t)))))
  1440. (defun org-odt-format-frame (text width height style &optional
  1441. extra anchor-type)
  1442. (let ((frame-attrs
  1443. (concat
  1444. (if width (format " svg:width=\"%0.2fcm\"" width) "")
  1445. (if height (format " svg:height=\"%0.2fcm\"" height) "")
  1446. extra
  1447. (format " text:anchor-type=\"%s\"" (or anchor-type "paragraph")))))
  1448. (org-odt-format-tags
  1449. '("<draw:frame draw:style-name=\"%s\"%s>" . "</draw:frame>")
  1450. (concat text (org-odt-format-object-description
  1451. (get-text-property 0 :title text)
  1452. (get-text-property 0 :description text)))
  1453. style frame-attrs)))
  1454. (defun org-odt-format-textbox (text width height style &optional
  1455. extra anchor-type)
  1456. (org-odt-format-frame
  1457. (org-odt-format-tags
  1458. '("<draw:text-box %s>" . "</draw:text-box>")
  1459. text (concat (format " fo:min-height=\"%0.2fcm\"" (or height .2))
  1460. (format " fo:min-width=\"%0.2fcm\"" (or width .2))))
  1461. width nil style extra anchor-type))
  1462. (defun org-odt-format-inlinetask (heading content
  1463. &optional todo priority tags)
  1464. (org-odt-format-stylized-paragraph
  1465. nil (org-odt-format-textbox
  1466. (concat (org-odt-format-stylized-paragraph
  1467. "OrgInlineTaskHeading"
  1468. (org-lparse-format
  1469. 'HEADLINE (concat (org-lparse-format-todo todo) " " heading)
  1470. nil tags))
  1471. content) nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\"")))
  1472. (defvar org-odt-entity-frame-styles
  1473. '(("InlineImage" "__Figure__" ("OrgInlineImage" nil "as-char"))
  1474. ("DisplayImage" "__Figure__" ("OrgDisplayImage" nil "paragraph"))
  1475. ("CaptionedDisplayImage" "__Figure__"
  1476. ("OrgCaptionedImage"
  1477. " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
  1478. ("OrgImageCaptionFrame"))
  1479. ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil "as-char"))
  1480. ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil "as-char"))
  1481. ("CaptionedDisplayFormula" "__MathFormula__"
  1482. ("OrgCaptionedFormula" nil "paragraph")
  1483. ("OrgFormulaCaptionFrame" nil "as-char"))))
  1484. (defun org-odt-format-entity (entity href width height
  1485. &optional caption label category)
  1486. (let* ((entity-style (assoc entity org-odt-entity-frame-styles))
  1487. (entity-frame (apply 'org-odt-format-frame
  1488. href width height (nth 2 entity-style))))
  1489. (if (not (or caption label)) entity-frame
  1490. (apply 'org-odt-format-textbox
  1491. (org-odt-format-stylized-paragraph
  1492. 'illustration
  1493. (concat entity-frame
  1494. (org-odt-format-entity-caption
  1495. label caption (or category (nth 1 entity-style)))))
  1496. width height (nth 3 entity-style)))))
  1497. (defvar org-odt-embedded-images-count 0)
  1498. (defun org-odt-copy-image-file (path)
  1499. "Returns the internal name of the file"
  1500. (let* ((image-type (file-name-extension path))
  1501. (media-type (format "image/%s" image-type))
  1502. (src-file (expand-file-name
  1503. path (file-name-directory org-current-export-file)))
  1504. (target-dir "Images/")
  1505. (target-file
  1506. (format "%s%04d.%s" target-dir
  1507. (incf org-odt-embedded-images-count) image-type)))
  1508. (when (not org-lparse-to-buffer)
  1509. (message "Embedding %s as %s ..."
  1510. (substring-no-properties path) target-file)
  1511. (when (= 1 org-odt-embedded-images-count)
  1512. (make-directory target-dir)
  1513. (org-odt-create-manifest-file-entry "" target-dir))
  1514. (copy-file src-file target-file 'overwrite)
  1515. (org-odt-create-manifest-file-entry media-type target-file))
  1516. target-file))
  1517. (defvar org-export-odt-image-size-probe-method
  1518. '(emacs imagemagick force)
  1519. "Ordered list of methods by for determining size of an embedded
  1520. image.")
  1521. (defvar org-export-odt-default-image-sizes-alist
  1522. '(("character" . (5 . 0.4))
  1523. ("paragraph" . (5 . 5)))
  1524. "Hardcoded image dimensions one for each of the anchor
  1525. methods.")
  1526. ;; A4 page size is 21.0 by 29.7 cms
  1527. ;; The default page settings has 2cm margin on each of the sides. So
  1528. ;; the effective text area is 17.0 by 25.7 cm
  1529. (defvar org-export-odt-max-image-size '(17.0 . 20.0)
  1530. "Limiting dimensions for an embedded image.")
  1531. (defun org-odt-do-image-size (probe-method file &optional dpi anchor-type)
  1532. (setq dpi (or dpi org-export-odt-pixels-per-inch))
  1533. (setq anchor-type (or anchor-type "paragraph"))
  1534. (flet ((size-in-cms (size-in-pixels)
  1535. (flet ((pixels-to-cms (pixels)
  1536. (let* ((cms-per-inch 2.54)
  1537. (inches (/ pixels dpi)))
  1538. (* cms-per-inch inches))))
  1539. (and size-in-pixels
  1540. (cons (pixels-to-cms (car size-in-pixels))
  1541. (pixels-to-cms (cdr size-in-pixels)))))))
  1542. (case probe-method
  1543. (emacs
  1544. (size-in-cms (ignore-errors (image-size (create-image file) 'pixels))))
  1545. (imagemagick
  1546. (size-in-cms
  1547. (let ((dim (shell-command-to-string
  1548. (format "identify -format \"%%w:%%h\" \"%s\"" file))))
  1549. (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim)
  1550. (cons (string-to-number (match-string 1 dim))
  1551. (string-to-number (match-string 2 dim)))))))
  1552. (t
  1553. (cdr (assoc-string anchor-type
  1554. org-export-odt-default-image-sizes-alist))))))
  1555. (defun org-odt-image-size-from-file (file &optional user-width
  1556. user-height scale dpi embed-as)
  1557. (unless (file-name-absolute-p file)
  1558. (setq file (expand-file-name
  1559. file (file-name-directory org-current-export-file))))
  1560. (let* (size width height)
  1561. (unless (and user-height user-width)
  1562. (loop for probe-method in org-export-odt-image-size-probe-method
  1563. until size
  1564. do (setq size (org-odt-do-image-size
  1565. probe-method file dpi embed-as)))
  1566. (or size (error "Cannot determine Image size. Aborting ..."))
  1567. (setq width (car size) height (cdr size)))
  1568. (cond
  1569. (scale
  1570. (setq width (* width scale) height (* height scale)))
  1571. ((and user-height user-width)
  1572. (setq width user-width height user-height))
  1573. (user-height
  1574. (setq width (* user-height (/ width height)) height user-height))
  1575. (user-width
  1576. (setq height (* user-width (/ height width)) width user-width))
  1577. (t (ignore)))
  1578. ;; ensure that an embedded image fits comfortably within a page
  1579. (let ((max-width (car org-export-odt-max-image-size))
  1580. (max-height (cdr org-export-odt-max-image-size)))
  1581. (when (or (> width max-width) (> height max-height))
  1582. (let* ((scale1 (/ max-width width))
  1583. (scale2 (/ max-height height))
  1584. (scale (min scale1 scale2)))
  1585. (setq width (* scale width) height (* scale height)))))
  1586. (cons width height)))
  1587. (defvar org-odt-entity-labels-alist nil
  1588. "Associate Labels with the Labelled entities.
  1589. Each element of the alist is of the form (LABEL-NAME
  1590. CATEGORY-NAME SEQNO LABEL-STYLE-NAME). LABEL-NAME is same as
  1591. that specified by \"#+LABEL: ...\" line. CATEGORY-NAME is the
  1592. type of the entity that LABEL-NAME is attached to. CATEGORY-NAME
  1593. can be one of \"Table\", \"Figure\" or \"Equation\". SEQNO is
  1594. the unique number assigned to the referenced entity on a
  1595. per-CATEGORY basis. It is generated sequentially and is 1-based.
  1596. LABEL-STYLE-NAME is a key `org-odt-label-styles'.
  1597. See `org-odt-add-label-definition' and
  1598. `org-odt-fixup-label-references'.")
  1599. (defvar org-odt-entity-counts-plist nil
  1600. "Plist of running counters of SEQNOs for each of the CATEGORY-NAMEs.
  1601. See `org-odt-entity-labels-alist' for known CATEGORY-NAMEs.")
  1602. (defvar org-odt-label-styles
  1603. '(("text" "(%n)" "text" "(%n)")
  1604. ("category-and-value" "%e %n%c" "category-and-value" "%e %n"))
  1605. "Specify how labels are applied and referenced.
  1606. This is an alist where each element is of the
  1607. form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
  1608. LABEL-REF-FMT).
  1609. LABEL-ATTACH-FMT controls how labels and captions are attached to
  1610. an entity. It may contain following specifiers - %e, %n and %c.
  1611. %e is replaced with the CATEGORY-NAME. %n is replaced with
  1612. \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
  1613. with CAPTION. See `org-odt-format-label-definition'.
  1614. LABEL-REF-MODE and LABEL-REF-FMT controls how label references
  1615. are generated. The following XML is generated for a label
  1616. reference - \"<text:sequence-ref
  1617. text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
  1618. </text:sequence-ref>\". LABEL-REF-FMT may contain following
  1619. specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
  1620. %n is replaced with SEQNO. See
  1621. `org-odt-format-label-reference'.")
  1622. (defvar org-odt-category-map-alist
  1623. '(("__Table__" "Table" "category-and-value")
  1624. ("__Figure__" "Figure" "category-and-value")
  1625. ("__MathFormula__" "Equation" "text")
  1626. ("__DvipngImage__" "Equation" "category-and-value"))
  1627. "Map a CATEGORY-HANDLE to CATEGORY-NAME and LABEL-STYLE.
  1628. This is an alist where each element is of the form
  1629. \\(CATEGORY-HANDLE CATEGORY-NAME LABEL-STYLE\\). CATEGORY_HANDLE
  1630. could either be one of the internal handles (as seen above) or be
  1631. derived from the \"#+LABEL:<label-name>\" specification. See
  1632. `org-export-odt-get-category-from-label'. CATEGORY-NAME and
  1633. LABEL-STYLE are used for generating ODT labels. See
  1634. `org-odt-label-styles'.")
  1635. (defvar org-export-odt-user-categories
  1636. '("Illustration" "Table" "Text" "Drawing" "Equation" "Figure"))
  1637. (defvar org-export-odt-get-category-from-label nil
  1638. "Should category of label be inferred from label itself.
  1639. When this option is non-nil, a label is parsed in to two
  1640. component parts delimited by a \":\" (colon) as shown here -
  1641. #+LABEL:[CATEGORY-HANDLE:]EXTRA. The CATEGORY-HANDLE is mapped
  1642. to a CATEGORY-NAME and LABEL-STYLE using
  1643. `org-odt-category-map-alist'. (If no such map is provided and
  1644. CATEGORY-NAME is set to CATEGORY-HANDLE and LABEL-STYLE is set to
  1645. \"category-and-value\"). If CATEGORY-NAME so obtained is listed
  1646. under `org-export-odt-user-categories' then the user specified
  1647. styles are used. Otherwise styles as determined by the internal
  1648. CATEGORY-HANDLE is used. See
  1649. `org-odt-get-label-category-and-style' for details.")
  1650. (defun org-odt-get-label-category-and-style (label default-category)
  1651. "See `org-export-odt-get-category-from-label'."
  1652. (let ((default-category-map
  1653. (assoc default-category org-odt-category-map-alist))
  1654. user-category user-category-map category)
  1655. (cond
  1656. ((not org-export-odt-get-category-from-label)
  1657. default-category-map)
  1658. ((not (setq user-category
  1659. (save-match-data
  1660. (and (string-match "\\`\\(.*\\):.+" label)
  1661. (match-string 1 label)))))
  1662. default-category-map)
  1663. (t
  1664. (setq user-category-map
  1665. (or (assoc user-category org-odt-category-map-alist)
  1666. (list nil user-category "category-and-value"))
  1667. category (nth 1 user-category-map))
  1668. (if (member category org-export-odt-user-categories)
  1669. user-category-map
  1670. default-category-map)))))
  1671. (defun org-odt-add-label-definition (label default-category)
  1672. "Create an entry in `org-odt-entity-labels-alist' and return it."
  1673. (setq label (substring-no-properties label))
  1674. (let* ((label-props (org-odt-get-label-category-and-style
  1675. label default-category))
  1676. (category (nth 1 label-props))
  1677. (counter category)
  1678. (label-style (nth 2 label-props))
  1679. (sequence-var (intern (mapconcat
  1680. 'downcase
  1681. (org-split-string counter) "-")))
  1682. (seqno (1+ (or (plist-get org-odt-entity-counts-plist sequence-var)
  1683. 0)))
  1684. (label-props (list label category seqno label-style)))
  1685. (setq org-odt-entity-counts-plist
  1686. (plist-put org-odt-entity-counts-plist sequence-var seqno))
  1687. (push label-props org-odt-entity-labels-alist)
  1688. label-props))
  1689. (defun org-odt-format-label-definition (caption label category seqno label-style)
  1690. (assert label)
  1691. (format-spec
  1692. (cadr (assoc-string label-style org-odt-label-styles t))
  1693. `((?e . ,category)
  1694. (?n . ,(org-odt-format-tags
  1695. '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" . "</text:sequence>")
  1696. (format "%d" seqno) label category category))
  1697. (?c . ,(or (and caption (concat ": " caption)) "")))))
  1698. (defun org-odt-format-label-reference (label category seqno label-style)
  1699. (assert label)
  1700. (save-match-data
  1701. (let* ((fmt (cddr (assoc-string label-style org-odt-label-styles t)))
  1702. (fmt1 (car fmt))
  1703. (fmt2 (cadr fmt)))
  1704. (org-odt-format-tags
  1705. '("<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">"
  1706. . "</text:sequence-ref>")
  1707. (format-spec fmt2 `((?e . ,category)
  1708. (?n . ,(format "%d" seqno)))) fmt1 label))))
  1709. (defun org-odt-fixup-label-references ()
  1710. (goto-char (point-min))
  1711. (while (re-search-forward
  1712. "<text:sequence-ref text:ref-name=\"\\([^\"]+\\)\">[ \t\n]*</text:sequence-ref>"
  1713. nil t)
  1714. (let* ((label (match-string 1))
  1715. (label-def (assoc label org-odt-entity-labels-alist))
  1716. (rpl (and label-def
  1717. (apply 'org-odt-format-label-reference label-def))))
  1718. (if rpl (replace-match rpl t t)
  1719. (org-lparse-warn
  1720. (format "Unable to resolve reference to label \"%s\"" label))))))
  1721. (defun org-odt-format-entity-caption (label caption category)
  1722. (or (and label
  1723. (apply 'org-odt-format-label-definition
  1724. caption (org-odt-add-label-definition label category)))
  1725. caption ""))
  1726. (defun org-odt-format-tags (tag text &rest args)
  1727. (let ((prefix (when org-lparse-encode-pending "@"))
  1728. (suffix (when org-lparse-encode-pending "@")))
  1729. (apply 'org-lparse-format-tags tag text prefix suffix args)))
  1730. (defvar org-odt-manifest-file-entries nil)
  1731. (defun org-odt-init-outfile (filename)
  1732. (unless (executable-find "zip")
  1733. ;; Not at all OSes ship with zip by default
  1734. (error "Executable \"zip\" needed for creating OpenDocument files"))
  1735. (let* ((outdir (make-temp-file
  1736. (format org-export-odt-tmpdir-prefix org-lparse-backend) t))
  1737. (content-file (expand-file-name "content.xml" outdir)))
  1738. ;; init conten.xml
  1739. (with-current-buffer (find-file-noselect content-file t))
  1740. ;; reset variables
  1741. (setq org-odt-manifest-file-entries nil
  1742. org-odt-embedded-images-count 0
  1743. org-odt-embedded-formulas-count 0
  1744. org-odt-entity-labels-alist nil
  1745. org-odt-entity-counts-plist nil)
  1746. content-file))
  1747. (defcustom org-export-odt-prettify-xml nil
  1748. "Specify whether or not the xml output should be prettified.
  1749. When this option is turned on, `indent-region' is run on all
  1750. component xml buffers before they are saved. Turn this off for
  1751. regular use. Turn this on if you need to examine the xml
  1752. visually."
  1753. :group 'org-export-odt
  1754. :type 'boolean)
  1755. (defvar hfy-user-sheet-assoc) ; bound during org-do-lparse
  1756. (defun org-odt-save-as-outfile (target opt-plist)
  1757. ;; write meta file
  1758. (org-odt-update-meta-file opt-plist)
  1759. ;; write styles file
  1760. (when (equal org-lparse-backend 'odt)
  1761. (org-odt-update-styles-file opt-plist))
  1762. ;; create mimetype file
  1763. (let ((mimetype (org-odt-write-mimetype-file org-lparse-backend)))
  1764. (org-odt-create-manifest-file-entry mimetype "/" "1.2"))
  1765. ;; create a manifest entry for content.xml
  1766. (org-odt-create-manifest-file-entry "text/xml" "content.xml")
  1767. ;; write out the manifest entries before zipping
  1768. (org-odt-write-manifest-file)
  1769. (let ((xml-files '("mimetype" "META-INF/manifest.xml" "content.xml"
  1770. "meta.xml"))
  1771. (zipdir default-directory))
  1772. (when (equal org-lparse-backend 'odt)
  1773. (push "styles.xml" xml-files))
  1774. (message "Switching to directory %s" (expand-file-name zipdir))
  1775. ;; save all xml files
  1776. (mapc (lambda (file)
  1777. (with-current-buffer
  1778. (find-file-noselect (expand-file-name file) t)
  1779. ;; prettify output if needed
  1780. (when org-export-odt-prettify-xml
  1781. (indent-region (point-min) (point-max)))
  1782. (save-buffer 0)))
  1783. xml-files)
  1784. (let* ((target-name (file-name-nondirectory target))
  1785. (target-dir (file-name-directory target))
  1786. (cmds `(("zip" "-mX0" ,target-name "mimetype")
  1787. ("zip" "-rmTq" ,target-name "."))))
  1788. (when (file-exists-p target)
  1789. ;; FIXME: If the file is locked this throws a cryptic error
  1790. (delete-file target))
  1791. (let ((coding-system-for-write 'no-conversion) exitcode err-string)
  1792. (message "Creating odt file...")
  1793. (mapc
  1794. (lambda (cmd)
  1795. (message "Running %s" (mapconcat 'identity cmd " "))
  1796. (setq err-string
  1797. (with-output-to-string
  1798. (setq exitcode
  1799. (apply 'call-process (car cmd)
  1800. nil standard-output nil (cdr cmd)))))
  1801. (or (zerop exitcode)
  1802. (ignore (message "%s" err-string))
  1803. (error "Unable to create odt file (%S)" exitcode)))
  1804. cmds))
  1805. ;; move the file from outdir to target-dir
  1806. (rename-file target-name target-dir)
  1807. ;; kill all xml buffers
  1808. (mapc (lambda (file)
  1809. (kill-buffer
  1810. (find-file-noselect (expand-file-name file zipdir) t)))
  1811. xml-files)
  1812. (delete-directory zipdir)))
  1813. (message "Created %s" target)
  1814. (set-buffer (find-file-noselect target t)))
  1815. (defconst org-odt-manifest-file-entry-tag
  1816. "
  1817. <manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
  1818. (defun org-odt-create-manifest-file-entry (&rest args)
  1819. (push args org-odt-manifest-file-entries))
  1820. (defun org-odt-write-manifest-file ()
  1821. (make-directory "META-INF")
  1822. (let ((manifest-file (expand-file-name "META-INF/manifest.xml")))
  1823. (with-current-buffer
  1824. (find-file-noselect manifest-file t)
  1825. (insert
  1826. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  1827. <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
  1828. (mapc
  1829. (lambda (file-entry)
  1830. (let* ((version (nth 2 file-entry))
  1831. (extra (if version
  1832. (format " manifest:version=\"%s\"" version)
  1833. "")))
  1834. (insert
  1835. (format org-odt-manifest-file-entry-tag
  1836. (nth 0 file-entry) (nth 1 file-entry) extra))))
  1837. org-odt-manifest-file-entries)
  1838. (insert "\n</manifest:manifest>"))))
  1839. (defun org-odt-update-meta-file (opt-plist)
  1840. (let ((date (org-odt-format-date (plist-get opt-plist :date)))
  1841. (author (or (plist-get opt-plist :author) ""))
  1842. (email (plist-get opt-plist :email))
  1843. (keywords (plist-get opt-plist :keywords))
  1844. (description (plist-get opt-plist :description))
  1845. (title (plist-get opt-plist :title)))
  1846. (write-region
  1847. (concat
  1848. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  1849. <office:document-meta
  1850. xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
  1851. xmlns:xlink=\"http://www.w3.org/1999/xlink\"
  1852. xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
  1853. xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
  1854. xmlns:ooo=\"http://openoffice.org/2004/office\"
  1855. office:version=\"1.2\">
  1856. <office:meta>" "\n"
  1857. (org-odt-format-author)
  1858. (org-odt-format-tags
  1859. '("\n<meta:initial-creator>" . "</meta:initial-creator>") author)
  1860. (org-odt-format-tags '("\n<dc:date>" . "</dc:date>") date)
  1861. (org-odt-format-tags
  1862. '("\n<meta:creation-date>" . "</meta:creation-date>") date)
  1863. (org-odt-format-tags '("\n<meta:generator>" . "</meta:generator>")
  1864. (when org-export-creator-info
  1865. (format "Org-%s/Emacs-%s"
  1866. org-version emacs-version)))
  1867. (org-odt-format-tags '("\n<meta:keyword>" . "</meta:keyword>") keywords)
  1868. (org-odt-format-tags '("\n<dc:subject>" . "</dc:subject>") description)
  1869. (org-odt-format-tags '("\n<dc:title>" . "</dc:title>") title)
  1870. "\n"
  1871. " </office:meta>" "</office:document-meta>")
  1872. nil (expand-file-name "meta.xml")))
  1873. ;; create a manifest entry for meta.xml
  1874. (org-odt-create-manifest-file-entry "text/xml" "meta.xml"))
  1875. (defun org-odt-update-styles-file (opt-plist)
  1876. ;; write styles file
  1877. (let ((styles-file (plist-get opt-plist :odt-styles-file)))
  1878. (org-odt-copy-styles-file (and styles-file
  1879. (read (org-trim styles-file)))))
  1880. ;; Update styles.xml - take care of outline numbering
  1881. (with-current-buffer
  1882. (find-file-noselect (expand-file-name "styles.xml") t)
  1883. ;; Don't make automatic backup of styles.xml file. This setting
  1884. ;; prevents the backedup styles.xml file from being zipped in to
  1885. ;; odt file. This is more of a hackish fix. Better alternative
  1886. ;; would be to fix the zip command so that the output odt file
  1887. ;; includes only the needed files and excludes any auto-generated
  1888. ;; extra files like backups and auto-saves etc etc. Note that
  1889. ;; currently the zip command zips up the entire temp directory so
  1890. ;; that any auto-generated files created under the hood ends up in
  1891. ;; the resulting odt file.
  1892. (set (make-local-variable 'backup-inhibited) t)
  1893. ;; Import local setting of `org-export-with-section-numbers'
  1894. (org-lparse-bind-local-variables opt-plist)
  1895. (org-odt-configure-outline-numbering
  1896. (if org-export-with-section-numbers org-export-headline-levels 0)))
  1897. ;; Write custom stlyes for source blocks
  1898. (org-odt-insert-custom-styles-for-srcblocks
  1899. (mapconcat
  1900. (lambda (style)
  1901. (format " %s\n" (cddr style)))
  1902. hfy-user-sheet-assoc "")))
  1903. (defun org-odt-write-mimetype-file (format)
  1904. ;; create mimetype file
  1905. (let ((mimetype
  1906. (case format
  1907. (odt "application/vnd.oasis.opendocument.text")
  1908. (odf "application/vnd.oasis.opendocument.formula")
  1909. (t (error "Unknown OpenDocument backend %S" org-lparse-backend)))))
  1910. (write-region mimetype nil (expand-file-name "mimetype"))
  1911. mimetype))
  1912. (defun org-odt-finalize-outfile ()
  1913. (org-odt-delete-empty-paragraphs))
  1914. (defun org-odt-delete-empty-paragraphs ()
  1915. (goto-char (point-min))
  1916. (let ((open "<text:p[^>]*>")
  1917. (close "</text:p>"))
  1918. (while (re-search-forward (format "%s[ \r\n\t]*%s" open close) nil t)
  1919. (replace-match ""))))
  1920. (defcustom org-export-odt-convert-processes
  1921. '(("BasicODConverter"
  1922. ("soffice" "-norestore" "-invisible" "-headless"
  1923. "\"macro:///BasicODConverter.Main.Convert(%I,%f,%O)\""))
  1924. ("unoconv"
  1925. ("unoconv" "-f" "%f" "-o" "%d" "%i")))
  1926. "Specify a list of document converters and their usage.
  1927. The converters in this list are offered as choices while
  1928. customizing `org-export-odt-convert-process'.
  1929. This variable is an alist where each element is of the
  1930. form (CONVERTER-NAME CONVERTER-PROCESS). CONVERTER-NAME is name
  1931. of the converter. CONVERTER-PROCESS specifies the command-line
  1932. syntax of the converter and is of the form (CONVERTER-PROGRAM
  1933. ARG1 ARG2 ...). CONVERTER-PROGRAM is the name of the executable.
  1934. ARG1, ARG2 etc are command line options that are passed to
  1935. CONVERTER-PROGRAM. Format specifiers can be used in the ARGs and
  1936. they are interpreted as below:
  1937. %i input file name in full
  1938. %I input file name as a URL
  1939. %f format of the output file
  1940. %o output file name in full
  1941. %O output file name as a URL
  1942. %d output dir in full
  1943. %D output dir as a URL."
  1944. :group 'org-export-odt
  1945. :type
  1946. '(choice
  1947. (const :tag "None" nil)
  1948. (alist :tag "Converters"
  1949. :key-type (string :tag "Converter Name")
  1950. :value-type (group (cons (string :tag "Executable")
  1951. (repeat (string :tag "Command line args")))))))
  1952. (defcustom org-export-odt-convert-process nil
  1953. "Use this converter to convert from \"odt\" format to other formats.
  1954. During customization, the list of converter names are populated
  1955. from `org-export-odt-convert-processes'."
  1956. :group 'org-export-odt
  1957. :type '(choice :convert-widget
  1958. (lambda (w)
  1959. (apply 'widget-convert (widget-type w)
  1960. (eval (car (widget-get w :args)))))
  1961. `((const :tag "None" nil)
  1962. ,@(mapcar (lambda (c)
  1963. `(const :tag ,(car c) ,(car c)))
  1964. org-export-odt-convert-processes))))
  1965. (defcustom org-export-odt-convert-capabilities
  1966. '(("Text"
  1967. ("odt" "ott" "doc" "rtf")
  1968. (("pdf" "pdf") ("odt" "odt") ("xhtml" "html") ("rtf" "rtf")
  1969. ("ott" "ott") ("doc" "doc") ("ooxml" "xml") ("html" "html")))
  1970. ("Web"
  1971. ("html" "xhtml") (("pdf" "pdf") ("odt" "txt") ("html" "html")))
  1972. ("Spreadsheet"
  1973. ("ods" "ots" "xls" "csv")
  1974. (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv")
  1975. ("ods" "ods") ("xls" "xls") ("xhtml" "xhtml") ("ooxml" "xml")))
  1976. ("Presentation"
  1977. ("odp" "otp" "ppt")
  1978. (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("xhtml" "xml")
  1979. ("otp" "otp") ("ppt" "ppt") ("odg" "odg") ("html" "html"))))
  1980. "Specify input and output formats of `org-export-odt-convert-process'.
  1981. More correctly, specify the set of input and output formats that
  1982. the user is actually interested in.
  1983. This variable is an alist where each element is of the
  1984. form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
  1985. INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
  1986. alist where each element is of the form (OUTPUT-FMT
  1987. OUTPUT-FILE-EXTENSION).
  1988. The variable is interpreted as follows:
  1989. `org-export-odt-convert-process' can take any document that is in
  1990. INPUT-FMT-LIST and produce any document that is in the
  1991. OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
  1992. OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
  1993. serves dual purposes:
  1994. - It is used for populating completion candidates during
  1995. `org-export-odt-convert' commands.
  1996. - It is used as the value of \"%f\" specifier in
  1997. `org-export-odt-convert-process'.
  1998. DOCUMENT-CLASS is used to group a set of file formats in
  1999. INPUT-FMT-LIST in to a single class.
  2000. Note that this variable inherently captures how LibreOffice based
  2001. converters work. LibreOffice maps documents of various formats
  2002. to classes like Text, Web, Spreadsheet, Presentation etc and
  2003. allow document of a given class (irrespective of it's source
  2004. format) to be converted to any of the export formats associated
  2005. with that class.
  2006. See default setting of this variable for an typical
  2007. configuration."
  2008. :group 'org-export-odt
  2009. :type
  2010. '(choice
  2011. (const :tag "None" nil)
  2012. (alist :key-type (string :tag "Document Class")
  2013. :value-type
  2014. (group (repeat :tag "Input formats" (string :tag "Input format"))
  2015. (alist :tag "Output formats"
  2016. :key-type (string :tag "Output format")
  2017. :value-type
  2018. (group (string :tag "Output file extension")))))))
  2019. (declare-function org-create-math-formula "org"
  2020. (latex-frag &optional mathml-file))
  2021. ;;;###autoload
  2022. (defun org-export-odt-convert (&optional in-file out-fmt prefix-arg)
  2023. "Convert IN-FILE to format OUT-FMT using a command line converter.
  2024. IN-FILE is the file to be converted. If unspecified, it defaults
  2025. to variable `buffer-file-name'. OUT-FMT is the desired output
  2026. format. Use `org-export-odt-convert-process' as the converter.
  2027. If PREFIX-ARG is non-nil then the newly converted file is opened
  2028. using `org-open-file'."
  2029. (interactive
  2030. (append (org-lparse-convert-read-params) current-prefix-arg))
  2031. (org-lparse-do-convert in-file out-fmt prefix-arg))
  2032. (defun org-odt-get (what &optional opt-plist)
  2033. (case what
  2034. (BACKEND 'odt)
  2035. (EXPORT-DIR (org-export-directory :html opt-plist))
  2036. (FILE-NAME-EXTENSION "odt")
  2037. (EXPORT-BUFFER-NAME "*Org ODT Export*")
  2038. (ENTITY-CONTROL org-odt-entity-control-callbacks-alist)
  2039. (ENTITY-FORMAT org-odt-entity-format-callbacks-alist)
  2040. (INIT-METHOD 'org-odt-init-outfile)
  2041. (FINAL-METHOD 'org-odt-finalize-outfile)
  2042. (SAVE-METHOD 'org-odt-save-as-outfile)
  2043. (CONVERT-METHOD
  2044. (and org-export-odt-convert-process
  2045. (cadr (assoc-string org-export-odt-convert-process
  2046. org-export-odt-convert-processes t))))
  2047. (CONVERT-CAPABILITIES
  2048. (and org-export-odt-convert-process
  2049. (cadr (assoc-string org-export-odt-convert-process
  2050. org-export-odt-convert-processes t))
  2051. org-export-odt-convert-capabilities))
  2052. (TOPLEVEL-HLEVEL 1)
  2053. (SPECIAL-STRING-REGEXPS org-export-odt-special-string-regexps)
  2054. (INLINE-IMAGES 'maybe)
  2055. (INLINE-IMAGE-EXTENSIONS '("png" "jpeg" "jpg" "gif" "svg"))
  2056. (PLAIN-TEXT-MAP '(("&" . "&amp;") ("<" . "&lt;") (">" . "&gt;")))
  2057. (TABLE-FIRST-COLUMN-AS-LABELS nil)
  2058. (FOOTNOTE-SEPARATOR (org-lparse-format 'FONTIFY "," 'superscript))
  2059. (CODING-SYSTEM-FOR-WRITE 'utf-8)
  2060. (CODING-SYSTEM-FOR-SAVE 'utf-8)
  2061. (t (error "Unknown property: %s" what))))
  2062. (defvar org-lparse-latex-fragment-fallback) ; set by org-do-lparse
  2063. (defun org-export-odt-do-preprocess-latex-fragments ()
  2064. "Convert LaTeX fragments to images."
  2065. (let* ((latex-frag-opt (plist-get org-lparse-opt-plist :LaTeX-fragments))
  2066. (latex-frag-opt ; massage the options
  2067. (or (and (member latex-frag-opt '(mathjax t))
  2068. (not (and (fboundp 'org-format-latex-mathml-available-p)
  2069. (org-format-latex-mathml-available-p)))
  2070. (prog1 org-lparse-latex-fragment-fallback
  2071. (org-lparse-warn
  2072. (concat
  2073. "LaTeX to MathML converter not available. "
  2074. (format "Using %S instead."
  2075. org-lparse-latex-fragment-fallback)))))
  2076. latex-frag-opt))
  2077. cache-dir display-msg)
  2078. (cond
  2079. ((eq latex-frag-opt 'dvipng)
  2080. (setq cache-dir "ltxpng/")
  2081. (setq display-msg "Creating LaTeX image %s"))
  2082. ((member latex-frag-opt '(mathjax t))
  2083. (setq latex-frag-opt 'mathml)
  2084. (setq cache-dir "ltxmathml/")
  2085. (setq display-msg "Creating MathML formula %s")))
  2086. (when (and org-current-export-file)
  2087. (org-format-latex
  2088. (concat cache-dir (file-name-sans-extension
  2089. (file-name-nondirectory org-current-export-file)))
  2090. org-current-export-dir nil display-msg
  2091. nil nil latex-frag-opt))))
  2092. (defadvice org-format-latex-as-mathml
  2093. (after org-odt-protect-latex-fragment activate)
  2094. "Encode LaTeX fragment as XML.
  2095. Do this when translation to MathML fails."
  2096. (when (or (not (> (length ad-return-value) 0))
  2097. (get-text-property 0 'org-protected ad-return-value))
  2098. (setq ad-return-value
  2099. (org-propertize (org-odt-encode-plain-text (ad-get-arg 0))
  2100. 'org-protected t))))
  2101. (defun org-export-odt-preprocess-latex-fragments ()
  2102. (when (equal org-export-current-backend 'odt)
  2103. (org-export-odt-do-preprocess-latex-fragments)))
  2104. (defun org-export-odt-preprocess-label-references ()
  2105. (goto-char (point-min))
  2106. (let (label label-components category value pretty-label)
  2107. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  2108. (org-if-unprotected-at (match-beginning 1)
  2109. (replace-match
  2110. (let ((org-lparse-encode-pending t)
  2111. (label (match-string 1)))
  2112. ;; markup generated below is mostly an eye-candy. At
  2113. ;; pre-processing stage, there is no information on which
  2114. ;; entity a label reference points to. The actual markup
  2115. ;; is generated as part of `org-odt-fixup-label-references'
  2116. ;; which gets called at the fag end of export. By this
  2117. ;; time we would have seen and collected all the label
  2118. ;; definitions in `org-odt-entity-labels-alist'.
  2119. (org-odt-format-tags
  2120. '("<text:sequence-ref text:ref-name=\"%s\">" .
  2121. "</text:sequence-ref>")
  2122. "" (org-add-props label '(org-protected t)))) t t)))))
  2123. ;; process latex fragments as part of
  2124. ;; `org-export-preprocess-after-blockquote-hook'. Note that this hook
  2125. ;; is the one that is closest and well before the call to
  2126. ;; `org-export-attach-captions-and-attributes' in
  2127. ;; `org-export-preprocess-stirng'. The above arrangement permits
  2128. ;; captions, labels and attributes to be attached to png images
  2129. ;; generated out of latex equations.
  2130. (add-hook 'org-export-preprocess-after-blockquote-hook
  2131. 'org-export-odt-preprocess-latex-fragments)
  2132. (defun org-export-odt-preprocess (parameters)
  2133. (org-export-odt-preprocess-label-references))
  2134. (declare-function archive-zip-extract "arc-mode.el" (archive name))
  2135. (defun org-odt-zip-extract-one (archive member &optional target)
  2136. (require 'arc-mode)
  2137. (let* ((target (or target default-directory))
  2138. (archive (expand-file-name archive))
  2139. (archive-zip-extract
  2140. (list "unzip" "-qq" "-o" "-d" target))
  2141. exit-code command-output)
  2142. (setq command-output
  2143. (with-temp-buffer
  2144. (setq exit-code (archive-zip-extract archive member))
  2145. (buffer-string)))
  2146. (unless (zerop exit-code)
  2147. (message command-output)
  2148. (error "Extraction failed"))))
  2149. (defun org-odt-zip-extract (archive members &optional target)
  2150. (when (atom members) (setq members (list members)))
  2151. (mapc (lambda (member)
  2152. (org-odt-zip-extract-one archive member target))
  2153. members))
  2154. (defun org-odt-copy-styles-file (&optional styles-file)
  2155. ;; Non-availability of styles.xml is not a critical error. For now
  2156. ;; throw an error purely for aesthetic reasons.
  2157. (setq styles-file (or styles-file
  2158. org-export-odt-styles-file
  2159. (expand-file-name "OrgOdtStyles.xml"
  2160. org-odt-styles-dir)
  2161. (error "org-odt: Missing styles file?")))
  2162. (cond
  2163. ((listp styles-file)
  2164. (let ((archive (nth 0 styles-file))
  2165. (members (nth 1 styles-file)))
  2166. (org-odt-zip-extract archive members)
  2167. (mapc
  2168. (lambda (member)
  2169. (when (org-file-image-p member)
  2170. (let* ((image-type (file-name-extension member))
  2171. (media-type (format "image/%s" image-type)))
  2172. (org-odt-create-manifest-file-entry media-type member))))
  2173. members)))
  2174. ((and (stringp styles-file) (file-exists-p styles-file))
  2175. (let ((styles-file-type (file-name-extension styles-file)))
  2176. (cond
  2177. ((string= styles-file-type "xml")
  2178. (copy-file styles-file "styles.xml" t))
  2179. ((member styles-file-type '("odt" "ott"))
  2180. (org-odt-zip-extract styles-file "styles.xml")))))
  2181. (t
  2182. (error (format "Invalid specification of styles.xml file: %S"
  2183. org-export-odt-styles-file))))
  2184. ;; create a manifest entry for styles.xml
  2185. (org-odt-create-manifest-file-entry "text/xml" "styles.xml"))
  2186. (defvar org-export-odt-factory-settings
  2187. "d4328fb9d1b6cb211d4320ff546829f26700dc5e"
  2188. "SHA1 hash of OrgOdtStyles.xml.")
  2189. (defun org-odt-configure-outline-numbering (level)
  2190. "Outline numbering is retained only upto LEVEL.
  2191. To disable outline numbering pass a LEVEL of 0."
  2192. (goto-char (point-min))
  2193. (let ((regex
  2194. "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
  2195. (replacement
  2196. "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
  2197. (while (re-search-forward regex nil t)
  2198. (when (> (string-to-number (match-string 2)) level)
  2199. (replace-match replacement t nil))))
  2200. (save-buffer 0))
  2201. ;;;###autoload
  2202. (defun org-export-as-odf (latex-frag &optional odf-file)
  2203. "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
  2204. Use `org-create-math-formula' to convert LATEX-FRAG first to
  2205. MathML. When invoked as an interactive command, use
  2206. `org-latex-regexps' to infer LATEX-FRAG from currently active
  2207. region. If no LaTeX fragments are found, prompt for it. Push
  2208. MathML source to kill ring, if `org-export-copy-to-kill-ring' is
  2209. non-nil."
  2210. (interactive
  2211. `(,(let (frag)
  2212. (setq frag (and (setq frag (and (region-active-p)
  2213. (buffer-substring (region-beginning)
  2214. (region-end))))
  2215. (loop for e in org-latex-regexps
  2216. thereis (when (string-match (nth 1 e) frag)
  2217. (match-string (nth 2 e) frag)))))
  2218. (read-string "LaTeX Fragment: " frag nil frag))
  2219. ,(let ((odf-filename (expand-file-name
  2220. (concat
  2221. (file-name-sans-extension
  2222. (or (file-name-nondirectory buffer-file-name)))
  2223. "." "odf")
  2224. (file-name-directory buffer-file-name))))
  2225. (message "default val is %s" odf-filename)
  2226. (read-file-name "ODF filename: " nil odf-filename nil
  2227. (file-name-nondirectory odf-filename)))))
  2228. (let* ((org-lparse-backend 'odf)
  2229. org-lparse-opt-plist
  2230. (filename (or odf-file
  2231. (expand-file-name
  2232. (concat
  2233. (file-name-sans-extension
  2234. (or (file-name-nondirectory buffer-file-name)))
  2235. "." "odf")
  2236. (file-name-directory buffer-file-name))))
  2237. (buffer (find-file-noselect (org-odt-init-outfile filename)))
  2238. (coding-system-for-write 'utf-8)
  2239. (save-buffer-coding-system 'utf-8))
  2240. (set-buffer buffer)
  2241. (set-buffer-file-coding-system coding-system-for-write)
  2242. (let ((mathml (org-create-math-formula latex-frag)))
  2243. (unless mathml (error "No Math formula created"))
  2244. (insert mathml)
  2245. (or (org-export-push-to-kill-ring
  2246. (upcase (symbol-name org-lparse-backend)))
  2247. (message "Exporting... done")))
  2248. (org-odt-save-as-outfile filename nil)))
  2249. ;;;###autoload
  2250. (defun org-export-as-odf-and-open ()
  2251. "Export LaTeX fragment as OpenDocument formula and immediately open it.
  2252. Use `org-export-as-odf' to read LaTeX fragment and OpenDocument
  2253. formula file."
  2254. (interactive)
  2255. (org-lparse-and-open
  2256. nil nil nil (call-interactively 'org-export-as-odf)))
  2257. (provide 'org-odt)
  2258. ;;; org-odt.el ends here