| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364 | 
							- ;;; org-e-odt.el --- OpenDocument Text exporter for Org-mode
 
- ;; Copyright (C) 2010-2013 Free Software Foundation, Inc.
 
- ;; Author: Jambunathan K <kjambunathan at gmail dot com>
 
- ;; Keywords: outlines, hypermedia, calendar, wp
 
- ;; Homepage: http://orgmode.org
 
- ;; This file is not part of GNU Emacs.
 
- ;; GNU Emacs is free software: you can redistribute it and/or modify
 
- ;; it under the terms of the GNU General Public License as published by
 
- ;; the Free Software Foundation, either version 3 of the License, or
 
- ;; (at your option) any later version.
 
- ;; GNU Emacs is distributed in the hope that it will be useful,
 
- ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
- ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
- ;; GNU General Public License for more details.
 
- ;; You should have received a copy of the GNU General Public License
 
- ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
- ;;; Commentary:
 
- ;;; Code:
 
- (eval-when-compile
 
-   (require 'cl)
 
-   (require 'table))
 
- (require 'format-spec)
 
- (require 'org-export)
 
- (require 'org-compat)
 
- ;;; Define Back-End
 
- (org-export-define-backend e-odt
 
-   ((bold . org-e-odt-bold)
 
-    (center-block . org-e-odt-center-block)
 
-    (clock . org-e-odt-clock)
 
-    (code . org-e-odt-code)
 
-    (drawer . org-e-odt-drawer)
 
-    (dynamic-block . org-e-odt-dynamic-block)
 
-    (entity . org-e-odt-entity)
 
-    (example-block . org-e-odt-example-block)
 
-    (export-block . org-e-odt-export-block)
 
-    (export-snippet . org-e-odt-export-snippet)
 
-    (fixed-width . org-e-odt-fixed-width)
 
-    (footnote-definition . org-e-odt-footnote-definition)
 
-    (footnote-reference . org-e-odt-footnote-reference)
 
-    (headline . org-e-odt-headline)
 
-    (horizontal-rule . org-e-odt-horizontal-rule)
 
-    (inline-src-block . org-e-odt-inline-src-block)
 
-    (inlinetask . org-e-odt-inlinetask)
 
-    (italic . org-e-odt-italic)
 
-    (item . org-e-odt-item)
 
-    (keyword . org-e-odt-keyword)
 
-    (latex-environment . org-e-odt-latex-environment)
 
-    (latex-fragment . org-e-odt-latex-fragment)
 
-    (line-break . org-e-odt-line-break)
 
-    (link . org-e-odt-link)
 
-    (paragraph . org-e-odt-paragraph)
 
-    (plain-list . org-e-odt-plain-list)
 
-    (plain-text . org-e-odt-plain-text)
 
-    (planning . org-e-odt-planning)
 
-    (property-drawer . org-e-odt-property-drawer)
 
-    (quote-block . org-e-odt-quote-block)
 
-    (quote-section . org-e-odt-quote-section)
 
-    (radio-target . org-e-odt-radio-target)
 
-    (section . org-e-odt-section)
 
-    (special-block . org-e-odt-special-block)
 
-    (src-block . org-e-odt-src-block)
 
-    (statistics-cookie . org-e-odt-statistics-cookie)
 
-    (strike-through . org-e-odt-strike-through)
 
-    (subscript . org-e-odt-subscript)
 
-    (superscript . org-e-odt-superscript)
 
-    (table . org-e-odt-table)
 
-    (table-cell . org-e-odt-table-cell)
 
-    (table-row . org-e-odt-table-row)
 
-    (target . org-e-odt-target)
 
-    (template . org-e-odt-template)
 
-    (timestamp . org-e-odt-timestamp)
 
-    (underline . org-e-odt-underline)
 
-    (verbatim . org-e-odt-verbatim)
 
-    (verse-block . org-e-odt-verse-block))
 
-   :export-block "ODT"
 
-   :filters-alist ((:filter-parse-tree
 
- 		   . (org-e-odt--translate-latex-fragments
 
- 		      org-e-odt--translate-description-lists
 
- 		      org-e-odt--translate-list-tables)))
 
-   :menu-entry
 
-   (?o "Export to ODT"
 
-       ((?o "As ODT file" org-e-odt-export-to-odt)
 
-        (?O "As ODT file and open"
 
- 	   (lambda (a s v b)
 
- 	     (if a (org-e-odt-export-to-odt t s v)
 
- 	       (org-open-file (org-e-odt-export-to-odt nil s v) 'system))))))
 
-   :options-alist
 
-   ((:odt-styles-file "ODT_STYLES_FILE" nil nil t)
 
-    (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments)))
 
- ;;; Dependencies
 
- ;;; Hooks
 
- ;;; Function Declarations
 
- (declare-function org-id-find-id-file "org-id" (id))
 
- (declare-function hfy-face-to-style "htmlfontify" (fn))
 
- (declare-function hfy-face-or-def-to-name "htmlfontify" (fn))
 
- (declare-function archive-zip-extract "arc-mode" (archive name))
 
- (declare-function org-create-math-formula "org" (latex-frag &optional mathml-file))
 
- (declare-function browse-url-file-url "browse-url" (file))
 
- ;;; Internal Variables
 
- (defconst org-e-odt-lib-dir
 
-   (file-name-directory load-file-name)
 
-   "Location of ODT exporter.
 
- Use this to infer values of `org-e-odt-styles-dir' and
 
- `org-e-odt-schema-dir'.")
 
- (defvar org-e-odt-data-dir
 
-   (expand-file-name "../../etc/" org-e-odt-lib-dir)
 
-   "Data directory for ODT exporter.
 
- Use this to infer values of `org-e-odt-styles-dir' and
 
- `org-e-odt-schema-dir'.")
 
- (defconst org-e-odt-special-string-regexps
 
-   '(("\\\\-" . "­\\1")		; shy
 
-     ("---\\([^-]\\)" . "—\\1")	; mdash
 
-     ("--\\([^-]\\)" . "–\\1")	; ndash
 
-     ("\\.\\.\\." . "…"))		; hellip
 
-   "Regular expressions for special string conversion.")
 
- (defconst org-e-odt-schema-dir-list
 
-   (list
 
-    (and org-e-odt-data-dir
 
- 	(expand-file-name "./schema/" org-e-odt-data-dir)) ; bail out
 
-    (eval-when-compile
 
-      (and (boundp 'org-e-odt-data-dir) org-e-odt-data-dir ; see make install
 
- 	  (expand-file-name "./schema/" org-e-odt-data-dir))))
 
-   "List of directories to search for OpenDocument schema files.
 
- Use this list to set the default value of
 
- `org-e-odt-schema-dir'.  The entries in this list are
 
- populated heuristically based on the values of `org-e-odt-lib-dir'
 
- and `org-e-odt-data-dir'.")
 
- (defconst org-e-odt-styles-dir-list
 
-   (list
 
-    (and org-e-odt-data-dir
 
- 	(expand-file-name "./styles/" org-e-odt-data-dir)) ; bail out
 
-    (eval-when-compile
 
-      (and (boundp 'org-e-odt-data-dir) org-e-odt-data-dir ; see make install
 
- 	  (expand-file-name "./styles/" org-e-odt-data-dir)))
 
-    (expand-file-name "../../etc/styles/" org-e-odt-lib-dir) ; git
 
-    (expand-file-name "./etc/styles/" org-e-odt-lib-dir)  ; elpa
 
-    (expand-file-name "./org/" data-directory)	       ; system
 
-    )
 
-   "List of directories to search for OpenDocument styles files.
 
- See `org-e-odt-styles-dir'.  The entries in this list are populated
 
- heuristically based on the values of `org-e-odt-lib-dir' and
 
- `org-e-odt-data-dir'.")
 
- (defconst org-e-odt-styles-dir
 
-   (let* ((styles-dir
 
- 	  (catch 'styles-dir
 
- 	    (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
 
- 	    (mapc (lambda (styles-dir)
 
- 		    (when styles-dir
 
- 		      (message "Debug (org-e-odt): Trying %s..." styles-dir)
 
- 		      (when (and (file-readable-p
 
- 				  (expand-file-name
 
- 				   "OrgOdtContentTemplate.xml" styles-dir))
 
- 				 (file-readable-p
 
- 				  (expand-file-name
 
- 				   "OrgOdtStyles.xml" styles-dir)))
 
- 			(message "Debug (org-e-odt): Using styles under %s"
 
- 				 styles-dir)
 
- 			(throw 'styles-dir styles-dir))))
 
- 		  org-e-odt-styles-dir-list)
 
- 	    nil)))
 
-     (unless styles-dir
 
-       (error "Error (org-e-odt): Cannot find factory styles files, aborting"))
 
-     styles-dir)
 
-   "Directory that holds auxiliary XML files used by the ODT exporter.
 
- This directory contains the following XML files -
 
-  \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\".  These
 
-  XML files are used as the default values of
 
-  `org-e-odt-styles-file' and
 
-  `org-e-odt-content-template-file'.
 
- The default value of this variable varies depending on the
 
- version of org in use and is initialized from
 
- `org-e-odt-styles-dir-list'.  Note that the user could be using org
 
- from one of: org's own private git repository, GNU ELPA tar or
 
- standard Emacs.")
 
- (defconst org-e-odt-bookmark-prefix "OrgXref.")
 
- (defconst org-e-odt-manifest-file-entry-tag
 
-   "\n<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
 
- (defconst org-e-odt-file-extensions
 
-   '(("odt" . "OpenDocument Text")
 
-     ("ott" . "OpenDocument Text Template")
 
-     ("odm" . "OpenDocument Master Document")
 
-     ("ods" . "OpenDocument Spreadsheet")
 
-     ("ots" . "OpenDocument Spreadsheet Template")
 
-     ("odg" . "OpenDocument Drawing (Graphics)")
 
-     ("otg" . "OpenDocument Drawing Template")
 
-     ("odp" . "OpenDocument Presentation")
 
-     ("otp" . "OpenDocument Presentation Template")
 
-     ("odi" . "OpenDocument Image")
 
-     ("odf" . "OpenDocument Formula")
 
-     ("odc" . "OpenDocument Chart")))
 
- (defconst org-e-odt-table-style-format
 
-   "
 
- <style:style style:name=\"%s\" style:family=\"table\">
 
-   <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
 
- </style:style>
 
- "
 
-   "Template for auto-generated Table styles.")
 
- (defvar org-e-odt-automatic-styles '()
 
-   "Registry of automatic styles for various OBJECT-TYPEs.
 
- The variable has the following form:
 
- \(\(OBJECT-TYPE-A
 
-   \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
 
-    \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
 
-  \(OBJECT-TYPE-B
 
-   \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
 
-    \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
 
-  ...\).
 
- OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
 
- OBJECT-PROPS is (typically) a plist created by passing
 
- \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
 
- Use `org-e-odt-add-automatic-style' to add update this variable.'")
 
- (defvar org-e-odt-object-counters nil
 
-   "Running counters for various OBJECT-TYPEs.
 
- Use this to generate automatic names and style-names. See
 
- `org-e-odt-add-automatic-style'.")
 
- (defvar org-e-odt-src-block-paragraph-format
 
-   "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
 
-    <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
 
-     <style:background-image/>
 
-    </style:paragraph-properties>
 
-    <style:text-properties fo:color=\"%s\"/>
 
-   </style:style>"
 
-   "Custom paragraph style for colorized source and example blocks.
 
- This style is much the same as that of \"OrgFixedWidthBlock\"
 
- except that the foreground and background colors are set
 
- according to the default face identified by the `htmlfontify'.")
 
- (defvar hfy-optimisations)
 
- (defvar org-e-odt-embedded-formulas-count 0)
 
- (defvar org-e-odt-embedded-images-count 0)
 
- (defvar org-e-odt-image-size-probe-method
 
-   (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
 
- 	  '(emacs fixed))
 
-   "Ordered list of methods for determining image sizes.")
 
- (defvar org-e-odt-default-image-sizes-alist
 
-   '(("as-char" . (5 . 0.4))
 
-     ("paragraph" . (5 . 5)))
 
-   "Hardcoded image dimensions one for each of the anchor
 
-   methods.")
 
- ;; A4 page size is 21.0 by 29.7 cms
 
- ;; The default page settings has 2cm margin on each of the sides. So
 
- ;; the effective text area is 17.0 by 25.7 cm
 
- (defvar org-e-odt-max-image-size '(17.0 . 20.0)
 
-   "Limiting dimensions for an embedded image.")
 
- (defconst org-e-odt-label-styles
 
-   '(("math-formula" "%c" "text" "(%n)")
 
-     ("math-label" "(%n)" "text" "(%n)")
 
-     ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
 
-     ("value" "%e %n: %c" "value" "%n"))
 
-   "Specify how labels are applied and referenced.
 
- This is an alist where each element is of the
 
- form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
 
- LABEL-REF-FMT).
 
- LABEL-ATTACH-FMT controls how labels and captions are attached to
 
- an entity.  It may contain following specifiers - %e, %n and %c.
 
- %e is replaced with the CATEGORY-NAME.  %n is replaced with
 
- \"<text:sequence ...> SEQNO </text:sequence>\".  %c is replaced
 
- with CAPTION. See `org-e-odt-format-label-definition'.
 
- LABEL-REF-MODE and LABEL-REF-FMT controls how label references
 
- are generated.  The following XML is generated for a label
 
- reference - \"<text:sequence-ref
 
- text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
 
- </text:sequence-ref>\".  LABEL-REF-FMT may contain following
 
- specifiers - %e and %n.  %e is replaced with the CATEGORY-NAME.
 
- %n is replaced with SEQNO. See
 
- `org-e-odt-format-label-reference'.")
 
- (defvar org-e-odt-category-map-alist
 
-   '(("__Table__" "Table" "value" "Table" org-e-odt--enumerable-p)
 
-     ("__Figure__" "Illustration" "value" "Figure" org-e-odt--enumerable-image-p)
 
-     ("__MathFormula__" "Text" "math-formula" "Equation" org-e-odt--enumerable-formula-p)
 
-     ("__DvipngImage__" "Equation" "value" "Equation" org-e-odt--enumerable-latex-image-p)
 
-     ("__Listing__" "Listing" "value" "Listing" org-e-odt--enumerable-p)
 
-     ;; ("__Table__" "Table" "category-and-value")
 
-     ;; ("__Figure__" "Figure" "category-and-value")
 
-     ;; ("__DvipngImage__" "Equation" "category-and-value")
 
-     )
 
-   "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
 
- This is a list where each entry is of the form \\(CATEGORY-HANDLE
 
- OD-VARIABLE LABEL-STYLE CATEGORY-NAME ENUMERATOR-PREDICATE\\).
 
- CATEGORY_HANDLE identifies the captionable entity in question.
 
- OD-VARIABLE is the OpenDocument sequence counter associated with
 
- the entity.  These counters are declared within
 
- \"<text:sequence-decls>...</text:sequence-decls>\" block of
 
- `org-e-odt-content-template-file'.
 
- LABEL-STYLE is a key into `org-e-odt-label-styles' and specifies
 
- how a given entity should be captioned and referenced.
 
- CATEGORY-NAME is used for qualifying captions on export.  You can
 
- modify the CATEGORY-NAME used in the exported document by
 
- modifying `org-export-dictionary'.  For example, an embedded
 
- image in an English document is captioned as \"Figure 1: Orgmode
 
- Logo\", by default.  If you want the image to be captioned as
 
- \"Illustration 1: Orgmode Logo\" instead, install an entry in
 
- `org-export-dictionary' which translates \"Figure\" to
 
- \"Illustration\" when the language is \"en\" and encoding is
 
- `:utf-8'.
 
- ENUMERATOR-PREDICATE is used for assigning a sequence number to
 
- the entity.  See `org-e-odt--enumerate'.")
 
- (defvar org-e-odt-manifest-file-entries nil)
 
- (defvar hfy-user-sheet-assoc)
 
- (defvar org-e-odt-zip-dir nil
 
-   "Temporary work directory for OpenDocument exporter.")
 
- ;;; User Configuration Variables
 
- (defgroup org-export-e-odt nil
 
-   "Options for exporting Org mode files to ODT."
 
-   :tag "Org Export ODT"
 
-   :group 'org-export)
 
- ;;;; Debugging
 
- (defcustom org-e-odt-prettify-xml nil
 
-   "Specify whether or not the xml output should be prettified.
 
- When this option is turned on, `indent-region' is run on all
 
- component xml buffers before they are saved.  Turn this off for
 
- regular use.  Turn this on if you need to examine the xml
 
- visually."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type 'boolean)
 
- ;;;; Document schema
 
- (defcustom org-e-odt-schema-dir
 
-   (let* ((schema-dir
 
- 	  (catch 'schema-dir
 
- 	    (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
 
- 	    (mapc
 
- 	     (lambda (schema-dir)
 
- 	       (when schema-dir
 
- 		 (message "Debug (org-e-odt): Trying %s..." schema-dir)
 
- 		 (when (and (file-expand-wildcards
 
- 			     (expand-file-name "od-manifest-schema*.rnc"
 
- 					       schema-dir))
 
- 			    (file-expand-wildcards
 
- 			     (expand-file-name "od-schema*.rnc"
 
- 					       schema-dir))
 
- 			    (file-readable-p
 
- 			     (expand-file-name "schemas.xml" schema-dir)))
 
- 		   (message "Debug (org-e-odt): Using schema files under %s"
 
- 			    schema-dir)
 
- 		   (throw 'schema-dir schema-dir))))
 
- 	     org-e-odt-schema-dir-list)
 
- 	    (message "Debug (org-e-odt): No OpenDocument schema files installed")
 
- 	    nil)))
 
-     schema-dir)
 
-   "Directory that contains OpenDocument schema files.
 
- This directory contains:
 
- 1. rnc files for OpenDocument schema
 
- 2. a \"schemas.xml\" file that specifies locating rules needed
 
-    for auto validation of OpenDocument XML files.
 
- Use the customize interface to set this variable.  This ensures
 
- that `rng-schema-locating-files' is updated and auto-validation
 
- of OpenDocument XML takes place based on the value
 
- `rng-nxml-auto-validate-flag'.
 
- The default value of this variable varies depending on the
 
- version of org in use and is initialized from
 
- `org-e-odt-schema-dir-list'.  The OASIS schema files are available
 
- only in the org's private git repository.  It is *not* bundled
 
- with GNU ELPA tar or standard Emacs distribution."
 
-   :type '(choice
 
- 	  (const :tag "Not set" nil)
 
- 	  (directory :tag "Schema directory"))
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :set
 
-   (lambda (var value)
 
-     "Set `org-e-odt-schema-dir'.
 
- Also add it to `rng-schema-locating-files'."
 
-     (let ((schema-dir value))
 
-       (set var
 
- 	   (if (and
 
- 		(file-expand-wildcards
 
- 		 (expand-file-name "od-manifest-schema*.rnc" schema-dir))
 
- 		(file-expand-wildcards
 
- 		 (expand-file-name "od-schema*.rnc" schema-dir))
 
- 		(file-readable-p
 
- 		 (expand-file-name "schemas.xml" schema-dir)))
 
- 	       schema-dir
 
- 	     (when value
 
- 	       (message "Error (org-e-odt): %s has no OpenDocument schema files"
 
- 			value))
 
- 	     nil)))
 
-     (when org-e-odt-schema-dir
 
-       (eval-after-load 'rng-loc
 
- 	'(add-to-list 'rng-schema-locating-files
 
- 		      (expand-file-name "schemas.xml"
 
- 					org-e-odt-schema-dir))))))
 
- ;;;; Document styles
 
- (defcustom org-e-odt-content-template-file nil
 
-   "Template file for \"content.xml\".
 
- The exporter embeds the exported content just before
 
- \"</office:text>\" element.
 
- If unspecified, the file named \"OrgOdtContentTemplate.xml\"
 
- under `org-e-odt-styles-dir' is used."
 
-   :type 'file
 
-   :group 'org-export-e-odt
 
-   :version "24.1")
 
- (defcustom org-e-odt-styles-file nil
 
-   "Default styles file for use with ODT export.
 
- Valid values are one of:
 
- 1. nil
 
- 2. path to a styles.xml file
 
- 3. path to a *.odt or a *.ott file
 
- 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
 
- ...))
 
- In case of option 1, an in-built styles.xml is used. See
 
- `org-e-odt-styles-dir' for more information.
 
- In case of option 3, the specified file is unzipped and the
 
- styles.xml embedded therein is used.
 
- In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
 
- and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
 
- generated odt file.  Use relative path for specifying the
 
- FILE-MEMBERS.  styles.xml must be specified as one of the
 
- FILE-MEMBERS.
 
- Use options 1, 2 or 3 only if styles.xml alone suffices for
 
- achieving the desired formatting.  Use option 4, if the styles.xml
 
- references additional files like header and footer images for
 
- achieving the desired formatting.
 
- Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
 
- a per-file basis.  For example,
 
- #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
 
- #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type
 
-   '(choice
 
-     (const :tag "Factory settings" nil)
 
-     (file :must-match t :tag "styles.xml")
 
-     (file :must-match t :tag "ODT or OTT file")
 
-     (list :tag "ODT or OTT file + Members"
 
- 	  (file :must-match t :tag "ODF Text or Text Template file")
 
- 	  (cons :tag "Members"
 
- 		(file :tag "	Member" "styles.xml")
 
- 		(repeat (file :tag "Member"))))))
 
- (defcustom org-e-odt-display-outline-level 2
 
-   "Outline levels considered for enumerating captioned entities."
 
-   :group 'org-export-e-odt
 
-   :version "24.2"
 
-   :type 'integer)
 
- ;;;; Document conversion
 
- (defcustom org-e-odt-convert-processes
 
-   '(("LibreOffice"
 
-      "soffice --headless --convert-to %f%x --outdir %d %i")
 
-     ("unoconv"
 
-      "unoconv -f %f -o %d %i"))
 
-   "Specify a list of document converters and their usage.
 
- The converters in this list are offered as choices while
 
- customizing `org-e-odt-convert-process'.
 
- This variable is a list where each element is of the
 
- form (CONVERTER-NAME CONVERTER-CMD).  CONVERTER-NAME is the name
 
- of the converter.  CONVERTER-CMD is the shell command for the
 
- converter and can contain format specifiers.  These format
 
- specifiers are interpreted as below:
 
- %i input file name in full
 
- %I input file name as a URL
 
- %f format of the output file
 
- %o output file name in full
 
- %O output file name as a URL
 
- %d output dir in full
 
- %D output dir as a URL.
 
- %x extra options as set in `org-e-odt-convert-capabilities'."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type
 
-   '(choice
 
-     (const :tag "None" nil)
 
-     (alist :tag "Converters"
 
- 	   :key-type (string :tag "Converter Name")
 
- 	   :value-type (group (string :tag "Command line")))))
 
- (defcustom org-e-odt-convert-process "LibreOffice"
 
-   "Use this converter to convert from \"odt\" format to other formats.
 
- During customization, the list of converter names are populated
 
- from `org-e-odt-convert-processes'."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type '(choice :convert-widget
 
- 		 (lambda (w)
 
- 		   (apply 'widget-convert (widget-type w)
 
- 			  (eval (car (widget-get w :args)))))
 
- 		 `((const :tag "None" nil)
 
- 		   ,@(mapcar (lambda (c)
 
- 			       `(const :tag ,(car c) ,(car c)))
 
- 			     org-e-odt-convert-processes))))
 
- (defcustom org-e-odt-convert-capabilities
 
-   '(("Text"
 
-      ("odt" "ott" "doc" "rtf" "docx")
 
-      (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
 
-       ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
 
-     ("Web"
 
-      ("html")
 
-      (("pdf" "pdf") ("odt" "odt") ("html" "html")))
 
-     ("Spreadsheet"
 
-      ("ods" "ots" "xls" "csv" "xlsx")
 
-      (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
 
-       ("xls" "xls") ("xlsx" "xlsx")))
 
-     ("Presentation"
 
-      ("odp" "otp" "ppt" "pptx")
 
-      (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
 
-       ("pptx" "pptx") ("odg" "odg"))))
 
-   "Specify input and output formats of `org-e-odt-convert-process'.
 
- More correctly, specify the set of input and output formats that
 
- the user is actually interested in.
 
- This variable is an alist where each element is of the
 
- form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
 
- INPUT-FMT-LIST is a list of INPUT-FMTs.  OUTPUT-FMT-ALIST is an
 
- alist where each element is of the form (OUTPUT-FMT
 
- OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
 
- The variable is interpreted as follows:
 
- `org-e-odt-convert-process' can take any document that is in
 
- INPUT-FMT-LIST and produce any document that is in the
 
- OUTPUT-FMT-LIST.  A document converted to OUTPUT-FMT will have
 
- OUTPUT-FILE-EXTENSION as the file name extension.  OUTPUT-FMT
 
- serves dual purposes:
 
- - It is used for populating completion candidates during
 
-   `org-e-odt-convert' commands.
 
- - It is used as the value of \"%f\" specifier in
 
-   `org-e-odt-convert-process'.
 
- EXTRA-OPTIONS is used as the value of \"%x\" specifier in
 
- `org-e-odt-convert-process'.
 
- DOCUMENT-CLASS is used to group a set of file formats in
 
- INPUT-FMT-LIST in to a single class.
 
- Note that this variable inherently captures how LibreOffice based
 
- converters work.  LibreOffice maps documents of various formats
 
- to classes like Text, Web, Spreadsheet, Presentation etc and
 
- allow document of a given class (irrespective of it's source
 
- format) to be converted to any of the export formats associated
 
- with that class.
 
- See default setting of this variable for an typical
 
- configuration."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type
 
-   '(choice
 
-     (const :tag "None" nil)
 
-     (alist :tag "Capabilities"
 
- 	   :key-type (string :tag "Document Class")
 
- 	   :value-type
 
- 	   (group (repeat :tag "Input formats" (string :tag "Input format"))
 
- 		  (alist :tag "Output formats"
 
- 			 :key-type (string :tag "Output format")
 
- 			 :value-type
 
- 			 (group (string :tag "Output file extension")
 
- 				(choice
 
- 				 (const :tag "None" nil)
 
- 				 (string :tag "Extra options"))))))))
 
- (defcustom org-e-odt-preferred-output-format nil
 
-   "Automatically post-process to this format after exporting to \"odt\".
 
- Command `org-e-odt-export-to-odt' exports first to \"odt\" format
 
- and then uses `org-e-odt-convert-process' to convert the
 
- resulting document to this format.  During customization of this
 
- variable, the list of valid values are populated based on
 
- `org-e-odt-convert-capabilities'.
 
- You can set this option on per-file basis using file local
 
- values.  See Info node `(emacs) File Variables'."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type '(choice :convert-widget
 
- 		 (lambda (w)
 
- 		   (apply 'widget-convert (widget-type w)
 
- 			  (eval (car (widget-get w :args)))))
 
- 		 `((const :tag "None" nil)
 
- 		   ,@(mapcar (lambda (c)
 
- 			       `(const :tag ,c ,c))
 
- 			     (org-e-odt-reachable-formats "odt")))))
 
- ;;;###autoload
 
- (put 'org-e-odt-preferred-output-format 'safe-local-variable 'stringp)
 
- ;;;; Drawers
 
- (defcustom org-e-odt-format-drawer-function nil
 
-   "Function called to format a drawer in ODT code.
 
- The function must accept two parameters:
 
-   NAME      the drawer name, like \"LOGBOOK\"
 
-   CONTENTS  the contents of the drawer.
 
- The function should return the string to be exported.
 
- For example, the variable could be set to the following function
 
- in order to mimic default behaviour:
 
- \(defun org-e-odt-format-drawer-default \(name contents\)
 
-   \"Format a drawer element for ODT export.\"
 
-   contents\)"
 
-   :group 'org-export-e-odt
 
-   :type 'function)
 
- ;;;; Headline
 
- (defcustom org-e-odt-format-headline-function nil
 
-   "Function to format headline text.
 
- This function will be called with 5 arguments:
 
- TODO      the todo keyword \(string or nil\).
 
- TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
 
- PRIORITY  the priority of the headline \(integer or nil\)
 
- TEXT      the main headline text \(string\).
 
- TAGS      the tags string, separated with colons \(string or nil\).
 
- The function result will be used as headline text."
 
-   :group 'org-export-e-odt
 
-   :type 'function)
 
- ;;;; Inlinetasks
 
- (defcustom org-e-odt-format-inlinetask-function nil
 
-   "Function called to format an inlinetask in ODT code.
 
- The function must accept six parameters:
 
-   TODO      the todo keyword, as a string
 
-   TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
 
-   PRIORITY  the inlinetask priority, as a string
 
-   NAME      the inlinetask name, as a string.
 
-   TAGS      the inlinetask tags, as a string.
 
-   CONTENTS  the contents of the inlinetask, as a string.
 
- The function should return the string to be exported."
 
-   :group 'org-export-e-odt
 
-   :type 'function)
 
- ;;;; Links
 
- (defcustom org-e-odt-inline-formula-rules
 
-   '(("file" . "\\.\\(mathml\\|mml\\|odf\\)\\'"))
 
-   "Rules characterizing formula files that can be inlined into ODT.
 
- A rule consists in an association whose key is the type of link
 
- to consider, and value is a regexp that will be matched against
 
- link's path."
 
-   :group 'org-export-e-odt
 
-   :type '(alist :key-type (string :tag "Type")
 
- 		:value-type (regexp :tag "Path")))
 
- (defcustom org-e-odt-inline-image-rules
 
-   '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
 
-   "Rules characterizing image files that can be inlined into ODT.
 
- A rule consists in an association whose key is the type of link
 
- to consider, and value is a regexp that will be matched against
 
- link's path."
 
-   :group 'org-export-e-odt
 
-   :type '(alist :key-type (string :tag "Type")
 
- 		:value-type (regexp :tag "Path")))
 
- (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
 
-   "Scaling factor for converting images pixels to inches.
 
- Use this for sizing of embedded images.  See Info node `(org)
 
- Images in ODT export' for more information."
 
-   :type 'float
 
-   :group 'org-export-e-odt
 
-   :version "24.1")
 
- ;;;; Src Block
 
- (defcustom org-e-odt-create-custom-styles-for-srcblocks t
 
-   "Whether custom styles for colorized source blocks be automatically created.
 
- When this option is turned on, the exporter creates custom styles
 
- for source blocks based on the advice of `htmlfontify'.  Creation
 
- of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
 
- When this option is turned off exporter does not create such
 
- styles.
 
- Use the latter option if you do not want the custom styles to be
 
- based on your current display settings.  It is necessary that the
 
- styles.xml already contains needed styles for colorizing to work.
 
- This variable is effective only if
 
- `org-e-odt-fontify-srcblocks' is turned on."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type 'boolean)
 
- (defcustom org-e-odt-fontify-srcblocks t
 
-   "Specify whether or not source blocks need to be fontified.
 
- Turn this option on if you want to colorize the source code
 
- blocks in the exported file.  For colorization to work, you need
 
- to make available an enhanced version of `htmlfontify' library."
 
-   :type 'boolean
 
-   :group 'org-export-e-odt
 
-   :version "24.1")
 
- ;;;; Table
 
- (defcustom org-e-odt-table-styles
 
-   '(("OrgEquation" "OrgEquation"
 
-      ((use-first-column-styles . t)
 
-       (use-last-column-styles . t)))
 
-     ("TableWithHeaderRowAndColumn" "Custom"
 
-      ((use-first-row-styles . t)
 
-       (use-first-column-styles . t)))
 
-     ("TableWithFirstRowandLastRow" "Custom"
 
-      ((use-first-row-styles . t)
 
-       (use-last-row-styles . t)))
 
-     ("GriddedTable" "Custom" nil))
 
-   "Specify how Table Styles should be derived from a Table Template.
 
- This is a list where each element is of the
 
- form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
 
- TABLE-STYLE-NAME is the style associated with the table through
 
- \"#+ATTR_ODT: :style TABLE-STYLE-NAME\" line.
 
- TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
 
- TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
 
- below) that is included in
 
- `org-e-odt-content-template-file'.
 
- TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
 
-                          \"TableCell\"
 
- PARAGRAPH-STYLE-NAME  := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
 
-                          \"TableParagraph\"
 
- TABLE-CELL-TYPE       := \"FirstRow\"   | \"LastColumn\" |
 
-                          \"FirstRow\"   | \"LastRow\"    |
 
-                          \"EvenRow\"    | \"OddRow\"     |
 
-                          \"EvenColumn\" | \"OddColumn\"  | \"\"
 
- where \"+\" above denotes string concatenation.
 
- TABLE-CELL-OPTIONS is an alist where each element is of the
 
- form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
 
- TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles'       |
 
-                              `use-last-row-styles'        |
 
-                              `use-first-column-styles'    |
 
-                              `use-last-column-styles'     |
 
-                              `use-banding-rows-styles'    |
 
-                              `use-banding-columns-styles' |
 
-                              `use-first-row-styles'
 
- ON-OR-OFF                 := `t' | `nil'
 
- For example, with the following configuration
 
- \(setq org-e-odt-table-styles
 
-       '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
 
-          \(\(use-first-row-styles . t\)
 
-           \(use-first-column-styles . t\)\)\)
 
-         \(\"TableWithHeaderColumns\" \"Custom\"
 
-          \(\(use-first-column-styles . t\)\)\)\)\)
 
- 1. A table associated with \"TableWithHeaderRowsAndColumns\"
 
-    style will use the following table-cell styles -
 
-    \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
 
-    \"CustomTableCell\" and the following paragraph styles
 
-    \"CustomFirstRowTableParagraph\",
 
-    \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
 
-    as appropriate.
 
- 2. A table associated with \"TableWithHeaderColumns\" style will
 
-    use the following table-cell styles -
 
-    \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
 
-    following paragraph styles
 
-    \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
 
-    as appropriate..
 
- Note that TABLE-TEMPLATE-NAME corresponds to the
 
- \"<table:table-template>\" elements contained within
 
- \"<office:styles>\".  The entries (TABLE-STYLE-NAME
 
- TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
 
- \"table:template-name\" and \"table:use-first-row-styles\" etc
 
- attributes of \"<table:table>\" element.  Refer ODF-1.2
 
- specification for more information.  Also consult the
 
- implementation filed under `org-e-odt-get-table-cell-styles'.
 
- The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
 
- formatting of numbered display equations.  Do not delete this
 
- style from the list."
 
-   :group 'org-export-e-odt
 
-   :version "24.1"
 
-   :type '(choice
 
-           (const :tag "None" nil)
 
-           (repeat :tag "Table Styles"
 
-                   (list :tag "Table Style Specification"
 
- 			(string :tag "Table Style Name")
 
- 			(string  :tag "Table Template Name")
 
- 			(alist :options (use-first-row-styles
 
- 					 use-last-row-styles
 
- 					 use-first-column-styles
 
- 					 use-last-column-styles
 
- 					 use-banding-rows-styles
 
- 					 use-banding-columns-styles)
 
- 			       :key-type symbol
 
- 			       :value-type (const :tag "True" t))))))
 
- ;;;; Timestamps
 
- (defcustom org-e-odt-use-date-fields nil
 
-   "Non-nil, if timestamps should be exported as date fields.
 
- When nil, export timestamps as plain text.
 
- When non-nil, map `org-time-stamp-custom-formats' to a pair of
 
- OpenDocument date-styles with names \"OrgDate1\" and \"OrgDate2\"
 
- respectively.  A timestamp with no time component is formatted
 
- with style \"OrgDate1\" while one with explicit hour and minutes
 
- is formatted with style \"OrgDate2\".
 
- This feature is experimental.  Most (but not all) of the common
 
- %-specifiers in `format-time-string' are supported.
 
- Specifically, locale-dependent specifiers like \"%c\", \"%x\" are
 
- formatted as canonical Org timestamps.  For finer control, avoid
 
- these %-specifiers.
 
- Textutal specifiers like \"%b\", \"%h\", \"%B\", \"%a\", \"%A\"
 
- etc., are displayed by the application in the default language
 
- and country specified in `org-e-odt-styles-file'.  Note that the
 
- default styles file uses language \"en\" and country \"GB\".  You
 
- can localize the week day and month strings in the exported
 
- document by setting the default language and country either using
 
- the application UI or through a custom styles file.
 
- See `org-e-odt--build-date-styles' for implementation details."
 
-   :group 'org-export-e-odt
 
-   :type 'boolean)
 
- ;;; Internal functions
 
- ;;;; Date
 
- (defun org-e-odt--format-timestamp (timestamp &optional end iso-date-p)
 
-   (let* ((format-timestamp
 
- 	  (lambda (timestamp format &optional end utc)
 
- 	    (if timestamp
 
- 		(org-export-format-timestamp timestamp format end utc)
 
- 	      (format-time-string format nil utc))))
 
- 	 (has-time-p (or (not timestamp)
 
- 			 (org-export-timestamp-has-time-p timestamp)))
 
- 	 (iso-date (let ((format (if has-time-p "%Y-%m-%dT%H:%M:%S"
 
- 				   "%Y-%m-%dT%H:%M:%S")))
 
- 		     (funcall format-timestamp timestamp format end))))
 
-     (if iso-date-p iso-date
 
-       (let* ((style (if has-time-p "OrgDate2" "OrgDate1"))
 
- 	     ;; LibreOffice does not care about end goes as content
 
- 	     ;; within the "<text:date>...</text:date>" field.  The
 
- 	     ;; displayed date is automagically corrected to match the
 
- 	     ;; format requested by "style:data-style-name" attribute.  So
 
- 	     ;; don't bother about formatting the date contents to be
 
- 	     ;; compatible with "OrgDate1" and "OrgDateTime" styles.  A
 
- 	     ;; simple Org-style date should suffice.
 
- 	     (date (let* ((formats
 
- 			   (if org-display-custom-times
 
- 			       (cons (substring
 
- 				      (car org-time-stamp-custom-formats) 1 -1)
 
- 				     (substring
 
- 				      (cdr org-time-stamp-custom-formats) 1 -1))
 
- 			     '("%Y-%m-%d %a" . "%Y-%m-%d %a %H:%M")))
 
- 			  (format (if has-time-p (cdr formats) (car formats))))
 
- 		     (funcall format-timestamp timestamp format end)))
 
- 	     (repeater (let ((repeater-type (org-element-property
 
- 					     :repeater-type timestamp))
 
- 			     (repeater-value (org-element-property
 
- 					      :repeater-value timestamp))
 
- 			     (repeater-unit (org-element-property
 
- 					     :repeater-unit timestamp)))
 
- 			 (concat
 
- 			  (case repeater-type
 
- 			    (catchup "++") (restart ".+") (cumulate "+"))
 
- 			  (when repeater-value
 
- 			    (number-to-string repeater-value))
 
- 			  (case repeater-unit
 
- 			    (hour "h") (day "d") (week "w") (month "m")
 
- 			    (year "y"))))))
 
- 	(concat
 
- 	 (format "<text:date text:date-value=\"%s\" style:data-style-name=\"%s\" text:fixed=\"true\">%s</text:date>"
 
- 		 iso-date style date)
 
- 	 (and (not (string= repeater ""))  " ")
 
- 	 repeater)))))
 
- ;;;; Frame
 
- (defun org-e-odt--frame (text width height style &optional extra
 
- 			      anchor-type &rest title-and-desc)
 
-   (let ((frame-attrs
 
- 	 (concat
 
- 	  (if width (format " svg:width=\"%0.2fcm\"" width) "")
 
- 	  (if height (format " svg:height=\"%0.2fcm\"" height) "")
 
- 	  extra
 
- 	  (format " text:anchor-type=\"%s\"" (or anchor-type "paragraph")))))
 
-     (format
 
-      "\n<draw:frame draw:style-name=\"%s\"%s>\n%s\n</draw:frame>"
 
-      style frame-attrs
 
-      (concat text
 
- 	     (let ((title (car title-and-desc))
 
- 		   (desc (cadr title-and-desc)))
 
- 	       (concat (when title
 
- 			 (format "<svg:title>%s</svg:title>"
 
- 				 (org-e-odt--encode-plain-text title t)))
 
- 		       (when desc
 
- 			 (format "<svg:desc>%s</svg:desc>"
 
- 				 (org-e-odt--encode-plain-text desc t)))))))))
 
- ;;;; Library wrappers
 
- (defun org-e-odt--zip-extract (archive members target)
 
-   (when (atom members) (setq members (list members)))
 
-   (mapc (lambda (member)
 
- 	  (require 'arc-mode)
 
- 	  (let* ((--quote-file-name
 
- 		  ;; This is shamelessly stolen from `archive-zip-extract'.
 
- 		  (lambda (name)
 
- 		    (if (or (not (memq system-type '(windows-nt ms-dos)))
 
- 			    (and (boundp 'w32-quote-process-args)
 
- 				 (null w32-quote-process-args)))
 
- 			(shell-quote-argument name)
 
- 		      name)))
 
- 		 (target (funcall --quote-file-name target))
 
- 		 (archive (expand-file-name archive))
 
- 		 (archive-zip-extract
 
- 		  (list "unzip" "-qq" "-o" "-d" target))
 
- 		 exit-code command-output)
 
- 	    (setq command-output
 
- 		  (with-temp-buffer
 
- 		    (setq exit-code (archive-zip-extract archive member))
 
- 		    (buffer-string)))
 
- 	    (unless (zerop exit-code)
 
- 	      (message command-output)
 
- 	      (error "Extraction failed"))))
 
- 	members))
 
- (defun org-e-odt--suppress-some-translators (info types)
 
-   ;; See comments in `org-e-odt-format-label' and `org-e-odt-toc'.
 
-   (org-combine-plists
 
-    info (list
 
- 	 ;; Override translators.
 
- 	 :translate-alist
 
- 	 (nconc (mapcar (lambda (type) (cons type (lambda (data contents info)
 
- 						    contents))) types)
 
- 		(plist-get info :translate-alist))
 
- 	 ;; Reset data translation cache.  FIXME.
 
- 	 ;; :exported-data nil
 
- 	 )))
 
- ;;;; Target
 
- (defun org-e-odt--target (text id)
 
-   (if (not id) text
 
-     (concat
 
-      (format "\n<text:bookmark-start text:name=\"OrgXref.%s\"/>" id)
 
-      (format "\n<text:bookmark text:name=\"%s\"/>" id) text
 
-      (format "\n<text:bookmark-end text:name=\"OrgXref.%s\"/>" id))))
 
- ;;;; Textbox
 
- (defun org-e-odt--textbox (text width height style &optional
 
- 				extra anchor-type)
 
-   (org-e-odt--frame
 
-    (format "\n<draw:text-box %s>%s\n</draw:text-box>"
 
- 	   (concat (format " fo:min-height=\"%0.2fcm\"" (or height .2))
 
- 		   (and (not width)
 
- 			(format " fo:min-width=\"%0.2fcm\"" (or width .2))))
 
- 	   text)
 
-    width nil style extra anchor-type))
 
- ;;;; Table of Contents
 
- (defun org-e-odt-begin-toc (index-title depth)
 
-   (concat
 
-    (format "
 
-     <text:table-of-content text:style-name=\"OrgIndexSection\" text:protected=\"true\" text:name=\"Table of Contents\">
 
-      <text:table-of-content-source text:outline-level=\"%d\">
 
-       <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
 
- " depth index-title)
 
-    (let ((levels (number-sequence 1 10)))
 
-      (mapconcat
 
-       (lambda (level)
 
- 	(format
 
- 	 "
 
-       <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
 
-        <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
 
-        <text:index-entry-chapter/>
 
-        <text:index-entry-text/>
 
-        <text:index-entry-link-end/>
 
-       </text:table-of-content-entry-template>
 
- " level level)) levels ""))
 
-    (format  "
 
-      </text:table-of-content-source>
 
-      <text:index-body>
 
-       <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
 
-        <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
 
-       </text:index-title>
 
-  " index-title)))
 
- (defun org-e-odt-end-toc ()
 
-   (format "
 
-      </text:index-body>
 
-     </text:table-of-content>
 
- "))
 
- (defun* org-e-odt-format-toc-headline
 
-     (todo todo-type priority text tags
 
- 	  &key level section-number headline-label &allow-other-keys)
 
-   (setq text
 
- 	(concat
 
- 	 ;; Section number.
 
- 	 (when section-number (concat section-number ". "))
 
- 	 ;; Todo.
 
- 	 (when todo
 
- 	   (let ((style (if (member todo org-done-keywords)
 
- 			    "OrgDone" "OrgTodo")))
 
- 	     (format "<text:span text:style-name=\"%s\">%s</text:span> "
 
- 		     style todo)))
 
- 	 (when priority
 
- 	   (let* ((style (format "OrgPriority-%s" priority))
 
- 		  (priority (format "[#%c]" priority)))
 
- 	     (format "<text:span text:style-name=\"%s\">%s</text:span> "
 
- 		     style priority)))
 
- 	 ;; Title.
 
- 	 text
 
- 	 ;; Tags.
 
- 	 (when tags
 
- 	   (concat
 
- 	    (format " <text:span text:style-name=\"%s\">[%s]</text:span>"
 
- 		    "OrgTags"
 
- 		    (mapconcat
 
- 		     (lambda (tag)
 
- 		       (format
 
- 			"<text:span text:style-name=\"%s\">%s</text:span>"
 
- 			"OrgTag" tag)) tags " : "))))))
 
-   (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
 
- 	  headline-label text))
 
- (defun org-e-odt-toc (depth info)
 
-   (assert (wholenump depth))
 
-   ;; When a headline is marked as a radio target, as in the example below:
 
-   ;;
 
-   ;; ** <<<Some Heading>>>
 
-   ;;    Some text.
 
-   ;;
 
-   ;; suppress generation of radio targets.  i.e., Radio targets are to
 
-   ;; be marked as targets within /document body/ and *not* within
 
-   ;; /TOC/, as otherwise there will be duplicated anchors one in TOC
 
-   ;; and one in the document body.
 
-   ;;
 
-   ;; FIXME-1: Currently exported headings are memoized.  `org-export.el'
 
-   ;; doesn't provide a way to disable memoization.  So this doesn't
 
-   ;; work.
 
-   ;;
 
-   ;; FIXME-2: Are there any other objects that need to be suppressed
 
-   ;; within TOC?
 
-   (let* ((title (org-export-translate "Table of Contents" :utf-8 info))
 
- 	 (headlines (org-export-collect-headlines
 
- 		     info (and (wholenump depth) depth)))
 
- 	 (translations (nconc (mapcar
 
- 			       (lambda (type)
 
- 				 (cons type (lambda (data contents info)
 
- 					      contents)))
 
- 			       (list 'radio-target))
 
- 			      (plist-get info :translate-alist))))
 
-     (when headlines
 
-       (concat
 
-        (org-e-odt-begin-toc title depth)
 
-        (mapconcat
 
- 	(lambda (headline)
 
- 	  (let* ((entry (org-e-odt-format-headline--wrap
 
- 			 headline translations info
 
- 			 'org-e-odt-format-toc-headline))
 
- 		 (level (org-export-get-relative-level headline info))
 
- 		 (style (format "Contents_20_%d" level)))
 
- 	    (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		    style entry)))
 
- 	headlines "\n")
 
-        (org-e-odt-end-toc)))))
 
- ;;;; Document styles
 
- (defun org-e-odt-add-automatic-style (object-type &optional object-props)
 
-   "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
 
- OBJECT-PROPS is (typically) a plist created by passing
 
- \"#+ATTR_ODT: \" option of the object in question to
 
- `org-e-odt-parse-block-attributes'.
 
- Use `org-e-odt-object-counters' to generate an automatic
 
- OBJECT-NAME and STYLE-NAME.  If OBJECT-PROPS is non-nil, add a
 
- new entry in `org-e-odt-automatic-styles'.  Return (OBJECT-NAME
 
- . STYLE-NAME)."
 
-   (assert (stringp object-type))
 
-   (let* ((object (intern object-type))
 
- 	 (seqvar object)
 
- 	 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar) 0)))
 
- 	 (object-name (format "%s%d" object-type seqno)) style-name)
 
-     (setq org-e-odt-object-counters
 
- 	  (plist-put org-e-odt-object-counters seqvar seqno))
 
-     (when object-props
 
-       (setq style-name (format "Org%s" object-name))
 
-       (setq org-e-odt-automatic-styles
 
- 	    (plist-put org-e-odt-automatic-styles object
 
- 		       (append (list (list style-name object-props))
 
- 			       (plist-get org-e-odt-automatic-styles object)))))
 
-     (cons object-name style-name)))
 
- ;;;; Checkbox
 
- (defun org-e-odt--checkbox (item)
 
-   "Return check-box string associated to ITEM."
 
-   (let ((checkbox (org-element-property :checkbox item)))
 
-     (if (not checkbox) ""
 
-       (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	      "OrgCode" (case checkbox
 
- 			  (on "[✓] ") ; CHECK MARK
 
- 			  (off "[ ] ")
 
- 			  (trans "[-] "))))))
 
- ;;; Template
 
- (defun org-e-odt--build-date-styles (fmt style)
 
-   ;; In LibreOffice 3.4.6, there doesn't seem to be a convenient way
 
-   ;; to modify the date fields.  A date could be modified by
 
-   ;; offsetting in days.  That's about it.  Also, date and time may
 
-   ;; have to be emitted as two fields - a date field and a time field
 
-   ;; - separately.
 
-   ;; One can add Form Controls to date and time fields so that they
 
-   ;; can be easily modified.  But then, the exported document will
 
-   ;; become tightly coupled with LibreOffice and may not function
 
-   ;; properly with other OpenDocument applications.
 
-   ;; I have a strange feeling that Date styles are a bit flaky at the
 
-   ;; moment.
 
-   ;; The feature is experimental.
 
-   (when (and fmt style)
 
-     (let* ((fmt-alist
 
- 	    '(("%A" . "<number:day-of-week number:style=\"long\"/>")
 
- 	      ("%B" . "<number:month number:textual=\"true\" number:style=\"long\"/>")
 
- 	      ("%H" . "<number:hours number:style=\"long\"/>")
 
- 	      ("%M" . "<number:minutes number:style=\"long\"/>")
 
- 	      ("%S" . "<number:seconds number:style=\"long\"/>")
 
- 	      ("%V" . "<number:week-of-year/>")
 
- 	      ("%Y" . "<number:year number:style=\"long\"/>")
 
- 	      ("%a" . "<number:day-of-week number:style=\"short\"/>")
 
- 	      ("%b" . "<number:month number:textual=\"true\" number:style=\"short\"/>")
 
- 	      ("%d" . "<number:day number:style=\"long\"/>")
 
- 	      ("%e" . "<number:day number:style=\"short\"/>")
 
- 	      ("%h" . "<number:month number:textual=\"true\" number:style=\"short\"/>")
 
- 	      ("%k" . "<number:hours number:style=\"short\"/>")
 
- 	      ("%m" . "<number:month number:style=\"long\"/>")
 
- 	      ("%p" . "<number:am-pm/>")
 
- 	      ("%y" . "<number:year number:style=\"short\"/>")))
 
- 	   (case-fold-search nil)
 
- 	   (re (mapconcat 'identity (mapcar 'car fmt-alist) "\\|"))
 
- 	   match rpl (start 0) (filler-beg 0) filler-end filler output)
 
-       (mapc
 
-        (lambda (pair)
 
- 	 (setq fmt (replace-regexp-in-string (car pair) (cdr pair) fmt t t)))
 
-        '(("\\(?:%[[:digit:]]*N\\)" . "") ; strip ns, us and ns
 
- 	 ("%C" . "Y")			 ; replace century with year
 
- 	 ("%D" . "%m/%d/%y")
 
- 	 ("%G" . "Y")		      ; year corresponding to iso week
 
- 	 ("%I" . "%H")		      ; hour on a 12-hour clock
 
- 	 ("%R" . "%H:%M")
 
- 	 ("%T" . "%H:%M:%S")
 
- 	 ("%U\\|%W" . "%V")	      ; week no. starting on Sun./Mon.
 
- 	 ("%Z" . "")		      ; time zone name
 
- 	 ("%c" . "%Y-%M-%d %a %H:%M" ) ; locale's date and time format
 
- 	 ("%g" . "%y")
 
- 	 ("%X" . "%x" )	 ; locale's pref. time format
 
- 	 ("%j" . "")	 ; day of the year
 
- 	 ("%l" . "%k")	 ; like %I blank-padded
 
- 	 ("%s" . "")	 ; no. of secs since 1970-01-01 00:00:00 +0000
 
- 	 ("%n" . "<text:line-break/>")
 
- 	 ("%r" . "%I:%M:%S %p")
 
- 	 ("%t" . "<text:tab/>")
 
- 	 ("%u\\|%w" . "")  ; numeric day of week - Mon (1-7), Sun(0-6)
 
- 	 ("%x" . "%Y-%M-%d %a")		; locale's pref. time format
 
- 	 ("%z" . "")			; time zone in numeric form
 
- 	 ))
 
-       (while (string-match re fmt start)
 
- 	(setq match (match-string 0 fmt))
 
- 	(setq rpl (assoc-default match fmt-alist))
 
- 	(setq start (match-end 0))
 
- 	(setq filler-end (match-beginning 0))
 
- 	(setq filler (substring fmt (prog1 filler-beg
 
- 				      (setq filler-beg (match-end 0)))
 
- 				filler-end))
 
- 	(setq filler (and (not (string= filler ""))
 
- 			  (format "<number:text>%s</number:text>"
 
- 				  (org-e-odt--encode-plain-text filler))))
 
- 	(setq output (concat output "\n" filler "\n" rpl)))
 
-       (setq filler (substring fmt filler-beg))
 
-       (unless (string= filler "")
 
- 	(setq output (concat output
 
- 			     (format "\n<number:text>%s</number:text>"
 
- 				     (org-e-odt--encode-plain-text filler)))))
 
-       (format "\n<number:date-style style:name=\"%s\" %s>%s\n</number:date-style>"
 
- 	      style
 
- 	      (concat " number:automatic-order=\"true\""
 
- 		      " number:format-source=\"fixed\"")
 
- 	      output ))))
 
- (defun org-e-odt-template (contents info)
 
-   "Return complete document string after ODT conversion.
 
- CONTENTS is the transcoded contents string.  RAW-DATA is the
 
- original parsed data.  INFO is a plist holding export options."
 
-   ;; Write meta file.
 
-   (let ((title (org-export-data (plist-get info :title) info))
 
- 	(author (let ((author (plist-get info :author)))
 
- 		  (if (not author) "" (org-export-data author info))))
 
- 	(email (plist-get info :email))
 
- 	(keywords (plist-get info :keywords))
 
- 	(description (plist-get info :description)))
 
-     (write-region
 
-      (concat
 
-       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
 
-      <office:document-meta
 
-          xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
 
-          xmlns:xlink=\"http://www.w3.org/1999/xlink\"
 
-          xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
 
-          xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
 
-          xmlns:ooo=\"http://openoffice.org/2004/office\"
 
-          office:version=\"1.2\">
 
-        <office:meta>\n"
 
-       (format "<dc:creator>%s</dc:creator>\n" author)
 
-       (format "<meta:initial-creator>%s</meta:initial-creator>\n" author)
 
-       ;; Date, if required.
 
-       (when (plist-get info :with-date)
 
- 	;; Check if DATE is specified as an Org-timestamp.  If yes,
 
- 	;; include it as meta information.  Otherwise, just use
 
- 	;; today's date.
 
- 	(let* ((date (let ((date (plist-get info :date)))
 
- 		       (and (not (cdr date))
 
- 			    (eq (org-element-type (car date)) 'timestamp)
 
- 			    (car date)))))
 
- 	  (let ((iso-date (org-e-odt--format-timestamp date nil 'iso-date)))
 
- 	    (concat
 
- 	     (format "<dc:date>%s</dc:date>\n" iso-date)
 
- 	     (format "<meta:creation-date>%s</meta:creation-date>\n"
 
- 		     iso-date)))))
 
-       (format "<meta:generator>%s</meta:generator>\n"
 
- 	      (let ((creator-info (plist-get info :with-creator)))
 
- 		(if (or (not creator-info) (eq creator-info 'comment)) ""
 
- 		  (plist-get info :creator))))
 
-       (format "<meta:keyword>%s</meta:keyword>\n" keywords)
 
-       (format "<dc:subject>%s</dc:subject>\n" description)
 
-       (format "<dc:title>%s</dc:title>\n" title)
 
-       "\n"
 
-       "  </office:meta>\n" "</office:document-meta>")
 
-      nil (concat org-e-odt-zip-dir "meta.xml"))
 
-     ;; Add meta.xml in to manifest.
 
-     (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
 
-   ;; Update styles file.
 
-   ;; Copy styles.xml.  Also dump htmlfontify styles, if there is any.
 
-   ;; Write styles file.
 
-   (let* ((styles-file (plist-get info :odt-styles-file))
 
- 	 (styles-file (and styles-file (read (org-trim styles-file))))
 
- 	 ;; Non-availability of styles.xml is not a critical
 
- 	 ;; error. For now, throw an error.
 
- 	 (styles-file (or styles-file
 
- 			  org-e-odt-styles-file
 
- 			  (expand-file-name "OrgOdtStyles.xml"
 
- 					    org-e-odt-styles-dir)
 
- 			  (error "org-e-odt: Missing styles file?"))))
 
-     (cond
 
-      ((listp styles-file)
 
-       (let ((archive (nth 0 styles-file))
 
- 	    (members (nth 1 styles-file)))
 
- 	(org-e-odt--zip-extract archive members org-e-odt-zip-dir)
 
- 	(mapc
 
- 	 (lambda (member)
 
- 	   (when (org-file-image-p member)
 
- 	     (let* ((image-type (file-name-extension member))
 
- 		    (media-type (format "image/%s" image-type)))
 
- 	       (org-e-odt-create-manifest-file-entry media-type member))))
 
- 	 members)))
 
-      ((and (stringp styles-file) (file-exists-p styles-file))
 
-       (let ((styles-file-type (file-name-extension styles-file)))
 
- 	(cond
 
- 	 ((string= styles-file-type "xml")
 
- 	  (copy-file styles-file (concat org-e-odt-zip-dir "styles.xml") t))
 
- 	 ((member styles-file-type '("odt" "ott"))
 
- 	  (org-e-odt--zip-extract styles-file "styles.xml" org-e-odt-zip-dir)))))
 
-      (t
 
-       (error (format "Invalid specification of styles.xml file: %S"
 
- 		     org-e-odt-styles-file))))
 
-     ;; create a manifest entry for styles.xml
 
-     (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml")
 
-     ;; FIXME: Who is opening an empty styles.xml before this point?
 
-     (with-current-buffer
 
- 	(find-file-noselect (concat org-e-odt-zip-dir "styles.xml") t)
 
-       (revert-buffer t t)
 
-       ;; Write custom styles for source blocks
 
-       ;; Save STYLES used for colorizing of source blocks.
 
-       ;; Update styles.xml with styles that were collected as part of
 
-       ;; `org-e-odt-hfy-face-to-css' callbacks.
 
-       (let ((styles (mapconcat (lambda (style) (format " %s\n" (cddr style)))
 
- 			       hfy-user-sheet-assoc "")))
 
- 	(when styles
 
- 	  (goto-char (point-min))
 
- 	  (when (re-search-forward "</office:styles>" nil t)
 
- 	    (goto-char (match-beginning 0))
 
- 	    (insert "\n<!-- Org Htmlfontify Styles -->\n" styles "\n"))))
 
-       ;; Update styles.xml - take care of outline numbering
 
-       ;; Don't make automatic backup of styles.xml file. This setting
 
-       ;; prevents the backed-up styles.xml file from being zipped in to
 
-       ;; odt file. This is more of a hackish fix. Better alternative
 
-       ;; would be to fix the zip command so that the output odt file
 
-       ;; includes only the needed files and excludes any auto-generated
 
-       ;; extra files like backups and auto-saves etc etc. Note that
 
-       ;; currently the zip command zips up the entire temp directory so
 
-       ;; that any auto-generated files created under the hood ends up in
 
-       ;; the resulting odt file.
 
-       (set (make-local-variable 'backup-inhibited) t)
 
-       ;; Outline numbering is retained only upto LEVEL.
 
-       ;; To disable outline numbering pass a LEVEL of 0.
 
-       (goto-char (point-min))
 
-       (let ((regex
 
- 	     "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
 
- 	    (replacement
 
- 	     "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
 
- 	(while (re-search-forward regex nil t)
 
- 	  (unless (let ((sec-num (plist-get info :section-numbers))
 
- 			(level (string-to-number (match-string 2))))
 
- 		    (if (wholenump sec-num) (<= level sec-num) sec-num))
 
- 	    (replace-match replacement t nil))))
 
-       (save-buffer 0)))
 
-   ;; Update content.xml.
 
-   (let* ( ;; `org-display-custom-times' should be accessed right
 
- 	 ;; within the context of the Org buffer.  So obtain it's
 
- 	 ;; value before moving on to temp-buffer context down below.
 
- 	 (custom-time-fmts
 
- 	  (if org-display-custom-times
 
- 	      (cons (substring (car org-time-stamp-custom-formats) 1 -1)
 
- 		    (substring (cdr org-time-stamp-custom-formats) 1 -1))
 
- 	    '("%Y-%M-%d %a" . "%Y-%M-%d %a %H:%M"))))
 
-     (with-temp-buffer
 
-       (insert-file-contents
 
-        (or org-e-odt-content-template-file
 
- 	   (expand-file-name "OrgOdtContentTemplate.xml"
 
- 			     org-e-odt-styles-dir)))
 
-       ;; Write automatic styles.
 
-       ;; - Position the cursor.
 
-       (goto-char (point-min))
 
-       (re-search-forward "  </office:automatic-styles>" nil t)
 
-       (goto-char (match-beginning 0))
 
-       ;; - Dump automatic table styles.
 
-       (loop for (style-name props) in
 
- 	    (plist-get org-e-odt-automatic-styles 'Table) do
 
- 	    (when (setq props (or (plist-get props :rel-width) 96))
 
- 	      (insert (format org-e-odt-table-style-format style-name props))))
 
-       ;; - Dump date-styles.
 
-       (when org-e-odt-use-date-fields
 
- 	(insert (org-e-odt--build-date-styles (car custom-time-fmts)
 
- 					      "OrgDate1")
 
- 		(org-e-odt--build-date-styles (cdr custom-time-fmts)
 
- 					      "OrgDate2")))
 
-       ;; Update display level.
 
-       ;; - Remove existing sequence decls.  Also position the cursor.
 
-       (goto-char (point-min))
 
-       (when (re-search-forward "<text:sequence-decls" nil t)
 
- 	(delete-region (match-beginning 0)
 
- 		       (re-search-forward "</text:sequence-decls>" nil nil)))
 
-       ;; Update sequence decls according to user preference.
 
-       (insert
 
-        (format
 
- 	"\n<text:sequence-decls>\n%s\n</text:sequence-decls>"
 
- 	(mapconcat
 
- 	 (lambda (x)
 
- 	   (format
 
- 	    "<text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
 
- 	    org-e-odt-display-outline-level (nth 1 x)))
 
- 	 org-e-odt-category-map-alist "\n")))
 
-       ;; Position the cursor to document body.
 
-       (goto-char (point-min))
 
-       (re-search-forward "</office:text>" nil nil)
 
-       (goto-char (match-beginning 0))
 
-       ;; Preamble - Title, Author, Date etc.
 
-       (insert
 
-        (let* ((title (org-export-data (plist-get info :title) info))
 
- 	      (author (and (plist-get info :with-author)
 
- 			   (let ((auth (plist-get info :author)))
 
- 			     (and auth (org-export-data auth info)))))
 
- 	      (email (plist-get info :email))
 
- 	      ;; Switch on or off above vars based on user settings
 
- 	      (author (and (plist-get info :with-author) (or author email)))
 
- 	      (email (and (plist-get info :with-email) email)))
 
- 	 (concat
 
- 	  ;; Title.
 
- 	  (when title
 
- 	    (concat
 
- 	     (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		     "OrgTitle" (format "\n<text:title>%s</text:title>" title))
 
- 	     ;; Separator.
 
- 	     "\n<text:p text:style-name=\"OrgTitle\"/>"))
 
- 	  (cond
 
- 	   ((and author (not email))
 
- 	    ;; Author only.
 
- 	    (concat
 
- 	     (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		     "OrgSubtitle"
 
- 		     (format "<text:initial-creator>%s</text:initial-creator>" author))
 
- 	     ;; Separator.
 
- 	     "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
 
- 	   ((and author email)
 
- 	    ;; Author and E-mail.
 
- 	    (concat
 
- 	     (format
 
- 	      "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 	      "OrgSubtitle"
 
- 	      (format
 
- 	       "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
 
- 	       (concat "mailto:" email)
 
- 	       (format "<text:initial-creator>%s</text:initial-creator>" author)))
 
- 	     ;; Separator.
 
- 	     "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
 
- 	  ;; Date, if required.
 
- 	  (when (plist-get info :with-date)
 
- 	    (let* ((date (plist-get info :date))
 
- 		   ;; Check if DATE is specified as a timestamp.
 
- 		   (timestamp (and (not (cdr date))
 
- 				   (eq (org-element-type (car date)) 'timestamp)
 
- 				   (car date))))
 
- 	      (concat
 
- 	       (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		       "OrgSubtitle"
 
- 		       (if (and org-e-odt-use-date-fields timestamp)
 
- 			   (org-e-odt--format-timestamp (car date))
 
- 			 (org-export-data (plist-get info :date) info)))
 
- 	       ;; Separator
 
- 	       "<text:p text:style-name=\"OrgSubtitle\"/>"))))))
 
-       ;; Table of Contents
 
-       (let* ((with-toc (plist-get info :with-toc))
 
- 	     (depth (and with-toc (if (wholenump with-toc)
 
- 				      with-toc
 
- 				    (plist-get info :headline-levels)))))
 
- 	(when depth (insert (or (org-e-odt-toc depth info) ""))))
 
-       ;; Contents.
 
-       (insert contents)
 
-       ;; Return contents.
 
-       (buffer-substring-no-properties (point-min) (point-max)))))
 
- ;;; Transcode Functions
 
- ;;;; Bold
 
- (defun org-e-odt-bold (bold contents info)
 
-   "Transcode BOLD from Org to ODT.
 
- CONTENTS is the text with bold markup.  INFO is a plist holding
 
- contextual information."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "Bold" contents))
 
- ;;;; Center Block
 
- (defun org-e-odt-center-block (center-block contents info)
 
-   "Transcode a CENTER-BLOCK element from Org to ODT.
 
- CONTENTS holds the contents of the center block.  INFO is a plist
 
- holding contextual information."
 
-   contents)
 
- ;;;; Clock
 
- (defun org-e-odt-clock (clock contents info)
 
-   "Transcode a CLOCK element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist used as a communication
 
- channel."
 
-   (let ((timestamp (org-element-property :value clock))
 
- 	(duration (org-element-property :duration clock)))
 
-     (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 	    (if (eq (org-element-type (org-export-get-next-element clock info))
 
- 		    'clock) "OrgClock" "OrgClockLastLine")
 
- 	    (concat
 
- 	     (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		     "OrgClockKeyword" org-clock-string)
 
- 	     (org-e-odt-timestamp timestamp contents info)
 
- 	     (and duration (format " (%s)" duration))))))
 
- ;;;; Code
 
- (defun org-e-odt-code (code contents info)
 
-   "Transcode a CODE object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist used as a communication
 
- channel."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "OrgCode" (org-element-property :value code)))
 
- ;;;; Comment
 
- ;; Comments are ignored.
 
- ;;;; Comment Block
 
- ;; Comment Blocks are ignored.
 
- ;;;; Drawer
 
- (defun org-e-odt-drawer (drawer contents info)
 
-   "Transcode a DRAWER element from Org to ODT.
 
- CONTENTS holds the contents of the block.  INFO is a plist
 
- holding contextual information."
 
-   (let* ((name (org-element-property :drawer-name drawer))
 
- 	 (output (if (functionp org-e-odt-format-drawer-function)
 
- 		     (funcall org-e-odt-format-drawer-function
 
- 			      name contents)
 
- 		   ;; If there's no user defined function: simply
 
- 		   ;; display contents of the drawer.
 
- 		   contents)))
 
-     output))
 
- ;;;; Dynamic Block
 
- (defun org-e-odt-dynamic-block (dynamic-block contents info)
 
-   "Transcode a DYNAMIC-BLOCK element from Org to ODT.
 
- CONTENTS holds the contents of the block.  INFO is a plist
 
- holding contextual information.  See `org-export-data'."
 
-   contents)
 
- ;;;; Entity
 
- (defun org-e-odt-entity (entity contents info)
 
-   "Transcode an ENTITY object from Org to ODT.
 
- CONTENTS are the definition itself.  INFO is a plist holding
 
- contextual information."
 
-   (org-element-property :utf-8 entity))
 
- ;;;; Example Block
 
- (defun org-e-odt-example-block (example-block contents info)
 
-   "Transcode a EXAMPLE-BLOCK element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (org-e-odt-format-code example-block info))
 
- ;;;; Export Snippet
 
- (defun org-e-odt-export-snippet (export-snippet contents info)
 
-   "Transcode a EXPORT-SNIPPET object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (when (eq (org-export-snippet-backend export-snippet) 'e-odt)
 
-     (org-element-property :value export-snippet)))
 
- ;;;; Export Block
 
- (defun org-e-odt-export-block (export-block contents info)
 
-   "Transcode a EXPORT-BLOCK element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (when (string= (org-element-property :type export-block) "ODT")
 
-     (org-remove-indentation (org-element-property :value export-block))))
 
- ;;;; Fixed Width
 
- (defun org-e-odt-fixed-width (fixed-width contents info)
 
-   "Transcode a FIXED-WIDTH element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (org-e-odt-do-format-code (org-element-property :value fixed-width)))
 
- ;;;; Footnote Definition
 
- ;; Footnote Definitions are ignored.
 
- ;;;; Footnote Reference
 
- (defun org-e-odt-footnote-reference (footnote-reference contents info)
 
-   "Transcode a FOOTNOTE-REFERENCE element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (let ((--format-footnote-definition
 
- 	 (function
 
- 	  (lambda (n def)
 
- 	    (setq n (format "%d" n))
 
- 	    (let ((id (concat  "fn" n))
 
- 		  (note-class "footnote")
 
- 		  (par-style "Footnote"))
 
- 	      (format
 
- 	       "<text:note text:id=\"%s\" text:note-class=\"%s\">%s</text:note>"
 
- 	       id note-class
 
- 	       (concat
 
- 		(format "<text:note-citation>%s</text:note-citation>" n)
 
- 		(format "<text:note-body>%s</text:note-body>" def)))))))
 
- 	(--format-footnote-reference
 
- 	 (function
 
- 	  (lambda (n)
 
- 	    (setq n (format "%d" n))
 
- 	    (let ((note-class "footnote")
 
- 		  (ref-format "text")
 
- 		  (ref-name (concat "fn" n)))
 
- 	      (format
 
- 	       "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	       "OrgSuperscript"
 
- 	       (format "<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:note-ref>"
 
- 		       note-class ref-format ref-name n)))))))
 
-     (concat
 
-      ;; Insert separator between two footnotes in a row.
 
-      (let ((prev (org-export-get-previous-element footnote-reference info)))
 
-        (and (eq (org-element-type prev) 'footnote-reference)
 
- 	    (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		    "OrgSuperscript" ",")))
 
-      ;; Trancode footnote reference.
 
-      (let ((n (org-export-get-footnote-number footnote-reference info)))
 
-        (cond
 
- 	((not (org-export-footnote-first-reference-p footnote-reference info))
 
- 	 (funcall --format-footnote-reference n))
 
- 	;; Inline definitions are secondary strings.
 
- 	;; Non-inline footnotes definitions are full Org data.
 
- 	(t
 
- 	 (let* ((raw (org-export-get-footnote-definition footnote-reference
 
- 							 info))
 
- 		(def (let ((def (org-trim (org-export-data raw info))))
 
- 		       (if (eq (org-element-type raw) 'org-data) def
 
- 			 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 				 "Footnote" def)))))
 
- 	   (funcall --format-footnote-definition n def))))))))
 
- ;;;; Headline
 
- (defun* org-e-odt-format-headline
 
-     (todo todo-type priority text tags
 
- 	  &key level section-number headline-label &allow-other-keys)
 
-   (concat
 
-    ;; Todo.
 
-    (when todo
 
-      (let ((style (if (member todo org-done-keywords) "OrgDone" "OrgTodo")))
 
-        (format "<text:span text:style-name=\"%s\">%s</text:span> "
 
- 	       style todo)))
 
-    (when priority
 
-      (let* ((style (format "OrgPriority-%s" priority))
 
- 	    (priority (format "[#%c]" priority)))
 
-        (format "<text:span text:style-name=\"%s\">%s</text:span> "
 
- 	       style priority)))
 
-    ;; Title.
 
-    text
 
-    ;; Tags.
 
-    (when tags
 
-      (concat
 
-       "<text:tab/>"
 
-       (format "<text:span text:style-name=\"%s\">[%s]</text:span>"
 
- 	      "OrgTags" (mapconcat
 
- 			 (lambda (tag)
 
- 			   (format
 
- 			    "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 			    "OrgTag" tag)) tags " : "))))))
 
- (defun org-e-odt-format-headline--wrap (headline translations info
 
- 						 &optional format-function
 
- 						 &rest extra-keys)
 
-   "Transcode an HEADLINE element from Org to ODT.
 
- CONTENTS holds the contents of the headline.  INFO is a plist
 
- holding contextual information."
 
-   (setq translations (or translations (plist-get info :translate-alist)))
 
-   (let* ((level (+ (org-export-get-relative-level headline info)))
 
- 	 (headline-number (org-export-get-headline-number headline info))
 
- 	 (section-number (and (org-export-numbered-headline-p headline info)
 
- 			      (mapconcat 'number-to-string
 
- 					 headline-number ".")))
 
- 	 (todo (and (plist-get info :with-todo-keywords)
 
- 		    (let ((todo (org-element-property :todo-keyword headline)))
 
- 		      (and todo (org-export-data-with-translations
 
- 				 todo translations info)))))
 
- 	 (todo-type (and todo (org-element-property :todo-type headline)))
 
- 	 (priority (and (plist-get info :with-priority)
 
- 			(org-element-property :priority headline)))
 
- 	 (text (org-export-data-with-translations
 
- 		(org-element-property :title headline) translations info))
 
- 	 (tags (and (plist-get info :with-tags)
 
- 		    (org-export-get-tags headline info)))
 
- 	 (headline-label (concat "sec-" (mapconcat 'number-to-string
 
- 						   headline-number "-")))
 
- 	 (format-function (cond
 
- 			   ((functionp format-function) format-function)
 
- 			   ((functionp org-e-odt-format-headline-function)
 
- 			    (function*
 
- 			     (lambda (todo todo-type priority text tags
 
- 					   &allow-other-keys)
 
- 			       (funcall org-e-odt-format-headline-function
 
- 					todo todo-type priority text tags))))
 
- 			   (t 'org-e-odt-format-headline))))
 
-     (apply format-function
 
-     	   todo todo-type  priority text tags
 
-     	   :headline-label headline-label :level level
 
-     	   :section-number section-number extra-keys)))
 
- (defun org-e-odt-headline (headline contents info)
 
-   "Transcode an HEADLINE element from Org to ODT.
 
- CONTENTS holds the contents of the headline.  INFO is a plist
 
- holding contextual information."
 
-   ;; Case 1: This is a footnote section: ignore it.
 
-   (unless (org-element-property :footnote-section-p headline)
 
-     (let* ((text (org-export-data (org-element-property :title headline) info))
 
- 	   ;; Create the headline text.
 
- 	   (full-text (org-e-odt-format-headline--wrap headline nil info))
 
- 	   ;; Get level relative to current parsed data.
 
- 	   (level (org-export-get-relative-level headline info))
 
- 	   ;; Get canonical label for the headline.
 
- 	   (id (concat "sec-" (mapconcat 'number-to-string
 
- 					 (org-export-get-headline-number
 
- 					  headline info) "-")))
 
- 	   ;; Get user-specified labels for the headline.
 
- 	   (extra-ids (list (org-element-property :custom-id headline)
 
- 			    (org-element-property :id headline)))
 
- 	   ;; Extra targets.
 
- 	   (extra-targets
 
- 	    (mapconcat (lambda (x)
 
- 			 (when x
 
- 			   (let ((x (if (org-uuidgen-p x) (concat "ID-" x) x)))
 
- 			     (org-e-odt--target
 
- 			      "" (org-export-solidify-link-text x)))))
 
- 		       extra-ids ""))
 
- 	   ;; Title.
 
- 	   (anchored-title (org-e-odt--target full-text id)))
 
-       (cond
 
-        ;; Case 2. This is a deep sub-tree: export it as a list item.
 
-        ;;         Also export as items headlines for which no section
 
-        ;;         format has been found.
 
-        ((org-export-low-level-p headline info)
 
- 	;; Build the real contents of the sub-tree.
 
- 	(concat
 
- 	 (and (org-export-first-sibling-p headline info)
 
- 	      (format "\n<text:list text:style-name=\"%s\" %s>"
 
- 		      ;; Choose style based on list type.
 
- 		      (if (org-export-numbered-headline-p headline info)
 
- 			  "OrgNumberedList" "OrgBulletedList")
 
- 		      ;; If top-level list, re-start numbering.  Otherwise,
 
- 		      ;; continue numbering.
 
- 		      (format "text:continue-numbering=\"%s\""
 
- 			      (let* ((parent (org-export-get-parent-headline
 
- 					      headline)))
 
- 				(if (and parent
 
- 					 (org-export-low-level-p parent info))
 
- 				    "true" "false")))))
 
- 	 (let ((headline-has-table-p
 
- 		(let ((section (assq 'section (org-element-contents headline))))
 
- 		  (assq 'table (and section (org-element-contents section))))))
 
- 	   (format "\n<text:list-item>\n%s\n%s"
 
- 		   (concat
 
- 		    (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 			    "Text_20_body"
 
- 			    (concat extra-targets anchored-title))
 
- 		    contents)
 
- 		   (if headline-has-table-p
 
- 		       "</text:list-header>"
 
- 		     "</text:list-item>")))
 
- 	 (and (org-export-last-sibling-p headline info)
 
- 	      "</text:list>")))
 
-        ;; Case 3. Standard headline.  Export it as a section.
 
-        (t
 
- 	(concat
 
- 	 (format
 
- 	  "\n<text:h text:style-name=\"%s\" text:outline-level=\"%s\">%s</text:h>"
 
- 	  (format "Heading_20_%s" level)
 
- 	  level
 
- 	  (concat extra-targets anchored-title))
 
- 	 contents))))))
 
- ;;;; Horizontal Rule
 
- (defun org-e-odt-horizontal-rule (horizontal-rule contents info)
 
-   "Transcode an HORIZONTAL-RULE  object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 	  "Horizontal_20_Line" ""))
 
- ;;;; Inline Babel Call
 
- ;; Inline Babel Calls are ignored.
 
- ;;;; Inline Src Block
 
- (defun org-e-odt--find-verb-separator (s)
 
-   "Return a character not used in string S.
 
- This is used to choose a separator for constructs like \\verb."
 
-   (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
 
-     (loop for c across ll
 
- 	  when (not (string-match (regexp-quote (char-to-string c)) s))
 
- 	  return (char-to-string c))))
 
- (defun org-e-odt-inline-src-block (inline-src-block contents info)
 
-   "Transcode an INLINE-SRC-BLOCK element from Org to ODT.
 
- CONTENTS holds the contents of the item.  INFO is a plist holding
 
- contextual information."
 
-   (let* ((org-lang (org-element-property :language inline-src-block))
 
- 	 (code (org-element-property :value inline-src-block))
 
- 	 (separator (org-e-odt--find-verb-separator code)))
 
-     (error "FIXME")))
 
- ;;;; Inlinetask
 
- (defun org-e-odt-inlinetask (inlinetask contents info)
 
-   "Transcode an INLINETASK element from Org to ODT.
 
- CONTENTS holds the contents of the block.  INFO is a plist
 
- holding contextual information."
 
-   (cond
 
-    ;; If `org-e-odt-format-inlinetask-function' is provided, call it
 
-    ;; with appropriate arguments.
 
-    ((functionp org-e-odt-format-inlinetask-function)
 
-     (let ((format-function
 
- 	   (function*
 
- 	    (lambda (todo todo-type priority text tags
 
- 			  &key contents &allow-other-keys)
 
- 	      (funcall org-e-odt-format-inlinetask-function
 
- 		       todo todo-type priority text tags contents)))))
 
-       (org-e-odt-format-headline--wrap
 
-        inlinetask nil info format-function :contents contents)))
 
-    ;; Otherwise, use a default template.
 
-    (t
 
-     (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 	    "Text_20_body"
 
- 	    (org-e-odt--textbox
 
- 	     (concat
 
- 	      (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		      "OrgInlineTaskHeading"
 
- 		      (org-e-odt-format-headline--wrap inlinetask nil info))
 
- 	      contents)
 
- 	     nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\"")))))
 
- ;;;; Italic
 
- (defun org-e-odt-italic (italic contents info)
 
-   "Transcode ITALIC from Org to ODT.
 
- CONTENTS is the text with italic markup.  INFO is a plist holding
 
- contextual information."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "Emphasis" contents))
 
- ;;;; Item
 
- (defun org-e-odt-item (item contents info)
 
-   "Transcode an ITEM element from Org to ODT.
 
- CONTENTS holds the contents of the item.  INFO is a plist holding
 
- contextual information."
 
-   (let* ((plain-list (org-export-get-parent item))
 
- 	 (type (org-element-property :type plain-list))
 
- 	 (counter (org-element-property :counter item))
 
- 	 (tag (let ((tag (org-element-property :tag item)))
 
- 		(and tag
 
- 		     (concat (org-e-odt--checkbox item)
 
- 			     (org-export-data tag info))))))
 
-     (case type
 
-       ((ordered unordered descriptive-1 descriptive-2)
 
-        (format "\n<text:list-item>\n%s\n%s"
 
- 	       contents
 
- 	       (let* ((--element-has-a-table-p
 
- 		       (function
 
- 			(lambda (element info)
 
- 			  (loop for el in (org-element-contents element)
 
- 				thereis (eq (org-element-type el) 'table))))))
 
- 		 (cond
 
- 		  ((funcall --element-has-a-table-p item info)
 
- 		   "</text:list-header>")
 
- 		  (t "</text:list-item>")))))
 
-       (t (error "Unknown list type: %S" type)))))
 
- ;;;; Keyword
 
- (defun org-e-odt-keyword (keyword contents info)
 
-   "Transcode a KEYWORD element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (let ((key (org-element-property :key keyword))
 
- 	(value (org-element-property :value keyword)))
 
-     (cond
 
-      ((string= key "ODT") value)
 
-      ((string= key "INDEX")
 
-       ;; FIXME
 
-       (ignore))
 
-      ((string= key "TARGET") nil)
 
-      ((string= key "toc")
 
-       (let ((value (downcase value)))
 
- 	(cond
 
- 	 ((string-match "\\<headlines\\>" value)
 
- 	  (let ((depth (or (and (string-match "[0-9]+" value)
 
- 				(string-to-number (match-string 0 value)))
 
- 			   (plist-get info :with-toc))))
 
- 	    (when (wholenump depth) (org-e-odt-toc depth info))))
 
- 	 ((member value '("tables" "figures" "listings"))
 
- 	  ;; FIXME
 
- 	  (ignore))))))))
 
- ;;;; Latex Environment
 
- (eval-after-load 'org-odt
 
-   '(ad-deactivate 'org-format-latex-as-mathml))
 
- ;; (defadvice org-format-latex-as-mathml	; FIXME
 
- ;;   (after org-e-odt-protect-latex-fragment activate)
 
- ;;   "Encode LaTeX fragment as XML.
 
- ;; Do this when translation to MathML fails."
 
- ;;   (when (or (not (> (length ad-return-value) 0))
 
- ;; 	    (get-text-property 0 'org-protected ad-return-value))
 
- ;;     (setq ad-return-value
 
- ;; 	  (org-propertize (org-e-odt--encode-plain-text (ad-get-arg 0))
 
- ;; 			  'org-protected t))))
 
- (defun org-e-odt-latex-environment (latex-environment contents info)
 
-   "Transcode a LATEX-ENVIRONMENT element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (let* ((latex-frag (org-remove-indentation
 
- 		      (org-element-property :value latex-environment))))
 
-     (org-e-odt-do-format-code latex-frag)))
 
- ;;;; Latex Fragment
 
- ;; (when latex-frag			; FIXME
 
- ;; 	(setq href (org-propertize href :title "LaTeX Fragment"
 
- ;; 				   :description latex-frag)))
 
- ;; handle verbatim
 
- ;; provide descriptions
 
- (defun org-e-odt-latex-fragment (latex-fragment contents info)
 
-   "Transcode a LATEX-FRAGMENT object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (let* ((latex-frag (org-element-property :value latex-fragment))
 
- 	 (processing-type (plist-get info :LaTeX-fragments)))
 
-     (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	    "OrgCode" (org-e-odt--encode-plain-text latex-frag t))))
 
- ;;;; Line Break
 
- (defun org-e-odt-line-break (line-break contents info)
 
-   "Transcode a LINE-BREAK object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   "<text:line-break/>\n")
 
- ;;;; Link
 
- ;;;; Links :: Label references
 
- (defun org-e-odt--enumerate (element info &optional predicate n)
 
-   (when predicate (assert (funcall predicate element info)))
 
-   (let* ((--numbered-parent-headline-at-<=-n
 
- 	  (function
 
- 	   (lambda (element n info)
 
- 	     (loop for x in (org-export-get-genealogy element)
 
- 		   thereis (and (eq (org-element-type x) 'headline)
 
- 		   		(<= (org-export-get-relative-level x info) n)
 
- 		   		(org-export-numbered-headline-p x info)
 
- 		   		x)))))
 
- 	 (--enumerate
 
- 	  (function
 
- 	   (lambda (element scope info &optional predicate)
 
- 	     (let ((counter 0))
 
- 	       (org-element-map
 
- 		(or scope (plist-get info :parse-tree))
 
- 		(org-element-type element)
 
- 		(lambda (el)
 
- 		  (and (or (not predicate) (funcall predicate el info))
 
- 		       (incf counter)
 
- 		       (eq element el)
 
- 		       counter))
 
- 		info 'first-match)))))
 
- 	 (scope (funcall --numbered-parent-headline-at-<=-n
 
- 			 element (or n org-e-odt-display-outline-level) info))
 
- 	 (ordinal (funcall --enumerate element scope info predicate))
 
- 	 (tag
 
- 	  (concat
 
- 	   ;; Section number.
 
- 	   (and scope
 
- 		(mapconcat 'number-to-string
 
- 			   (org-export-get-headline-number scope info) "."))
 
- 	   ;; Separator.
 
- 	   (and scope ".")
 
- 	   ;; Ordinal.
 
- 	   (number-to-string ordinal))))
 
-     tag))
 
- (defun org-e-odt-format-label (element info op)
 
-   (assert (memq (org-element-type element) '(link table src-block paragraph)))
 
-   (let* ((caption-from
 
- 	  (case (org-element-type element)
 
- 	    (link (org-export-get-parent-element element))
 
- 	    (t element)))
 
- 	 ;; Get label and caption.
 
- 	 (label (org-element-property :name caption-from))
 
- 	 (caption (org-export-get-caption caption-from))
 
- 	 (short-caption (org-export-get-caption caption-from t))
 
- 	 ;; Transcode captions.
 
- 	 (caption (and caption (org-export-data caption info)))
 
- 	 ;; Currently short caption are sneaked in as object names.
 
- 	 ;;
 
- 	 ;; The advantages are:
 
- 	 ;;
 
- 	 ;; - Table Of Contents: Currently, there is no support for
 
- 	 ;;   building TOC for figures, listings and tables.  See
 
- 	 ;;   `org-e-odt-keyword'.  User instead has to rely on
 
- 	 ;;   external application for building such indices.  Within
 
- 	 ;;   LibreOffice, building an "Illustration Index" or "Index
 
- 	 ;;   of Tables" will create a table with long captions (only)
 
- 	 ;;   and building a table with "Object names" will create a
 
- 	 ;;   table with short captions.
 
- 	 ;;
 
- 	 ;; - Easy navigation: In LibreOffice, object names are
 
- 	 ;;   offered via the navigation bar.  This way one can
 
- 	 ;;   quickly locate and jump to object of his choice in the
 
- 	 ;;   exported document.
 
- 	 ;;
 
- 	 ;; The main disadvantage is that there cannot be any markups
 
- 	 ;; within object names i.e., one cannot embolden, italicize
 
- 	 ;; or underline text within short caption.  So suppress
 
- 	 ;; generation of <text:span >...</text:span> and other
 
- 	 ;; markups by overriding the default translators.  We
 
- 	 ;; probably shouldn't be suppressing translators for all
 
- 	 ;; elements in `org-element-all-objects', but for now this
 
- 	 ;; will do.
 
- 	 (short-caption
 
- 	  (let ((short-caption (or short-caption caption))
 
- 		(translations (nconc (mapcar
 
- 				      (lambda (type)
 
- 					(cons type (lambda (data contents info)
 
- 						     contents)))
 
- 				      org-element-all-objects)
 
- 				     (plist-get info :translate-alist))))
 
- 	    (when short-caption
 
- 	      (org-export-data-with-translations short-caption
 
- 						 translations info)))))
 
-     (when (or label caption)
 
-       (let* ((default-category
 
- 	       (case (org-element-type element)
 
- 		 (table "__Table__")
 
- 		 (src-block "__Listing__")
 
- 		 ((link paragraph)
 
- 		  (cond
 
- 		   ((org-e-odt--enumerable-latex-image-p element info)
 
- 		    "__DvipngImage__")
 
- 		   ((org-e-odt--enumerable-image-p element info)
 
- 		    "__Figure__")
 
- 		   ((org-e-odt--enumerable-formula-p element info)
 
- 		    "__MathFormula__")
 
- 		   (t (error "Don't know how to format label for link: %S"
 
- 			     element))))
 
- 		 (t (error "Don't know how to format label for element type: %s"
 
- 			   (org-element-type element)))))
 
- 	     seqno)
 
- 	(assert default-category)
 
- 	(destructuring-bind (counter label-style category predicate)
 
- 	    (assoc-default default-category org-e-odt-category-map-alist)
 
- 	  ;; Compute sequence number of the element.
 
- 	  (setq seqno (org-e-odt--enumerate element info predicate))
 
- 	  ;; Localize category string.
 
- 	  (setq category (org-export-translate category :utf-8 info))
 
- 	  (case op
 
- 	    ;; Case 1: Handle Label definition.
 
- 	    (definition
 
- 	      ;; Assign an internal label, if user has not provided one
 
- 	      (setq label (or label (format  "%s-%s" default-category seqno)))
 
- 	      (setq label (org-export-solidify-link-text label))
 
- 	      (cons
 
- 	       (concat
 
- 		;; Sneak in a bookmark.  The bookmark is used when the
 
- 		;; labeled element is referenced with a link that
 
- 		;; provides it's own description.
 
- 		(format "\n<text:bookmark text:name=\"%s\"/>" label)
 
- 		;; Label definition: Typically formatted as below:
 
- 		;;     CATEGORY SEQ-NO: LONG CAPTION
 
- 		(format-spec
 
- 		 (cadr (assoc-string label-style org-e-odt-label-styles t))
 
- 		 `((?e . ,category)
 
- 		   (?n . ,(format
 
- 			   "<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">%s</text:sequence>"
 
- 			   label counter counter seqno))
 
- 		   (?c . ,(or caption "")))))
 
- 	       short-caption))
 
- 	    ;; Case 2: Handle Label reference.
 
- 	    (reference
 
- 	     (assert label)
 
- 	     (setq label (org-export-solidify-link-text label))
 
- 	     (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t)))
 
- 		    (fmt1 (car fmt))
 
- 		    (fmt2 (cadr fmt)))
 
- 	       (format "<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:sequence-ref>"
 
- 		       fmt1 label (format-spec fmt2 `((?e . ,category)
 
- 						      (?n . ,seqno))))))
 
- 	    (t (error "Unknown %S on label" op))))))))
 
- ;;;; Links :: Inline Images
 
- (defun org-e-odt--copy-image-file (path)
 
-   "Returns the internal name of the file"
 
-   (let* ((image-type (file-name-extension path))
 
- 	 (media-type (format "image/%s" image-type))
 
- 	 (target-dir "Images/")
 
- 	 (target-file
 
- 	  (format "%s%04d.%s" target-dir
 
- 		  (incf org-e-odt-embedded-images-count) image-type)))
 
-     (message "Embedding %s as %s ..."
 
- 	     (substring-no-properties path) target-file)
 
-     (when (= 1 org-e-odt-embedded-images-count)
 
-       (make-directory (concat org-e-odt-zip-dir target-dir))
 
-       (org-e-odt-create-manifest-file-entry "" target-dir))
 
-     (copy-file path (concat org-e-odt-zip-dir target-file) 'overwrite)
 
-     (org-e-odt-create-manifest-file-entry media-type target-file)
 
-     target-file))
 
- (defun org-e-odt--image-size (file &optional user-width
 
- 				   user-height scale dpi embed-as)
 
-   (let* ((--pixels-to-cms
 
- 	  (function (lambda (pixels dpi)
 
- 		      (let ((cms-per-inch 2.54)
 
- 			    (inches (/ pixels dpi)))
 
- 			(* cms-per-inch inches)))))
 
- 	 (--size-in-cms
 
- 	  (function
 
- 	   (lambda (size-in-pixels dpi)
 
- 	     (and size-in-pixels
 
- 		  (cons (funcall --pixels-to-cms (car size-in-pixels) dpi)
 
- 			(funcall --pixels-to-cms (cdr size-in-pixels) dpi))))))
 
- 	 (dpi (or dpi org-e-odt-pixels-per-inch))
 
- 	 (anchor-type (or embed-as "paragraph"))
 
- 	 (user-width (and (not scale) user-width))
 
- 	 (user-height (and (not scale) user-height))
 
- 	 (size
 
- 	  (and
 
- 	   (not (and user-height user-width))
 
- 	   (or
 
- 	    ;; Use Imagemagick.
 
- 	    (and (executable-find "identify")
 
- 		 (let ((size-in-pixels
 
- 			(let ((dim (shell-command-to-string
 
- 				    (format "identify -format \"%%w:%%h\" \"%s\""
 
- 					    file))))
 
- 			  (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim)
 
- 			    (cons (string-to-number (match-string 1 dim))
 
- 				  (string-to-number (match-string 2 dim)))))))
 
- 		   (funcall --size-in-cms size-in-pixels dpi)))
 
- 	    ;; Use Emacs.
 
- 	    (let ((size-in-pixels
 
- 		   (ignore-errors	; Emacs could be in batch mode
 
- 		     (clear-image-cache)
 
- 		     (image-size (create-image file) 'pixels))))
 
- 	      (funcall --size-in-cms size-in-pixels dpi))
 
- 	    ;; Use hard-coded values.
 
- 	    (cdr (assoc-string anchor-type
 
- 			       org-e-odt-default-image-sizes-alist))
 
- 	    ;; Error out.
 
- 	    (error "Cannot determine image size, aborting"))))
 
- 	 (width (car size)) (height (cdr size)))
 
-     (cond
 
-      (scale
 
-       (setq width (* width scale) height (* height scale)))
 
-      ((and user-height user-width)
 
-       (setq width user-width height user-height))
 
-      (user-height
 
-       (setq width (* user-height (/ width height)) height user-height))
 
-      (user-width
 
-       (setq height (* user-width (/ height width)) width user-width))
 
-      (t (ignore)))
 
-     ;; ensure that an embedded image fits comfortably within a page
 
-     (let ((max-width (car org-e-odt-max-image-size))
 
- 	  (max-height (cdr org-e-odt-max-image-size)))
 
-       (when (or (> width max-width) (> height max-height))
 
- 	(let* ((scale1 (/ max-width width))
 
- 	       (scale2 (/ max-height height))
 
- 	       (scale (min scale1 scale2)))
 
- 	  (setq width (* scale width) height (* scale height)))))
 
-     (cons width height)))
 
- (defun org-e-odt-link--inline-image (element info)
 
-   "Return ODT code for an inline image.
 
- LINK is the link pointing to the inline image.  INFO is a plist
 
- used as a communication channel."
 
-   (assert (eq (org-element-type element) 'link))
 
-   (let* ((src (let* ((type (org-element-property :type element))
 
- 		     (raw-path (org-element-property :path element)))
 
- 		(cond ((member type '("http" "https"))
 
- 		       (concat type ":" raw-path))
 
- 		      ((file-name-absolute-p raw-path)
 
- 		       (expand-file-name raw-path))
 
- 		      (t raw-path))))
 
- 	 (src-expanded (if (file-name-absolute-p src) src
 
- 			 (expand-file-name src (file-name-directory
 
- 						(plist-get info :input-file)))))
 
- 	 (href (format
 
- 		"\n<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>"
 
- 		(org-e-odt--copy-image-file src-expanded)))
 
- 	 ;; Extract attributes from #+ATTR_ODT line.
 
- 	 (attr-from (case (org-element-type element)
 
- 		      (link (org-export-get-parent-element element))
 
- 		      (t element)))
 
- 	 ;; Convert attributes to a plist.
 
- 	 (attr-plist (org-export-read-attribute :attr_odt attr-from))
 
- 	 ;; Handle `:anchor', `:style' and `:attributes' properties.
 
- 	 (user-frame-anchor
 
- 	  (car (assoc-string (plist-get attr-plist :anchor)
 
- 			     '(("as-char") ("paragraph") ("page")) t)))
 
- 	 (user-frame-style
 
- 	  (and user-frame-anchor (plist-get attr-plist :style)))
 
- 	 (user-frame-attrs
 
- 	  (and user-frame-anchor (plist-get attr-plist :attributes)))
 
- 	 (user-frame-params
 
- 	  (list user-frame-style user-frame-attrs user-frame-anchor))
 
- 	 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
 
- 	 ;; extrac
 
- 	 ;; handle `:width', `:height' and `:scale' properties.
 
- 	 (size (org-e-odt--image-size
 
- 		src-expanded (plist-get attr-plist :width)
 
- 		(plist-get attr-plist :height)
 
- 		(plist-get attr-plist :scale) nil ;; embed-as
 
- 		"paragraph"			  ; FIXME
 
- 		))
 
- 	 (width (car size)) (height (cdr size))
 
- 	 (standalone-link-p (org-e-odt--standalone-link-p element info))
 
- 	 (embed-as (if standalone-link-p "paragraph" "as-char"))
 
- 	 (captions (org-e-odt-format-label element info 'definition))
 
- 	 (caption (car captions)) (short-caption (cdr captions))
 
- 	 (entity (concat (and caption "Captioned") embed-as "Image"))
 
- 	 ;; Check if this link was created by LaTeX-to-PNG converter.
 
- 	 (replaces (org-element-property
 
- 		    :replaces (if (not standalone-link-p) element
 
- 				(org-export-get-parent-element element))))
 
- 	 ;; If yes, note down the type of the element - LaTeX Fragment
 
- 	 ;; or LaTeX environment.  It will go in to frame title.
 
- 	 (title (and replaces (capitalize
 
- 			       (symbol-name (org-element-type replaces)))))
 
- 	 ;; If yes, note down it's contents.  It will go in to frame
 
- 	 ;; description.  This quite useful for debugging.
 
- 	 (desc (and replaces (org-element-property :value replaces))))
 
-     (org-e-odt--render-image/formula entity href width height
 
- 				     captions user-frame-params title desc)))
 
- ;;;; Links :: Math formula
 
- (defun org-e-odt-link--inline-formula (element info)
 
-   (let* ((src (let* ((type (org-element-property :type element))
 
- 		     (raw-path (org-element-property :path element)))
 
- 		(cond
 
- 		 ((file-name-absolute-p raw-path)
 
- 		  (expand-file-name raw-path))
 
- 		 (t raw-path))))
 
- 	 (src-expanded (if (file-name-absolute-p src) src
 
- 			 (expand-file-name src (file-name-directory
 
- 						(plist-get info :input-file)))))
 
- 	 (href
 
- 	  (format
 
- 	   "\n<draw:object %s xlink:href=\"%s\" xlink:type=\"simple\"/>"
 
- 	   " xlink:show=\"embed\" xlink:actuate=\"onLoad\""
 
- 	   (file-name-directory (org-e-odt--copy-formula-file src-expanded))))
 
- 	 (standalone-link-p (org-e-odt--standalone-link-p element info))
 
- 	 (embed-as (if standalone-link-p 'paragraph 'character))
 
- 	 (captions (org-e-odt-format-label element info 'definition))
 
- 	 (caption (car captions)) (short-caption (cdr captions))
 
- 	 ;; Check if this link was created by LaTeX-to-MathML
 
- 	 ;; converter.
 
- 	 (replaces (org-element-property
 
- 		    :replaces (if (not standalone-link-p) element
 
- 				(org-export-get-parent-element element))))
 
- 	 ;; If yes, note down the type of the element - LaTeX Fragment
 
- 	 ;; or LaTeX environment.  It will go in to frame title.
 
- 	 (title (and replaces (capitalize
 
- 			       (symbol-name (org-element-type replaces)))))
 
- 	 ;; If yes, note down it's contents.  It will go in to frame
 
- 	 ;; description.  This quite useful for debugging.
 
- 	 (desc (and replaces (org-element-property :value replaces)))
 
- 	 width height)
 
-     (cond
 
-      ((eq embed-as 'character)
 
-       (org-e-odt--render-image/formula "InlineFormula" href width height
 
- 				       nil nil title desc))
 
-      (t
 
-       (let* ((equation (org-e-odt--render-image/formula
 
- 			"CaptionedDisplayFormula" href width height
 
- 			captions nil title desc))
 
- 	     (label
 
- 	      (let* ((org-e-odt-category-map-alist
 
- 		      '(("__MathFormula__" "Text" "math-label" "Equation"
 
- 			 org-e-odt--enumerable-formula-p))))
 
- 		(car (org-e-odt-format-label element info 'definition)))))
 
- 	(concat equation "<text:tab/>" label))))))
 
- (defun org-e-odt--copy-formula-file (src-file)
 
-   "Returns the internal name of the file"
 
-   (let* ((target-dir (format "Formula-%04d/"
 
- 			     (incf org-e-odt-embedded-formulas-count)))
 
- 	 (target-file (concat target-dir "content.xml")))
 
-     ;; Create a directory for holding formula file.  Also enter it in
 
-     ;; to manifest.
 
-     (make-directory (concat org-e-odt-zip-dir target-dir))
 
-     (org-e-odt-create-manifest-file-entry
 
-      "application/vnd.oasis.opendocument.formula" target-dir "1.2")
 
-     ;; Copy over the formula file from user directory to zip
 
-     ;; directory.
 
-     (message "Embedding %s as %s ..." src-file target-file)
 
-     (let ((case-fold-search nil))
 
-       (cond
 
-        ;; Case 1: Mathml.
 
-        ((string-match "\\.\\(mathml\\|mml\\)\\'" src-file)
 
- 	(copy-file src-file (concat org-e-odt-zip-dir target-file) 'overwrite))
 
-        ;; Case 2: OpenDocument formula.
 
-        ((string-match "\\.odf\\'" src-file)
 
- 	(org-e-odt--zip-extract src-file "content.xml"
 
- 				(concat org-e-odt-zip-dir target-dir)))
 
-        (t (error "%s is not a formula file" src-file))))
 
-     ;; Enter the formula file in to manifest.
 
-     (org-e-odt-create-manifest-file-entry "text/xml" target-file)
 
-     target-file))
 
- ;;;; Targets
 
- (defun org-e-odt--render-image/formula (cfg-key href width height &optional
 
- 						captions user-frame-params
 
- 						&rest title-and-desc)
 
-   (let* ((frame-cfg-alist
 
- 	  ;; Each element of this alist is of the form (CFG-HANDLE
 
- 	  ;; INNER-FRAME-PARAMS OUTER-FRAME-PARAMS).
 
- 	  ;; CFG-HANDLE is the key to the alist.
 
- 	  ;; INNER-FRAME-PARAMS and OUTER-FRAME-PARAMS specify the
 
- 	  ;; frame params for INNER-FRAME and OUTER-FRAME
 
- 	  ;; respectively.  See below.
 
- 	  ;; Configurations that are meant to be applied to
 
- 	  ;; non-captioned image/formula specifies no
 
- 	  ;; OUTER-FRAME-PARAMS.
 
- 	  ;; TERMINOLOGY
 
- 	  ;; ===========
 
- 	  ;; INNER-FRAME :: Frame that directly surrounds an
 
- 	  ;;                image/formula.
 
- 	  ;; OUTER-FRAME :: Frame that encloses the INNER-FRAME.  This
 
- 	  ;;                frame also contains the caption, if any.
 
- 	  ;; FRAME-PARAMS :: List of the form (FRAME-STYLE-NAME
 
- 	  ;;                 FRAME-ATTRIBUTES FRAME-ANCHOR).  Note
 
- 	  ;;                 that these are the last three arguments
 
- 	  ;;                 to `org-e-odt--frame'.
 
- 	  ;; Note that an un-captioned image/formula requires just an
 
- 	  ;; INNER-FRAME, while a captioned image/formula requires
 
- 	  ;; both an INNER and an OUTER-FRAME.
 
- 	  '(("As-CharImage" ("OrgInlineImage" nil "as-char"))
 
- 	    ("ParagraphImage" ("OrgDisplayImage" nil "paragraph"))
 
- 	    ("PageImage" ("OrgPageImage" nil "page"))
 
- 	    ("CaptionedAs-CharImage"
 
- 	     ("OrgCaptionedImage"
 
- 	      " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
 
- 	     ("OrgInlineImage" nil "as-char"))
 
- 	    ("CaptionedParagraphImage"
 
- 	     ("OrgCaptionedImage"
 
- 	      " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
 
- 	     ("OrgImageCaptionFrame" nil "paragraph"))
 
- 	    ("CaptionedPageImage"
 
- 	     ("OrgCaptionedImage"
 
- 	      " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
 
- 	     ("OrgPageImageCaptionFrame" nil "page"))
 
- 	    ("InlineFormula" ("OrgInlineFormula" nil "as-char"))
 
- 	    ("DisplayFormula" ("OrgDisplayFormula" nil "as-char"))
 
- 	    ("CaptionedDisplayFormula"
 
- 	     ("OrgCaptionedFormula" nil "paragraph")
 
- 	     ("OrgFormulaCaptionFrame" nil "paragraph"))))
 
- 	 (caption (car captions)) (short-caption (cdr captions))
 
- 	 ;; Retrieve inner and outer frame params, from configuration.
 
- 	 (frame-cfg (assoc-string cfg-key frame-cfg-alist t))
 
- 	 (inner (nth 1 frame-cfg))
 
- 	 (outer (nth 2 frame-cfg))
 
- 	 ;; User-specified frame params (from #+ATTR_ODT spec)
 
- 	 (user user-frame-params)
 
- 	 (--merge-frame-params (function
 
- 				(lambda (default user)
 
- 				  "Merge default and user frame params."
 
- 				  (if (not user) default
 
- 				    (assert (= (length default) 3))
 
- 				    (assert (= (length user) 3))
 
- 				    (loop for u in user
 
- 					  for d in default
 
- 					  collect (or u d)))))))
 
-     (cond
 
-      ;; Case 1: Image/Formula has no caption.
 
-      ;;         There is only one frame, one that surrounds the image
 
-      ;;         or formula.
 
-      ((not caption)
 
-       ;; Merge user frame params with that from configuration.
 
-       (setq inner (funcall --merge-frame-params inner user))
 
-       (apply 'org-e-odt--frame href width height
 
- 	     (append inner title-and-desc)))
 
-      ;; Case 2: Image/Formula is captioned or labeled.
 
-      ;;         There are two frames: The inner one surrounds the
 
-      ;;         image or formula.  The outer one contains the
 
-      ;;         caption/sequence number.
 
-      (t
 
-       ;; Merge user frame params with outer frame params.
 
-       (setq outer (funcall --merge-frame-params outer user))
 
-       ;; Short caption, if specified, goes as part of inner frame.
 
-       (setq inner (let ((frame-params (copy-sequence inner)))
 
- 		    (setcar (cdr frame-params)
 
- 			    (concat
 
- 			     (cadr frame-params)
 
- 			     (when short-caption
 
- 			       (format " draw:name=\"%s\" " short-caption))))
 
- 		    frame-params))
 
-       (apply 'org-e-odt--textbox
 
- 	     (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		     "Illustration"
 
- 		     (concat
 
- 		      (apply 'org-e-odt--frame href width height
 
- 			     (append inner title-and-desc))
 
- 		      caption))
 
- 	     width height outer)))))
 
- (defun org-e-odt--enumerable-p (element info)
 
-   ;; Element should have a caption or label.
 
-   (or (org-element-property :caption element)
 
-       (org-element-property :name element)))
 
- (defun org-e-odt--enumerable-image-p (element info)
 
-   (org-e-odt--standalone-link-p
 
-    element info
 
-    ;; Paragraph should have a caption or label.  It SHOULD NOT be a
 
-    ;; replacement element. (i.e., It SHOULD NOT be a result of LaTeX
 
-    ;; processing.)
 
-    (lambda (p)
 
-      (and (not (org-element-property :replaces p))
 
- 	  (or (org-element-property :caption p)
 
- 	      (org-element-property :name p))))
 
-    ;; Link should point to an image file.
 
-    (lambda (l)
 
-      (assert (eq (org-element-type l) 'link))
 
-      (org-export-inline-image-p l org-e-odt-inline-image-rules))))
 
- (defun org-e-odt--enumerable-latex-image-p (element info)
 
-   (org-e-odt--standalone-link-p
 
-    element info
 
-    ;; Paragraph should have a caption or label.  It SHOULD also be a
 
-    ;; replacement element. (i.e., It SHOULD be a result of LaTeX
 
-    ;; processing.)
 
-    (lambda (p)
 
-      (and (org-element-property :replaces p)
 
- 	  (or (org-element-property :caption p)
 
- 	      (org-element-property :name p))))
 
-    ;; Link should point to an image file.
 
-    (lambda (l)
 
-      (assert (eq (org-element-type l) 'link))
 
-      (org-export-inline-image-p l org-e-odt-inline-image-rules))))
 
- (defun org-e-odt--enumerable-formula-p (element info)
 
-   (org-e-odt--standalone-link-p
 
-    element info
 
-    ;; Paragraph should have a caption or label.
 
-    (lambda (p)
 
-      (or (org-element-property :caption p)
 
- 	 (org-element-property :name p)))
 
-    ;; Link should point to a MathML or ODF file.
 
-    (lambda (l)
 
-      (assert (eq (org-element-type l) 'link))
 
-      (org-export-inline-image-p l org-e-odt-inline-formula-rules))))
 
- (defun org-e-odt--standalone-link-p (element info &optional
 
- 					     paragraph-predicate
 
- 					     link-predicate)
 
-   "Test if ELEMENT is a standalone link for the purpose ODT export.
 
- INFO is a plist holding contextual information.
 
- Return non-nil, if ELEMENT is of type paragraph satisfying
 
- PARAGRAPH-PREDICATE and it's sole content, save for whitespaces,
 
- is a link that satisfies LINK-PREDICATE.
 
- Return non-nil, if ELEMENT is of type link satisfying
 
- LINK-PREDICATE and it's containing paragraph satisfies
 
- PARAGRAPH-PREDICATE inaddtion to having no other content save for
 
- leading and trailing whitespaces.
 
- Return nil, otherwise."
 
-   (let ((p (case (org-element-type element)
 
- 	     (paragraph element)
 
- 	     (link (and (or (not link-predicate)
 
- 			    (funcall link-predicate element))
 
- 			(org-export-get-parent element)))
 
- 	     (t nil))))
 
-     (when (and p (eq (org-element-type p) 'paragraph))
 
-       (when (or (not paragraph-predicate)
 
- 		(funcall paragraph-predicate p))
 
- 	(let ((contents (org-element-contents p)))
 
- 	  (loop for x in contents
 
- 		with inline-image-count = 0
 
- 		always (case (org-element-type x)
 
- 			 (plain-text
 
- 			  (not (org-string-nw-p x)))
 
- 			 (link
 
- 			  (and (or (not link-predicate)
 
- 				   (funcall link-predicate x))
 
- 			       (= (incf inline-image-count) 1)))
 
- 			 (t nil))))))))
 
- (defun org-e-odt-link--infer-description (destination info)
 
-   ;; DESTINATION is a HEADLINE, a "<<target>>" or an element (like
 
-   ;; paragraph, verse-block etc) to which a "#+NAME: label" can be
 
-   ;; attached.  Note that labels that are attached to captioned
 
-   ;; entities - inline images, math formulae and tables - get resolved
 
-   ;; as part of `org-e-odt-format-label' and `org-e-odt--enumerate'.
 
-   ;; Create a cross-reference to DESTINATION but make best-efforts to
 
-   ;; create a *meaningful* description.  Check item numbers, section
 
-   ;; number and section title in that order.
 
-   ;; NOTE: Counterpart of `org-export-get-ordinal'.
 
-   ;; FIXME: Handle footnote-definition footnote-reference?
 
-   (let* ((genealogy (org-export-get-genealogy destination))
 
- 	 (data (reverse genealogy))
 
- 	 (label (case (org-element-type destination)
 
- 		  (headline
 
- 		   (format "sec-%s" (mapconcat 'number-to-string
 
- 					       (org-export-get-headline-number
 
- 						destination info) "-")))
 
- 		  (target
 
- 		   (org-element-property :value destination))
 
- 		  (t (error "FIXME: Resolve %S" destination)))))
 
-     (or
 
-      (let* ( ;; Locate top-level list.
 
- 	    (top-level-list
 
- 	     (loop for x on data
 
- 		   when (eq (org-element-type (car x)) 'plain-list)
 
- 		   return x))
 
- 	    ;; Get list item nos.
 
- 	    (item-numbers
 
- 	     (loop for (plain-list item . rest) on top-level-list by #'cddr
 
- 		   until (not (eq (org-element-type plain-list) 'plain-list))
 
- 		   collect (when (eq (org-element-property :type
 
- 							   plain-list)
 
- 				     'ordered)
 
- 			     (1+ (length (org-export-get-previous-element
 
- 					  item info t))))))
 
- 	    ;; Locate top-most listified headline.
 
- 	    (listified-headlines
 
- 	     (loop for x on data
 
- 		   when (and (eq (org-element-type (car x)) 'headline)
 
- 			     (org-export-low-level-p (car x) info))
 
- 		   return x))
 
- 	    ;; Get listified headline numbers.
 
- 	    (listified-headline-nos
 
- 	     (loop for el in listified-headlines
 
- 		   when (eq (org-element-type el) 'headline)
 
- 		   collect (when (org-export-numbered-headline-p el info)
 
- 			     (1+ (length (org-export-get-previous-element
 
- 					  el info t)))))))
 
-        ;; Combine item numbers from both the listified headlines and
 
-        ;; regular list items.
 
-        ;; Case 1: Check if all the parents of list item are numbered.
 
-        ;; If yes, link to the item proper.
 
-        (let ((item-numbers (append listified-headline-nos item-numbers)))
 
- 	 (when (and item-numbers (not (memq nil item-numbers)))
 
- 	   (format "<text:bookmark-ref text:reference-format=\"number-all-superior\" text:ref-name=\"%s\">%s</text:bookmark-ref>"
 
- 		   (org-export-solidify-link-text label)
 
- 		   (mapconcat (lambda (n) (if (not n) " "
 
- 					    (concat (number-to-string n) ".")))
 
- 			      item-numbers "")))))
 
-      ;; Case 2: Locate a regular and numbered headline in the
 
-      ;; hierarchy.  Display it's section number.
 
-      (let ((headline (loop for el in (cons destination genealogy)
 
- 			   when (and (eq (org-element-type el) 'headline)
 
- 				     (not (org-export-low-level-p el info))
 
- 				     (org-export-numbered-headline-p el info))
 
- 			   return el)))
 
-        ;; We found one.
 
-        (when headline
 
- 	 (format "<text:bookmark-ref text:reference-format=\"chapter\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
 
- 		 (org-export-solidify-link-text label)
 
- 		 (mapconcat 'number-to-string (org-export-get-headline-number
 
- 					       headline info) "."))))
 
-      ;; Case 4: Locate a regular headline in the hierarchy.  Display
 
-      ;; it's title.
 
-      (let ((headline (loop for el in (cons destination genealogy)
 
- 			   when (and (eq (org-element-type el) 'headline)
 
- 				     (not (org-export-low-level-p el info)))
 
- 			   return el)))
 
-        ;; We found one.
 
-        (when headline
 
- 	 (format "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
 
- 		 (org-export-solidify-link-text label)
 
- 		 (let ((title (org-element-property :title headline)))
 
- 		   (org-export-data title info)))))
 
-      (error "FIXME?"))))
 
- (defun org-e-odt-link (link desc info)
 
-   "Transcode a LINK object from Org to ODT.
 
- DESC is the description part of the link, or the empty string.
 
- INFO is a plist holding contextual information.  See
 
- `org-export-data'."
 
-   (let* ((type (org-element-property :type link))
 
- 	 (raw-path (org-element-property :path link))
 
- 	 ;; Ensure DESC really exists, or set it to nil.
 
- 	 (desc (and (not (string= desc "")) desc))
 
- 	 (imagep (org-export-inline-image-p
 
- 		  link org-e-odt-inline-image-rules))
 
- 	 (path (cond
 
- 		((member type '("http" "https" "ftp" "mailto"))
 
- 		 (concat type ":" raw-path))
 
- 		((string= type "file")
 
- 		 (if (file-name-absolute-p raw-path)
 
- 		     (concat "file://" (expand-file-name raw-path))
 
- 		   (concat "file://" raw-path)))
 
- 		(t raw-path)))
 
- 	 protocol)
 
-     (cond
 
-      ;; Image file.
 
-      ((and (not desc) (org-export-inline-image-p
 
- 		       link org-e-odt-inline-image-rules))
 
-       (org-e-odt-link--inline-image link info))
 
-      ;; Formula file.
 
-      ((and (not desc) (org-export-inline-image-p
 
- 		       link org-e-odt-inline-formula-rules))
 
-       (org-e-odt-link--inline-formula link info))
 
-      ;; Radio target: Transcode target's contents and use them as
 
-      ;; link's description.
 
-      ((string= type "radio")
 
-       (let ((destination (org-export-resolve-radio-link link info)))
 
- 	(when destination
 
- 	  (let ((desc (org-export-data (org-element-contents destination) info))
 
- 		(href (org-export-solidify-link-text path)))
 
- 	    (format
 
- 	     "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
 
- 	     href desc)))))
 
-      ;; Links pointing to an headline: Find destination and build
 
-      ;; appropriate referencing command.
 
-      ((member type '("custom-id" "fuzzy" "id"))
 
-       (let* ((destination (if (string= type "fuzzy")
 
- 			      (org-export-resolve-fuzzy-link link info)
 
- 			    (org-export-resolve-id-link link info))))
 
- 	(or
 
- 	 ;; Case 1: Fuzzy link points nowhere.
 
- 	 (when (null (org-element-type destination))
 
- 	   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		   "Emphasis" (or desc (org-export-data
 
- 					(org-element-property
 
- 					 :raw-link link) info))))
 
- 	 ;; Case 2: Fuzzy link points to an invisible target.  Strip it.
 
- 	 (when (eq (org-element-type destination) 'keyword) "")
 
- 	 ;; Case 3: LINK points to an headline.
 
- 	 (when (eq (org-element-type destination) 'headline)
 
- 	   ;; Case 3.1: LINK has a custom description that is
 
- 	   ;; different from headline's title.  Create a hyperlink.
 
- 	   (when (and desc
 
- 		      (let ((link-desc (org-element-contents link)))
 
- 			(not (string= (org-element-interpret-data link-desc)
 
- 				      (org-element-property :raw-value
 
- 							    destination)))))
 
- 	     (let* ((headline-no (org-export-get-headline-number
 
- 				  destination info))
 
- 		    (label (format "sec-%s" (mapconcat 'number-to-string
 
- 						       headline-no "-"))))
 
- 	       (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
 
- 		       label desc))))
 
- 	 ;; Case 4: LINK points to an Inline image, Math formula or a Table.
 
- 	 (let ((label-reference (ignore-errors (org-e-odt-format-label
 
- 						destination info 'reference))))
 
- 	   (when label-reference
 
- 	     (cond
 
- 	      ;; Case 4.1: LINK has no description. Create a
 
- 	      ;; cross-reference showing entity's sequence number.
 
- 	      ((not desc) label-reference)
 
- 	      ;; Case 4.2: LINK has description.  Insert a hyperlink
 
- 	      ;; with user-provided description.
 
- 	      (t (let* ((caption-from (case (org-element-type destination)
 
- 					(link (org-export-get-parent-element
 
- 					       destination))
 
- 					(t destination)))
 
- 			;; Get label and caption.
 
- 			(label (org-element-property :name caption-from)))
 
- 		   (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
 
- 			   (org-export-solidify-link-text label) desc))))))
 
- 	 ;; Case 5: Fuzzy link points to a TARGET.
 
- 	 (when (eq (org-element-type destination) 'target)
 
- 	   ;; Case 5.1: LINK has description.  Create a hyperlink.
 
- 	   (when desc
 
- 	     (let ((label (org-element-property :value destination)))
 
- 	       (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
 
- 		       (org-export-solidify-link-text label) desc))))
 
- 	 ;; LINK has no description. It points to either a HEADLINE, a
 
- 	 ;; TARGET or an ELEMENT with a #+NAME: LABEL attached to it.
 
- 	 ;; LINK to DESTINATION, but make a best effort to provide a
 
- 	 ;; *meaningful* description.
 
- 	 (org-e-odt-link--infer-description destination info))))
 
-      ;; Coderef: replace link with the reference name or the
 
-      ;; equivalent line number.
 
-      ((string= type "coderef")
 
-       (let* ((line-no (format "%d" (org-export-resolve-coderef path info)))
 
- 	     (href (concat "coderef-" path)))
 
- 	(format
 
- 	 (org-export-get-coderef-format path desc)
 
- 	 (format
 
- 	  "<text:bookmark-ref text:reference-format=\"number\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
 
- 	  href line-no))))
 
-      ;; Link type is handled by a special function.
 
-      ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
 
-       (funcall protocol (org-link-unescape path) desc 'odt))
 
-      ;; External link with a description part.
 
-      ((and path desc)
 
-       (let ((link-contents (org-element-contents link)))
 
- 	;; Check if description is a link to an inline image.
 
- 	(if (and (not (cdr link-contents))
 
- 		 (let ((desc-element (car link-contents)))
 
- 		   (and (eq (org-element-type desc-element) 'link)
 
- 			(org-export-inline-image-p
 
- 			 desc-element org-e-odt-inline-image-rules))))
 
- 	    ;; Format link as a clickable image.
 
- 	    (format "\n<draw:a xlink:type=\"simple\" xlink:href=\"%s\">\n%s\n</draw:a>"
 
- 		    path desc)
 
- 	  ;; Otherwise, format it as a regular link.
 
- 	  (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
 
- 		  path desc))))
 
-      ;; External link without a description part.
 
-      (path
 
-       (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
 
- 	      path path))
 
-      ;; No path, only description.  Try to do something useful.
 
-      (t (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		"Emphasis" desc)))))
 
- ;;;; Paragraph
 
- (defun org-e-odt-paragraph (paragraph contents info)
 
-   "Transcode a PARAGRAPH element from Org to ODT.
 
- CONTENTS is the contents of the paragraph, as a string.  INFO is
 
- the plist used as a communication channel."
 
-   (let* ((parent (org-export-get-parent paragraph))
 
- 	 (parent-type (org-element-type parent))
 
- 	 (style (case parent-type
 
- 		  (quote-block "Quotations")
 
- 		  (center-block "OrgCenter")
 
- 		  (footnote-definition "Footnote")
 
- 		  (t (or (org-element-property :style paragraph)
 
- 			 "Text_20_body")))))
 
-     ;; If this paragraph is a leading paragraph in an item and the
 
-     ;; item has a checkbox, splice the checkbox and paragraph contents
 
-     ;; together.
 
-     (when (and (eq (org-element-type parent) 'item)
 
-     	       (eq paragraph (car (org-element-contents parent))))
 
-       (setq contents (concat (org-e-odt--checkbox parent) contents)))
 
-     (assert style)
 
-     (format "\n<text:p text:style-name=\"%s\">%s</text:p>" style contents)))
 
- ;;;; Plain List
 
- (defun org-e-odt-plain-list (plain-list contents info)
 
-   "Transcode a PLAIN-LIST element from Org to ODT.
 
- CONTENTS is the contents of the list.  INFO is a plist holding
 
- contextual information."
 
-   (format "\n<text:list text:style-name=\"%s\" %s>\n%s</text:list>"
 
- 	  ;; Choose style based on list type.
 
- 	  (case (org-element-property :type plain-list)
 
- 	    (ordered "OrgNumberedList")
 
- 	    (unordered "OrgBulletedList")
 
- 	    (descriptive-1 "OrgDescriptionList")
 
- 	    (descriptive-2 "OrgDescriptionList"))
 
- 	  ;; If top-level list, re-start numbering.  Otherwise,
 
- 	  ;; continue numbering.
 
- 	  (format "text:continue-numbering=\"%s\""
 
- 		  (let* ((parent (org-export-get-parent plain-list)))
 
- 		    (if (and parent (eq (org-element-type parent) 'item))
 
- 			"true" "false")))
 
- 	  contents))
 
- ;;;; Plain Text
 
- (defun org-e-odt--encode-tabs-and-spaces (line)
 
-   (replace-regexp-in-string
 
-    "\\([\t]\\|\\([ ]+\\)\\)"
 
-    (lambda (s)
 
-      (cond
 
-       ((string= s "\t") "<text:tab/>")
 
-       (t (let ((n (length s)))
 
- 	   (cond
 
- 	    ((= n 1) " ")
 
- 	    ((> n 1) (concat " " (format "<text:s text:c=\"%d\"/>" (1- n))))
 
- 	    (t ""))))))
 
-    line))
 
- (defun org-e-odt--encode-plain-text (text &optional no-whitespace-filling)
 
-   (mapc
 
-    (lambda (pair)
 
-      (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
 
-    '(("&" . "&") ("<" . "<") (">" . ">")))
 
-   (if no-whitespace-filling text
 
-     (org-e-odt--encode-tabs-and-spaces text)))
 
- (defun org-e-odt-plain-text (text info)
 
-   "Transcode a TEXT string from Org to ODT.
 
- TEXT is the string to transcode.  INFO is a plist holding
 
- contextual information."
 
-   (let ((output text))
 
-     ;; Protect &, < and >.
 
-     (setq output (org-e-odt--encode-plain-text output t))
 
-     ;; Handle smart quotes.  Be sure to provide original string since
 
-     ;; OUTPUT may have been modified.
 
-     (setq output (org-export-activate-smart-quotes output :utf-8 info text))
 
-     ;; Convert special strings.
 
-     (when (plist-get info :with-special-strings)
 
-       (mapc
 
-        (lambda (pair)
 
- 	 (setq output
 
- 	       (replace-regexp-in-string (car pair) (cdr pair) output t nil)))
 
-        org-e-odt-special-string-regexps))
 
-     ;; Handle break preservation if required.
 
-     (when (plist-get info :preserve-breaks)
 
-       (setq output (replace-regexp-in-string
 
- 		    "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>\n" output t)))
 
-     ;; Return value.
 
-     output))
 
- ;;;; Planning
 
- (defun org-e-odt-planning (planning contents info)
 
-   "Transcode a PLANNING element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist used as a communication
 
- channel."
 
-   (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 	  "OrgPlanning"
 
- 	  (concat
 
- 	   (let ((closed (org-element-property :closed planning)))
 
- 	     (when closed
 
- 	       (concat
 
- 		(format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 			"OrgClosedKeyword" org-closed-string)
 
- 		(org-e-odt-timestamp closed contents info))))
 
- 	   (let ((deadline (org-element-property :deadline planning)))
 
- 	     (when deadline
 
- 	       (concat
 
- 		(format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 			"OrgDeadlineKeyword" org-deadline-string)
 
- 		(org-e-odt-timestamp deadline contents info))))
 
- 	   (let ((scheduled (org-element-property :scheduled planning)))
 
- 	     (when scheduled
 
- 	       (concat
 
- 		(format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 			"OrgScheduledKeyword" org-deadline-string)
 
- 		(org-e-odt-timestamp scheduled contents info)))))))
 
- ;;;; Property Drawer
 
- (defun org-e-odt-property-drawer (property-drawer contents info)
 
-   "Transcode a PROPERTY-DRAWER element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual
 
- information."
 
-   ;; The property drawer isn't exported but we want separating blank
 
-   ;; lines nonetheless.
 
-   "")
 
- ;;;; Quote Block
 
- (defun org-e-odt-quote-block (quote-block contents info)
 
-   "Transcode a QUOTE-BLOCK element from Org to ODT.
 
- CONTENTS holds the contents of the block.  INFO is a plist
 
- holding contextual information."
 
-   contents)
 
- ;;;; Quote Section
 
- (defun org-e-odt-quote-section (quote-section contents info)
 
-   "Transcode a QUOTE-SECTION element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (let ((value (org-remove-indentation
 
- 		(org-element-property :value quote-section))))
 
-     (when value (org-e-odt-do-format-code value))))
 
- ;;;; Section
 
- (defun org-e-odt-format-section (text style &optional name)
 
-   (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
 
-     (format "\n<text:section text:style-name=\"%s\" %s>\n%s\n</text:section>"
 
- 	    style
 
- 	    (format "text:name=\"%s\"" (or name default-name))
 
- 	    text)))
 
- (defun org-e-odt-section (section contents info) ; FIXME
 
-   "Transcode a SECTION element from Org to ODT.
 
- CONTENTS holds the contents of the section.  INFO is a plist
 
- holding contextual information."
 
-   contents)
 
- ;;;; Radio Target
 
- (defun org-e-odt-radio-target (radio-target text info)
 
-   "Transcode a RADIO-TARGET object from Org to ODT.
 
- TEXT is the text of the target.  INFO is a plist holding
 
- contextual information."
 
-   (org-e-odt--target
 
-    text (org-export-solidify-link-text
 
- 	 (org-element-property :value radio-target))))
 
- ;;;; Special Block
 
- (defun org-e-odt-special-block (special-block contents info)
 
-   "Transcode a SPECIAL-BLOCK element from Org to ODT.
 
- CONTENTS holds the contents of the block.  INFO is a plist
 
- holding contextual information."
 
-   (let ((type (downcase (org-element-property :type special-block)))
 
- 	(attributes (org-export-read-attribute :attr_odt special-block)))
 
-     (cond
 
-      ;; Annotation.
 
-      ((string= type "annotation")
 
-       (let* ((author (or (plist-get attributes :author)
 
- 			 (let ((author (plist-get info :author)))
 
- 			   (and author (org-export-data author info)))))
 
- 	     (date (or (plist-get attributes :date)
 
- 		       ;; FIXME: Is `car' right thing to do below?
 
- 		       (car (plist-get info :date)))))
 
- 	(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		"Text_20_body"
 
- 		(format "<office:annotation>\n%s\n</office:annotation>"
 
- 			(concat
 
- 			 (and author
 
- 			      (format "<dc:creator>%s</dc:creator>" author))
 
- 			 (and date
 
- 			      (format "<dc:date>%s</dc:date>"
 
- 				      (org-e-odt--format-timestamp date nil 'iso-date)))
 
- 			 contents)))))
 
-      ;; Textbox.
 
-      ((string= type "textbox")
 
-       (let ((width (plist-get attributes :width))
 
- 	    (height (plist-get attributes :height))
 
- 	    (style (plist-get attributes :style))
 
- 	    (extra (plist-get attributes :extra))
 
- 	    (anchor (plist-get attributes :anchor)))
 
- 	(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		"Text_20_body" (org-e-odt--textbox contents width height
 
- 						   style extra anchor))))
 
-      (t contents))))
 
- ;;;; Src Block
 
- (defun org-e-odt-hfy-face-to-css (fn)
 
-   "Create custom style for face FN.
 
- When FN is the default face, use it's foreground and background
 
- properties to create \"OrgSrcBlock\" paragraph style.  Otherwise
 
- use it's color attribute to create a character style whose name
 
- is obtained from FN.  Currently all attributes of FN other than
 
- color are ignored.
 
- The style name for a face FN is derived using the following
 
- operations on the face name in that order - de-dash, CamelCase
 
- and prefix with \"OrgSrc\".  For example,
 
- `font-lock-function-name-face' is associated with
 
- \"OrgSrcFontLockFunctionNameFace\"."
 
-   (let* ((css-list (hfy-face-to-style fn))
 
- 	 (style-name ((lambda (fn)
 
- 			(concat "OrgSrc"
 
- 				(mapconcat
 
- 				 'capitalize (split-string
 
- 					      (hfy-face-or-def-to-name fn) "-")
 
- 				 ""))) fn))
 
- 	 (color-val (cdr (assoc "color" css-list)))
 
- 	 (background-color-val (cdr (assoc "background" css-list)))
 
- 	 (style (and org-e-odt-create-custom-styles-for-srcblocks
 
- 		     (cond
 
- 		      ((eq fn 'default)
 
- 		       (format org-e-odt-src-block-paragraph-format
 
- 			       background-color-val color-val))
 
- 		      (t
 
- 		       (format
 
- 			"
 
- <style:style style:name=\"%s\" style:family=\"text\">
 
-   <style:text-properties fo:color=\"%s\"/>
 
-  </style:style>" style-name color-val))))))
 
-     (cons style-name style)))
 
- (defun org-e-odt-htmlfontify-string (line)
 
-   (let* ((hfy-html-quote-regex "\\([<\"&> 	]\\)")
 
- 	 (hfy-html-quote-map '(("\"" """)
 
- 			       ("<" "<")
 
- 			       ("&" "&")
 
- 			       (">" ">")
 
- 			       (" " "<text:s/>")
 
- 			       ("	" "<text:tab/>")))
 
- 	 (hfy-face-to-css 'org-e-odt-hfy-face-to-css)
 
- 	 (hfy-optimisations-1 (copy-sequence hfy-optimisations))
 
- 	 (hfy-optimisations (add-to-list 'hfy-optimisations-1
 
- 					 'body-text-only))
 
- 	 (hfy-begin-span-handler
 
- 	  (lambda (style text-block text-id text-begins-block-p)
 
- 	    (insert (format "<text:span text:style-name=\"%s\">" style))))
 
- 	 (hfy-end-span-handler (lambda nil (insert "</text:span>"))))
 
-     (org-no-warnings (htmlfontify-string line))))
 
- (defun org-e-odt-do-format-code
 
-   (code &optional lang refs retain-labels num-start)
 
-   (let* ((lang (or (assoc-default lang org-src-lang-modes) lang))
 
- 	 (lang-mode (and lang (intern (format "%s-mode" lang))))
 
- 	 (code-lines (org-split-string code "\n"))
 
- 	 (code-length (length code-lines))
 
- 	 (use-htmlfontify-p (and (functionp lang-mode)
 
- 				 org-e-odt-fontify-srcblocks
 
- 				 (require 'htmlfontify nil t)
 
- 				 (fboundp 'htmlfontify-string)))
 
- 	 (code (if (not use-htmlfontify-p) code
 
- 		 (with-temp-buffer
 
- 		   (insert code)
 
- 		   (funcall lang-mode)
 
- 		   (font-lock-fontify-buffer)
 
- 		   (buffer-string))))
 
- 	 (fontifier (if use-htmlfontify-p 'org-e-odt-htmlfontify-string
 
- 		      'org-e-odt--encode-plain-text))
 
- 	 (par-style (if use-htmlfontify-p "OrgSrcBlock"
 
- 		      "OrgFixedWidthBlock"))
 
- 	 (i 0))
 
-     (assert (= code-length (length (org-split-string code "\n"))))
 
-     (setq code
 
- 	  (org-export-format-code
 
- 	   code
 
- 	   (lambda (loc line-num ref)
 
- 	     (setq par-style
 
- 		   (concat par-style (and (= (incf i) code-length) "LastLine")))
 
- 	     (setq loc (concat loc (and ref retain-labels (format " (%s)" ref))))
 
- 	     (setq loc (funcall fontifier loc))
 
- 	     (when ref
 
- 	       (setq loc (org-e-odt--target loc (concat "coderef-" ref))))
 
- 	     (assert par-style)
 
- 	     (setq loc (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 			       par-style loc))
 
- 	     (if (not line-num) loc
 
- 	       (format "\n<text:list-item>%s\n</text:list-item>" loc)))
 
- 	   num-start refs))
 
-     (cond
 
-      ((not num-start) code)
 
-      ((= num-start 0)
 
-       (format
 
-        "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
 
-        " text:continue-numbering=\"false\"" code))
 
-      (t
 
-       (format
 
-        "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
 
-        " text:continue-numbering=\"true\"" code)))))
 
- (defun org-e-odt-format-code (element info)
 
-   (let* ((lang (org-element-property :language element))
 
- 	 ;; Extract code and references.
 
- 	 (code-info (org-export-unravel-code element))
 
- 	 (code (car code-info))
 
- 	 (refs (cdr code-info))
 
- 	 ;; Does the src block contain labels?
 
- 	 (retain-labels (org-element-property :retain-labels element))
 
- 	 ;; Does it have line numbers?
 
- 	 (num-start (case (org-element-property :number-lines element)
 
- 		      (continued (org-export-get-loc element info))
 
- 		      (new 0))))
 
-     (org-e-odt-do-format-code code lang refs retain-labels num-start)))
 
- (defun org-e-odt-src-block (src-block contents info)
 
-   "Transcode a SRC-BLOCK element from Org to ODT.
 
- CONTENTS holds the contents of the item.  INFO is a plist holding
 
- contextual information."
 
-   (let* ((lang (org-element-property :language src-block))
 
- 	 (attributes (org-export-read-attribute :attr_odt src-block))
 
- 	 (captions (org-e-odt-format-label src-block info 'definition))
 
- 	 (caption (car captions)) (short-caption (cdr captions)))
 
-     (concat
 
-      (and caption
 
- 	  (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		  "Listing" caption))
 
-      (let ((--src-block (org-e-odt-format-code src-block info)))
 
-        (if (not (plist-get attributes :textbox)) --src-block
 
- 	 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		 "Text_20_body"
 
- 		 (org-e-odt--textbox --src-block nil nil nil)))))))
 
- ;;;; Statistics Cookie
 
- (defun org-e-odt-statistics-cookie (statistics-cookie contents info)
 
-   "Transcode a STATISTICS-COOKIE object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual information."
 
-   (let ((cookie-value (org-element-property :value statistics-cookie)))
 
-     (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	    "OrgCode" cookie-value)))
 
- ;;;; Strike-Through
 
- (defun org-e-odt-strike-through (strike-through contents info)
 
-   "Transcode STRIKE-THROUGH from Org to ODT.
 
- CONTENTS is the text with strike-through markup.  INFO is a plist
 
- holding contextual information."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "Strikethrough" contents))
 
- ;;;; Subscript
 
- (defun org-e-odt-subscript (subscript contents info)
 
-   "Transcode a SUBSCRIPT object from Org to ODT.
 
- CONTENTS is the contents of the object.  INFO is a plist holding
 
- contextual information."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "OrgSubscript" contents))
 
- ;;;; Superscript
 
- (defun org-e-odt-superscript (superscript contents info)
 
-   "Transcode a SUPERSCRIPT object from Org to ODT.
 
- CONTENTS is the contents of the object.  INFO is a plist holding
 
- contextual information."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "OrgSuperscript" contents))
 
- ;;;; Table Cell
 
- (defun org-e-odt-table-style-spec (element info)
 
-   (let* ((table (org-export-get-parent-table element))
 
- 	 (table-attributes (org-export-read-attribute :attr_odt table))
 
- 	 (table-style (plist-get table-attributes :style)))
 
-     (assoc table-style org-e-odt-table-styles)))
 
- (defun org-e-odt-get-table-cell-styles (table-cell info)
 
-   "Retrieve styles applicable to a table cell.
 
- R and C are (zero-based) row and column numbers of the table
 
- cell.  STYLE-SPEC is an entry in `org-e-odt-table-styles'
 
- applicable to the current table.  It is `nil' if the table is not
 
- associated with any style attributes.
 
- Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
 
- When STYLE-SPEC is nil, style the table cell the conventional way
 
- - choose cell borders based on row and column groupings and
 
- choose paragraph alignment based on `org-col-cookies' text
 
- property.  See also
 
- `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
 
- When STYLE-SPEC is non-nil, ignore the above cookie and return
 
- styles congruent with the ODF-1.2 specification."
 
-   (let* ((table-cell-address (org-export-table-cell-address table-cell info))
 
- 	 (r (car table-cell-address)) (c (cdr table-cell-address))
 
- 	 (style-spec (org-e-odt-table-style-spec table-cell info))
 
- 	 (table-dimensions (org-export-table-dimensions
 
- 			    (org-export-get-parent-table table-cell)
 
- 			    info)))
 
-     (when style-spec
 
-       ;; LibreOffice - particularly the Writer - honors neither table
 
-       ;; templates nor custom table-cell styles.  Inorder to retain
 
-       ;; inter-operability with LibreOffice, only automatic styles are
 
-       ;; used for styling of table-cells.  The current implementation is
 
-       ;; congruent with ODF-1.2 specification and hence is
 
-       ;; future-compatible.
 
-       ;; Additional Note: LibreOffice's AutoFormat facility for tables -
 
-       ;; which recognizes as many as 16 different cell types - is much
 
-       ;; richer. Unfortunately it is NOT amenable to easy configuration
 
-       ;; by hand.
 
-       (let* ((template-name (nth 1 style-spec))
 
- 	     (cell-style-selectors (nth 2 style-spec))
 
- 	     (cell-type
 
- 	      (cond
 
- 	       ((and (cdr (assoc 'use-first-column-styles cell-style-selectors))
 
- 		     (= c 0)) "FirstColumn")
 
- 	       ((and (cdr (assoc 'use-last-column-styles cell-style-selectors))
 
- 		     (= (1+ c) (cdr table-dimensions)))
 
- 		"LastColumn")
 
- 	       ((and (cdr (assoc 'use-first-row-styles cell-style-selectors))
 
- 		     (= r 0)) "FirstRow")
 
- 	       ((and (cdr (assoc 'use-last-row-styles cell-style-selectors))
 
- 		     (= (1+ r) (car table-dimensions)))
 
- 		"LastRow")
 
- 	       ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors))
 
- 		     (= (% r 2) 1)) "EvenRow")
 
- 	       ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors))
 
- 		     (= (% r 2) 0)) "OddRow")
 
- 	       ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors))
 
- 		     (= (% c 2) 1)) "EvenColumn")
 
- 	       ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors))
 
- 		     (= (% c 2) 0)) "OddColumn")
 
- 	       (t ""))))
 
- 	(concat template-name cell-type)))))
 
- (defun org-e-odt-table-cell (table-cell contents info)
 
-   "Transcode a TABLE-CELL element from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist used as a communication
 
- channel."
 
-   (let* ((table-cell-address (org-export-table-cell-address table-cell info))
 
- 	 (r (car table-cell-address))
 
- 	 (c (cdr table-cell-address))
 
- 	 (horiz-span (or (org-export-table-cell-width table-cell info) 0))
 
- 	 (table-row (org-export-get-parent table-cell))
 
- 	 (custom-style-prefix (org-e-odt-get-table-cell-styles
 
- 			       table-cell info))
 
- 	 (paragraph-style
 
- 	  (or
 
- 	   (and custom-style-prefix
 
- 		(format "%sTableParagraph" custom-style-prefix))
 
- 	   (concat
 
- 	    (cond
 
- 	     ((and (= 1 (org-export-table-row-group table-row info))
 
- 		   (org-export-table-has-header-p
 
- 		    (org-export-get-parent-table table-row) info))
 
- 	      "OrgTableHeading")
 
- 	     ((let* ((table (org-export-get-parent-table table-cell))
 
- 		     (table-attrs (org-export-read-attribute :attr_odt table))
 
- 		     (table-header-columns (plist-get table-attrs
 
- 						      :header-columns)))
 
- 		(<= c (cond ((wholenump table-header-columns)
 
- 			     (- table-header-columns 1))
 
- 			    (table-header-columns 0)
 
- 			    (t -1))))
 
- 	      "OrgTableHeading")
 
- 	     (t "OrgTableContents"))
 
- 	    (capitalize (symbol-name (org-export-table-cell-alignment
 
- 				      table-cell info))))))
 
- 	 (cell-style-name
 
- 	  (or
 
- 	   (and custom-style-prefix (format "%sTableCell"
 
- 					    custom-style-prefix))
 
- 	   (concat
 
- 	    "OrgTblCell"
 
- 	    (when (or (org-export-table-row-starts-rowgroup-p table-row info)
 
- 		      (zerop r)) "T")
 
- 	    (when (org-export-table-row-ends-rowgroup-p table-row info) "B")
 
- 	    (when (and (org-export-table-cell-starts-colgroup-p table-cell info)
 
- 		       (not (zerop c)) ) "L"))))
 
- 	 (cell-attributes
 
- 	  (concat
 
- 	   (format " table:style-name=\"%s\"" cell-style-name)
 
- 	   (and (> horiz-span 0)
 
- 		(format " table:number-columns-spanned=\"%d\""
 
- 			(1+ horiz-span))))))
 
-     (unless contents (setq contents ""))
 
-     (concat
 
-      (assert paragraph-style)
 
-      (format "\n<table:table-cell%s>\n%s\n</table:table-cell>"
 
- 	     cell-attributes
 
- 	     (let ((table-cell-contents (org-element-contents table-cell)))
 
- 	       (if (memq (org-element-type (car table-cell-contents))
 
- 			 org-element-all-elements)
 
- 		   contents
 
- 		 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 			 paragraph-style contents))))
 
-      (let (s)
 
-        (dotimes (i horiz-span s)
 
- 	 (setq s (concat s "\n<table:covered-table-cell/>"))))
 
-      "\n")))
 
- ;;;; Table Row
 
- (defun org-e-odt-table-row (table-row contents info)
 
-   "Transcode a TABLE-ROW element from Org to ODT.
 
- CONTENTS is the contents of the row.  INFO is a plist used as a
 
- communication channel."
 
-   ;; Rules are ignored since table separators are deduced from
 
-   ;; borders of the current row.
 
-   (when (eq (org-element-property :type table-row) 'standard)
 
-     (let* ((rowgroup-tags
 
- 	    (if (and (= 1 (org-export-table-row-group table-row info))
 
- 		     (org-export-table-has-header-p
 
- 		      (org-export-get-parent-table table-row) info))
 
- 		;; If the row belongs to the first rowgroup and the
 
- 		;; table has more than one row groups, then this row
 
- 		;; belongs to the header row group.
 
- 		'("\n<table:table-header-rows>" . "\n</table:table-header-rows>")
 
- 	      ;; Otherwise, it belongs to non-header row group.
 
- 	      '("\n<table:table-rows>" . "\n</table:table-rows>"))))
 
-       (concat
 
-        ;; Does this row begin a rowgroup?
 
-        (when (org-export-table-row-starts-rowgroup-p table-row info)
 
-   	 (car rowgroup-tags))
 
-        ;; Actual table row
 
-        (format "\n<table:table-row>\n%s\n</table:table-row>" contents)
 
-        ;; Does this row end a rowgroup?
 
-        (when (org-export-table-row-ends-rowgroup-p table-row info)
 
-   	 (cdr rowgroup-tags))))))
 
- ;;;; Table
 
- (defun org-e-odt-table-first-row-data-cells (table info)
 
-   (let ((table-row
 
- 	 (org-element-map
 
- 	  table 'table-row
 
- 	  (lambda (row)
 
- 	    (unless (eq (org-element-property :type row) 'rule) row))
 
- 	  info 'first-match))
 
- 	(special-column-p (org-export-table-has-special-column-p table)))
 
-     (if (not special-column-p) (org-element-contents table-row)
 
-       (cdr (org-element-contents table-row)))))
 
- (defun org-e-odt--table (table contents info)
 
-   "Transcode a TABLE element from Org to ODT.
 
- CONTENTS is the contents of the table.  INFO is a plist holding
 
- contextual information."
 
-   (case (org-element-property :type table)
 
-     ;; Case 1: table.el doesn't support export to OD format.  Strip
 
-     ;; such tables from export.
 
-     (table.el
 
-      (prog1 nil
 
-        (message
 
- 	(concat
 
- 	 "(org-e-odt): Found table.el-type table in the source Org file."
 
- 	 "  table.el doesn't support export to ODT format."
 
- 	 "  Stripping the table from export."))))
 
-     ;; Case 2: Native Org tables.
 
-     (otherwise
 
-      (let* ((captions (org-e-odt-format-label table info 'definition))
 
- 	    (caption (car captions)) (short-caption (cdr captions))
 
- 	    (attributes (org-export-read-attribute :attr_odt table))
 
- 	    (custom-table-style (nth 1 (org-e-odt-table-style-spec table info)))
 
- 	    (table-column-specs
 
- 	     (function
 
- 	      (lambda (table info)
 
- 		(let* ((table-style (or custom-table-style "OrgTable"))
 
- 		       (column-style (format "%sColumn" table-style)))
 
- 		  (mapconcat
 
- 		   (lambda (table-cell)
 
- 		     (let ((width (1+ (or (org-export-table-cell-width
 
- 					   table-cell info) 0)))
 
- 			   (s (format
 
- 			       "\n<table:table-column table:style-name=\"%s\"/>"
 
- 			       column-style))
 
- 			   out)
 
- 		       (dotimes (i width out) (setq out (concat s out)))))
 
- 		   (org-e-odt-table-first-row-data-cells table info) "\n"))))))
 
-        (concat
 
- 	;; caption.
 
- 	(when caption
 
- 	  (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 		  "Table" caption))
 
- 	;; begin table.
 
- 	(let* ((automatic-name
 
- 		(org-e-odt-add-automatic-style "Table" attributes)))
 
- 	  (format
 
- 	   "\n<table:table table:style-name=\"%s\"%s>"
 
- 	   (or custom-table-style (cdr automatic-name) "OrgTable")
 
- 	   (concat (when short-caption
 
- 		     (format " table:name=\"%s\"" short-caption)))))
 
- 	;; column specification.
 
- 	(funcall table-column-specs table info)
 
- 	;; actual contents.
 
- 	"\n" contents
 
- 	;; end table.
 
- 	"</table:table>")))))
 
- (defun org-e-odt-table (table contents info)
 
-   "Transcode a TABLE element from Org to ODT.
 
- CONTENTS is the contents of the table.  INFO is a plist holding
 
- contextual information.
 
- Use `org-e-odt--table' to typeset the table.  Handle details
 
- pertaining to indentation here."
 
-   (let* ((--element-preceded-by-table-p
 
- 	  (function
 
- 	   (lambda (element info)
 
- 	     (loop for el in (org-export-get-previous-element element info t)
 
- 		   thereis (eq (org-element-type el) 'table)))))
 
- 	 (--walk-list-genealogy-and-collect-tags
 
- 	  (function
 
- 	   (lambda (table info)
 
- 	     (let* ((genealogy (org-export-get-genealogy table))
 
- 		    (list-genealogy
 
- 		     (when (eq (org-element-type (car genealogy)) 'item)
 
- 		       (loop for el in genealogy
 
- 			     when (memq (org-element-type el)
 
- 					'(item plain-list))
 
- 			     collect el)))
 
- 		    (llh-genealogy
 
- 		     (apply 'nconc
 
- 			    (loop for el in genealogy
 
- 				  when (and (eq (org-element-type el) 'headline)
 
- 					    (org-export-low-level-p el info))
 
- 				  collect
 
- 				  (list el
 
- 					(assq 'headline
 
- 					      (org-element-contents
 
- 					       (org-export-get-parent el)))))))
 
- 		    parent-list)
 
- 	       (nconc
 
- 		;; Handle list genealogy.
 
- 		(loop for el in list-genealogy collect
 
- 		      (case (org-element-type el)
 
- 			(plain-list
 
- 			 (setq parent-list el)
 
- 			 (cons "</text:list>"
 
- 			       (format "\n<text:list text:style-name=\"%s\" %s>"
 
- 				       (case (org-element-property :type el)
 
- 					 (ordered "OrgNumberedList")
 
- 					 (unordered "OrgBulletedList")
 
- 					 (descriptive-1 "OrgDescriptionList")
 
- 					 (descriptive-2 "OrgDescriptionList"))
 
- 				       "text:continue-numbering=\"true\"")))
 
- 			(item
 
- 			 (cond
 
- 			  ((not parent-list)
 
- 			   (if (funcall --element-preceded-by-table-p table info)
 
- 			       '("</text:list-header>" . "<text:list-header>")
 
- 			     '("</text:list-item>" . "<text:list-header>")))
 
- 			  ((funcall --element-preceded-by-table-p
 
- 				    parent-list info)
 
- 			   '("</text:list-header>" . "<text:list-header>"))
 
- 			  (t '("</text:list-item>" . "<text:list-item>"))))))
 
- 		;; Handle low-level headlines.
 
- 		(loop for el in llh-genealogy
 
- 		      with step = 'item collect
 
- 		      (case step
 
- 			(plain-list
 
- 			 (setq step 'item) ; Flip-flop
 
- 			 (setq parent-list el)
 
- 			 (cons "</text:list>"
 
- 			       (format "\n<text:list text:style-name=\"%s\" %s>"
 
- 				       (if (org-export-numbered-headline-p
 
- 					    el info)
 
- 					   "OrgNumberedList"
 
- 					 "OrgBulletedList")
 
- 				       "text:continue-numbering=\"true\"")))
 
- 			(item
 
- 			 (setq step 'plain-list) ; Flip-flop
 
- 			 (cond
 
- 			  ((not parent-list)
 
- 			   (if (funcall --element-preceded-by-table-p table info)
 
- 			       '("</text:list-header>" . "<text:list-header>")
 
- 			     '("</text:list-item>" . "<text:list-header>")))
 
- 			  ((let ((section? (org-export-get-previous-element
 
- 					    parent-list info)))
 
- 			     (and section?
 
- 				  (eq (org-element-type section?) 'section)
 
- 				  (assq 'table (org-element-contents section?))))
 
- 			   '("</text:list-header>" . "<text:list-header>"))
 
- 			  (t
 
- 			   '("</text:list-item>" . "<text:list-item>")))))))))))
 
- 	 (close-open-tags (funcall --walk-list-genealogy-and-collect-tags
 
- 				   table info)))
 
-     ;; OpenDocument schema does not permit table to occur within a
 
-     ;; list item.
 
-     ;; One solution - the easiest and lightweight, in terms of
 
-     ;; implementation - is to put the table in an indented text box
 
-     ;; and make the text box part of the list-item.  Unfortunately if
 
-     ;; the table is big and spans multiple pages, the text box could
 
-     ;; overflow.  In this case, the following attribute will come
 
-     ;; handy.
 
-     ;; ,---- From OpenDocument-v1.1.pdf
 
-     ;; | 15.27.28 Overflow behavior
 
-     ;; |
 
-     ;; | For text boxes contained within text document, the
 
-     ;; | style:overflow-behavior property specifies the behavior of text
 
-     ;; | boxes where the containing text does not fit into the text
 
-     ;; | box.
 
-     ;; |
 
-     ;; | If the attribute's value is clip, the text that does not fit
 
-     ;; | into the text box is not displayed.
 
-     ;; |
 
-     ;; | If the attribute value is auto-create-new-frame, a new frame
 
-     ;; | will be created on the next page, with the same position and
 
-     ;; | dimensions of the original frame.
 
-     ;; |
 
-     ;; | If the style:overflow-behavior property's value is
 
-     ;; | auto-create-new-frame and the text box has a minimum width or
 
-     ;; | height specified, then the text box will grow until the page
 
-     ;; | bounds are reached before a new frame is created.
 
-     ;; `----
 
-     ;; Unfortunately, LibreOffice-3.4.6 doesn't honor
 
-     ;; auto-create-new-frame property and always resorts to clipping
 
-     ;; the text box.  This results in table being truncated.
 
-     ;; So we solve the problem the hard (and fun) way using list
 
-     ;; continuations.
 
-     ;; The problem only becomes more interesting if you take in to
 
-     ;; account the following facts:
 
-     ;;
 
-     ;; - Description lists are simulated as plain lists.
 
-     ;; - Low-level headlines can be listified.
 
-     ;; - In Org-mode, a table can occur not only as a regular list
 
-     ;;   item, but also within description lists and low-level
 
-     ;;   headlines.
 
-     ;; See `org-e-odt-translate-description-lists' and
 
-     ;; `org-e-odt-translate-low-level-headlines' for how this is
 
-     ;; tackled.
 
-     (concat "\n"
 
- 	    ;; Discontinue the list.
 
- 	    (mapconcat 'car close-open-tags "\n")
 
- 	    ;; Put the table in an indented section.
 
- 	    (let* ((table (org-e-odt--table table contents info))
 
- 		   (level (/ (length (mapcar 'car close-open-tags)) 2))
 
- 		   (style (format "OrgIndentedSection-Level-%d" level)))
 
- 	      (when table (org-e-odt-format-section table style)))
 
- 	    ;; Continue the list.
 
- 	    (mapconcat 'cdr (nreverse close-open-tags) "\n"))))
 
- ;;;; Target
 
- (defun org-e-odt-target (target contents info)
 
-   "Transcode a TARGET object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist holding contextual
 
- information."
 
-   (let ((value (org-element-property :value target)))
 
-     (org-e-odt--target "" (org-export-solidify-link-text value))))
 
- ;;;; Timestamp
 
- (defun org-e-odt-timestamp (timestamp contents info)
 
-   "Transcode a TIMESTAMP object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist used as a communication
 
- channel."
 
-   (let* ((raw-value (org-element-property :raw-value timestamp))
 
-   	 (type (org-element-property :type timestamp)))
 
-     (if (not org-e-odt-use-date-fields)
 
- 	(let ((value (org-e-odt-plain-text
 
- 		      (org-export-translate-timestamp timestamp) info)))
 
- 	  (case (org-element-property :type timestamp)
 
- 	    ((active active-range)
 
- 	     (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		     "OrgActiveTimestamp" value))
 
- 	    ((inactive inactive-range)
 
- 	     (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		     "OrgInactiveTimestamp" value))
 
- 	    (otherwise value)))
 
-       (case type
 
- 	(active
 
- 	 (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		 "OrgActiveTimestamp"
 
- 		 (format "<%s>" (org-e-odt--format-timestamp timestamp))))
 
- 	(inactive
 
- 	 (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		 "OrgInactiveTimestamp"
 
- 		 (format "[%s]" (org-e-odt--format-timestamp timestamp))))
 
- 	(active-range
 
- 	 (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		 "OrgActiveTimestamp"
 
- 		 (format "<%s>–<%s>"
 
- 			 (org-e-odt--format-timestamp timestamp)
 
- 			 (org-e-odt--format-timestamp timestamp 'end))))
 
- 	(inactive-range
 
- 	 (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		 "OrgInactiveTimestamp"
 
- 		 (format "[%s]–[%s]"
 
- 			 (org-e-odt--format-timestamp timestamp)
 
- 			 (org-e-odt--format-timestamp timestamp 'end))))
 
- 	(otherwise
 
- 	 (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 		 "OrgDiaryTimestamp"
 
- 		 (org-e-odt-plain-text (org-export-translate-timestamp
 
- 					timestamp) info)))))))
 
- ;;;; Underline
 
- (defun org-e-odt-underline (underline contents info)
 
-   "Transcode UNDERLINE from Org to ODT.
 
- CONTENTS is the text with underline markup.  INFO is a plist
 
- holding contextual information."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "Underline" contents))
 
- ;;;; Verbatim
 
- (defun org-e-odt-verbatim (verbatim contents info)
 
-   "Transcode a VERBATIM object from Org to ODT.
 
- CONTENTS is nil.  INFO is a plist used as a communication
 
- channel."
 
-   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 
- 	  "OrgCode" (org-element-property :value verbatim)))
 
- ;;;; Verse Block
 
- (defun org-e-odt-verse-block (verse-block contents info)
 
-   "Transcode a VERSE-BLOCK element from Org to ODT.
 
- CONTENTS is verse block contents.  INFO is a plist holding
 
- contextual information."
 
-   ;; Add line breaks to each line of verse.
 
-   (setq contents (replace-regexp-in-string
 
- 		  "\\(<text:line-break/>\\)?[ \t]*\n"
 
- 		  "<text:line-break/>" contents))
 
-   ;; Replace tabs and spaces.
 
-   (setq contents (org-e-odt--encode-tabs-and-spaces contents))
 
-   ;; Surround it in a verse environment.
 
-   (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 
- 	  "OrgVerse" contents))
 
- ;;; Filters
 
- ;;;; LaTeX fragments
 
- (defun org-e-odt--translate-latex-fragments (tree backend info)
 
-   (let ((processing-type (plist-get info :LaTeX-fragments))
 
- 	(count 0))
 
-     ;; Normalize processing-type to one of dvipng, mathml or verbatim.
 
-     ;; If the desired converter is not available, force verbatim
 
-     ;; processing.
 
-     (case processing-type
 
-       ((t mathml)
 
-        (if (and (fboundp 'org-format-latex-mathml-available-p)
 
- 		(org-format-latex-mathml-available-p))
 
- 	   (setq processing-type 'mathml)
 
- 	 (message "LaTeX to MathML converter not available.")
 
- 	 (setq processing-type 'verbatim)))
 
-       (dvipng
 
-        (unless (and (org-check-external-command "latex" "" t)
 
- 		    (org-check-external-command "dvipng" "" t))
 
- 	 (message "LaTeX to PNG converter not available.")
 
- 	 (setq processing-type 'verbatim)))
 
-       (otherwise
 
-        (message "Unknown LaTeX option.  Forcing verbatim.")
 
-        (setq processing-type 'verbatim)))
 
-     ;; Store normalized value for later use.
 
-     (when (plist-get info :LaTeX-fragments)
 
-       (plist-put info :LaTeX-fragments processing-type))
 
-     (message "Formatting LaTeX using %s" processing-type)
 
-     ;; Convert `latex-fragment's and `latex-environment's.
 
-     (when (memq processing-type '(mathml dvipng))
 
-       (org-element-map
 
-        tree '(latex-fragment latex-environment)
 
-        (lambda (latex-*)
 
- 	 (incf count)
 
- 	 (let* ((latex-frag (org-element-property :value latex-*))
 
- 		(input-file (plist-get info :input-file))
 
- 		(cache-dir (file-name-directory input-file))
 
- 		(cache-subdir (concat
 
- 			       (case processing-type
 
- 				 (dvipng "ltxpng/")
 
- 				 (mathml "ltxmathml/"))
 
- 			       (file-name-sans-extension
 
- 				(file-name-nondirectory input-file))))
 
- 		(display-msg
 
- 		 (case processing-type
 
- 		   (dvipng (format "Creating LaTeX Image %d..." count))
 
- 		   (mathml (format "Creating MathML snippet %d..." count))))
 
- 	 	;; Get an Org-style link to PNG image or the MathML
 
- 		;; file.
 
- 		(org-link
 
- 		 (let ((link (with-temp-buffer
 
- 			       (insert latex-frag)
 
- 			       (org-format-latex cache-subdir cache-dir
 
- 						 nil display-msg
 
- 						 nil nil processing-type)
 
- 			       (buffer-substring-no-properties
 
- 				(point-min) (point-max)))))
 
- 		   (if (not (string-match "file:\\([^]]*\\)" link))
 
- 		       (prog1 nil (message "LaTeX Conversion failed."))
 
- 		     link))))
 
- 	   (when org-link
 
- 	     ;; Conversion succeeded.  Parse above Org-style link to a
 
- 	     ;; `link' object.
 
- 	     (let* ((link (car (org-element-map (with-temp-buffer
 
- 						  (org-mode)
 
- 						  (insert org-link)
 
- 						  (org-element-parse-buffer))
 
- 						'link 'identity))))
 
- 	       ;; Orphan the link.
 
- 	       (org-element-put-property link :parent nil)
 
- 	       (let* (
 
- 		      (replacement
 
- 		       (case (org-element-type latex-*)
 
- 			 ;; Case 1: LaTeX environment.
 
- 			 ;; Mimic a "standalone image or formula" by
 
- 			 ;; enclosing the `link' in a `paragraph'.
 
- 			 ;; Copy over original attributes, captions to
 
- 			 ;; the enclosing paragraph.
 
-  			 (latex-environment
 
- 			  (org-element-adopt-elements
 
- 			   (list 'paragraph
 
- 				 (list :style "OrgFormula"
 
- 				       :name (org-element-property :name
 
- 								   latex-*)
 
- 				       :caption (org-element-property :caption
 
- 								      latex-*)))
 
- 			   link))
 
- 			 ;; Case 2: LaTeX fragment.
 
- 			 ;; No special action.
 
- 			 (latex-fragment link))))
 
- 		 ;; Note down the object that link replaces.
 
- 		 (org-element-put-property replacement :replaces
 
- 					   (list (org-element-type latex-*)
 
- 						 (list :value latex-frag)))
 
- 		 ;; Replace now.
 
- 		 (org-element-set-element latex-* replacement))))))
 
-        info)))
 
-   tree)
 
- ;;;; Description lists
 
- ;; This translator is necessary to handle indented tables in a uniform
 
- ;; manner.  See comment in `org-e-odt--table'.
 
- (defun org-e-odt--translate-description-lists (tree backend info)
 
-   ;; OpenDocument has no notion of a description list.  So simulate it
 
-   ;; using plain lists.  Description lists in the exported document
 
-   ;; are typeset in the same manner as they are in a typical HTML
 
-   ;; document.
 
-   ;;
 
-   ;; Specifically, a description list like this:
 
-   ;;
 
-   ;;     ,----
 
-   ;;     | - term-1 :: definition-1
 
-   ;;     | - term-2 :: definition-2
 
-   ;;     `----
 
-   ;;
 
-   ;; gets translated in to the following form:
 
-   ;;
 
-   ;;     ,----
 
-   ;;     | - term-1
 
-   ;;     |   - definition-1
 
-   ;;     | - term-2
 
-   ;;     |   - definition-2
 
-   ;;     `----
 
-   ;;
 
-   ;; Further effect is achieved by fixing the OD styles as below:
 
-   ;;
 
-   ;; 1. Set the :type property of the simulated lists to
 
-   ;;    `descriptive-1' and `descriptive-2'.  Map these to list-styles
 
-   ;;    that has *no* bullets whatsoever.
 
-   ;;
 
-   ;; 2. The paragraph containing the definition term is styled to be
 
-   ;;    in bold.
 
-   ;;
 
-   (org-element-map
 
-    tree 'plain-list
 
-    (lambda (el)
 
-      (when (equal (org-element-property :type el) 'descriptive)
 
-        (org-element-set-element
 
- 	el
 
- 	(apply 'org-element-adopt-elements
 
- 	       (list 'plain-list (list :type 'descriptive-1))
 
- 	       (mapcar
 
- 		(lambda (item)
 
- 		  (org-element-adopt-elements
 
- 		   (list 'item (list :checkbox (org-element-property
 
- 						:checkbox item)))
 
- 		   (list 'paragraph (list :style "Text_20_body_20_bold")
 
- 			 (or (org-element-property :tag item) "(no term)"))
 
- 		   (org-element-adopt-elements
 
- 		    (list 'plain-list (list :type 'descriptive-2))
 
- 		    (apply 'org-element-adopt-elements
 
- 			   (list 'item nil)
 
- 			   (org-element-contents item)))))
 
- 		(org-element-contents el)))))
 
-      nil)
 
-    info)
 
-   tree)
 
- ;;;; List tables
 
- ;; Lists that are marked with attribute `:list-table' are called as
 
- ;; list tables.  They will be rendered as a table within the exported
 
- ;; document.
 
- ;; Consider an example.  The following list table
 
- ;;
 
- ;; #+attr_odt :list-table t
 
- ;; - Row 1
 
- ;;   - 1.1
 
- ;;   - 1.2
 
- ;;   - 1.3
 
- ;; - Row 2
 
- ;;   - 2.1
 
- ;;   - 2.2
 
- ;;   - 2.3
 
- ;;
 
- ;; will be exported as though it were an Org table like the one show
 
- ;; below.
 
- ;;
 
- ;; | Row 1 | 1.1 | 1.2 | 1.3 |
 
- ;; | Row 2 | 2.1 | 2.2 | 2.3 |
 
- ;;
 
- ;; Note that org-tables are NOT multi-line and each line is mapped to
 
- ;; a unique row in the exported document.  So if an exported table
 
- ;; needs to contain a single paragraph (with copious text) it needs to
 
- ;; be typed up in a single line.  Editing such long lines using the
 
- ;; table editor will be a cumbersome task.  Furthermore inclusion of
 
- ;; multi-paragraph text in a table cell is well-nigh impossible.
 
- ;;
 
- ;; A LIST-TABLE circumvents above problems.
 
- ;;
 
- ;; Note that in the example above the list items could be paragraphs
 
- ;; themselves and the list can be arbitrarily deep.
 
- ;;
 
- ;; Inspired by following thread:
 
- ;; https://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01101.html
 
- ;; Translate lists to tables
 
- (defun org-e-odt--translate-list-tables (tree backend info)
 
-   (org-element-map
 
-    tree 'plain-list
 
-    (lambda (l1-list)
 
-      (when (org-export-read-attribute :attr_odt l1-list :list-table)
 
-        ;; Replace list with table.
 
-        (org-element-set-element
 
- 	l1-list
 
- 	;; Build replacement table.
 
- 	(apply 'org-element-adopt-elements
 
- 	       (list 'table '(:type org :attr_odt (":style \"GriddedTable\"")))
 
- 	       (org-element-map
 
- 		l1-list
 
- 		'item
 
- 		(lambda (l1-item)
 
- 		  (let* ((l1-item-contents (org-element-contents l1-item))
 
- 			 l1-item-leading-text l2-list)
 
- 		    ;; Remove Level-2 list from the Level-item.  It
 
- 		    ;; will be subsequently attached as table-cells.
 
- 		    (let ((cur l1-item-contents) prev)
 
- 		      (while (and cur (not (eq (org-element-type (car cur))
 
- 					       'plain-list)))
 
- 			(setq prev cur)
 
- 			(setq cur (cdr cur)))
 
- 		      (when prev
 
- 			(setcdr prev nil)
 
- 			(setq l2-list (car cur)))
 
- 		      (setq l1-item-leading-text l1-item-contents))
 
- 		    ;; Level-1 items start a table row.
 
- 		    (apply 'org-element-adopt-elements
 
- 			   (list 'table-row (list :type 'standard))
 
- 			   ;;  Leading text of level-1 item define the
 
- 			   ;;  first table-cell.
 
- 			   (apply 'org-element-adopt-elements
 
- 				  (list 'table-cell nil)
 
- 				  l1-item-leading-text)
 
- 			   ;; Level-2 items define subsequent
 
- 			   ;; table-cells of the row.
 
- 			   (org-element-map
 
- 			    l2-list
 
- 			    'item
 
- 			    (lambda (l2-item)
 
- 			      (apply 'org-element-adopt-elements
 
- 				     (list 'table-cell nil)
 
- 				     (org-element-contents l2-item)))
 
- 			    info nil 'item))))
 
- 		info nil 'item))))
 
-      nil)
 
-    info)
 
-   tree)
 
- ;;; Interactive functions
 
- (defun org-e-odt-create-manifest-file-entry (&rest args)
 
-   (push args org-e-odt-manifest-file-entries))
 
- (defun org-e-odt-write-manifest-file ()
 
-   (make-directory (concat org-e-odt-zip-dir "META-INF"))
 
-   (let ((manifest-file (concat org-e-odt-zip-dir "META-INF/manifest.xml")))
 
-     (with-current-buffer
 
- 	(let ((nxml-auto-insert-xml-declaration-flag nil))
 
- 	  (find-file-noselect manifest-file t))
 
-       (insert
 
-        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
 
-      <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
 
-       (mapc
 
-        (lambda (file-entry)
 
- 	 (let* ((version (nth 2 file-entry))
 
- 		(extra (if (not version) ""
 
- 			 (format " manifest:version=\"%s\"" version))))
 
- 	   (insert
 
- 	    (format org-e-odt-manifest-file-entry-tag
 
- 		    (nth 0 file-entry) (nth 1 file-entry) extra))))
 
-        org-e-odt-manifest-file-entries)
 
-       (insert "\n</manifest:manifest>"))))
 
- (defmacro org-e-odt--export-wrap (out-file &rest body)
 
-   `(let* ((--out-file ,out-file)
 
- 	  (out-file-type (file-name-extension --out-file))
 
- 	  (org-e-odt-xml-files '("META-INF/manifest.xml" "content.xml"
 
- 				 "meta.xml" "styles.xml"))
 
- 	  ;; Initialize temporary workarea.  All files that end up in
 
- 	  ;; the exported document get parked/created here.
 
- 	  (org-e-odt-zip-dir (file-name-as-directory
 
- 			      (make-temp-file (format "%s-" out-file-type) t)))
 
- 	  (org-e-odt-manifest-file-entries nil)
 
- 	  (--cleanup-xml-buffers
 
- 	   (function
 
- 	    (lambda nil
 
- 	      ;; Kill all XML buffers.
 
- 	      (mapc (lambda (file)
 
- 		      (let ((buf (find-buffer-visiting
 
- 				  (concat org-e-odt-zip-dir file))))
 
- 			(when buf
 
- 			  (with-current-buffer buf
 
- 			    (set-buffer-modified-p nil)
 
- 			    (kill-buffer buf)))))
 
- 		    org-e-odt-xml-files)
 
- 	      ;; Delete temporary directory and also other embedded
 
- 	      ;; files that get copied there.
 
- 	      (delete-directory org-e-odt-zip-dir t)))))
 
-      (org-condition-case-unless-debug err
 
- 	 (progn
 
- 	   (unless (executable-find "zip")
 
- 	     ;; Not at all OSes ship with zip by default
 
- 	     (error "Executable \"zip\" needed for creating OpenDocument files"))
 
- 	   ;; Do export.  This creates a bunch of xml files ready to be
 
- 	   ;; saved and zipped.
 
- 	   (progn ,@body)
 
- 	   ;; Create a manifest entry for content.xml.
 
- 	   (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
 
- 	   ;; Write mimetype file
 
- 	   (let* ((mimetypes
 
- 		   '(("odt" . "application/vnd.oasis.opendocument.text")
 
- 		     ("odf" .  "application/vnd.oasis.opendocument.formula")))
 
- 		  (mimetype (cdr (assoc-string out-file-type mimetypes t))))
 
- 	     (unless mimetype
 
- 	       (error "Unknown OpenDocument backend %S" out-file-type))
 
- 	     (write-region mimetype nil (concat org-e-odt-zip-dir "mimetype"))
 
- 	     (org-e-odt-create-manifest-file-entry mimetype "/" "1.2"))
 
- 	   ;; Write out the manifest entries before zipping
 
- 	   (org-e-odt-write-manifest-file)
 
- 	   ;; Save all XML files.
 
- 	   (mapc (lambda (file)
 
- 		   (let ((buf (find-buffer-visiting
 
- 			       (concat org-e-odt-zip-dir file))))
 
- 		     (when buf
 
- 		       (with-current-buffer buf
 
- 			 ;; Prettify output if needed.
 
- 			 (when org-e-odt-prettify-xml
 
- 			   (indent-region (point-min) (point-max)))
 
- 			 (save-buffer 0)))))
 
- 		 org-e-odt-xml-files)
 
- 	   ;; Run zip.
 
- 	   (let* ((target --out-file)
 
- 		  (target-name (file-name-nondirectory target))
 
- 		  (cmds `(("zip" "-mX0" ,target-name "mimetype")
 
- 			  ("zip" "-rmTq" ,target-name "."))))
 
- 	     ;; If a file with same name as the desired output file
 
- 	     ;; exists, remove it.
 
- 	     (when (file-exists-p target)
 
- 	       (delete-file target))
 
- 	     ;; Zip up the xml files.
 
- 	     (let ((coding-system-for-write 'no-conversion) exitcode err-string)
 
- 	       (message "Creating ODT file...")
 
- 	       ;; Switch temporarily to content.xml.  This way Zip
 
- 	       ;; process will inherit `org-e-odt-zip-dir' as the current
 
- 	       ;; directory.
 
- 	       (with-current-buffer
 
- 		   (find-file-noselect (concat org-e-odt-zip-dir "content.xml") t)
 
- 		 (mapc
 
- 		  (lambda (cmd)
 
- 		    (message "Running %s" (mapconcat 'identity cmd " "))
 
- 		    (setq err-string
 
- 			  (with-output-to-string
 
- 			    (setq exitcode
 
- 				  (apply 'call-process (car cmd)
 
- 					 nil standard-output nil (cdr cmd)))))
 
- 		    (or (zerop exitcode)
 
- 			(error (concat "Unable to create OpenDocument file."
 
- 				       (format "  Zip failed with error (%s)"
 
- 					       err-string)))))
 
- 		  cmds)))
 
- 	     ;; Move the zip file from temporary work directory to
 
- 	     ;; user-mandated location.
 
- 	     (rename-file (concat org-e-odt-zip-dir target-name) target)
 
- 	     (message "Created %s" (expand-file-name target))
 
- 	     ;; Cleanup work directory and work files.
 
- 	     (funcall --cleanup-xml-buffers)
 
- 	     ;; Open the OpenDocument file in archive-mode for
 
- 	     ;; examination.
 
- 	     (find-file-noselect target t)
 
- 	     ;; Return exported file.
 
- 	     (cond
 
- 	      ;; Case 1: Conversion desired on exported file.  Run the
 
- 	      ;; converter on the OpenDocument file.  Return the
 
- 	      ;; converted file.
 
- 	      (org-e-odt-preferred-output-format
 
- 	       (or (org-e-odt-convert target org-e-odt-preferred-output-format)
 
- 		   target))
 
- 	      ;; Case 2: No further conversion.  Return exported
 
- 	      ;; OpenDocument file.
 
- 	      (t target))))
 
-        (error
 
- 	;; Cleanup work directory and work files.
 
- 	(funcall --cleanup-xml-buffers)
 
- 	(message "OpenDocument export failed: %s"
 
- 		 (error-message-string err))))))
 
- ;;;; Export to OpenDocument formula
 
- ;;;###autoload
 
- (defun org-e-odt-export-as-odf (latex-frag &optional odf-file)
 
-   "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
 
- Use `org-create-math-formula' to convert LATEX-FRAG first to
 
- MathML.  When invoked as an interactive command, use
 
- `org-latex-regexps' to infer LATEX-FRAG from currently active
 
- region.  If no LaTeX fragments are found, prompt for it.  Push
 
- MathML source to kill ring, if `org-export-copy-to-kill-ring' is
 
- non-nil."
 
-   (interactive
 
-    `(,(let (frag)
 
- 	(setq frag (and (setq frag (and (region-active-p)
 
- 					(buffer-substring (region-beginning)
 
- 							  (region-end))))
 
- 			(loop for e in org-latex-regexps
 
- 			      thereis (when (string-match (nth 1 e) frag)
 
- 					(match-string (nth 2 e) frag)))))
 
- 	(read-string "LaTeX Fragment: " frag nil frag))
 
-      ,(let ((odf-filename (expand-file-name
 
- 			   (concat
 
- 			    (file-name-sans-extension
 
- 			     (or (file-name-nondirectory buffer-file-name)))
 
- 			    "." "odf")
 
- 			   (file-name-directory buffer-file-name))))
 
- 	(read-file-name "ODF filename: " nil odf-filename nil
 
- 			(file-name-nondirectory odf-filename)))))
 
-   (let ((filename (or odf-file
 
- 		      (expand-file-name
 
- 		       (concat
 
- 			(file-name-sans-extension
 
- 			 (or (file-name-nondirectory buffer-file-name)))
 
- 			"." "odf")
 
- 		       (file-name-directory buffer-file-name)))))
 
-     (org-e-odt--export-wrap
 
-      filename
 
-      (let* ((buffer (progn
 
- 		      (require 'nxml-mode)
 
- 		      (let ((nxml-auto-insert-xml-declaration-flag nil))
 
- 			(find-file-noselect (concat org-e-odt-zip-dir
 
- 						    "content.xml") t))))
 
- 	    (coding-system-for-write 'utf-8)
 
- 	    (save-buffer-coding-system 'utf-8))
 
-        (set-buffer buffer)
 
-        (set-buffer-file-coding-system coding-system-for-write)
 
-        (let ((mathml (org-create-math-formula latex-frag)))
 
- 	 (unless mathml (error "No Math formula created"))
 
- 	 (insert mathml)
 
- 	 ;; Add MathML to kill ring, if needed.
 
- 	 (when org-export-copy-to-kill-ring
 
- 	   (org-kill-new (buffer-string))))))))
 
- ;;;###autoload
 
- (defun org-e-odt-export-as-odf-and-open ()
 
-   "Export LaTeX fragment as OpenDocument formula and immediately open it.
 
- Use `org-e-odt-export-as-odf' to read LaTeX fragment and OpenDocument
 
- formula file."
 
-   (interactive)
 
-   (org-open-file (call-interactively 'org-e-odt-export-as-odf) 'system))
 
- ;;;; Export to OpenDocument Text
 
- ;;;###autoload
 
- (defun org-e-odt-export-to-odt (&optional async subtreep visible-only ext-plist)
 
-   "Export current buffer to a ODT file.
 
- If narrowing is active in the current buffer, only export its
 
- narrowed part.
 
- If a region is active, export that region.
 
- A non-nil optional argument ASYNC means the process should happen
 
- asynchronously.  The resulting file should be accessible through
 
- the `org-export-stack' interface.
 
- When optional argument SUBTREEP is non-nil, export the sub-tree
 
- at point, extracting information from the headline properties
 
- first.
 
- When optional argument VISIBLE-ONLY is non-nil, don't export
 
- contents of hidden elements.
 
- EXT-PLIST, when provided, is a property list with external
 
- parameters overriding Org default settings, but still inferior to
 
- file-local settings.
 
- Return output file's name."
 
-   (interactive)
 
-   (let ((outfile (org-export-output-file-name ".odt" subtreep)))
 
-     (if async
 
- 	(org-export-async-start (lambda (f) (org-export-add-to-stack f 'e-odt))
 
- 	  `(expand-file-name
 
- 	    (org-e-odt--export-wrap
 
- 	     ,outfile
 
- 	     (let* ((org-e-odt-embedded-images-count 0)
 
- 		    (org-e-odt-embedded-formulas-count 0)
 
- 		    (org-e-odt-automatic-styles nil)
 
- 		    (org-e-odt-object-counters nil)
 
- 		    ;; Let `htmlfontify' know that we are interested in
 
- 		    ;; collecting styles.
 
- 		    (hfy-user-sheet-assoc nil))
 
- 	       ;; Initialize content.xml and kick-off the export
 
- 	       ;; process.
 
- 	       (let ((out-buf
 
- 		      (progn
 
- 			(require 'nxml-mode)
 
- 			(let ((nxml-auto-insert-xml-declaration-flag nil))
 
- 			  (find-file-noselect
 
- 			   (concat org-e-odt-zip-dir "content.xml") t)))))
 
- 		 (org-export-to-buffer
 
- 		  'e-odt out-buf ,subtreep ,visible-only nil ',ext-plist))))))
 
-       (org-e-odt--export-wrap
 
-        outfile
 
-        (let* ((org-e-odt-embedded-images-count 0)
 
- 	      (org-e-odt-embedded-formulas-count 0)
 
- 	      (org-e-odt-automatic-styles nil)
 
- 	      (org-e-odt-object-counters nil)
 
- 	      ;; Let `htmlfontify' know that we are interested in collecting
 
- 	      ;; styles.
 
- 	      (hfy-user-sheet-assoc nil))
 
- 	 ;; Initialize content.xml and kick-off the export process.
 
- 	 (let ((out-buf (progn
 
- 			  (require 'nxml-mode)
 
- 			  (let ((nxml-auto-insert-xml-declaration-flag nil))
 
- 			    (find-file-noselect
 
- 			     (concat org-e-odt-zip-dir "content.xml") t)))))
 
- 	   (org-export-to-buffer
 
- 	    'e-odt out-buf subtreep visible-only nil ext-plist)))))))
 
- ;;;; Convert between OpenDocument and other formats
 
- (defun org-e-odt-reachable-p (in-fmt out-fmt)
 
-   "Return non-nil if IN-FMT can be converted to OUT-FMT."
 
-   (catch 'done
 
-     (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt)))
 
-       (dolist (e reachable-formats)
 
- 	(let ((out-fmt-spec (assoc out-fmt (cdr e))))
 
- 	  (when out-fmt-spec
 
- 	    (throw 'done (cons (car e) out-fmt-spec))))))))
 
- (defun org-e-odt-do-convert (in-file out-fmt &optional prefix-arg)
 
-   "Workhorse routine for `org-e-odt-convert'."
 
-   (require 'browse-url)
 
-   (let* ((in-file (expand-file-name (or in-file buffer-file-name)))
 
- 	 (dummy (or (file-readable-p in-file)
 
- 		    (error "Cannot read %s" in-file)))
 
- 	 (in-fmt (file-name-extension in-file))
 
- 	 (out-fmt (or out-fmt (error "Output format unspecified")))
 
- 	 (how (or (org-e-odt-reachable-p in-fmt out-fmt)
 
- 		  (error "Cannot convert from %s format to %s format?"
 
- 			 in-fmt out-fmt)))
 
- 	 (convert-process (car how))
 
- 	 (out-file (concat (file-name-sans-extension in-file) "."
 
- 			   (nth 1 (or (cdr how) out-fmt))))
 
- 	 (extra-options (or (nth 2 (cdr how)) ""))
 
- 	 (out-dir (file-name-directory in-file))
 
- 	 (cmd (format-spec convert-process
 
- 			   `((?i . ,(shell-quote-argument in-file))
 
- 			     (?I . ,(browse-url-file-url in-file))
 
- 			     (?f . ,out-fmt)
 
- 			     (?o . ,out-file)
 
- 			     (?O . ,(browse-url-file-url out-file))
 
- 			     (?d . , (shell-quote-argument out-dir))
 
- 			     (?D . ,(browse-url-file-url out-dir))
 
- 			     (?x . ,extra-options)))))
 
-     (when (file-exists-p out-file)
 
-       (delete-file out-file))
 
-     (message "Executing %s" cmd)
 
-     (let ((cmd-output (shell-command-to-string cmd)))
 
-       (message "%s" cmd-output))
 
-     (cond
 
-      ((file-exists-p out-file)
 
-       (message "Exported to %s" out-file)
 
-       (when prefix-arg
 
- 	(message "Opening %s..."  out-file)
 
- 	(org-open-file out-file 'system))
 
-       out-file)
 
-      (t
 
-       (message "Export to %s failed" out-file)
 
-       nil))))
 
- (defun org-e-odt-do-reachable-formats (in-fmt)
 
-   "Return verbose info about formats to which IN-FMT can be converted.
 
- Return a list where each element is of the
 
- form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST).  See
 
- `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
 
- `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
 
-   (let* ((converter
 
- 	  (and org-e-odt-convert-process
 
- 	       (cadr (assoc-string org-e-odt-convert-process
 
- 				   org-e-odt-convert-processes t))))
 
- 	 (capabilities
 
- 	  (and org-e-odt-convert-process
 
- 	       (cadr (assoc-string org-e-odt-convert-process
 
- 				   org-e-odt-convert-processes t))
 
- 	       org-e-odt-convert-capabilities))
 
- 	 reachable-formats)
 
-     (when converter
 
-       (dolist (c capabilities)
 
- 	(when (member in-fmt (nth 1 c))
 
- 	  (push (cons converter (nth 2 c)) reachable-formats))))
 
-     reachable-formats))
 
- (defun org-e-odt-reachable-formats (in-fmt)
 
-   "Return list of formats to which IN-FMT can be converted.
 
- The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
 
-   (let (l)
 
-     (mapc (lambda (e) (add-to-list 'l e))
 
- 	  (apply 'append (mapcar
 
- 			  (lambda (e) (mapcar 'car (cdr e)))
 
- 			  (org-e-odt-do-reachable-formats in-fmt))))
 
-     l))
 
- (defun org-e-odt-convert-read-params ()
 
-   "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
 
- This is a helper routine for interactive use."
 
-   (let* ((input (if (featurep 'ido) 'ido-completing-read 'completing-read))
 
- 	 (in-file (read-file-name "File to be converted: "
 
- 				  nil buffer-file-name t))
 
- 	 (in-fmt (file-name-extension in-file))
 
- 	 (out-fmt-choices (org-e-odt-reachable-formats in-fmt))
 
- 	 (out-fmt
 
- 	  (or (and out-fmt-choices
 
- 		   (funcall input "Output format:  "
 
- 			    out-fmt-choices nil nil nil))
 
- 	      (error
 
- 	       "No known converter or no known output formats for %s files"
 
- 	       in-fmt))))
 
-     (list in-file out-fmt)))
 
- ;;;###autoload
 
- (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg)
 
-   "Convert IN-FILE to format OUT-FMT using a command line converter.
 
- IN-FILE is the file to be converted.  If unspecified, it defaults
 
- to variable `buffer-file-name'.  OUT-FMT is the desired output
 
- format.  Use `org-e-odt-convert-process' as the converter.
 
- If PREFIX-ARG is non-nil then the newly converted file is opened
 
- using `org-open-file'."
 
-   (interactive
 
-    (append (org-e-odt-convert-read-params) current-prefix-arg))
 
-   (org-e-odt-do-convert in-file out-fmt prefix-arg))
 
- ;;; Library Initializations
 
- (mapc
 
-  (lambda (desc)
 
-    ;; Let Emacs open all OpenDocument files in archive mode
 
-    (add-to-list 'auto-mode-alist
 
- 		(cons (concat  "\\." (car desc) "\\'") 'archive-mode)))
 
-  org-e-odt-file-extensions)
 
- (provide 'org-e-odt)
 
- ;;; org-e-odt.el ends here
 
 
  |