ox-latex.el 160 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341
  1. ;;; ox-latex.el --- LaTeX Back-End for Org Export Engine -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2011-2022 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Maintainer: Daniel Fleischer <danflscr@gmail.com>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;
  19. ;; See Org manual for details.
  20. ;;; Code:
  21. (require 'cl-lib)
  22. (require 'ox)
  23. (require 'ox-publish)
  24. ;;; Function Declarations
  25. (defvar org-latex-default-packages-alist)
  26. (defvar org-latex-packages-alist)
  27. (defvar orgtbl-exp-regexp)
  28. (declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
  29. (declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
  30. (declare-function engrave-faces-latex-gen-preamble-line "ext:engrave-faces-latex")
  31. (declare-function engrave-faces-get-theme "ext:engrave-faces")
  32. (defvar engrave-faces-latex-output-style)
  33. (defvar engrave-faces-current-preset-style)
  34. (defvar engrave-faces-latex-mathescape)
  35. ;;; Define Back-End
  36. (org-export-define-backend 'latex
  37. '((bold . org-latex-bold)
  38. (center-block . org-latex-center-block)
  39. (clock . org-latex-clock)
  40. (code . org-latex-code)
  41. (drawer . org-latex-drawer)
  42. (dynamic-block . org-latex-dynamic-block)
  43. (entity . org-latex-entity)
  44. (example-block . org-latex-example-block)
  45. (export-block . org-latex-export-block)
  46. (export-snippet . org-latex-export-snippet)
  47. (fixed-width . org-latex-fixed-width)
  48. (footnote-definition . org-latex-footnote-definition)
  49. (footnote-reference . org-latex-footnote-reference)
  50. (headline . org-latex-headline)
  51. (horizontal-rule . org-latex-horizontal-rule)
  52. (inline-src-block . org-latex-inline-src-block)
  53. (inlinetask . org-latex-inlinetask)
  54. (italic . org-latex-italic)
  55. (item . org-latex-item)
  56. (keyword . org-latex-keyword)
  57. (latex-environment . org-latex-latex-environment)
  58. (latex-fragment . org-latex-latex-fragment)
  59. (line-break . org-latex-line-break)
  60. (link . org-latex-link)
  61. (node-property . org-latex-node-property)
  62. (paragraph . org-latex-paragraph)
  63. (plain-list . org-latex-plain-list)
  64. (plain-text . org-latex-plain-text)
  65. (planning . org-latex-planning)
  66. (property-drawer . org-latex-property-drawer)
  67. (quote-block . org-latex-quote-block)
  68. (radio-target . org-latex-radio-target)
  69. (section . org-latex-section)
  70. (special-block . org-latex-special-block)
  71. (src-block . org-latex-src-block)
  72. (statistics-cookie . org-latex-statistics-cookie)
  73. (strike-through . org-latex-strike-through)
  74. (subscript . org-latex-subscript)
  75. (superscript . org-latex-superscript)
  76. (table . org-latex-table)
  77. (table-cell . org-latex-table-cell)
  78. (table-row . org-latex-table-row)
  79. (target . org-latex-target)
  80. (template . org-latex-template)
  81. (timestamp . org-latex-timestamp)
  82. (underline . org-latex-underline)
  83. (verbatim . org-latex-verbatim)
  84. (verse-block . org-latex-verse-block)
  85. ;; Pseudo objects and elements.
  86. (latex-math-block . org-latex-math-block)
  87. (latex-matrices . org-latex-matrices))
  88. :menu-entry
  89. '(?l "Export to LaTeX"
  90. ((?L "As LaTeX buffer" org-latex-export-as-latex)
  91. (?l "As LaTeX file" org-latex-export-to-latex)
  92. (?p "As PDF file" org-latex-export-to-pdf)
  93. (?o "As PDF file and open"
  94. (lambda (a s v b)
  95. (if a (org-latex-export-to-pdf t s v b)
  96. (org-open-file (org-latex-export-to-pdf nil s v b)))))))
  97. :filters-alist '((:filter-options . org-latex-math-block-options-filter)
  98. (:filter-paragraph . org-latex-clean-invalid-line-breaks)
  99. (:filter-parse-tree org-latex-math-block-tree-filter
  100. org-latex-matrices-tree-filter
  101. org-latex-image-link-filter)
  102. (:filter-verse-block . org-latex-clean-invalid-line-breaks))
  103. :options-alist
  104. '((:latex-class "LATEX_CLASS" nil org-latex-default-class t)
  105. (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
  106. (:latex-header "LATEX_HEADER" nil nil newline)
  107. (:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline)
  108. (:description "DESCRIPTION" nil nil parse)
  109. (:keywords "KEYWORDS" nil nil parse)
  110. (:subtitle "SUBTITLE" nil nil parse)
  111. ;; Other variables.
  112. (:latex-active-timestamp-format nil nil org-latex-active-timestamp-format)
  113. (:latex-caption-above nil nil org-latex-caption-above)
  114. (:latex-classes nil nil org-latex-classes)
  115. (:latex-default-figure-position nil nil org-latex-default-figure-position)
  116. (:latex-default-table-environment nil nil org-latex-default-table-environment)
  117. (:latex-default-quote-environment nil nil org-latex-default-quote-environment)
  118. (:latex-default-table-mode nil nil org-latex-default-table-mode)
  119. (:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
  120. (:latex-engraved-options nil nil org-latex-engraved-options)
  121. (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
  122. (:latex-engraved-theme "LATEX_ENGRAVED_THEME" nil org-latex-engraved-theme)
  123. (:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
  124. (:latex-footnote-separator nil nil org-latex-footnote-separator)
  125. (:latex-format-drawer-function nil nil org-latex-format-drawer-function)
  126. (:latex-format-headline-function nil nil org-latex-format-headline-function)
  127. (:latex-format-inlinetask-function nil nil org-latex-format-inlinetask-function)
  128. (:latex-hyperref-template nil nil org-latex-hyperref-template t)
  129. (:latex-image-default-scale nil nil org-latex-image-default-scale)
  130. (:latex-image-default-height nil nil org-latex-image-default-height)
  131. (:latex-image-default-option nil nil org-latex-image-default-option)
  132. (:latex-image-default-width nil nil org-latex-image-default-width)
  133. (:latex-images-centered nil nil org-latex-images-centered)
  134. (:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
  135. (:latex-inline-image-rules nil nil org-latex-inline-image-rules)
  136. (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
  137. (:latex-src-block-backend nil nil org-latex-src-block-backend)
  138. (:latex-listings-langs nil nil org-latex-listings-langs)
  139. (:latex-listings-options nil nil org-latex-listings-options)
  140. (:latex-minted-langs nil nil org-latex-minted-langs)
  141. (:latex-minted-options nil nil org-latex-minted-options)
  142. (:latex-prefer-user-labels nil nil org-latex-prefer-user-labels)
  143. (:latex-subtitle-format nil nil org-latex-subtitle-format)
  144. (:latex-subtitle-separate nil nil org-latex-subtitle-separate)
  145. (:latex-table-scientific-notation nil nil org-latex-table-scientific-notation)
  146. (:latex-tables-booktabs nil nil org-latex-tables-booktabs)
  147. (:latex-tables-centered nil nil org-latex-tables-centered)
  148. (:latex-text-markup-alist nil nil org-latex-text-markup-alist)
  149. (:latex-title-command nil nil org-latex-title-command)
  150. (:latex-toc-command nil nil org-latex-toc-command)
  151. (:latex-compiler "LATEX_COMPILER" nil org-latex-compiler)
  152. ;; Redefine regular options.
  153. (:date "DATE" nil "\\today" parse)))
  154. ;;; Internal Variables
  155. (defconst org-latex-language-alist
  156. ;; TODO: replace this list with a property list (the actual
  157. ;; implementation is not very robust).
  158. '(("am" "amharic" "*")
  159. ("ar" "arabic")
  160. ("ast" "asturian" "*")
  161. ("bg" "bulgarian")
  162. ("bn" "bengali" "*")
  163. ("bo" "tibetan" "*")
  164. ("br" "breton")
  165. ("ca" "catalan")
  166. ("cop" "coptic" "*")
  167. ("cs" "czech")
  168. ("cy" "welsh")
  169. ("da" "danish")
  170. ("de" "ngerman" "german" "german")
  171. ("de-at" "naustrian" "german" "austrian")
  172. ("dsb" "lsorbian" "*")
  173. ("dv" "divehi" "*")
  174. ("el" "greek")
  175. ("el-polyton" "polutonikogreek" "greek" "polytonic")
  176. ("en" "american" "english" "usmax")
  177. ("en-au" "australian" "english" "australian")
  178. ("en-gb" "british" "english" "uk")
  179. ("en-nz" "newzealand" "english" "newzealand")
  180. ("en-us" "american" "english" "usmax")
  181. ("eo" "esperanto")
  182. ("es" "spanish")
  183. ("es-mx" "spanishmx" "spanish" "mexican")
  184. ("et" "estonian")
  185. ("eu" "basque")
  186. ("fa" "farsi")
  187. ("fi" "finnish")
  188. ("fr" "french")
  189. ("fr-ca" "canadien" "french" "canadian")
  190. ("fur" "friulan")
  191. ("ga" "irish")
  192. ("gd" "scottish")
  193. ("gl" "galician")
  194. ("he" "hebrew")
  195. ("hi" "hindi")
  196. ("hr" "croatian")
  197. ("hsb" "uppersorbian" "sorbian" "upper")
  198. ("hu" "magyar")
  199. ("hy" "armenian" "*")
  200. ("ia" "interlingua")
  201. ("id" "bahasai" "*")
  202. ("is" "icelandic")
  203. ("it" "italian")
  204. ("kn" "kannada" "*")
  205. ("la" "latin")
  206. ("la-classic" "classiclatin" "latin" "classic")
  207. ("la-medieval" "medievallatin" "latin" "medieval")
  208. ("la-ecclesiastic" "ecclesiasticlatin" "latin" "ecclesiastic")
  209. ("lo" "lao" "*")
  210. ("lt" "lithuanian")
  211. ("lv" "latvian")
  212. ("ml" "malayalam" "*")
  213. ("mr" "maranthi" "*")
  214. ("nb" "norsk" "norwegian" "bokmal")
  215. ("nl" "dutch")
  216. ("nn" "nynorsk" "norwegian" "nynorsk")
  217. ("no" "norsk")
  218. ("oc" "occitan")
  219. ("pl" "polish")
  220. ("pms" "piedmontese")
  221. ("pt" "portuges")
  222. ("pt-br" "brazilian")
  223. ("rm" "romansh" "*")
  224. ("ro" "romanian")
  225. ("ru" "russian")
  226. ("sa" "sanskrit" "*")
  227. ("sk" "slovak")
  228. ("sl" "slovene")
  229. ("sq" "albanian")
  230. ("sr" "serbian")
  231. ("sv" "swedish")
  232. ("syr" "syriac" "*")
  233. ("ta" "tamil" "*")
  234. ("te" "telugu" "*")
  235. ("th" "thai")
  236. ("tk" "turkmen")
  237. ("tr" "turkish")
  238. ("uk" "ukrainian")
  239. ("ur" "urdu" "*")
  240. ("vi" "vietnamese"))
  241. "Alist between language code and corresponding Babel/Polyglossia option.
  242. For the names of the languages, the Babel nomenclature is
  243. preferred to that of Polyglossia, in those cases where both
  244. coincide.
  245. The alist supports three types of members:
  246. - Members with two elements: CODE BABEL/POLYGLOSSIA OPTION.
  247. - Members with three elements: CODE BABEL/POLYGLOSSIA OPTION
  248. ASTERISK (the presence of the asterisk indicates that this
  249. language is not loaded in Babel using the old method of ldf
  250. files but using ini files. If Babel is loaded in an Org
  251. document with these languages, the \"AUTO \" argument is just
  252. removed, to avoid compilation errors).
  253. - Members with four elements (for variants of languages): CODE
  254. BABEL-OPTION POLYGLOSSIA-OPTION POLYGLOSSIA-VARIANT")
  255. (defconst org-latex-table-matrix-macros '(("bordermatrix" . "\\cr")
  256. ("qbordermatrix" . "\\cr")
  257. ("kbordermatrix" . "\\\\"))
  258. "Alist between matrix macros and their row ending.")
  259. (defconst org-latex-math-environments-re
  260. (format
  261. "\\`[ \t]*\\\\begin{%s\\*?}"
  262. (regexp-opt
  263. '("equation" "eqnarray" "math" "displaymath"
  264. "align" "gather" "multline" "flalign" "alignat"
  265. "xalignat" "xxalignat"
  266. "subequations"
  267. ;; breqn
  268. "dmath" "dseries" "dgroup" "darray"
  269. ;; empheq
  270. "empheq")))
  271. "Regexp of LaTeX math environments.")
  272. ;;; User Configurable Variables
  273. (defgroup org-export-latex nil
  274. "Options for exporting Org mode files to LaTeX."
  275. :tag "Org Export LaTeX"
  276. :group 'org-export)
  277. ;;;; Generic
  278. (defcustom org-latex-caption-above '(table)
  279. "When non-nil, place caption string at the beginning of elements.
  280. Otherwise, place it near the end. When value is a list of
  281. symbols, put caption above selected elements only. Allowed
  282. symbols are: `image', `table', `src-block' and `special-block'."
  283. :group 'org-export-latex
  284. :version "26.1"
  285. :package-version '(Org . "8.3")
  286. :type '(choice
  287. (const :tag "For all elements" t)
  288. (const :tag "For no element" nil)
  289. (set :tag "For the following elements only" :greedy t
  290. (const :tag "Images" image)
  291. (const :tag "Tables" table)
  292. (const :tag "Source code" src-block)
  293. (const :tag "Special blocks" special-block))))
  294. (defcustom org-latex-prefer-user-labels nil
  295. "Use user-provided labels instead of internal ones when non-nil.
  296. When this variable is non-nil, Org will use the value of
  297. CUSTOM_ID property, NAME keyword or Org target as the key for the
  298. \\label commands generated.
  299. By default, Org generates its own internal labels during LaTeX
  300. export. This process ensures that the \\label keys are unique
  301. and valid, but it means the keys are not available in advance of
  302. the export process.
  303. Setting this variable gives you control over how Org generates
  304. labels during LaTeX export, so that you may know their keys in
  305. advance. One reason to do this is that it allows you to refer to
  306. various elements using a single label both in Org's link syntax
  307. and in embedded LaTeX code.
  308. For example, when this variable is non-nil, a headline like this:
  309. ** Some section
  310. :PROPERTIES:
  311. :CUSTOM_ID: sec:foo
  312. :END:
  313. This is section [[#sec:foo]].
  314. #+BEGIN_EXPORT latex
  315. And this is still section \\ref{sec:foo}.
  316. #+END_EXPORT
  317. will be exported to LaTeX as:
  318. \\subsection{Some section}
  319. \\label{sec:foo}
  320. This is section \\ref{sec:foo}.
  321. And this is still section \\ref{sec:foo}.
  322. A non-default value of `org-latex-reference-command' will change the
  323. command (\\ref by default) used to create label references.
  324. Note, however, that setting this variable introduces a limitation
  325. on the possible values for CUSTOM_ID and NAME. When this
  326. variable is non-nil, Org passes their value to \\label unchanged.
  327. You are responsible for ensuring that the value is a valid LaTeX
  328. \\label key, and that no other \\label commands with the same key
  329. appear elsewhere in your document. (Keys may contain letters,
  330. numbers, and the following punctuation: `_' `.' `-' `:'.) There
  331. are no such limitations on CUSTOM_ID and NAME when this variable
  332. is nil.
  333. For headlines that do not define the CUSTOM_ID property or
  334. elements without a NAME, Org will continue to use its default
  335. labeling scheme to generate labels and resolve links into proper
  336. references."
  337. :group 'org-export-latex
  338. :type 'boolean
  339. :version "26.1"
  340. :package-version '(Org . "8.3"))
  341. (defcustom org-latex-reference-command "\\ref{%s}"
  342. "Format string that takes a reference to produce a LaTeX reference command.
  343. The reference is a label such as sec:intro. A format string of \"\\ref{%s}\"
  344. produces numbered references and will always work. It may be desirable to make
  345. use of a package such as hyperref or cleveref and then change the format string
  346. to \"\\autoref{%s}\" or \"\\cref{%s}\" for example."
  347. :group 'org-export-latex
  348. :type 'string
  349. :package-version '(Org . "9.5")
  350. :safe #'stringp)
  351. ;;;; Preamble
  352. (defcustom org-latex-default-class "article"
  353. "The default LaTeX class."
  354. :group 'org-export-latex
  355. :type '(string :tag "LaTeX class"))
  356. (defcustom org-latex-classes
  357. '(("article"
  358. "\\documentclass[11pt]{article}"
  359. ("\\section{%s}" . "\\section*{%s}")
  360. ("\\subsection{%s}" . "\\subsection*{%s}")
  361. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  362. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  363. ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
  364. ("report"
  365. "\\documentclass[11pt]{report}"
  366. ("\\part{%s}" . "\\part*{%s}")
  367. ("\\chapter{%s}" . "\\chapter*{%s}")
  368. ("\\section{%s}" . "\\section*{%s}")
  369. ("\\subsection{%s}" . "\\subsection*{%s}")
  370. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
  371. ("book"
  372. "\\documentclass[11pt]{book}"
  373. ("\\part{%s}" . "\\part*{%s}")
  374. ("\\chapter{%s}" . "\\chapter*{%s}")
  375. ("\\section{%s}" . "\\section*{%s}")
  376. ("\\subsection{%s}" . "\\subsection*{%s}")
  377. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
  378. "Alist of LaTeX classes and associated header and structure.
  379. If #+LATEX_CLASS is set in the buffer, use its value and the
  380. associated information. Here is the structure of each cell:
  381. (class-name
  382. header-string
  383. (numbered-section . unnumbered-section)
  384. ...)
  385. The header string
  386. -----------------
  387. The HEADER-STRING is the header that will be inserted into the
  388. LaTeX file. It should contain the \\documentclass macro, and
  389. anything else that is needed for this setup. To this header, the
  390. following commands will be added:
  391. - Calls to \\usepackage for all packages mentioned in the
  392. variables `org-latex-default-packages-alist' and
  393. `org-latex-packages-alist'. Thus, your header definitions
  394. should avoid to also request these packages.
  395. - Lines specified via \"#+LATEX_HEADER:\" and
  396. \"#+LATEX_HEADER_EXTRA:\" keywords.
  397. If you need more control about the sequence in which the header
  398. is built up, or if you want to exclude one of these building
  399. blocks for a particular class, you can use the following
  400. macro-like placeholders.
  401. [DEFAULT-PACKAGES] \\usepackage statements for default packages
  402. [NO-DEFAULT-PACKAGES] do not include any of the default packages
  403. [PACKAGES] \\usepackage statements for packages
  404. [NO-PACKAGES] do not include the packages
  405. [EXTRA] the stuff from #+LATEX_HEADER(_EXTRA)
  406. [NO-EXTRA] do not include #+LATEX_HEADER(_EXTRA) stuff
  407. So a header like
  408. \\documentclass{article}
  409. [NO-DEFAULT-PACKAGES]
  410. [EXTRA]
  411. \\providecommand{\\alert}[1]{\\textbf{#1}}
  412. [PACKAGES]
  413. will omit the default packages, and will include the
  414. #+LATEX_HEADER and #+LATEX_HEADER_EXTRA lines, then have a call
  415. to \\providecommand, and then place \\usepackage commands based
  416. on the content of `org-latex-packages-alist'.
  417. If your header, `org-latex-default-packages-alist' or
  418. `org-latex-packages-alist' inserts \"\\usepackage[AUTO]{inputenc}\",
  419. AUTO will automatically be replaced with a coding system derived
  420. from `buffer-file-coding-system'. See also the variable
  421. `org-latex-inputenc-alist' for a way to influence this mechanism.
  422. Likewise, if your header contains \"\\usepackage[AUTO]{babel}\"
  423. or \"\\usepackage[AUTO]{polyglossia}\", AUTO will be replaced
  424. with the language related to the language code specified by
  425. `org-export-default-language'. Note that constructions such as
  426. \"\\usepackage[french,AUTO,english]{babel}\" are permitted. For
  427. Polyglossia the language will be set via the macros
  428. \"\\setmainlanguage\" and \"\\setotherlanguage\". See also
  429. `org-latex-guess-babel-language' and
  430. `org-latex-guess-polyglossia-language'.
  431. The sectioning structure
  432. ------------------------
  433. The sectioning structure of the class is given by the elements
  434. following the header string. For each sectioning level, a number
  435. of strings is specified. A %s formatter is mandatory in each
  436. section string and will be replaced by the title of the section.
  437. Instead of a cons cell (numbered . unnumbered), you can also
  438. provide a list of 2 or 4 elements,
  439. (numbered-open numbered-close)
  440. or
  441. (numbered-open numbered-close unnumbered-open unnumbered-close)
  442. providing opening and closing strings for a LaTeX environment
  443. that should represent the document section. The opening clause
  444. should have a %s to represent the section title.
  445. Instead of a list of sectioning commands, you can also specify
  446. a function name. That function will be called with two
  447. parameters, the (reduced) level of the headline, and a predicate
  448. non-nil when the headline should be numbered. It must return
  449. a format string in which the section title will be added."
  450. :group 'org-export-latex
  451. :type '(repeat
  452. (list (string :tag "LaTeX class")
  453. (string :tag "LaTeX header")
  454. (repeat :tag "Levels" :inline t
  455. (choice
  456. (cons :tag "Heading"
  457. (string :tag " numbered")
  458. (string :tag "unnumbered"))
  459. (list :tag "Environment"
  460. (string :tag "Opening (numbered)")
  461. (string :tag "Closing (numbered)")
  462. (string :tag "Opening (unnumbered)")
  463. (string :tag "Closing (unnumbered)"))
  464. (function :tag "Hook computing sectioning"))))))
  465. (defcustom org-latex-inputenc-alist nil
  466. "Alist of inputenc coding system names, and what should really be used.
  467. For example, adding an entry
  468. (\"utf8\" . \"utf8x\")
  469. will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
  470. are written as utf8 files."
  471. :group 'org-export-latex
  472. :type '(repeat
  473. (cons
  474. (string :tag "Derived from buffer")
  475. (string :tag "Use this instead"))))
  476. (defcustom org-latex-title-command "\\maketitle"
  477. "The command used to insert the title just after \\begin{document}.
  478. This format string may contain these elements:
  479. %a for AUTHOR keyword
  480. %t for TITLE keyword
  481. %s for SUBTITLE keyword
  482. %k for KEYWORDS line
  483. %d for DESCRIPTION line
  484. %c for CREATOR line
  485. %l for Language keyword
  486. %L for capitalized language keyword
  487. %D for DATE keyword
  488. If you need to use a \"%\" character, you need to escape it
  489. like that: \"%%\".
  490. Setting :latex-title-command in publishing projects will take
  491. precedence over this variable."
  492. :group 'org-export-latex
  493. :type '(string :tag "Format string"))
  494. (defcustom org-latex-subtitle-format "\\\\\\medskip\n\\large %s"
  495. "Format string used for transcoded subtitle.
  496. The format string should have at most one \"%s\"-expression,
  497. which is replaced with the subtitle."
  498. :group 'org-export-latex
  499. :version "26.1"
  500. :package-version '(Org . "8.3")
  501. :type '(string :tag "Format string"))
  502. (defcustom org-latex-subtitle-separate nil
  503. "Non-nil means the subtitle is not typeset as part of title."
  504. :group 'org-export-latex
  505. :version "26.1"
  506. :package-version '(Org . "8.3")
  507. :type 'boolean)
  508. (defcustom org-latex-toc-command "\\tableofcontents\n\n"
  509. "LaTeX command to set the table of contents, list of figures, etc.
  510. This command only applies to the table of contents generated with
  511. the toc:nil option, not to those generated with #+TOC keyword."
  512. :group 'org-export-latex
  513. :type 'string)
  514. (defcustom org-latex-hyperref-template
  515. "\\hypersetup{\n pdfauthor={%a},\n pdftitle={%t},\n pdfkeywords={%k},
  516. pdfsubject={%d},\n pdfcreator={%c}, \n pdflang={%L}}\n"
  517. "Template for hyperref package options.
  518. This format string may contain these elements:
  519. %a for AUTHOR keyword
  520. %t for TITLE keyword
  521. %s for SUBTITLE keyword
  522. %k for KEYWORDS line
  523. %d for DESCRIPTION line
  524. %c for CREATOR line
  525. %l for Language keyword
  526. %L for capitalized language keyword
  527. %D for DATE keyword
  528. If you need to use a \"%\" character, you need to escape it
  529. like that: \"%%\".
  530. As a special case, a nil value prevents template from being
  531. inserted.
  532. Setting :latex-hyperref-template in publishing projects will take
  533. precedence over this variable."
  534. :group 'org-export-latex
  535. :version "26.1"
  536. :package-version '(Org . "8.3")
  537. :type '(choice (const :tag "No template" nil)
  538. (string :tag "Format string")))
  539. ;;;; Headline
  540. (defcustom org-latex-format-headline-function
  541. 'org-latex-format-headline-default-function
  542. "Function for formatting the headline's text.
  543. This function will be called with six arguments:
  544. TODO the todo keyword (string or nil)
  545. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  546. PRIORITY the priority of the headline (integer or nil)
  547. TEXT the main headline text (string)
  548. TAGS the tags (list of strings or nil)
  549. INFO the export options (plist)
  550. The function result will be used in the section format string."
  551. :group 'org-export-latex
  552. :version "24.4"
  553. :package-version '(Org . "8.0")
  554. :type 'function)
  555. ;;;; Footnotes
  556. (defcustom org-latex-footnote-separator "\\textsuperscript{,}\\,"
  557. "Text used to separate footnotes."
  558. :group 'org-export-latex
  559. :type 'string)
  560. (defcustom org-latex-footnote-defined-format "\\textsuperscript{\\ref{%s}}"
  561. "Format string used to format reference to footnote already defined.
  562. %s will be replaced by the label of the referred footnote."
  563. :group 'org-export-latex
  564. :type '(choice
  565. (const :tag "Use plain superscript (default)" "\\textsuperscript{\\ref{%s}}")
  566. (const :tag "Use Memoir/KOMA-Script footref" "\\footref{%s}")
  567. (string :tag "Other format string"))
  568. :version "26.1"
  569. :package-version '(Org . "9.0"))
  570. ;;;; Timestamps
  571. (defcustom org-latex-active-timestamp-format "\\textit{%s}"
  572. "A printf format string to be applied to active timestamps."
  573. :group 'org-export-latex
  574. :type 'string)
  575. (defcustom org-latex-inactive-timestamp-format "\\textit{%s}"
  576. "A printf format string to be applied to inactive timestamps."
  577. :group 'org-export-latex
  578. :type 'string)
  579. (defcustom org-latex-diary-timestamp-format "\\textit{%s}"
  580. "A printf format string to be applied to diary timestamps."
  581. :group 'org-export-latex
  582. :type 'string)
  583. ;;;; Links
  584. (defcustom org-latex-images-centered t
  585. "When non-nil, images are centered."
  586. :group 'org-export-latex
  587. :version "26.1"
  588. :package-version '(Org . "9.0")
  589. :type 'boolean
  590. :safe #'booleanp)
  591. (defcustom org-latex-image-default-option ""
  592. "Default option for images."
  593. :group 'org-export-latex
  594. :version "24.4"
  595. :package-version '(Org . "8.0")
  596. :type 'string)
  597. (defcustom org-latex-image-default-width ".9\\linewidth"
  598. "Default width for images.
  599. This value will not be used if a height is provided."
  600. :group 'org-export-latex
  601. :version "24.4"
  602. :package-version '(Org . "8.0")
  603. :type 'string)
  604. (defcustom org-latex-image-default-scale ""
  605. "Default scale for images.
  606. This value will not be used if a width or a scale is provided,
  607. or if the image is wrapped within a \"wrapfigure\" environment.
  608. Scale overrides width and height."
  609. :group 'org-export-latex
  610. :package-version '(Org . "9.3")
  611. :type 'string
  612. :safe #'stringp)
  613. (defcustom org-latex-image-default-height ""
  614. "Default height for images.
  615. This value will not be used if a width is provided, or if the
  616. image is wrapped within a \"figure\" or \"wrapfigure\"
  617. environment."
  618. :group 'org-export-latex
  619. :version "24.4"
  620. :package-version '(Org . "8.0")
  621. :type 'string)
  622. (defcustom org-latex-default-figure-position "htbp"
  623. "Default position for LaTeX figures."
  624. :group 'org-export-latex
  625. :type 'string
  626. :version "26.1"
  627. :package-version '(Org . "9.0")
  628. :safe #'stringp)
  629. (defcustom org-latex-inline-image-rules
  630. `(("file" . ,(rx "."
  631. (or "pdf" "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg")
  632. eos))
  633. ("https" . ,(rx "."
  634. (or "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg")
  635. eos)))
  636. "Rules characterizing image files that can be inlined into LaTeX.
  637. A rule consists in an association whose key is the type of link
  638. to consider, and value is a regexp that will be matched against
  639. link's path.
  640. Note that, by default, the image extension *actually* allowed
  641. depend on the way the LaTeX file is processed. When used with
  642. pdflatex, pdf, jpg and png images are OK. When processing
  643. through dvi to Postscript, only ps and eps are allowed. The
  644. default we use here encompasses both."
  645. :group 'org-export-latex
  646. :package-version '(Org . "9.4")
  647. :type '(alist :key-type (string :tag "Type")
  648. :value-type (regexp :tag "Path")))
  649. (defcustom org-latex-link-with-unknown-path-format "\\texttt{%s}"
  650. "Format string for links with unknown path type."
  651. :group 'org-export-latex
  652. :type 'string)
  653. ;;;; Tables
  654. (defcustom org-latex-default-table-environment "tabular"
  655. "Default environment used to build tables."
  656. :group 'org-export-latex
  657. :version "24.4"
  658. :package-version '(Org . "8.0")
  659. :type 'string)
  660. (defcustom org-latex-default-quote-environment "quote"
  661. "Default environment used to `quote' blocks."
  662. :group 'org-export-latex
  663. :package-version '(Org . "9.5")
  664. :type 'string
  665. :safe #'stringp)
  666. (defcustom org-latex-default-table-mode 'table
  667. "Default mode for tables.
  668. Value can be a symbol among:
  669. `table' Regular LaTeX table.
  670. `math' In this mode, every cell is considered as being in math
  671. mode and the complete table will be wrapped within a math
  672. environment. It is particularly useful to write matrices.
  673. `inline-math' This mode is almost the same as `math', but the
  674. math environment will be inlined.
  675. `verbatim' The table is exported as it appears in the Org
  676. buffer, within a verbatim environment.
  677. This value can be overridden locally with, i.e. \":mode math\" in
  678. LaTeX attributes.
  679. When modifying this variable, it may be useful to change
  680. `org-latex-default-table-environment' accordingly."
  681. :group 'org-export-latex
  682. :version "24.4"
  683. :package-version '(Org . "8.0")
  684. :type '(choice (const :tag "Table" table)
  685. (const :tag "Matrix" math)
  686. (const :tag "Inline matrix" inline-math)
  687. (const :tag "Verbatim" verbatim))
  688. :safe (lambda (s) (memq s '(table math inline-math verbatim))))
  689. (defcustom org-latex-tables-centered t
  690. "When non-nil, tables are exported in a center environment."
  691. :group 'org-export-latex
  692. :type 'boolean
  693. :safe #'booleanp)
  694. (defcustom org-latex-tables-booktabs nil
  695. "When non-nil, display tables in a formal \"booktabs\" style.
  696. This option assumes that the \"booktabs\" package is properly
  697. loaded in the header of the document. This value can be ignored
  698. locally with \":booktabs t\" and \":booktabs nil\" LaTeX
  699. attributes."
  700. :group 'org-export-latex
  701. :version "24.4"
  702. :package-version '(Org . "8.0")
  703. :type 'boolean
  704. :safe #'booleanp)
  705. (defcustom org-latex-table-scientific-notation nil
  706. "Format string to display numbers in scientific notation.
  707. The format should have \"%s\" twice, for mantissa and exponent
  708. \(i.e., \"%s\\\\times10^{%s}\").
  709. When nil, no transformation is made."
  710. :group 'org-export-latex
  711. :version "24.4"
  712. :package-version '(Org . "8.0")
  713. :type '(choice
  714. (string :tag "Format string")
  715. (const :tag "No formatting" nil)))
  716. ;;;; Text markup
  717. (defcustom org-latex-text-markup-alist '((bold . "\\textbf{%s}")
  718. (code . protectedtexttt)
  719. (italic . "\\emph{%s}")
  720. (strike-through . "\\sout{%s}")
  721. (underline . "\\uline{%s}")
  722. (verbatim . protectedtexttt))
  723. "Alist of LaTeX expressions to convert text markup.
  724. The key must be a symbol among `bold', `code', `italic',
  725. `strike-through', `underline' and `verbatim'. The value is
  726. a formatting string to wrap fontified text with.
  727. Value can also be set to the following symbols: `verb' and
  728. `protectedtexttt'. For the former, Org will use \"\\verb\" to
  729. create a format string and select a delimiter character that
  730. isn't in the string. For the latter, Org will use \"\\texttt\"
  731. to typeset and try to protect special characters.
  732. If no association can be found for a given markup, text will be
  733. returned as-is."
  734. :group 'org-export-latex
  735. :version "26.1"
  736. :package-version '(Org . "8.3")
  737. :type 'alist
  738. :options '(bold code italic strike-through underline verbatim))
  739. ;;;; Drawers
  740. (defcustom org-latex-format-drawer-function (lambda (_ contents) contents)
  741. "Function called to format a drawer in LaTeX code.
  742. The function must accept two parameters:
  743. NAME the drawer name, like \"LOGBOOK\"
  744. CONTENTS the contents of the drawer.
  745. The function should return the string to be exported.
  746. The default function simply returns the value of CONTENTS."
  747. :group 'org-export-latex
  748. :version "26.1"
  749. :package-version '(Org . "8.3")
  750. :type 'function)
  751. ;;;; Inlinetasks
  752. (defcustom org-latex-format-inlinetask-function
  753. 'org-latex-format-inlinetask-default-function
  754. "Function called to format an inlinetask in LaTeX code.
  755. The function must accept seven parameters:
  756. TODO the todo keyword (string or nil)
  757. TODO-TYPE the todo type (symbol: `todo', `done', nil)
  758. PRIORITY the inlinetask priority (integer or nil)
  759. NAME the inlinetask name (string)
  760. TAGS the inlinetask tags (list of strings or nil)
  761. CONTENTS the contents of the inlinetask (string or nil)
  762. INFO the export options (plist)
  763. The function should return the string to be exported."
  764. :group 'org-export-latex
  765. :type 'function
  766. :version "26.1"
  767. :package-version '(Org . "8.3"))
  768. ;; Src blocks
  769. (defcustom org-latex-src-block-backend 'verbatim
  770. "Backend used to generate source code listings.
  771. This sets the behaviour for fontifying source code, possibly even with
  772. color. There are four implementations of this functionality you may
  773. choose from (ordered from least to most capable):
  774. 1. Verbatim
  775. 2. Listings
  776. 3. Minted
  777. 4. Engraved
  778. The first two options provide basic syntax
  779. highlighting (listings), or none at all (verbatim).
  780. When using listings, you also need to make use of LaTeX package
  781. \"listings\"e. The \"color\" LaTeX package is also needed if you
  782. would like color too. These can simply be added to
  783. `org-latex-packages-alist', using customise or something like:
  784. (require \\='ox-latex)
  785. (add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
  786. (add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
  787. There are two further options for more comprehensive
  788. fontification. The first can be set with,
  789. (setq org-latex-src-block-backend \\='minted)
  790. which causes source code to be exported using the LaTeX package
  791. minted as opposed to listings. If you want to use minted, you
  792. need to add the minted package to `org-latex-packages-alist', for
  793. example using customize, or with
  794. (require \\='ox-latex)
  795. (add-to-list \\='org-latex-packages-alist \\='(\"newfloat\" \"minted\"))
  796. In addition, it is necessary to install pygments
  797. \(URL `https://pygments.org>'), and to configure the variable
  798. `org-latex-pdf-process' so that the -shell-escape option is
  799. passed to pdflatex.
  800. The minted choice has possible repercussions on the preview of
  801. latex fragments (see `org-preview-latex-fragment'). If you run
  802. into previewing problems, please consult
  803. URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'.
  804. The most comprehensive option can be set with,
  805. (setq org-latex-src-block-backend \\='engraved)
  806. which causes source code to be run through
  807. `engrave-faces-latex-buffer', which generates colorings using
  808. Emacs' font-lock information. This requires the Emacs package
  809. engrave-faces (available from ELPA), and the LaTeX package
  810. fvextra be installed.
  811. The styling of the engraved result can customised with
  812. `org-latex-engraved-preamble' and `org-latex-engraved-options'.
  813. The default preamble also uses the LaTeX package tcolorbox in
  814. addition to fvextra."
  815. :group 'org-export-latex
  816. :type '(choice
  817. (const :tag "Use listings" listings)
  818. (const :tag "Use minted" minted)
  819. (const :tag "Use engrave-faces-latex" engraved)
  820. (const :tag "Export verbatim" verbatim))
  821. :safe (lambda (s) (memq s '(listings minted engraved verbatim))))
  822. (defcustom org-latex-listings-langs
  823. '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
  824. (c "C") (cc "C++")
  825. (fortran "fortran")
  826. (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
  827. (html "HTML") (xml "XML")
  828. (tex "TeX") (latex "[LaTeX]TeX")
  829. (shell-script "bash")
  830. (gnuplot "Gnuplot")
  831. (ocaml "[Objective]Caml") (caml "Caml")
  832. (sql "SQL") (sqlite "sql")
  833. (makefile "make")
  834. (R "r"))
  835. "Alist mapping languages to their listing language counterpart.
  836. The key is a symbol, the major mode symbol without the \"-mode\".
  837. The value is the string that should be inserted as the language
  838. parameter for the listings package. If the mode name and the
  839. listings name are the same, the language does not need an entry
  840. in this list - but it does not hurt if it is present."
  841. :group 'org-export-latex
  842. :version "26.1"
  843. :package-version '(Org . "8.3")
  844. :type '(repeat
  845. (list
  846. (symbol :tag "Major mode ")
  847. (string :tag "Listings language"))))
  848. (defcustom org-latex-listings-options nil
  849. "Association list of options for the latex listings package.
  850. These options are supplied as a comma-separated list to the
  851. \\lstset command. Each element of the association list should be
  852. a list or cons cell containing two strings: the name of the
  853. option, and the value. For example,
  854. (setq org-latex-listings-options
  855. \\='((\"basicstyle\" \"\\\\small\")
  856. (\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
  857. ; or
  858. (setq org-latex-listings-options
  859. \\='((\"basicstyle\" . \"\\\\small\")
  860. (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\")))
  861. will typeset the code in a small size font with underlined, bold
  862. black keywords.
  863. Note that the same options will be applied to blocks of all
  864. languages. If you need block-specific options, you may use the
  865. following syntax:
  866. #+ATTR_LATEX: :options key1=value1,key2=value2
  867. #+BEGIN_SRC <LANG>
  868. ...
  869. #+END_SRC"
  870. :group 'org-export-latex
  871. :type '(repeat
  872. (list
  873. (string :tag "Listings option name ")
  874. (string :tag "Listings option value"))))
  875. (defcustom org-latex-minted-langs
  876. '((emacs-lisp "common-lisp")
  877. (cc "c++")
  878. (cperl "perl")
  879. (shell-script "bash")
  880. (caml "ocaml"))
  881. "Alist mapping languages to their minted language counterpart.
  882. The key is a symbol, the major mode symbol without the \"-mode\".
  883. The value is the string that should be inserted as the language
  884. parameter for the minted package. If the mode name and the
  885. listings name are the same, the language does not need an entry
  886. in this list - but it does not hurt if it is present.
  887. Note that minted uses all lower case for language identifiers,
  888. and that the full list of language identifiers can be obtained
  889. with:
  890. pygmentize -L lexers"
  891. :group 'org-export-latex
  892. :type '(repeat
  893. (list
  894. (symbol :tag "Major mode ")
  895. (string :tag "Minted language"))))
  896. (defcustom org-latex-minted-options nil
  897. "Association list of options for the latex minted package.
  898. These options are supplied within square brackets in
  899. \\begin{minted} environments. Each element of the alist should
  900. be a list or cons cell containing two strings: the name of the
  901. option, and the value. For example,
  902. (setq org-latex-minted-options
  903. \\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
  904. ; or
  905. (setq org-latex-minted-options
  906. \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
  907. will result in source blocks being exported with
  908. \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
  909. as the start of the minted environment. Note that the same
  910. options will be applied to blocks of all languages. If you need
  911. block-specific options, you may use the following syntax:
  912. #+ATTR_LATEX: :options key1=value1,key2=value2
  913. #+BEGIN_SRC <LANG>
  914. ...
  915. #+END_SRC"
  916. :group 'org-export-latex
  917. :type '(repeat
  918. (list
  919. (string :tag "Minted option name ")
  920. (string :tag "Minted option value"))))
  921. (defcustom org-latex-custom-lang-environments nil
  922. "Alist mapping languages to language-specific LaTeX environments.
  923. It is used during export of source blocks by the listings and
  924. minted LaTeX packages. The environment may be a simple string,
  925. composed of only letters and numbers. In this case, the string
  926. is directly the name of the LaTeX environment to use. The
  927. environment may also be a format string. In this case the format
  928. string will be directly exported. This format string may contain
  929. these elements:
  930. %s for the formatted source
  931. %c for the caption
  932. %f for the float attribute
  933. %l for an appropriate label
  934. %o for the LaTeX attributes
  935. For example,
  936. (setq org-latex-custom-lang-environments
  937. \\='((python \"pythoncode\")
  938. (ocaml \"\\\\begin{listing}
  939. \\\\begin{minted}[%o]{ocaml}
  940. %s\\\\end{minted}
  941. \\\\caption{%c}
  942. \\\\label{%l}\")))
  943. would have the effect that if Org encounters a Python source block
  944. during LaTeX export it will produce
  945. \\begin{pythoncode}
  946. <source block body>
  947. \\end{pythoncode}
  948. and if Org encounters an Ocaml source block during LaTeX export it
  949. will produce
  950. \\begin{listing}
  951. \\begin{minted}[<attr_latex options>]{ocaml}
  952. <source block body>
  953. \\end{minted}
  954. \\caption{<caption>}
  955. \\label{<label>}
  956. \\end{listing}"
  957. :group 'org-export-latex
  958. :type '(repeat
  959. (list
  960. (symbol :tag "Language name ")
  961. (string :tag "Environment name or format string")))
  962. :version "26.1"
  963. :package-version '(Org . "9.0"))
  964. (defcustom org-latex-engraved-preamble
  965. "\\usepackage{fvextra}
  966. [FVEXTRA-SETUP]
  967. % Make line numbers smaller and grey.
  968. \\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
  969. \\usepackage{xcolor}
  970. % In case engrave-faces-latex-gen-preamble has not been run.
  971. \\providecolor{EfD}{HTML}{f7f7f7}
  972. \\providecolor{EFD}{HTML}{28292e}
  973. % Define a Code environment to prettily wrap the fontified code.
  974. \\usepackage[breakable,xparse]{tcolorbox}
  975. \\DeclareTColorBox[]{Code}{o}%
  976. {colback=EfD!98!EFD, colframe=EfD!95!EFD,
  977. fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
  978. colupper=EFD,
  979. IfNoValueTF={#1}%
  980. {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
  981. boxrule=0.5pt, left=2pt}%
  982. {boxsep=2.5pt, arc=0pt, outer arc=0pt,
  983. boxrule=0pt, leftrule=1.5pt, left=0.5pt},
  984. right=2pt, top=1pt, bottom=0.5pt,
  985. breakable}
  986. [LISTINGS-SETUP]"
  987. "Preamble content injected when using engrave-faces-latex for source blocks.
  988. This is relevant when `org-latex-src-block-backend' is set to `engraved'.
  989. There is quite a lot of flexibility in what this preamble can be,
  990. as long as it:
  991. - Loads the fvextra package.
  992. - Loads the package xcolor (if it is not already loaded elsewhere).
  993. - Defines a \"Code\" environment (note the capital C), which all
  994. \"Verbatim\" environments (provided by fvextra) will be wrapped with.
  995. In the default value the colors \"EFD\" and \"EfD\" are provided
  996. as they are respectively the foreground and background colours,
  997. just in case they aren't provided by the generated preamble, so
  998. we can assume they are always set.
  999. Within this preamble there are two recognised macro-like placeholders:
  1000. [FVEXTRA-SETUP]
  1001. [LISTINGS-SETUP]
  1002. Unless you have a very good reason, both of these placeholders
  1003. should be included in the preamble.
  1004. FVEXTRA-SETUP sets fvextra's defaults according to
  1005. `org-latex-engraved-options', and LISTINGS-SETUP creates the
  1006. listings environment used for captioned or floating code blocks,
  1007. as well as defining \\listoflistings."
  1008. :group 'org-export-latex
  1009. :type 'string
  1010. :package-version '(Org . "9.6"))
  1011. (defcustom org-latex-engraved-options
  1012. '(("commandchars" . "\\\\\\{\\}")
  1013. ("highlightcolor" . "white!95!black!80!blue")
  1014. ("breaklines" . "true")
  1015. ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
  1016. "Association list of options for the latex fvextra package when engraving code.
  1017. These options are set using \\fvset{...} in the preamble of the
  1018. LaTeX export. Each element of the alist should be a list or cons
  1019. cell containing two strings: the name of the option, and the
  1020. value. For example,
  1021. (setq org-latex-engraved-options
  1022. \\='((\"highlightcolor\" \"green\") (\"frame\" \"lines\")))
  1023. ; or
  1024. (setq org-latex-engraved-options
  1025. \\='((\"highlightcolor\" . \"green\") (\"frame\" . \"lines\")))
  1026. will result in the following LaTeX in the preamble
  1027. \\fvset{%
  1028. bgcolor=bg,
  1029. frame=lines}
  1030. This will affect all fvextra environments. Note that the same
  1031. options will be applied to all blocks. If you need
  1032. block-specific options, you may use the following syntax:
  1033. #+ATTR_LATEX: :options key1=value1,key2=value2
  1034. #+BEGIN_SRC <LANG>
  1035. ...
  1036. #+END_SRC"
  1037. :group 'org-export-latex
  1038. :type '(alist :key-type (string :tag "option")
  1039. :value-type (string :tag "value")))
  1040. (defcustom org-latex-engraved-theme nil
  1041. "The theme that should be used for engraved code, when non-nil.
  1042. This can be set to any theme defined in `engrave-faces-themes' or
  1043. loadable by Emacs. When set to t, the current Emacs theme is
  1044. used. When nil, no theme is applied."
  1045. :group 'org-export-latex
  1046. :type 'symbol)
  1047. (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
  1048. "Generate the preamble to setup engraved code.
  1049. The result is constructed from the :latex-engraved-preamble and
  1050. :latex-engraved-optionsn export options, the default values of
  1051. which are given by `org-latex-engraved-preamble' and
  1052. `org-latex-engraved-options' respectively."
  1053. (let* ((engraved-options
  1054. (plist-get info :latex-engraved-options))
  1055. (engraved-preamble (plist-get info :latex-engraved-preamble))
  1056. (engraved-theme (plist-get info :latex-engraved-theme))
  1057. (engraved-themes
  1058. (cl-delete-duplicates
  1059. (org-element-map
  1060. (plist-get info :parse-tree)
  1061. '(src-block inline-src-block)
  1062. (lambda (src)
  1063. (plist-get
  1064. (org-export-read-attribute :attr_latex src)
  1065. :engraved-theme))
  1066. info)))
  1067. (gen-theme-spec
  1068. (lambda (theme)
  1069. (if (eq engrave-faces-latex-output-style 'preset)
  1070. (engrave-faces-latex-gen-preamble (when theme (intern theme)))
  1071. (engrave-faces-latex-gen-preamble-line
  1072. 'default
  1073. (alist-get 'default
  1074. (if theme
  1075. (engrave-faces-get-theme (intern theme))
  1076. engrave-faces-current-preset-style)))))))
  1077. (when (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?" engraved-preamble)
  1078. (setq engraved-preamble
  1079. (replace-match
  1080. (concat
  1081. "\\fvset{%\n "
  1082. (org-latex--make-option-string engraved-options ",\n ")
  1083. "}\n")
  1084. t t
  1085. engraved-preamble)))
  1086. (when (string-match "^[ \t]*\\[LISTINGS-SETUP\\][ \t]*\n?" engraved-preamble)
  1087. (setq engraved-preamble
  1088. (replace-match
  1089. (format
  1090. "%% Support listings with captions
  1091. \\usepackage{float}
  1092. \\floatstyle{%s}
  1093. \\newfloat{listing}{htbp}{lst}
  1094. \\newcommand{\\listingsname}{Listing}
  1095. \\floatname{listing}{\\listingsname}
  1096. \\newcommand{\\listoflistingsname}{List of Listings}
  1097. \\providecommand{\\listoflistings}{\\listof{listing}{\\listoflistingsname}}\n"
  1098. (if (memq 'src-block org-latex-caption-above)
  1099. "plaintop" "plain"))
  1100. t t
  1101. engraved-preamble)))
  1102. (if syntax-colours-p
  1103. (concat
  1104. "\n% Setup for code blocks [1/2]\n\n"
  1105. engraved-preamble
  1106. "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n\n"
  1107. (if (require 'engrave-faces-latex nil t)
  1108. (if engraved-themes
  1109. (concat
  1110. (mapconcat
  1111. (lambda (theme)
  1112. (format
  1113. "\n\\newcommand{\\engravedtheme%s}{%%\n%s\n}"
  1114. (replace-regexp-in-string "[^A-Za-z]" "" theme)
  1115. (replace-regexp-in-string
  1116. "newcommand" "renewcommand"
  1117. (replace-regexp-in-string
  1118. "#" "##"
  1119. (funcall gen-theme-spec theme)))))
  1120. engraved-themes
  1121. "\n")
  1122. "\n\n"
  1123. (cond
  1124. ((memq engraved-theme engraved-themes)
  1125. (concat "\\engravedtheme"
  1126. (replace-regexp-in-string
  1127. "[^A-Za-z]" "" engraved-theme)
  1128. "\n"))
  1129. (t (funcall gen-theme-spec engraved-theme))))
  1130. (funcall gen-theme-spec engraved-theme))
  1131. (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
  1132. "% WARNING syntax highlighting unavailable as engrave-faces-latex was missing.\n")
  1133. "\n")
  1134. (concat
  1135. "\n% Setup for code blocks\n\n"
  1136. engraved-preamble
  1137. "\n"))))
  1138. ;;;; Compilation
  1139. (defcustom org-latex-compiler-file-string "%% Intended LaTeX compiler: %s\n"
  1140. "LaTeX compiler format-string.
  1141. See also `org-latex-compiler'."
  1142. :group 'org-export-latex
  1143. :type '(choice
  1144. (const :tag "Comment" "%% Intended LaTeX compiler: %s\n")
  1145. (const :tag "latex-mode file variable" "%% -*- latex-run-command: %s -*-\n")
  1146. (const :tag "AUCTeX file variable" "%% -*- LaTeX-command: %s -*-\n")
  1147. (string :tag "custom format" "%% %s"))
  1148. :version "26.1"
  1149. :package-version '(Org . "9.0"))
  1150. (defcustom org-latex-compiler "pdflatex"
  1151. "LaTeX compiler to use.
  1152. Must be an element in `org-latex-compilers' or the empty quote.
  1153. Can also be set in buffers via #+LATEX_COMPILER. See also
  1154. `org-latex-compiler-file-string'."
  1155. :group 'org-export-latex
  1156. :type '(choice
  1157. (const :tag "pdfLaTeX" "pdflatex")
  1158. (const :tag "XeLaTeX" "xelatex")
  1159. (const :tag "LuaLaTeX" "lualatex")
  1160. (const :tag "Unset" ""))
  1161. :version "26.1"
  1162. :package-version '(Org . "9.0"))
  1163. (defconst org-latex-compilers '("pdflatex" "xelatex" "lualatex")
  1164. "Known LaTeX compilers.
  1165. See also `org-latex-compiler'.")
  1166. (defcustom org-latex-bib-compiler "bibtex"
  1167. "Command to process a LaTeX file's bibliography.
  1168. The shorthand %bib in `org-latex-pdf-process' is replaced with
  1169. this value.
  1170. A better approach is to use a compiler suit such as `latexmk'."
  1171. :group 'org-export-latex
  1172. :type '(choice (const :tag "BibTeX" "bibtex")
  1173. (const :tag "Biber" "biber")
  1174. (string :tag "Other process"))
  1175. :version "26.1"
  1176. :package-version '(Org . "9.0"))
  1177. (defcustom org-latex-pdf-process
  1178. (if (executable-find "latexmk")
  1179. '("latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f")
  1180. '("%latex -interaction nonstopmode -output-directory %o %f"
  1181. "%latex -interaction nonstopmode -output-directory %o %f"
  1182. "%latex -interaction nonstopmode -output-directory %o %f"))
  1183. "Commands to process a LaTeX file to a PDF file.
  1184. The command output will be parsed to extract compilation errors and
  1185. warnings according to `org-latex-known-warnings'.
  1186. This is a list of strings, each of them will be given to the
  1187. shell as a command. %f in the command will be replaced by the
  1188. relative file name, %F by the absolute file name, %b by the file
  1189. base name (i.e. without directory and extension parts), %o by the
  1190. base directory of the file, %O by the absolute file name of the
  1191. output file, %latex is the LaTeX compiler (see
  1192. `org-latex-compiler'), and %bib is the BibTeX-like compiler (see
  1193. `org-latex-bib-compiler').
  1194. The reason why this is a list is that it usually takes several
  1195. runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
  1196. does not have a clever mechanism to detect which of these
  1197. commands have to be run to get to a stable result, and it also
  1198. does not do any error checking.
  1199. Consider a smart LaTeX compiler such as `texi2dvi' or `latexmk',
  1200. which calls the \"correct\" combinations of auxiliary programs.
  1201. Alternatively, this may be a Lisp function that does the
  1202. processing, so you could use this to apply the machinery of
  1203. AUCTeX or the Emacs LaTeX mode. This function should accept the
  1204. file name as its single argument."
  1205. :group 'org-export-pdf
  1206. :type '(choice
  1207. (repeat :tag "Shell command sequence"
  1208. (string :tag "Shell command"))
  1209. (const :tag "2 runs of latex"
  1210. ("%latex -interaction nonstopmode -output-directory %o %f"
  1211. "%latex -interaction nonstopmode -output-directory %o %f"))
  1212. (const :tag "3 runs of latex"
  1213. ("%latex -interaction nonstopmode -output-directory %o %f"
  1214. "%latex -interaction nonstopmode -output-directory %o %f"
  1215. "%latex -interaction nonstopmode -output-directory %o %f"))
  1216. (const :tag "latex,bibtex,latex,latex"
  1217. ("%latex -interaction nonstopmode -output-directory %o %f"
  1218. "%bib %b"
  1219. "%latex -interaction nonstopmode -output-directory %o %f"
  1220. "%latex -interaction nonstopmode -output-directory %o %f"))
  1221. (const :tag "texi2dvi"
  1222. ("cd %o; LATEX=\"%latex\" texi2dvi -p -b -V %b.tex"))
  1223. (const :tag "latexmk"
  1224. ("latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f"))
  1225. (function)))
  1226. (defcustom org-latex-logfiles-extensions
  1227. '("aux" "bcf" "blg" "fdb_latexmk" "fls" "figlist" "idx" "log" "nav" "out"
  1228. "ptc" "run.xml" "snm" "toc" "vrb" "xdv")
  1229. "The list of file extensions to consider as LaTeX logfiles.
  1230. The logfiles will be removed if `org-latex-remove-logfiles' is
  1231. non-nil."
  1232. :group 'org-export-latex
  1233. :version "26.1"
  1234. :package-version '(Org . "8.3")
  1235. :type '(repeat (string :tag "Extension")))
  1236. (defcustom org-latex-remove-logfiles t
  1237. "Non-nil means remove the logfiles produced by PDF production.
  1238. By default, logfiles are files with these extensions: .aux, .idx,
  1239. .log, .out, .toc, .nav, .snm and .vrb. To define the set of
  1240. logfiles to remove, set `org-latex-logfiles-extensions'."
  1241. :group 'org-export-latex
  1242. :type 'boolean)
  1243. (defcustom org-latex-known-warnings
  1244. '(("Reference.*?undefined" . "[undefined reference]")
  1245. ("Runaway argument" . "[runaway argument]")
  1246. ("Underfull \\hbox" . "[underfull hbox]")
  1247. ("Overfull \\hbox" . "[overfull hbox]")
  1248. ("Citation.*?undefined" . "[undefined citation]")
  1249. ("Undefined control sequence" . "[undefined control sequence]"))
  1250. "Alist of regular expressions and associated messages for the user.
  1251. The regular expressions are used to find possible warnings in the
  1252. log of a LaTeX-run. These warnings will be reported after
  1253. calling `org-latex-compile'."
  1254. :group 'org-export-latex
  1255. :version "26.1"
  1256. :package-version '(Org . "8.3")
  1257. :type '(repeat
  1258. (cons
  1259. (regexp :tag "Regexp")
  1260. (string :tag "Message"))))
  1261. ;;; Internal Functions
  1262. (defun org-latex--caption-above-p (element info)
  1263. "Non-nil when caption is expected to be located above ELEMENT.
  1264. INFO is a plist holding contextual information."
  1265. (let ((above (plist-get info :latex-caption-above)))
  1266. (if (symbolp above) above
  1267. (let ((type (org-element-type element)))
  1268. (memq (if (eq type 'link) 'image type) above)))))
  1269. (defun org-latex--label (datum info &optional force full)
  1270. "Return an appropriate label for DATUM.
  1271. DATUM is an element or a `target' type object. INFO is the
  1272. current export state, as a plist.
  1273. Return nil if element DATUM has no NAME or VALUE affiliated
  1274. keyword or no CUSTOM_ID property, unless FORCE is non-nil. In
  1275. this case always return a unique label.
  1276. Eventually, if FULL is non-nil, wrap label within \"\\label{}\"."
  1277. (let* ((type (org-element-type datum))
  1278. (user-label
  1279. (org-element-property
  1280. (cl-case type
  1281. ((headline inlinetask) :CUSTOM_ID)
  1282. (target :value)
  1283. (otherwise :name))
  1284. datum))
  1285. (label
  1286. (and (or user-label force)
  1287. (if (and user-label (plist-get info :latex-prefer-user-labels))
  1288. user-label
  1289. (concat (pcase type
  1290. (`headline "sec:")
  1291. (`table "tab:")
  1292. (`latex-environment
  1293. (and (string-match-p
  1294. org-latex-math-environments-re
  1295. (org-element-property :value datum))
  1296. "eq:"))
  1297. (`latex-matrices "eq:")
  1298. (`paragraph
  1299. (and (org-element-property :caption datum)
  1300. "fig:"))
  1301. (`src-block "lst:")
  1302. (_ nil))
  1303. (org-export-get-reference datum info))))))
  1304. (cond ((not full) label)
  1305. (label (format "\\label{%s}%s"
  1306. label
  1307. (if (eq type 'target) "" "\n")))
  1308. (t ""))))
  1309. (defun org-latex--caption/label-string (element info)
  1310. "Return caption and label LaTeX string for ELEMENT.
  1311. INFO is a plist holding contextual information. If there's no
  1312. caption nor label, return the empty string.
  1313. For non-floats, see `org-latex--wrap-label'."
  1314. (let* ((label (org-latex--label element info nil t))
  1315. (main (org-export-get-caption element))
  1316. (attr (org-export-read-attribute :attr_latex element))
  1317. (type (org-element-type element))
  1318. (nonfloat (or (and (plist-member attr :float)
  1319. (not (plist-get attr :float))
  1320. main)
  1321. (and (eq type 'src-block)
  1322. (not (plist-get attr :float))
  1323. (memq (plist-get info :latex-src-block-backend)
  1324. '(verbatim nil)))))
  1325. (short (org-export-get-caption element t))
  1326. (caption-from-attr-latex (plist-get attr :caption)))
  1327. (cond
  1328. ((org-string-nw-p caption-from-attr-latex)
  1329. (concat caption-from-attr-latex "\n"))
  1330. ((and (not main) (equal label "")) "")
  1331. ((not main) label)
  1332. ;; Option caption format with short name.
  1333. (t
  1334. (format (if nonfloat "\\captionof{%s}%s{%s%s}\n"
  1335. "\\caption%s%s{%s%s}\n")
  1336. (let ((type* (if (eq type 'latex-environment)
  1337. (org-latex--environment-type element)
  1338. type)))
  1339. (if nonfloat
  1340. (cl-case type*
  1341. (paragraph "figure")
  1342. (image "figure")
  1343. (special-block "figure")
  1344. (src-block (if (not (memq (plist-get info :latex-src-block-backend)
  1345. '(verbatim nil)))
  1346. "listing"
  1347. "figure"))
  1348. (t (symbol-name type*)))
  1349. ""))
  1350. (if short (format "[%s]" (org-export-data short info)) "")
  1351. (org-trim label)
  1352. (org-export-data main info))))))
  1353. (defun org-latex-guess-inputenc (header)
  1354. "Set the coding system in inputenc to what the buffer is.
  1355. HEADER is the LaTeX header string. This function only applies
  1356. when specified inputenc option is \"AUTO\".
  1357. Return the new header, as a string."
  1358. (let* ((cs (or (ignore-errors
  1359. (latexenc-coding-system-to-inputenc
  1360. (or org-export-coding-system buffer-file-coding-system)))
  1361. "utf8")))
  1362. (if (not cs) header
  1363. ;; First translate if that is requested.
  1364. (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
  1365. ;; Then find the \usepackage statement and replace the option.
  1366. (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
  1367. cs header t nil 1))))
  1368. (defun org-latex-guess-babel-language (header info)
  1369. "Set Babel's language according to LANGUAGE keyword.
  1370. HEADER is the LaTeX header string. INFO is the plist used as
  1371. a communication channel.
  1372. Insertion of guessed language only happens when Babel package has
  1373. explicitly been loaded. Then it is added to the rest of
  1374. package's options.
  1375. The optional argument to Babel or the mandatory argument to
  1376. `\babelprovide' command may be \"AUTO\" which is then replaced
  1377. with the language of the document or
  1378. `org-export-default-language' unless language in question is
  1379. already loaded.
  1380. Return the new header."
  1381. (let* ((language-code (plist-get info :language))
  1382. (language (nth 1 (assoc language-code
  1383. org-latex-language-alist)))
  1384. ;; If no language is set or Babel package is not loaded, return
  1385. ;; HEADER as-is.
  1386. (header (if (or (not (stringp language-code))
  1387. (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
  1388. header
  1389. (let ((options (save-match-data
  1390. (org-split-string (match-string 1 header) ",[ \t]*"))))
  1391. ;; If LANGUAGE is already loaded, return header
  1392. ;; without AUTO. Otherwise, replace AUTO with language or
  1393. ;; append language if AUTO is not present. Languages that are
  1394. ;; served in Babel exclusively through ini files are not added
  1395. ;; to the babel argument, and must be loaded using
  1396. ;; `\babelprovide'.
  1397. (let ((l (assoc language-code org-latex-language-alist)))
  1398. ;; Three elements imply that LANGUAGE is served
  1399. ;; in Babel only by means of an ini file.
  1400. ;; Therefore it will not be added to the Babel
  1401. ;; argument. TODO: this should be improved
  1402. ;; when `org-latex-language-alist' is replaced
  1403. ;; by a more robust list.
  1404. (if (and (consp l) (= (length l) 3))
  1405. header
  1406. (replace-match
  1407. (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
  1408. (cond ((member language options) (delete "AUTO" options))
  1409. ((member "AUTO" options) options)
  1410. (t (append options (list language))))
  1411. ", ")
  1412. t nil header 1)))))))
  1413. ;; If `\babelprovide[args]{AUTO}' is present, AUTO is
  1414. ;; replaced by LANGUAGE.
  1415. (if (not (string-match "\\\\babelprovide\\[.*\\]{\\(.+\\)}" header))
  1416. header
  1417. (let ((prov (match-string 1 header)))
  1418. (when (equal "AUTO" prov)
  1419. (replace-regexp-in-string (format
  1420. "\\(\\\\babelprovide\\[.*\\]\\)\\({\\)%s}" prov)
  1421. (format "\\1\\2%s}" language) header t))))))
  1422. (defun org-latex-guess-polyglossia-language (header info)
  1423. "Set the Polyglossia language according to the LANGUAGE keyword.
  1424. HEADER is the LaTeX header string. INFO is the plist used as
  1425. a communication channel.
  1426. Insertion of guessed language only happens when the Polyglossia
  1427. package has been explicitly loaded.
  1428. The argument to Polyglossia may be \"AUTO\" which is then
  1429. replaced with the language of the document or
  1430. `org-export-default-language'. Note, the language is really set
  1431. using \setdefaultlanguage and not as an option to the package.
  1432. Return the new header."
  1433. (let ((language (plist-get info :language)))
  1434. ;; If no language is set or Polyglossia is not loaded, return
  1435. ;; HEADER as-is.
  1436. (if (or (not (stringp language))
  1437. (not (string-match
  1438. "\\\\usepackage\\(?:\\[\\([^]]+?\\)\\]\\){polyglossia}\n"
  1439. header)))
  1440. header
  1441. (let* ((options (org-string-nw-p (match-string 1 header)))
  1442. (languages (and options
  1443. ;; Reverse as the last loaded language is
  1444. ;; the main language.
  1445. (nreverse
  1446. (delete-dups
  1447. (save-match-data
  1448. (org-split-string
  1449. (replace-regexp-in-string
  1450. "AUTO" language options t)
  1451. ",[ \t]*"))))))
  1452. (main-language-set
  1453. (string-match-p "\\\\setmainlanguage{.*?}" header)))
  1454. (replace-match
  1455. (concat "\\usepackage{polyglossia}\n"
  1456. (mapconcat
  1457. (lambda (l)
  1458. (let ((l (or (assoc l org-latex-language-alist)
  1459. l)))
  1460. (format (if main-language-set "\\setotherlanguage%s{%s}\n"
  1461. (setq main-language-set t)
  1462. "\\setmainlanguage%s{%s}\n")
  1463. ;; Four elements implies that there is a
  1464. ;; variant (4) for LANGUAGE when
  1465. ;; declared by Polyglossia (3).
  1466. ;; FIXME: This should be improved when
  1467. ;; `org-latex-language-alist' is
  1468. ;; replaced by a more robust list.
  1469. (if (and (consp l) (= (length l) 4))
  1470. (format "[variant=%s]" (nth 3 l))
  1471. "")
  1472. (if (and (consp l) (= (length l) 4))
  1473. (nth 2 l)
  1474. (nth 1 l)))))
  1475. languages
  1476. ""))
  1477. t t header 0)))))
  1478. (defun org-latex--remove-packages (pkg-alist info)
  1479. "Remove packages based on the current LaTeX compiler.
  1480. PKG-ALIST is a list of packages, as in `org-latex-packages-alist'
  1481. and `org-latex-default-packages-alist'. If the fourth argument
  1482. of a package is neither nil nor a member of the LaTeX compiler
  1483. associated to the document, the package is removed.
  1484. Return new list of packages."
  1485. (let ((compiler (or (plist-get info :latex-compiler) "")))
  1486. (if (not (member-ignore-case compiler org-latex-compilers)) pkg-alist
  1487. (cl-remove-if-not
  1488. (lambda (package)
  1489. (pcase package
  1490. (`(,_ ,_ ,_ nil) t)
  1491. (`(,_ ,_ ,_ ,compilers) (member-ignore-case compiler compilers))
  1492. (_ t)))
  1493. pkg-alist))))
  1494. (defun org-latex--find-verb-separator (s)
  1495. "Return a character not used in string S.
  1496. This is used to choose a separator for constructs like \\verb."
  1497. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1498. (cl-loop for c across ll
  1499. when (not (string-match (regexp-quote (char-to-string c)) s))
  1500. return (char-to-string c))))
  1501. (defun org-latex--make-option-string (options &optional separator)
  1502. "Return a comma separated string of keywords and values.
  1503. OPTIONS is an alist where the key is the options keyword as
  1504. a string, and the value a list containing the keyword value, or
  1505. nil."
  1506. (mapconcat (lambda (pair)
  1507. (let ((keyword (car pair))
  1508. (value (pcase (cdr pair)
  1509. ((pred stringp) (cdr pair))
  1510. ((pred consp) (cadr pair)))))
  1511. (concat keyword
  1512. (when value
  1513. (concat "="
  1514. (if (string-match-p (rx (any "[]")) value)
  1515. (format "{%s}" value)
  1516. value))))))
  1517. options
  1518. (or separator ",")))
  1519. (defun org-latex--wrap-label (element output info)
  1520. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  1521. INFO is the current export state, as a plist. This function
  1522. should not be used for floats. See
  1523. `org-latex--caption/label-string'."
  1524. (if (not (and (org-string-nw-p output) (org-element-property :name element)))
  1525. output
  1526. (concat (format "\\phantomsection\n\\label{%s}\n"
  1527. (org-latex--label element info))
  1528. output)))
  1529. (defun org-latex--protect-text (text)
  1530. "Protect special characters in string TEXT and return it."
  1531. (replace-regexp-in-string "[\\{}$%&_#~^]" "\\\\\\&" text))
  1532. (defun org-latex--text-markup (text markup info)
  1533. "Format TEXT depending on MARKUP text markup.
  1534. INFO is a plist used as a communication channel. See
  1535. `org-latex-text-markup-alist' for details."
  1536. (let ((fmt (cdr (assq markup (plist-get info :latex-text-markup-alist)))))
  1537. (cl-case fmt
  1538. ;; No format string: Return raw text.
  1539. ((nil) text)
  1540. ;; Handle the `verb' special case: Find an appropriate separator
  1541. ;; and use "\\verb" command.
  1542. (verb
  1543. (let ((separator (org-latex--find-verb-separator text)))
  1544. (concat "\\verb"
  1545. separator
  1546. (replace-regexp-in-string "\n" " " text)
  1547. separator)))
  1548. (protectedtexttt (org-latex--protect-texttt text))
  1549. ;; Else use format string.
  1550. (t (format fmt text)))))
  1551. (defun org-latex--protect-texttt (text)
  1552. "Protect special chars, then wrap TEXT in \"\\texttt{}\"."
  1553. (format "\\texttt{%s}"
  1554. (replace-regexp-in-string
  1555. "--\\|[\\{}$%&_#~^]"
  1556. (lambda (m)
  1557. (cond ((equal m "--") "-{}-")
  1558. ((equal m "\\") "\\textbackslash{}")
  1559. ((equal m "~") "\\textasciitilde{}")
  1560. ((equal m "^") "\\textasciicircum{}")
  1561. (t (org-latex--protect-text m))))
  1562. text nil t)))
  1563. (defun org-latex--delayed-footnotes-definitions (element info)
  1564. "Return footnotes definitions in ELEMENT as a string.
  1565. INFO is a plist used as a communication channel.
  1566. Footnotes definitions are returned within \"\\footnotetext{}\"
  1567. commands.
  1568. This function is used within constructs that don't support
  1569. \"\\footnote{}\" command (e.g., an item tag). In that case,
  1570. \"\\footnotemark\" is used within the construct and the function
  1571. just outside of it."
  1572. (mapconcat
  1573. (lambda (ref)
  1574. (let ((def (org-export-get-footnote-definition ref info)))
  1575. (format "\\footnotetext[%d]{%s%s}"
  1576. (org-export-get-footnote-number ref info)
  1577. (org-trim (org-latex--label def info t t))
  1578. (org-trim (org-export-data def info)))))
  1579. ;; Find every footnote reference in ELEMENT.
  1580. (letrec ((all-refs nil)
  1581. (search-refs
  1582. (lambda (data)
  1583. ;; Return a list of all footnote references never seen
  1584. ;; before in DATA.
  1585. (org-element-map data 'footnote-reference
  1586. (lambda (ref)
  1587. (when (org-export-footnote-first-reference-p ref info)
  1588. (push ref all-refs)
  1589. (when (eq (org-element-property :type ref) 'standard)
  1590. (funcall search-refs
  1591. (org-export-get-footnote-definition ref info)))))
  1592. info)
  1593. (reverse all-refs))))
  1594. (funcall search-refs element))
  1595. ""))
  1596. (defun org-latex--translate (s info)
  1597. "Translate string S according to specified language.
  1598. INFO is a plist used as a communication channel."
  1599. (org-export-translate s :latex info))
  1600. (defun org-latex--format-spec (info)
  1601. "Create a format-spec for document meta-data.
  1602. INFO is a plist used as a communication channel."
  1603. (let ((language (let ((lang (plist-get info :language)))
  1604. ;; The second element in
  1605. ;; `org-latex-language-alist' is always the
  1606. ;; language name, regardless of the type of the
  1607. ;; alist entry.
  1608. (or (nth 1 (assoc-string lang org-latex-language-alist t))
  1609. lang))))
  1610. `((?a . ,(org-export-data (plist-get info :author) info))
  1611. (?t . ,(org-export-data (plist-get info :title) info))
  1612. (?s . ,(org-export-data (plist-get info :subtitle) info))
  1613. (?k . ,(org-export-data (org-latex--wrap-latex-math-block
  1614. (plist-get info :keywords) info)
  1615. info))
  1616. (?d . ,(org-export-data (org-latex--wrap-latex-math-block
  1617. (plist-get info :description) info)
  1618. info))
  1619. (?c . ,(plist-get info :creator))
  1620. (?l . ,language)
  1621. (?L . ,(capitalize language))
  1622. (?D . ,(org-export-get-date info)))))
  1623. (defun org-latex--insert-compiler (info)
  1624. "Insert LaTeX_compiler info into the document.
  1625. INFO is a plist used as a communication channel."
  1626. (let ((compiler (plist-get info :latex-compiler)))
  1627. (and (org-string-nw-p org-latex-compiler-file-string)
  1628. (member (or compiler "") org-latex-compilers)
  1629. (format org-latex-compiler-file-string compiler))))
  1630. ;;; Filters
  1631. (defun org-latex-matrices-tree-filter (tree _backend info)
  1632. (org-latex--wrap-latex-matrices tree info))
  1633. (defun org-latex-math-block-tree-filter (tree _backend info)
  1634. (org-latex--wrap-latex-math-block tree info))
  1635. (defun org-latex-math-block-options-filter (info _backend)
  1636. (dolist (prop '(:author :date :title) info)
  1637. (plist-put info prop
  1638. (org-latex--wrap-latex-math-block (plist-get info prop) info))))
  1639. (defun org-latex-clean-invalid-line-breaks (data _backend _info)
  1640. (replace-regexp-in-string
  1641. "\\(\\\\end{[A-Za-z0-9*]+}\\|^\\)[ \t]*\\\\\\\\[ \t]*$" "\\1"
  1642. data))
  1643. ;;; Template
  1644. ;;;###autoload
  1645. (defun org-latex-make-preamble (info &optional template snippet?)
  1646. "Return a formatted LaTeX preamble.
  1647. INFO is a plist used as a communication channel. Optional
  1648. argument TEMPLATE, when non-nil, is the header template string,
  1649. as expected by `org-splice-latex-header'. When SNIPPET? is
  1650. non-nil, only includes packages relevant to image generation, as
  1651. specified in `org-latex-default-packages-alist' or
  1652. `org-latex-packages-alist'."
  1653. (let* ((class (plist-get info :latex-class))
  1654. (class-template
  1655. (or template
  1656. (let* ((class-options (plist-get info :latex-class-options))
  1657. (header (nth 1 (assoc class (plist-get info :latex-classes)))))
  1658. (and (stringp header)
  1659. (if (not class-options) header
  1660. (replace-regexp-in-string
  1661. "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
  1662. class-options header t nil 1))))
  1663. (user-error "Unknown LaTeX class `%s'" class))))
  1664. (org-latex-guess-polyglossia-language
  1665. (org-latex-guess-babel-language
  1666. (org-latex-guess-inputenc
  1667. (org-element-normalize-string
  1668. (org-splice-latex-header
  1669. class-template
  1670. (org-latex--remove-packages org-latex-default-packages-alist info)
  1671. (org-latex--remove-packages org-latex-packages-alist info)
  1672. snippet?
  1673. (mapconcat #'org-element-normalize-string
  1674. (list (plist-get info :latex-header)
  1675. (and (not snippet?)
  1676. (plist-get info :latex-header-extra)))
  1677. ""))))
  1678. info)
  1679. info)))
  1680. (defun org-latex-template (contents info)
  1681. "Return complete document string after LaTeX conversion.
  1682. CONTENTS is the transcoded contents string. INFO is a plist
  1683. holding export options."
  1684. (let ((title (org-export-data (plist-get info :title) info))
  1685. (spec (org-latex--format-spec info)))
  1686. (concat
  1687. ;; Time-stamp.
  1688. (and (plist-get info :time-stamp-file)
  1689. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  1690. ;; LaTeX compiler.
  1691. (org-latex--insert-compiler info)
  1692. ;; Document class and packages.
  1693. (org-latex-make-preamble info)
  1694. ;; Possibly limit depth for headline numbering.
  1695. (let ((sec-num (plist-get info :section-numbers)))
  1696. (when (integerp sec-num)
  1697. (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
  1698. ;; Author.
  1699. (let ((author (and (plist-get info :with-author)
  1700. (let ((auth (plist-get info :author)))
  1701. (and auth (org-export-data auth info)))))
  1702. (email (and (plist-get info :with-email)
  1703. (org-export-data (plist-get info :email) info))))
  1704. (cond ((and author email (not (string= "" email)))
  1705. (format "\\author{%s\\thanks{%s}}\n" author email))
  1706. ((or author email) (format "\\author{%s}\n" (or author email)))))
  1707. ;; Date.
  1708. (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
  1709. (when date
  1710. (format "\\date{%s}\n" (org-export-data date info))))
  1711. ;; Title and subtitle.
  1712. (let* ((subtitle (plist-get info :subtitle))
  1713. (formatted-subtitle
  1714. (when subtitle
  1715. (format (plist-get info :latex-subtitle-format)
  1716. (org-export-data subtitle info))))
  1717. (separate (plist-get info :latex-subtitle-separate)))
  1718. (concat
  1719. (format "\\title{%s%s}\n" title
  1720. (if separate "" (or formatted-subtitle "")))
  1721. (when (and separate subtitle)
  1722. (concat formatted-subtitle "\n"))))
  1723. ;; Hyperref options.
  1724. (let ((template (plist-get info :latex-hyperref-template)))
  1725. (and (stringp template)
  1726. (format-spec template spec)))
  1727. ;; engrave-faces-latex preamble
  1728. (when (and (eq org-latex-src-block-backend 'engraved)
  1729. (org-element-map (plist-get info :parse-tree)
  1730. '(src-block inline-src-block) #'identity
  1731. info t))
  1732. (org-latex-generate-engraved-preamble info t))
  1733. ;; Document start.
  1734. "\\begin{document}\n\n"
  1735. ;; Title command.
  1736. (let* ((title-command (plist-get info :latex-title-command))
  1737. (command (and (stringp title-command)
  1738. (format-spec title-command spec))))
  1739. (org-element-normalize-string
  1740. (cond ((not (plist-get info :with-title)) nil)
  1741. ((string= "" title) nil)
  1742. ((not (stringp command)) nil)
  1743. ((string-match "\\(?:[^%]\\|^\\)%s" command)
  1744. (format command title))
  1745. (t command))))
  1746. ;; Table of contents.
  1747. (let ((depth (plist-get info :with-toc)))
  1748. (when depth
  1749. (concat (when (integerp depth)
  1750. (format "\\setcounter{tocdepth}{%d}\n" depth))
  1751. (plist-get info :latex-toc-command))))
  1752. ;; Document's body.
  1753. contents
  1754. ;; Creator.
  1755. (and (plist-get info :with-creator)
  1756. (concat (plist-get info :creator) "\n"))
  1757. ;; Document end.
  1758. "\\end{document}")))
  1759. ;;; Transcode Functions
  1760. ;;;; Bold
  1761. (defun org-latex-bold (_bold contents info)
  1762. "Transcode BOLD from Org to LaTeX.
  1763. CONTENTS is the text with bold markup. INFO is a plist holding
  1764. contextual information."
  1765. (org-latex--text-markup contents 'bold info))
  1766. ;;;; Center Block
  1767. (defun org-latex-center-block (center-block contents info)
  1768. "Transcode a CENTER-BLOCK element from Org to LaTeX.
  1769. CONTENTS holds the contents of the center block. INFO is a plist
  1770. holding contextual information."
  1771. (org-latex--wrap-label
  1772. center-block (format "\\begin{center}\n%s\\end{center}" contents) info))
  1773. ;;;; Clock
  1774. (defun org-latex-clock (clock _contents info)
  1775. "Transcode a CLOCK element from Org to LaTeX.
  1776. CONTENTS is nil. INFO is a plist holding contextual
  1777. information."
  1778. (concat
  1779. "\\noindent"
  1780. (format "\\textbf{%s} " org-clock-string)
  1781. (format (plist-get info :latex-inactive-timestamp-format)
  1782. (concat (org-timestamp-translate (org-element-property :value clock))
  1783. (let ((time (org-element-property :duration clock)))
  1784. (and time (format " (%s)" time)))))
  1785. "\\\\"))
  1786. ;;;; Code
  1787. (defun org-latex-code (code _contents info)
  1788. "Transcode a CODE object from Org to LaTeX.
  1789. CONTENTS is nil. INFO is a plist used as a communication
  1790. channel."
  1791. (org-latex--text-markup (org-element-property :value code) 'code info))
  1792. ;;;; Drawer
  1793. (defun org-latex-drawer (drawer contents info)
  1794. "Transcode a DRAWER element from Org to LaTeX.
  1795. CONTENTS holds the contents of the block. INFO is a plist
  1796. holding contextual information."
  1797. (let* ((name (org-element-property :drawer-name drawer))
  1798. (output (funcall (plist-get info :latex-format-drawer-function)
  1799. name contents)))
  1800. (org-latex--wrap-label drawer output info)))
  1801. ;;;; Dynamic Block
  1802. (defun org-latex-dynamic-block (dynamic-block contents info)
  1803. "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
  1804. CONTENTS holds the contents of the block. INFO is a plist
  1805. holding contextual information. See `org-export-data'."
  1806. (org-latex--wrap-label dynamic-block contents info))
  1807. ;;;; Entity
  1808. (defun org-latex-entity (entity _contents _info)
  1809. "Transcode an ENTITY object from Org to LaTeX.
  1810. CONTENTS are the definition itself. INFO is a plist holding
  1811. contextual information."
  1812. (org-element-property :latex entity))
  1813. ;;;; Example Block
  1814. (defun org-latex-example-block (example-block _contents info)
  1815. "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
  1816. CONTENTS is nil. INFO is a plist holding contextual
  1817. information."
  1818. (when (org-string-nw-p (org-element-property :value example-block))
  1819. (let ((environment (or (org-export-read-attribute
  1820. :attr_latex example-block :environment)
  1821. "verbatim")))
  1822. (org-latex--wrap-label
  1823. example-block
  1824. (format "\\begin{%s}\n%s\\end{%s}"
  1825. environment
  1826. (org-export-format-code-default example-block info)
  1827. environment)
  1828. info))))
  1829. ;;;; Export Block
  1830. (defun org-latex-export-block (export-block _contents _info)
  1831. "Transcode a EXPORT-BLOCK element from Org to LaTeX.
  1832. CONTENTS is nil. INFO is a plist holding contextual information."
  1833. (when (member (org-element-property :type export-block) '("LATEX" "TEX"))
  1834. (org-remove-indentation (org-element-property :value export-block))))
  1835. ;;;; Export Snippet
  1836. (defun org-latex-export-snippet (export-snippet _contents _info)
  1837. "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
  1838. CONTENTS is nil. INFO is a plist holding contextual information."
  1839. (when (eq (org-export-snippet-backend export-snippet) 'latex)
  1840. (org-element-property :value export-snippet)))
  1841. ;;;; Fixed Width
  1842. (defun org-latex-fixed-width (fixed-width _contents info)
  1843. "Transcode a FIXED-WIDTH element from Org to LaTeX.
  1844. CONTENTS is nil. INFO is a plist holding contextual information."
  1845. (org-latex--wrap-label
  1846. fixed-width
  1847. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  1848. (org-remove-indentation
  1849. (org-element-property :value fixed-width)))
  1850. info))
  1851. ;;;; Footnote Reference
  1852. (defun org-latex-footnote-reference (footnote-reference _contents info)
  1853. "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
  1854. CONTENTS is nil. INFO is a plist holding contextual information."
  1855. (let ((label (org-element-property :label footnote-reference)))
  1856. (concat
  1857. ;; Insert separator between two footnotes in a row.
  1858. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1859. (when (eq (org-element-type prev) 'footnote-reference)
  1860. (plist-get info :latex-footnote-separator)))
  1861. (cond
  1862. ;; Use `:latex-footnote-defined-format' if the footnote has
  1863. ;; already been defined.
  1864. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1865. (format (plist-get info :latex-footnote-defined-format)
  1866. (org-latex--label
  1867. (org-export-get-footnote-definition footnote-reference info)
  1868. info t)))
  1869. ;; Use \footnotemark if reference is within another footnote
  1870. ;; reference, footnote definition, table cell, verse block, or
  1871. ;; item's tag.
  1872. ((or (org-element-lineage footnote-reference
  1873. '(footnote-reference footnote-definition
  1874. table-cell verse-block))
  1875. (eq 'item (org-element-type
  1876. (org-export-get-parent-element footnote-reference))))
  1877. "\\footnotemark")
  1878. ;; Otherwise, define it with \footnote command.
  1879. (t
  1880. (let ((def (org-export-get-footnote-definition footnote-reference info)))
  1881. (concat
  1882. (format "\\footnote{%s%s}" (org-trim (org-export-data def info))
  1883. ;; Only insert a \label if there exist another
  1884. ;; reference to def.
  1885. (cond ((not label) "")
  1886. ((org-element-map (plist-get info :parse-tree)
  1887. 'footnote-reference
  1888. (lambda (f)
  1889. (and (not (eq f footnote-reference))
  1890. (equal (org-element-property :label f) label)
  1891. (org-trim (org-latex--label def info t t))))
  1892. info t))
  1893. (t "")))
  1894. ;; Retrieve all footnote references within the footnote and
  1895. ;; add their definition after it, since LaTeX doesn't support
  1896. ;; them inside.
  1897. (org-latex--delayed-footnotes-definitions def info))))))))
  1898. ;;;; Headline
  1899. (defun org-latex-headline (headline contents info)
  1900. "Transcode a HEADLINE element from Org to LaTeX.
  1901. CONTENTS holds the contents of the headline. INFO is a plist
  1902. holding contextual information."
  1903. (unless (org-element-property :footnote-section-p headline)
  1904. (let* ((class (plist-get info :latex-class))
  1905. (level (org-export-get-relative-level headline info))
  1906. (numberedp (org-export-numbered-headline-p headline info))
  1907. (class-sectioning (assoc class (plist-get info :latex-classes)))
  1908. ;; Section formatting will set two placeholders: one for
  1909. ;; the title and the other for the contents.
  1910. (section-fmt
  1911. (let ((sec (if (functionp (nth 2 class-sectioning))
  1912. (funcall (nth 2 class-sectioning) level numberedp)
  1913. (nth (1+ level) class-sectioning))))
  1914. (cond
  1915. ;; No section available for that LEVEL.
  1916. ((not sec) nil)
  1917. ;; Section format directly returned by a function. Add
  1918. ;; placeholder for contents.
  1919. ((stringp sec) (concat sec "\n%s"))
  1920. ;; (numbered-section . unnumbered-section)
  1921. ((not (consp (cdr sec)))
  1922. (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
  1923. ;; (numbered-open numbered-close)
  1924. ((= (length sec) 2)
  1925. (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
  1926. ;; (num-in num-out no-num-in no-num-out)
  1927. ((= (length sec) 4)
  1928. (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
  1929. (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
  1930. ;; Create a temporary export back-end that hard-codes
  1931. ;; "\underline" within "\section" and alike.
  1932. (section-back-end
  1933. (org-export-create-backend
  1934. :parent 'latex
  1935. :transcoders
  1936. '((underline . (lambda (o c i) (format "\\underline{%s}" c)))
  1937. ;; LaTeX isn't happy when you try to use \verb inside the argument of other
  1938. ;; commands (like \section, etc.), and this causes compilation to fail.
  1939. ;; So, within headings it's a good idea to replace any instances of \verb
  1940. ;; with \texttt.
  1941. (code . (lambda (o _ _) (org-latex--protect-texttt (org-element-property :value o))))
  1942. (verbatim . (lambda (o _ _) (org-latex--protect-texttt (org-element-property :value o)))))))
  1943. (text
  1944. (org-export-data-with-backend
  1945. (org-element-property :title headline) section-back-end info))
  1946. (todo
  1947. (and (plist-get info :with-todo-keywords)
  1948. (let ((todo (org-element-property :todo-keyword headline)))
  1949. (and todo (org-export-data todo info)))))
  1950. (todo-type (and todo (org-element-property :todo-type headline)))
  1951. (tags (and (plist-get info :with-tags)
  1952. (org-export-get-tags headline info)))
  1953. (priority (and (plist-get info :with-priority)
  1954. (org-element-property :priority headline)))
  1955. ;; Create the headline text along with a no-tag version.
  1956. ;; The latter is required to remove tags from toc.
  1957. (full-text (funcall (plist-get info :latex-format-headline-function)
  1958. todo todo-type priority text tags info))
  1959. ;; Associate \label to the headline for internal links.
  1960. (headline-label (org-latex--label headline info t t))
  1961. (pre-blanks
  1962. (make-string (org-element-property :pre-blank headline) ?\n)))
  1963. (if (or (not section-fmt) (org-export-low-level-p headline info))
  1964. ;; This is a deep sub-tree: export it as a list item. Also
  1965. ;; export as items headlines for which no section format has
  1966. ;; been found.
  1967. (let ((low-level-body
  1968. (concat
  1969. ;; If headline is the first sibling, start a list.
  1970. (when (org-export-first-sibling-p headline info)
  1971. (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
  1972. ;; Itemize headline
  1973. "\\item"
  1974. (and full-text
  1975. (string-match-p "\\`[ \t]*\\[" full-text)
  1976. "\\relax")
  1977. " " full-text "\n"
  1978. headline-label
  1979. pre-blanks
  1980. contents)))
  1981. ;; If headline is not the last sibling simply return
  1982. ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
  1983. ;; any blank line.
  1984. (if (not (org-export-last-sibling-p headline info)) low-level-body
  1985. (replace-regexp-in-string
  1986. "[ \t\n]*\\'"
  1987. (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
  1988. low-level-body)))
  1989. ;; This is a standard headline. Export it as a section. Add
  1990. ;; an alternative heading when possible, and when this is not
  1991. ;; identical to the usual heading.
  1992. (let ((opt-title
  1993. (funcall (plist-get info :latex-format-headline-function)
  1994. todo todo-type priority
  1995. (org-export-data-with-backend
  1996. (org-export-get-alt-title headline info)
  1997. section-back-end info)
  1998. (and (eq (plist-get info :with-tags) t) tags)
  1999. info))
  2000. ;; Maybe end local TOC (see `org-latex-keyword').
  2001. (contents
  2002. (concat
  2003. contents
  2004. (let ((case-fold-search t)
  2005. (section
  2006. (let ((first (car (org-element-contents headline))))
  2007. (and (eq (org-element-type first) 'section) first))))
  2008. (org-element-map section 'keyword
  2009. (lambda (k)
  2010. (and (equal (org-element-property :key k) "TOC")
  2011. (let ((v (org-element-property :value k)))
  2012. (and (string-match-p "\\<headlines\\>" v)
  2013. (string-match-p "\\<local\\>" v)
  2014. (format "\\stopcontents[level-%d]" level)))))
  2015. info t)))))
  2016. (if (and opt-title
  2017. (not (equal opt-title full-text))
  2018. (string-match "\\`\\\\\\(.+?\\){" section-fmt))
  2019. (format (replace-match "\\1[%s]" nil nil section-fmt 1)
  2020. ;; Replace square brackets with parenthesis
  2021. ;; since square brackets are not supported in
  2022. ;; optional arguments.
  2023. (replace-regexp-in-string
  2024. "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
  2025. full-text
  2026. (concat headline-label pre-blanks contents))
  2027. ;; Impossible to add an alternative heading. Fallback to
  2028. ;; regular sectioning format string.
  2029. (format section-fmt full-text
  2030. (concat headline-label pre-blanks contents))))))))
  2031. (defun org-latex-format-headline-default-function
  2032. (todo _todo-type priority text tags _info)
  2033. "Default format function for a headline.
  2034. See `org-latex-format-headline-function' for details."
  2035. (concat
  2036. (and todo (format "{\\bfseries\\sffamily %s} " todo))
  2037. (and priority (format "\\framebox{\\#%c} " priority))
  2038. text
  2039. (and tags
  2040. (format "\\hfill{}\\textsc{%s}"
  2041. (mapconcat #'org-latex--protect-text tags ":")))))
  2042. ;;;; Horizontal Rule
  2043. (defun org-latex-horizontal-rule (horizontal-rule _contents info)
  2044. "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
  2045. CONTENTS is nil. INFO is a plist holding contextual information."
  2046. (let ((attr (org-export-read-attribute :attr_latex horizontal-rule))
  2047. (prev (org-export-get-previous-element horizontal-rule info)))
  2048. (concat
  2049. ;; Make sure the rule doesn't start at the end of the current
  2050. ;; line by separating it with a blank line from previous element.
  2051. (when (and prev
  2052. (let ((prev-blank (org-element-property :post-blank prev)))
  2053. (or (not prev-blank) (zerop prev-blank))))
  2054. "\n")
  2055. (org-latex--wrap-label
  2056. horizontal-rule
  2057. (format "\\noindent\\rule{%s}{%s}"
  2058. (or (plist-get attr :width) "\\textwidth")
  2059. (or (plist-get attr :thickness) "0.5pt"))
  2060. info))))
  2061. ;;;; Inline Src Block
  2062. (defun org-latex-inline-src-block (inline-src-block _contents info)
  2063. "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
  2064. CONTENTS holds the contents of the item. INFO is a plist holding
  2065. contextual information."
  2066. (let ((code (org-element-property :value inline-src-block))
  2067. (lang (org-element-property :language inline-src-block)))
  2068. (pcase (plist-get info :latex-src-block-backend)
  2069. (`verbatim (org-latex--text-markup code 'code info))
  2070. (`minted (org-latex-inline-src-block--minted info code lang))
  2071. (`engraved (org-latex-inline-src-block--engraved info code lang))
  2072. (`listings (org-latex-inline-src-block--listings info code lang))
  2073. (oldval
  2074. (message "Please update the LaTeX src-block-backend to %s"
  2075. (if oldval "listings" "verbatim"))
  2076. (if oldval
  2077. (org-latex-inline-src-block--listings info code lang)
  2078. (org-latex--text-markup code 'code info))))))
  2079. (defun org-latex-inline-src-block--minted (info code lang)
  2080. "Transcode an inline src block's content from Org to LaTeX, using minted.
  2081. INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
  2082. (let ((mint-lang (or (cadr (assq (intern lang)
  2083. (plist-get info :latex-minted-langs)))
  2084. (downcase lang)))
  2085. (options (org-latex--make-option-string
  2086. (plist-get info :latex-minted-options))))
  2087. (format "\\mintinline%s{%s}{%s}"
  2088. (if (string= options "") "" (format "[%s]" options))
  2089. mint-lang
  2090. code)))
  2091. (defun org-latex-inline-src-block--engraved (info code lang)
  2092. "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
  2093. INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
  2094. (org-latex-src--engrave-code
  2095. code lang nil (plist-get info :latex-engraved-options) t))
  2096. (defun org-latex-inline-src-block--listings (info code lang)
  2097. "Transcode an inline src block's content from Org to LaTeX, using lstlistings.
  2098. INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
  2099. (let* ((lst-lang (or (cadr (assq (intern lang)
  2100. (plist-get info :latex-listings-langs)))
  2101. lang))
  2102. (separator (org-latex--find-verb-separator code))
  2103. (options (org-latex--make-option-string
  2104. (append (plist-get info :latex-listings-options)
  2105. `(("language" ,lst-lang))))))
  2106. (concat (format "\\lstinline[%s]" options)
  2107. separator code separator)))
  2108. ;;;; Inlinetask
  2109. (defun org-latex-inlinetask (inlinetask contents info)
  2110. "Transcode an INLINETASK element from Org to LaTeX.
  2111. CONTENTS holds the contents of the block. INFO is a plist
  2112. holding contextual information."
  2113. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  2114. (todo (and (plist-get info :with-todo-keywords)
  2115. (let ((todo (org-element-property :todo-keyword inlinetask)))
  2116. (and todo (org-export-data todo info)))))
  2117. (todo-type (org-element-property :todo-type inlinetask))
  2118. (tags (and (plist-get info :with-tags)
  2119. (org-export-get-tags inlinetask info)))
  2120. (priority (and (plist-get info :with-priority)
  2121. (org-element-property :priority inlinetask)))
  2122. (contents (concat (org-latex--label inlinetask info) contents)))
  2123. (funcall (plist-get info :latex-format-inlinetask-function)
  2124. todo todo-type priority title tags contents info)))
  2125. (defun org-latex-format-inlinetask-default-function
  2126. (todo _todo-type priority title tags contents _info)
  2127. "Default format function for inlinetasks.
  2128. See `org-latex-format-inlinetask-function' for details."
  2129. (let ((full-title
  2130. (concat (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2131. (when priority (format "\\framebox{\\#%c} " priority))
  2132. title
  2133. (when tags
  2134. (format "\\hfill{}\\textsc{%s}"
  2135. (org-make-tag-string
  2136. (mapcar #'org-latex--protect-text tags)))))))
  2137. (concat "\\begin{center}\n"
  2138. "\\fbox{\n"
  2139. "\\begin{minipage}[c]{.6\\linewidth}\n"
  2140. full-title "\n\n"
  2141. (and (org-string-nw-p contents)
  2142. (concat "\\rule[.8em]{\\linewidth}{2pt}\n\n" contents))
  2143. "\\end{minipage}\n"
  2144. "}\n"
  2145. "\\end{center}")))
  2146. ;;;; Italic
  2147. (defun org-latex-italic (_italic contents info)
  2148. "Transcode ITALIC from Org to LaTeX.
  2149. CONTENTS is the text with italic markup. INFO is a plist holding
  2150. contextual information."
  2151. (org-latex--text-markup contents 'italic info))
  2152. ;;;; Item
  2153. (defun org-latex-item (item contents info)
  2154. "Transcode an ITEM element from Org to LaTeX.
  2155. CONTENTS holds the contents of the item. INFO is a plist holding
  2156. contextual information."
  2157. (let* ((orderedp (eq (org-element-property
  2158. :type (org-export-get-parent item))
  2159. 'ordered))
  2160. (level
  2161. ;; Determine level of current item to determine the
  2162. ;; correct LaTeX counter to use (enumi, enumii...).
  2163. (let ((parent item) (level 0))
  2164. (while (memq (org-element-type
  2165. (setq parent (org-export-get-parent parent)))
  2166. '(plain-list item))
  2167. (when (and (eq (org-element-type parent) 'plain-list)
  2168. (eq (org-element-property :type parent)
  2169. 'ordered))
  2170. (cl-incf level)))
  2171. level))
  2172. (count (org-element-property :counter item))
  2173. (counter (and count
  2174. (< level 5)
  2175. (format "\\setcounter{enum%s}{%s}\n"
  2176. (nth (1- level) '("i" "ii" "iii" "iv"))
  2177. (1- count))))
  2178. (checkbox (cl-case (org-element-property :checkbox item)
  2179. (on "$\\boxtimes$")
  2180. (off "$\\square$")
  2181. (trans "$\\boxminus$")))
  2182. (tag (let ((tag (org-element-property :tag item)))
  2183. (and tag (org-export-data tag info))))
  2184. ;; If there are footnotes references in tag, be sure to add
  2185. ;; their definition at the end of the item. This workaround
  2186. ;; is necessary since "\footnote{}" command is not supported
  2187. ;; in tags.
  2188. (tag-footnotes
  2189. (or (and tag (org-latex--delayed-footnotes-definitions
  2190. (org-element-property :tag item) info))
  2191. "")))
  2192. (concat counter
  2193. "\\item"
  2194. (cond
  2195. ((and checkbox tag)
  2196. (format (if orderedp "{%s %s} %s" "[{%s %s}] %s")
  2197. checkbox tag tag-footnotes))
  2198. ((or checkbox tag)
  2199. (format (if orderedp "{%s} %s" "[{%s}] %s")
  2200. (or checkbox tag) tag-footnotes))
  2201. ;; Without a tag or a check-box, if CONTENTS starts with
  2202. ;; an opening square bracket, add "\relax" to "\item",
  2203. ;; unless the brackets comes from an initial export
  2204. ;; snippet (i.e. it is inserted willingly by the user).
  2205. ((and contents
  2206. (string-match-p "\\`[ \t]*\\[" contents)
  2207. (not (let ((e (car (org-element-contents item))))
  2208. (and (eq (org-element-type e) 'paragraph)
  2209. (let ((o (car (org-element-contents e))))
  2210. (and (eq (org-element-type o) 'export-snippet)
  2211. (eq (org-export-snippet-backend o)
  2212. 'latex)))))))
  2213. "\\relax ")
  2214. (t " "))
  2215. (and contents (org-trim contents)))))
  2216. ;;;; Keyword
  2217. (defun org-latex-keyword (keyword _contents info)
  2218. "Transcode a KEYWORD element from Org to LaTeX.
  2219. CONTENTS is nil. INFO is a plist holding contextual information."
  2220. (let ((key (org-element-property :key keyword))
  2221. (value (org-element-property :value keyword)))
  2222. (cond
  2223. ((string= key "LATEX") value)
  2224. ((string= key "INDEX") (format "\\index{%s}" value))
  2225. ((string= key "TOC")
  2226. (let ((case-fold-search t))
  2227. (cond
  2228. ((string-match-p "\\<headlines\\>" value)
  2229. (let* ((localp (string-match-p "\\<local\\>" value))
  2230. (parent (org-element-lineage keyword '(headline)))
  2231. (level (if (not (and localp parent)) 0
  2232. (org-export-get-relative-level parent info)))
  2233. (depth
  2234. (and (string-match "\\<[0-9]+\\>" value)
  2235. (format
  2236. "\\setcounter{tocdepth}{%d}"
  2237. (+ (string-to-number (match-string 0 value)) level)))))
  2238. (if (and localp parent)
  2239. ;; Start local TOC, assuming package "titletoc" is
  2240. ;; required.
  2241. (format "\\startcontents[level-%d]
  2242. \\printcontents[level-%d]{}{0}{%s}"
  2243. level level (or depth ""))
  2244. (concat depth (and depth "\n") "\\tableofcontents"))))
  2245. ((string-match-p "\\<tables\\>" value) "\\listoftables")
  2246. ((string-match-p "\\<listings\\>" value)
  2247. (cl-case (plist-get info :latex-src-block-backend)
  2248. ((nil) "\\listoffigures")
  2249. (minted "\\listoflistings")
  2250. (engraved "\\listoflistings")
  2251. (otherwise "\\lstlistoflistings")))))))))
  2252. ;;;; Latex Environment
  2253. (defun org-latex--environment-type (latex-environment)
  2254. "Return the TYPE of LATEX-ENVIRONMENT.
  2255. The TYPE is determined from the actual latex environment, and
  2256. could be a member of `org-latex-caption-above' or `math'."
  2257. (let* ((latex-begin-re "\\\\begin{\\([A-Za-z0-9*]+\\)}")
  2258. (value (org-remove-indentation
  2259. (org-element-property :value latex-environment)))
  2260. (env (or (and (string-match latex-begin-re value)
  2261. (match-string 1 value))
  2262. "")))
  2263. (cond
  2264. ((string-match-p org-latex-math-environments-re value) 'math)
  2265. ((string-match-p
  2266. (eval-when-compile
  2267. (regexp-opt '("table" "longtable" "tabular" "tabu" "longtabu")))
  2268. env)
  2269. 'table)
  2270. ((string-match-p "figure" env) 'image)
  2271. ((string-match-p
  2272. (eval-when-compile
  2273. (regexp-opt '("lstlisting" "listing" "verbatim" "minted")))
  2274. env)
  2275. 'src-block)
  2276. (t 'special-block))))
  2277. (defun org-latex-latex-environment (latex-environment _contents info)
  2278. "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
  2279. CONTENTS is nil. INFO is a plist holding contextual information."
  2280. (when (plist-get info :with-latex)
  2281. (let* ((value (org-remove-indentation
  2282. (org-element-property :value latex-environment)))
  2283. (type (org-latex--environment-type latex-environment))
  2284. (caption (if (eq type 'math)
  2285. (org-latex--label latex-environment info nil t)
  2286. (org-latex--caption/label-string latex-environment info)))
  2287. (caption-above-p
  2288. (memq type (append (plist-get info :latex-caption-above) '(math)))))
  2289. (if (not (or (org-element-property :name latex-environment)
  2290. (org-element-property :caption latex-environment)))
  2291. value
  2292. ;; Environment is labeled: label must be within the environment
  2293. ;; (otherwise, a reference pointing to that element will count
  2294. ;; the section instead). Also insert caption if `latex-environment'
  2295. ;; is not a math environment.
  2296. (with-temp-buffer
  2297. (insert value)
  2298. (if caption-above-p
  2299. (progn
  2300. (goto-char (point-min))
  2301. (forward-line))
  2302. (goto-char (point-max))
  2303. (forward-line -1))
  2304. (insert caption)
  2305. (buffer-string))))))
  2306. ;;;; Latex Fragment
  2307. (defun org-latex-latex-fragment (latex-fragment _contents _info)
  2308. "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
  2309. CONTENTS is nil. INFO is a plist holding contextual information."
  2310. (let ((value (org-element-property :value latex-fragment)))
  2311. ;; Trim math markers since the fragment is enclosed within
  2312. ;; a latex-math-block object anyway.
  2313. (cond ((string-match-p "\\`\\$[^$]" value) (substring value 1 -1))
  2314. ((string-prefix-p "\\(" value) (substring value 2 -2))
  2315. (t value))))
  2316. ;;;; Line Break
  2317. (defun org-latex-line-break (_line-break _contents _info)
  2318. "Transcode a LINE-BREAK object from Org to LaTeX.
  2319. CONTENTS is nil. INFO is a plist holding contextual information."
  2320. "\\\\\n")
  2321. ;;;; Link
  2322. (defun org-latex-image-link-filter (data _backend info)
  2323. (org-export-insert-image-links data info org-latex-inline-image-rules))
  2324. (defun org-latex--inline-image (link info)
  2325. "Return LaTeX code for an inline image.
  2326. LINK is the link pointing to the inline image. INFO is a plist
  2327. used as a communication channel."
  2328. (let* ((parent (org-export-get-parent-element link))
  2329. (path (let ((raw-path (org-element-property :path link)))
  2330. (if (not (file-name-absolute-p raw-path)) raw-path
  2331. (expand-file-name raw-path))))
  2332. (filetype (file-name-extension path))
  2333. (caption (org-latex--caption/label-string parent info))
  2334. (caption-above-p (org-latex--caption-above-p link info))
  2335. ;; Retrieve latex attributes from the element around.
  2336. (attr (org-export-read-attribute :attr_latex parent))
  2337. (float (let ((float (plist-get attr :float)))
  2338. (cond ((string= float "wrap") 'wrap)
  2339. ((string= float "sideways") 'sideways)
  2340. ((string= float "multicolumn") 'multicolumn)
  2341. ((string= float "t") 'figure)
  2342. ((and (plist-member attr :float) (not float)) 'nonfloat)
  2343. (float float)
  2344. ((or (org-element-property :caption parent)
  2345. (org-string-nw-p (plist-get attr :caption)))
  2346. 'figure)
  2347. (t 'nonfloat))))
  2348. (placement
  2349. (let ((place (plist-get attr :placement)))
  2350. (cond
  2351. (place (format "%s" place))
  2352. ((eq float 'wrap) "{l}{0.5\\textwidth}")
  2353. ((eq float 'figure)
  2354. (format "[%s]" (plist-get info :latex-default-figure-position)))
  2355. (t ""))))
  2356. (center
  2357. (cond
  2358. ;; If link is an image link, do not center.
  2359. ((eq 'link (org-element-type (org-export-get-parent link))) nil)
  2360. ((plist-member attr :center) (plist-get attr :center))
  2361. (t (plist-get info :latex-images-centered))))
  2362. (comment-include (if (plist-get attr :comment-include) "%" ""))
  2363. ;; It is possible to specify scale or width and height in
  2364. ;; the ATTR_LATEX line, and also via default variables.
  2365. (scale (cond ((eq float 'wrap) "")
  2366. ((plist-get attr :scale))
  2367. (t (plist-get info :latex-image-default-scale))))
  2368. (width (cond ((org-string-nw-p scale) "")
  2369. ((plist-get attr :width))
  2370. ((plist-get attr :height) "")
  2371. ((eq float 'wrap) "0.48\\textwidth")
  2372. (t (plist-get info :latex-image-default-width))))
  2373. (height (cond ((org-string-nw-p scale) "")
  2374. ((plist-get attr :height))
  2375. ((or (plist-get attr :width)
  2376. (memq float '(figure wrap))) "")
  2377. (t (plist-get info :latex-image-default-height))))
  2378. (options (let ((opt (or (plist-get attr :options)
  2379. (plist-get info :latex-image-default-option))))
  2380. (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
  2381. (match-string 1 opt))))
  2382. image-code)
  2383. (if (member filetype '("tikz" "pgf"))
  2384. ;; For tikz images:
  2385. ;; - use \input to read in image file.
  2386. ;; - if options are present, wrap in a tikzpicture environment.
  2387. ;; - if width or height are present, use \resizebox to change
  2388. ;; the image size.
  2389. (progn
  2390. (setq image-code (format "\\input{%s}" path))
  2391. (when (org-string-nw-p options)
  2392. (setq image-code
  2393. (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
  2394. options
  2395. image-code)))
  2396. (setq image-code
  2397. (cond ((org-string-nw-p scale)
  2398. (format "\\scalebox{%s}{%s}" scale image-code))
  2399. ((or (org-string-nw-p width) (org-string-nw-p height))
  2400. (format "\\resizebox{%s}{%s}{%s}"
  2401. (if (org-string-nw-p width) width "!")
  2402. (if (org-string-nw-p height) height "!")
  2403. image-code))
  2404. (t image-code))))
  2405. ;; For other images:
  2406. ;; - add scale, or width and height to options.
  2407. ;; - include the image with \includegraphics.
  2408. (if (org-string-nw-p scale)
  2409. (setq options (concat options ",scale=" scale))
  2410. (when (org-string-nw-p width) (setq options (concat options ",width=" width)))
  2411. (when (org-string-nw-p height) (setq options (concat options ",height=" height))))
  2412. (let ((search-option (org-element-property :search-option link)))
  2413. (when (and search-option
  2414. (equal filetype "pdf")
  2415. (string-match-p "\\`[0-9]+\\'" search-option)
  2416. (not (string-match-p "page=" options)))
  2417. (setq options (concat options ",page=" search-option))))
  2418. (setq image-code
  2419. (format "\\includegraphics%s{%s}"
  2420. (cond ((not (org-string-nw-p options)) "")
  2421. ((string-prefix-p "," options)
  2422. (format "[%s]" (substring options 1)))
  2423. (t (format "[%s]" options)))
  2424. ;; While \includegraphics is fine with unicode in the path,
  2425. ;; \includesvg is prone to producing errors.
  2426. (if (and (string-match-p "[^[:ascii:]]" path)
  2427. (equal filetype "svg"))
  2428. (concat "\\detokenize{" path "}")
  2429. path)))
  2430. (when (equal filetype "svg")
  2431. (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
  2432. "\\includesvg"
  2433. image-code
  2434. nil t))
  2435. (setq image-code (replace-regexp-in-string "\\.svg}"
  2436. "}"
  2437. image-code
  2438. nil t))))
  2439. ;; Return proper string, depending on FLOAT.
  2440. (pcase float
  2441. ((and (pred stringp) env-string)
  2442. (format "\\begin{%s}%s
  2443. %s%s
  2444. %s%s
  2445. %s\\end{%s}"
  2446. env-string
  2447. placement
  2448. (if caption-above-p caption "")
  2449. (if center "\\centering" "")
  2450. comment-include image-code
  2451. (if caption-above-p "" caption)
  2452. env-string))
  2453. (`wrap (format "\\begin{wrapfigure}%s
  2454. %s%s
  2455. %s%s
  2456. %s\\end{wrapfigure}"
  2457. placement
  2458. (if caption-above-p caption "")
  2459. (if center "\\centering" "")
  2460. comment-include image-code
  2461. (if caption-above-p "" caption)))
  2462. (`sideways (format "\\begin{sidewaysfigure}
  2463. %s%s
  2464. %s%s
  2465. %s\\end{sidewaysfigure}"
  2466. (if caption-above-p caption "")
  2467. (if center "\\centering" "")
  2468. comment-include image-code
  2469. (if caption-above-p "" caption)))
  2470. (`multicolumn (format "\\begin{figure*}%s
  2471. %s%s
  2472. %s%s
  2473. %s\\end{figure*}"
  2474. placement
  2475. (if caption-above-p caption "")
  2476. (if center "\\centering" "")
  2477. comment-include image-code
  2478. (if caption-above-p "" caption)))
  2479. (`figure (format "\\begin{figure}%s
  2480. %s%s
  2481. %s%s
  2482. %s\\end{figure}"
  2483. placement
  2484. (if caption-above-p caption "")
  2485. (if center "\\centering" "")
  2486. comment-include image-code
  2487. (if caption-above-p "" caption)))
  2488. ((guard center)
  2489. (format "\\begin{center}
  2490. %s%s
  2491. %s\\end{center}"
  2492. (if caption-above-p caption "")
  2493. image-code
  2494. (if caption-above-p "" caption)))
  2495. (_
  2496. (concat (if caption-above-p caption "")
  2497. image-code
  2498. (if caption-above-p caption ""))))))
  2499. (defun org-latex-link (link desc info)
  2500. "Transcode a LINK object from Org to LaTeX.
  2501. DESC is the description part of the link, or the empty string.
  2502. INFO is a plist holding contextual information. See
  2503. `org-export-data'."
  2504. (let* ((type (org-element-property :type link))
  2505. (raw-path (org-element-property :path link))
  2506. ;; Ensure DESC really exists, or set it to nil.
  2507. (desc (and (not (string= desc "")) desc))
  2508. (imagep (org-export-inline-image-p
  2509. link (plist-get info :latex-inline-image-rules)))
  2510. (path (org-latex--protect-text
  2511. (pcase type
  2512. ((or "http" "https" "ftp" "mailto" "doi")
  2513. (concat type ":" raw-path))
  2514. ("file"
  2515. (org-export-file-uri raw-path))
  2516. (_
  2517. raw-path)))))
  2518. (cond
  2519. ;; Link type is handled by a special function.
  2520. ((org-export-custom-protocol-maybe link desc 'latex info))
  2521. ;; Image file.
  2522. (imagep (org-latex--inline-image (org-export-link-localise link) info))
  2523. ;; Radio link: Transcode target's contents and use them as link's
  2524. ;; description.
  2525. ((string= type "radio")
  2526. (let ((destination (org-export-resolve-radio-link link info)))
  2527. (if (not destination) desc
  2528. (format "\\hyperref[%s]{%s}"
  2529. (org-export-get-reference destination info)
  2530. desc))))
  2531. ;; Links pointing to a headline: Find destination and build
  2532. ;; appropriate referencing command.
  2533. ((member type '("custom-id" "fuzzy" "id"))
  2534. (let ((destination
  2535. (if (string= type "fuzzy")
  2536. (org-export-resolve-fuzzy-link link info 'latex-matrices)
  2537. (org-export-resolve-id-link link info))))
  2538. (cl-case (org-element-type destination)
  2539. ;; Id link points to an external file.
  2540. (plain-text
  2541. (if desc (format "\\href{%s}{%s}" destination desc)
  2542. (format "\\url{%s}" destination)))
  2543. ;; Fuzzy link points nowhere.
  2544. ((nil)
  2545. (format (plist-get info :latex-link-with-unknown-path-format)
  2546. (or desc
  2547. (org-export-data
  2548. (org-element-property :raw-link link) info))))
  2549. ;; LINK points to a headline. If headlines are numbered
  2550. ;; and the link has no description, display headline's
  2551. ;; number. Otherwise, display description or headline's
  2552. ;; title.
  2553. (headline
  2554. (let ((label (org-latex--label destination info t)))
  2555. (if (and (not desc)
  2556. (org-export-numbered-headline-p destination info))
  2557. (format org-latex-reference-command label)
  2558. (format "\\hyperref[%s]{%s}" label
  2559. (or desc
  2560. (org-export-data
  2561. (org-element-property :title destination) info))))))
  2562. ;; Fuzzy link points to a target. Do as above.
  2563. (otherwise
  2564. (let ((ref (org-latex--label destination info t)))
  2565. (if (not desc) (format org-latex-reference-command ref)
  2566. (format "\\hyperref[%s]{%s}" ref desc)))))))
  2567. ;; Coderef: replace link with the reference name or the
  2568. ;; equivalent line number.
  2569. ((string= type "coderef")
  2570. (format (org-export-get-coderef-format path desc)
  2571. ;; Resolve with RAW-PATH since PATH could be tainted
  2572. ;; with `org-latex--protect-text' call above.
  2573. (org-export-resolve-coderef raw-path info)))
  2574. ;; External link with a description part.
  2575. ((and path desc) (format "\\href{%s}{%s}" path desc))
  2576. ;; External link without a description part.
  2577. (path (format "\\url{%s}" path))
  2578. ;; No path, only description. Try to do something useful.
  2579. (t (format (plist-get info :latex-link-with-unknown-path-format) desc)))))
  2580. ;;;; Node Property
  2581. (defun org-latex-node-property (node-property _contents _info)
  2582. "Transcode a NODE-PROPERTY element from Org to LaTeX.
  2583. CONTENTS is nil. INFO is a plist holding contextual
  2584. information."
  2585. (format "%s:%s"
  2586. (org-element-property :key node-property)
  2587. (let ((value (org-element-property :value node-property)))
  2588. (if value (concat " " value) ""))))
  2589. ;;;; Paragraph
  2590. (defun org-latex-paragraph (_paragraph contents _info)
  2591. "Transcode a PARAGRAPH element from Org to LaTeX.
  2592. CONTENTS is the contents of the paragraph, as a string. INFO is
  2593. the plist used as a communication channel."
  2594. contents)
  2595. ;;;; Plain List
  2596. (defun org-latex-plain-list (plain-list contents info)
  2597. "Transcode a PLAIN-LIST element from Org to LaTeX.
  2598. CONTENTS is the contents of the list. INFO is a plist holding
  2599. contextual information."
  2600. (let* ((type (org-element-property :type plain-list))
  2601. (attr (org-export-read-attribute :attr_latex plain-list))
  2602. (latex-type (let ((env (plist-get attr :environment)))
  2603. (cond (env (format "%s" env))
  2604. ((eq type 'ordered) "enumerate")
  2605. ((eq type 'descriptive) "description")
  2606. (t "itemize")))))
  2607. (org-latex--wrap-label
  2608. plain-list
  2609. (format "\\begin{%s}%s\n%s\\end{%s}"
  2610. latex-type
  2611. (or (plist-get attr :options) "")
  2612. contents
  2613. latex-type)
  2614. info)))
  2615. ;;;; Plain Text
  2616. (defun org-latex-plain-text (text info)
  2617. "Transcode a TEXT string from Org to LaTeX.
  2618. TEXT is the string to transcode. INFO is a plist holding
  2619. contextual information."
  2620. (let* ((specialp (plist-get info :with-special-strings))
  2621. (output
  2622. ;; Turn LaTeX into \LaTeX{} and TeX into \TeX{}.
  2623. (let ((case-fold-search nil))
  2624. (replace-regexp-in-string
  2625. "\\<\\(?:La\\)?TeX\\>" "\\\\\\&{}"
  2626. ;; Protect ^, ~, %, #, &, $, _, { and }. Also protect \.
  2627. ;; However, if special strings are used, be careful not
  2628. ;; to protect "\" in "\-" constructs.
  2629. (replace-regexp-in-string
  2630. (concat "[%$#&{}_~^]\\|\\\\" (and specialp "\\([^-]\\|$\\)"))
  2631. (lambda (m)
  2632. (cl-case (string-to-char m)
  2633. (?\\ "$\\\\backslash$\\1")
  2634. (?~ "\\\\textasciitilde{}")
  2635. (?^ "\\\\^{}")
  2636. (t "\\\\\\&")))
  2637. text)))))
  2638. ;; Activate smart quotes. Be sure to provide original TEXT string
  2639. ;; since OUTPUT may have been modified.
  2640. (when (plist-get info :with-smart-quotes)
  2641. (setq output (org-export-activate-smart-quotes output :latex info text)))
  2642. ;; Convert special strings.
  2643. (when specialp
  2644. (setq output (replace-regexp-in-string "\\.\\.\\." "\\\\ldots{}" output)))
  2645. ;; Handle break preservation if required.
  2646. (when (plist-get info :preserve-breaks)
  2647. (setq output (replace-regexp-in-string
  2648. "\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n" output nil t)))
  2649. ;; Return value.
  2650. output))
  2651. ;;;; Planning
  2652. (defun org-latex-planning (planning _contents info)
  2653. "Transcode a PLANNING element from Org to LaTeX.
  2654. CONTENTS is nil. INFO is a plist holding contextual
  2655. information."
  2656. (concat
  2657. "\\noindent"
  2658. (mapconcat
  2659. 'identity
  2660. (delq nil
  2661. (list
  2662. (let ((closed (org-element-property :closed planning)))
  2663. (when closed
  2664. (concat
  2665. (format "\\textbf{%s} " org-closed-string)
  2666. (format (plist-get info :latex-inactive-timestamp-format)
  2667. (org-timestamp-translate closed)))))
  2668. (let ((deadline (org-element-property :deadline planning)))
  2669. (when deadline
  2670. (concat
  2671. (format "\\textbf{%s} " org-deadline-string)
  2672. (format (plist-get info :latex-active-timestamp-format)
  2673. (org-timestamp-translate deadline)))))
  2674. (let ((scheduled (org-element-property :scheduled planning)))
  2675. (when scheduled
  2676. (concat
  2677. (format "\\textbf{%s} " org-scheduled-string)
  2678. (format (plist-get info :latex-active-timestamp-format)
  2679. (org-timestamp-translate scheduled)))))))
  2680. " ")
  2681. "\\\\"))
  2682. ;;;; Property Drawer
  2683. (defun org-latex-property-drawer (_property-drawer contents _info)
  2684. "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
  2685. CONTENTS holds the contents of the drawer. INFO is a plist
  2686. holding contextual information."
  2687. (and (org-string-nw-p contents)
  2688. (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
  2689. ;;;; Pseudo Element: LaTeX Matrices
  2690. ;; `latex-matrices' elements have the following properties:
  2691. ;; `:caption', `:post-blank' and `:markup' (`inline', `equation' or
  2692. ;; `math').
  2693. (defun org-latex--wrap-latex-matrices (data info)
  2694. "Merge contiguous tables with the same mode within a pseudo-element.
  2695. DATA is a parse tree or a secondary string. INFO is a plist
  2696. containing export options. Modify DATA by side-effect and return
  2697. it."
  2698. (org-element-map data 'table
  2699. (lambda (table)
  2700. (when (eq (org-element-property :type table) 'org)
  2701. (let ((mode (or (org-export-read-attribute :attr_latex table :mode)
  2702. (plist-get info :latex-default-table-mode))))
  2703. (when (and (member mode '("inline-math" "math"))
  2704. ;; Do not wrap twice the same table.
  2705. (not (eq (org-element-type
  2706. (org-element-property :parent table))
  2707. 'latex-matrices)))
  2708. (let* ((caption (and (not (string= mode "inline-math"))
  2709. (org-element-property :caption table)))
  2710. (name (and (not (string= mode "inline-math"))
  2711. (org-element-property :name table)))
  2712. (matrices
  2713. (list 'latex-matrices
  2714. ;; Inherit name from the first table.
  2715. (list :name name
  2716. ;; FIXME: what syntax for captions?
  2717. ;;
  2718. ;; :caption caption
  2719. :markup
  2720. (cond ((string= mode "inline-math") 'inline)
  2721. ((or caption name) 'equation)
  2722. (t 'math)))))
  2723. (previous table)
  2724. (next (org-export-get-next-element table info)))
  2725. (org-element-insert-before matrices table)
  2726. ;; Swallow all contiguous tables sharing the same mode.
  2727. (while (and
  2728. (zerop (or (org-element-property :post-blank previous) 0))
  2729. (setq next (org-export-get-next-element previous info))
  2730. (eq (org-element-type next) 'table)
  2731. (eq (org-element-property :type next) 'org)
  2732. (string= (or (org-export-read-attribute
  2733. :attr_latex next :mode)
  2734. (plist-get info :latex-default-table-mode))
  2735. mode))
  2736. (org-element-put-property table :name nil)
  2737. (org-element-put-property table :caption nil)
  2738. (org-element-extract-element previous)
  2739. (org-element-adopt-elements matrices previous)
  2740. (setq previous next))
  2741. ;; Inherit `:post-blank' from the value of the last
  2742. ;; swallowed table. Set the latter's `:post-blank'
  2743. ;; value to 0 so as to not duplicate empty lines.
  2744. (org-element-put-property
  2745. matrices :post-blank (org-element-property :post-blank previous))
  2746. (org-element-put-property previous :post-blank 0)
  2747. (org-element-put-property table :name nil)
  2748. (org-element-put-property table :caption nil)
  2749. (org-element-extract-element previous)
  2750. (org-element-adopt-elements matrices previous))))))
  2751. info)
  2752. data)
  2753. (defun org-latex-matrices (matrices contents info)
  2754. "Transcode a MATRICES element from Org to LaTeX.
  2755. CONTENTS is a string. INFO is a plist used as a communication
  2756. channel."
  2757. (pcase (org-element-property :markup matrices)
  2758. (`inline (format "\\(%s\\)" contents))
  2759. (`equation
  2760. (let ((caption (org-latex--caption/label-string matrices info))
  2761. (caption-above? (org-latex--caption-above-p matrices info)))
  2762. (concat "\\begin{equation}\n"
  2763. (and caption-above? caption)
  2764. contents
  2765. (and (not caption-above?) caption)
  2766. "\\end{equation}")))
  2767. (_
  2768. (format "\\[\n%s\\]" contents))))
  2769. ;;;; Pseudo Object: LaTeX Math Block
  2770. ;; `latex-math-block' objects have the following property:
  2771. ;; `:post-blank'.
  2772. (defun org-latex--wrap-latex-math-block (data info)
  2773. "Merge contiguous math objects in a pseudo-object container.
  2774. DATA is a parse tree or a secondary string. INFO is a plist
  2775. containing export options. Modify DATA by side-effect and return it."
  2776. (let ((valid-object-p
  2777. ;; Non-nil when OBJECT can be added to a latex math block.
  2778. (lambda (object)
  2779. (pcase (org-element-type object)
  2780. (`entity (org-element-property :latex-math-p object))
  2781. (`latex-fragment
  2782. (let ((value (org-element-property :value object)))
  2783. (or (string-prefix-p "\\(" value)
  2784. (string-match-p "\\`\\$[^$]" value))))))))
  2785. (org-element-map data '(entity latex-fragment)
  2786. (lambda (object)
  2787. ;; Skip objects already wrapped.
  2788. (when (and (not (eq (org-element-type
  2789. (org-element-property :parent object))
  2790. 'latex-math-block))
  2791. (funcall valid-object-p object))
  2792. (let ((math-block (list 'latex-math-block nil))
  2793. (next-elements (org-export-get-next-element object info t))
  2794. (last object))
  2795. ;; Wrap MATH-BLOCK around OBJECT in DATA.
  2796. (org-element-insert-before math-block object)
  2797. (org-element-extract-element object)
  2798. (org-element-adopt-elements math-block object)
  2799. (when (zerop (or (org-element-property :post-blank object) 0))
  2800. ;; MATH-BLOCK swallows consecutive math objects.
  2801. (catch 'exit
  2802. (dolist (next next-elements)
  2803. (unless (funcall valid-object-p next) (throw 'exit nil))
  2804. (org-element-extract-element next)
  2805. (org-element-adopt-elements math-block next)
  2806. ;; Eschew the case: \beta$x$ -> \(\betax\).
  2807. (org-element-put-property last :post-blank 1)
  2808. (setq last next)
  2809. (when (> (or (org-element-property :post-blank next) 0) 0)
  2810. (throw 'exit nil)))))
  2811. (org-element-put-property
  2812. math-block :post-blank (org-element-property :post-blank last)))))
  2813. info nil '(latex-math-block) t)
  2814. ;; Return updated DATA.
  2815. data))
  2816. (defun org-latex-math-block (_math-block contents _info)
  2817. "Transcode a MATH-BLOCK object from Org to LaTeX.
  2818. CONTENTS is a string. INFO is a plist used as a communication
  2819. channel."
  2820. (when (org-string-nw-p contents)
  2821. (format "\\(%s\\)" (org-trim contents))))
  2822. ;;;; Quote Block
  2823. (defun org-latex-quote-block (quote-block contents info)
  2824. "Transcode a QUOTE-BLOCK element from Org to LaTeX.
  2825. CONTENTS holds the contents of the block. INFO is a plist
  2826. holding contextual information."
  2827. (let ((environment
  2828. (or (org-export-read-attribute :attr_latex quote-block :environment)
  2829. (plist-get info :latex-default-quote-environment)))
  2830. (options
  2831. (or (org-export-read-attribute :attr_latex quote-block :options)
  2832. "")))
  2833. (org-latex--wrap-label
  2834. quote-block (format "\\begin{%s}%s\n%s\\end{%s}"
  2835. environment
  2836. options
  2837. contents
  2838. environment)
  2839. info)))
  2840. ;;;; Radio Target
  2841. (defun org-latex-radio-target (radio-target text info)
  2842. "Transcode a RADIO-TARGET object from Org to LaTeX.
  2843. TEXT is the text of the target. INFO is a plist holding
  2844. contextual information."
  2845. (format "\\label{%s}%s" (org-export-get-reference radio-target info) text))
  2846. ;;;; Section
  2847. (defun org-latex-section (_section contents _info)
  2848. "Transcode a SECTION element from Org to LaTeX.
  2849. CONTENTS holds the contents of the section. INFO is a plist
  2850. holding contextual information."
  2851. contents)
  2852. ;;;; Special Block
  2853. (defun org-latex-special-block (special-block contents info)
  2854. "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
  2855. CONTENTS holds the contents of the block. INFO is a plist
  2856. holding contextual information."
  2857. (let ((type (org-element-property :type special-block))
  2858. (opt (org-export-read-attribute :attr_latex special-block :options))
  2859. (caption (org-latex--caption/label-string special-block info))
  2860. (caption-above-p (org-latex--caption-above-p special-block info)))
  2861. (concat (format "\\begin{%s}%s\n" type (or opt ""))
  2862. (and caption-above-p caption)
  2863. contents
  2864. (and (not caption-above-p) caption)
  2865. (format "\\end{%s}" type))))
  2866. ;;;; Src Block
  2867. (defun org-latex-src-block (src-block _contents info)
  2868. "Transcode a SRC-BLOCK element from Org to LaTeX.
  2869. CONTENTS holds the contents of the item. INFO is a plist holding
  2870. contextual information."
  2871. (when (org-string-nw-p (org-element-property :value src-block))
  2872. (let* ((lang (org-element-property :language src-block))
  2873. (caption (org-element-property :caption src-block))
  2874. (caption-above-p (org-latex--caption-above-p src-block info))
  2875. (label (org-element-property :name src-block))
  2876. (custom-env (and lang
  2877. (cadr (assq (intern lang)
  2878. org-latex-custom-lang-environments))))
  2879. (num-start (org-export-get-loc src-block info))
  2880. (retain-labels (org-element-property :retain-labels src-block))
  2881. (attributes (org-export-read-attribute :attr_latex src-block))
  2882. (float (plist-get attributes :float)))
  2883. (funcall
  2884. (pcase (plist-get info :latex-src-block-backend)
  2885. ((or `verbatim (guard (not lang))) #'org-latex-src-block--verbatim)
  2886. (`minted #'org-latex-src-block--minted)
  2887. (`engraved #'org-latex-src-block--engraved)
  2888. (`listings #'org-latex-src-block--listings)
  2889. ((guard custom-env) #'org-latex-src-block--custom)
  2890. (oldval
  2891. (message "Please update the LaTeX src-block-backend to %s"
  2892. (if oldval "listings" "verbatim"))
  2893. (if oldval
  2894. #'org-latex-src-block--listings
  2895. #'org-latex-src-block--verbatim)))
  2896. :src-block src-block
  2897. :info info
  2898. :lang lang
  2899. :caption caption
  2900. :caption-above-p caption-above-p
  2901. :label label
  2902. :num-start num-start
  2903. :retain-labels retain-labels
  2904. :attributes attributes
  2905. :float float
  2906. :custom-env custom-env))))
  2907. (cl-defun org-latex-src-block--verbatim
  2908. (&key src-block info caption caption-above-p float &allow-other-keys)
  2909. "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
  2910. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  2911. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  2912. (let ((caption-str (org-latex--caption/label-string src-block info))
  2913. (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
  2914. (org-export-format-code-default src-block info))))
  2915. (cond ((string= "multicolumn" float)
  2916. (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
  2917. (plist-get info :latex-default-figure-position)
  2918. (if caption-above-p caption-str "")
  2919. verbatim
  2920. (if caption-above-p "" caption-str)))
  2921. (caption (concat
  2922. (if caption-above-p caption-str "")
  2923. verbatim
  2924. (if caption-above-p "" (concat "\n" caption-str))))
  2925. (t verbatim))))
  2926. (cl-defun org-latex-src-block--custom
  2927. (&key src-block info caption caption-above-p attributes float custom-env &allow-other-keys)
  2928. "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
  2929. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  2930. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  2931. (let ((caption-str (org-latex--caption/label-string src-block info))
  2932. (formatted-src (org-export-format-code-default src-block info)))
  2933. (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
  2934. (format "\\begin{%s}\n%s\\end{%s}\n"
  2935. custom-env
  2936. (concat (and caption-above-p caption-str)
  2937. formatted-src
  2938. (and (not caption-above-p) caption-str))
  2939. custom-env)
  2940. (format-spec custom-env
  2941. `((?s . ,formatted-src)
  2942. (?c . ,caption)
  2943. (?f . ,float)
  2944. (?l . ,(org-latex--label src-block info))
  2945. (?o . ,(or (plist-get attributes :options) "")))))))
  2946. (cl-defun org-latex-src-block--minted
  2947. (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
  2948. "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
  2949. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  2950. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  2951. (let* ((caption-str (org-latex--caption/label-string src-block info))
  2952. (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
  2953. (plist-get info :latex-default-figure-position)))
  2954. (multicolumn-p (string= "multicolumn" float))
  2955. (float-env
  2956. (cond
  2957. ((or caption multicolumn-p)
  2958. (cons
  2959. (concat "\\begin{listing" (when multicolumn-p "*")
  2960. "}[" placement "]\n"
  2961. (if caption-above-p caption-str ""))
  2962. (concat "\n" (if caption-above-p "" caption-str)
  2963. "\\end{listing" (when multicolumn-p "*") "}")))
  2964. ((string= "t" float)
  2965. (cons
  2966. (concat "\\begin{listing}[" placement "]\n")
  2967. "\n\\end{listing}"))))
  2968. (options (plist-get info :latex-minted-options))
  2969. (body
  2970. (format
  2971. "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
  2972. ;; Options.
  2973. (concat
  2974. (org-latex--make-option-string
  2975. (if (or (not num-start) (assoc "linenos" options))
  2976. options
  2977. (append
  2978. `(("linenos")
  2979. ("firstnumber" ,(number-to-string (1+ num-start))))
  2980. options)))
  2981. (let ((local-options (plist-get attributes :options)))
  2982. (and local-options (concat "," local-options))))
  2983. ;; Language.
  2984. (or (cadr (assq (intern lang)
  2985. (plist-get info :latex-minted-langs)))
  2986. (downcase lang))
  2987. ;; Source code.
  2988. (let* ((code-info (org-export-unravel-code src-block))
  2989. (max-width
  2990. (apply 'max
  2991. (mapcar 'string-width
  2992. (org-split-string (car code-info)
  2993. "\n")))))
  2994. (org-export-format-code
  2995. (car code-info)
  2996. (lambda (loc _num ref)
  2997. (concat
  2998. loc
  2999. (when ref
  3000. ;; Ensure references are flushed to the right,
  3001. ;; separated with 6 spaces from the widest line
  3002. ;; of code.
  3003. (concat (make-string (+ (- max-width (length loc)) 6)
  3004. ?\s)
  3005. (format "(%s)" ref)))))
  3006. nil (and retain-labels (cdr code-info)))))))
  3007. (concat (car float-env) body (cdr float-env))))
  3008. (defun org-latex-src--engrave-mathescape-p (info options)
  3009. "From the export INFO plist, and the per-block OPTIONS, determine mathescape."
  3010. (let ((default-options (plist-get info :latex-engraved-options))
  3011. (mathescape-status
  3012. (lambda (opts)
  3013. (cl-some
  3014. (lambda (opt)
  3015. (or (and
  3016. (null (cdr opt))
  3017. (cond
  3018. ((string-match-p
  3019. "\\(?:^\\|,\\)mathescape=false\\(?:,\\|$\\)"
  3020. (car opt))
  3021. 'no)
  3022. ((or (string-match-p
  3023. "\\(?:^\\|,\\)mathescape\\(?:=true\\)?\\(?:,\\|$\\)"
  3024. (car opt))
  3025. (string= "mathescape" (car opt)))
  3026. 'yes)))
  3027. (and
  3028. (string= (car opt) "mathescape")
  3029. (cond
  3030. ((or (and (stringp (cdr opt)) (string= (cdr opt) "true"))
  3031. (equal '("true") (cdr opt)))
  3032. 'yes)
  3033. ((or (and (stringp (cdr opt)) (string= "false" (cdr opt)))
  3034. (equal '("false") (cdr opt)))
  3035. 'no)))))
  3036. opts))))
  3037. (let ((mathescape (or (funcall mathescape-status default-options)
  3038. (funcall mathescape-status options))))
  3039. (when (eq mathescape 'yes)
  3040. (or engrave-faces-latex-mathescape t)))))
  3041. (defun org-latex-src--engrave-code (content lang &optional theme options inline)
  3042. "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
  3043. When the THEME symbol is non-nil, that theme will be used.
  3044. When INLINE is nil, a Verbatim environment wrapped in a Code
  3045. environment will be used. When t, a Verb command will be used.
  3046. When OPTIONS is provided, as either a string or list of key-value
  3047. pairs accepted by `org-latex--make-option-string', it is passed
  3048. to the Verbatim environment or Verb command."
  3049. (if (require 'engrave-faces-latex nil t)
  3050. (let* ((lang-mode (and lang (org-src-get-lang-mode lang)))
  3051. (engrave-faces-current-preset-style
  3052. (if theme
  3053. (engrave-faces-get-theme theme)
  3054. engrave-faces-current-preset-style))
  3055. (engraved-buffer
  3056. (with-temp-buffer
  3057. (insert (replace-regexp-in-string "\n\\'" "" content))
  3058. (when lang-mode
  3059. (if (functionp lang-mode)
  3060. (funcall lang-mode)
  3061. (message "Cannot engrave code as %s. %s is undefined."
  3062. lang lang-mode)))
  3063. (engrave-faces-latex-buffer)))
  3064. (engraved-code
  3065. (with-current-buffer engraved-buffer
  3066. (buffer-string)))
  3067. (engraved-options
  3068. (when options
  3069. (concat "["
  3070. (if (listp options)
  3071. (org-latex--make-option-string options)
  3072. options)
  3073. "]")))
  3074. (engraved-wrapped
  3075. (if inline
  3076. (concat "\\Verb" engraved-options "{" engraved-code "}")
  3077. (concat "\\begin{Code}\n\\begin{Verbatim}" engraved-options "\n"
  3078. engraved-code "\n\\end{Verbatim}\n\\end{Code}"))))
  3079. (kill-buffer engraved-buffer)
  3080. (if theme
  3081. (concat "{\\engravedtheme"
  3082. (replace-regexp-in-string "[^A-Za-z]" ""
  3083. (symbol-name theme))
  3084. engraved-wrapped
  3085. "}")
  3086. engraved-wrapped))
  3087. (user-error "Cannot engrave code as `engrave-faces-latex' is unavailable.")))
  3088. (cl-defun org-latex-src-block--engraved
  3089. (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
  3090. "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
  3091. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  3092. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  3093. (let* ((caption-str (org-latex--caption/label-string src-block info))
  3094. (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
  3095. (plist-get info :latex-default-figure-position)))
  3096. (multicolumn-p (string= "multicolumn" float))
  3097. (float-env
  3098. (cond
  3099. ((or caption multicolumn-p)
  3100. (cons
  3101. (concat "\\begin{listing" (when multicolumn-p "*")
  3102. "}[" placement "]\n"
  3103. (if caption-above-p caption-str ""))
  3104. (concat "\n" (if caption-above-p "" caption-str)
  3105. "\\end{listing" (when multicolumn-p "*") "}")))
  3106. ((string= "t" float)
  3107. (cons
  3108. (concat "\\begin{listing}[" placement "]\n")
  3109. "\n\\end{listing}"))))
  3110. (options
  3111. (let ((engraved-options (plist-get info :latex-engraved-options))
  3112. (local-options (plist-get attributes :options)))
  3113. (append
  3114. (when (and num-start (not (assoc "linenos" engraved-options)))
  3115. `(("linenos")
  3116. ("firstnumber" ,(number-to-string (1+ num-start)))))
  3117. (and local-options `((,local-options))))))
  3118. (engraved-theme (plist-get attributes :engraved-theme))
  3119. (content
  3120. (let* ((code-info (org-export-unravel-code src-block))
  3121. (max-width
  3122. (apply 'max
  3123. (mapcar 'string-width
  3124. (org-split-string (car code-info)
  3125. "\n")))))
  3126. (org-export-format-code
  3127. (car code-info)
  3128. (lambda (loc _num ref)
  3129. (concat
  3130. loc
  3131. (when ref
  3132. ;; Ensure references are flushed to the right,
  3133. ;; separated with 6 spaces from the widest line
  3134. ;; of code.
  3135. (concat (make-string (+ (- max-width (length loc)) 6)
  3136. ?\s)
  3137. (format "(%s)" ref)))))
  3138. nil (and retain-labels (cdr code-info)))))
  3139. (body
  3140. (let ((engrave-faces-latex-mathescape
  3141. (org-latex-src--engrave-mathescape-p info options)))
  3142. (org-latex-src--engrave-code
  3143. content lang
  3144. (when engraved-theme (intern engraved-theme))
  3145. options))))
  3146. (concat (car float-env) body (cdr float-env))))
  3147. (cl-defun org-latex-src-block--listings
  3148. (&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
  3149. "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
  3150. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  3151. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  3152. (let ((lst-lang
  3153. (or (cadr (assq (intern lang)
  3154. (plist-get info :latex-listings-langs)))
  3155. lang))
  3156. (caption-str
  3157. (when caption
  3158. (let ((main (org-export-get-caption src-block))
  3159. (secondary (org-export-get-caption src-block t)))
  3160. (if (not secondary)
  3161. (format "{%s}" (org-export-data main info))
  3162. (format "{[%s]%s}"
  3163. (org-export-data secondary info)
  3164. (org-export-data main info))))))
  3165. (lst-opt (plist-get info :latex-listings-options)))
  3166. (concat
  3167. ;; Options.
  3168. (format
  3169. "\\lstset{%s}\n"
  3170. (concat
  3171. (org-latex--make-option-string
  3172. (append
  3173. lst-opt
  3174. (cond
  3175. ((and (not float) (plist-member attributes :float)) nil)
  3176. ((string= "multicolumn" float) '(("float" "*")))
  3177. ((and float (not (assoc "float" lst-opt)))
  3178. `(("float" ,(plist-get info :latex-default-figure-position)))))
  3179. `(("language" ,lst-lang))
  3180. (if label
  3181. `(("label" ,(org-latex--label src-block info)))
  3182. '(("label" " ")))
  3183. (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
  3184. `(("captionpos" ,(if caption-above-p "t" "b")))
  3185. (cond ((assoc "numbers" lst-opt) nil)
  3186. ((not num-start) '(("numbers" "none")))
  3187. (t `(("firstnumber" ,(number-to-string (1+ num-start)))
  3188. ("numbers" "left"))))))
  3189. (let ((local-options (plist-get attributes :options)))
  3190. (and local-options (concat "," local-options)))))
  3191. ;; Source code.
  3192. (format
  3193. "\\begin{lstlisting}\n%s\\end{lstlisting}"
  3194. (let* ((code-info (org-export-unravel-code src-block))
  3195. (max-width
  3196. (apply 'max
  3197. (mapcar 'string-width
  3198. (org-split-string (car code-info) "\n")))))
  3199. (org-export-format-code
  3200. (car code-info)
  3201. (lambda (loc _num ref)
  3202. (concat
  3203. loc
  3204. (when ref
  3205. ;; Ensure references are flushed to the right,
  3206. ;; separated with 6 spaces from the widest line of
  3207. ;; code
  3208. (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
  3209. (format "(%s)" ref)))))
  3210. nil (and retain-labels (cdr code-info))))))))
  3211. ;;;; Statistics Cookie
  3212. (defun org-latex-statistics-cookie (statistics-cookie _contents _info)
  3213. "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
  3214. CONTENTS is nil. INFO is a plist holding contextual information."
  3215. (replace-regexp-in-string
  3216. "%" "\\%" (org-element-property :value statistics-cookie) nil t))
  3217. ;;;; Strike-Through
  3218. (defun org-latex-strike-through (_strike-through contents info)
  3219. "Transcode STRIKE-THROUGH from Org to LaTeX.
  3220. CONTENTS is the text with strike-through markup. INFO is a plist
  3221. holding contextual information."
  3222. (org-latex--text-markup contents 'strike-through info))
  3223. ;;;; Subscript
  3224. (defun org-latex-subscript (_subscript contents _info)
  3225. "Transcode a SUBSCRIPT object from Org to LaTeX.
  3226. CONTENTS is the contents of the object."
  3227. (format "\\textsubscript{%s}" contents))
  3228. ;;;; Superscript
  3229. (defun org-latex-superscript (_superscript contents _info)
  3230. "Transcode a SUPERSCRIPT object from Org to LaTeX.
  3231. CONTENTS is the contents of the object."
  3232. (format "\\textsuperscript{%s}" contents))
  3233. ;;;; Table
  3234. ;;
  3235. ;; `org-latex-table' is the entry point for table transcoding. It
  3236. ;; takes care of tables with a "verbatim" mode. Otherwise, it
  3237. ;; delegates the job to either `org-latex--table.el-table',
  3238. ;; `org-latex--org-table', `org-latex--math-table' or
  3239. ;; `org-latex--org-tabbing' functions,
  3240. ;; depending of the type of the table and the mode requested.
  3241. ;;
  3242. ;; `org-latex--align-string' is a subroutine used to build alignment
  3243. ;; string for Org tables.
  3244. (defun org-latex-table (table contents info)
  3245. "Transcode a TABLE element from Org to LaTeX.
  3246. CONTENTS is the contents of the table. INFO is a plist holding
  3247. contextual information."
  3248. (if (eq (org-element-property :type table) 'table.el)
  3249. ;; "table.el" table. Convert it using appropriate tools.
  3250. (org-latex--table.el-table table info)
  3251. (let ((type (or (org-export-read-attribute :attr_latex table :mode)
  3252. (plist-get info :latex-default-table-mode))))
  3253. (cond
  3254. ;; Case 1: Verbatim table.
  3255. ((string= type "verbatim")
  3256. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  3257. ;; Re-create table, without affiliated keywords.
  3258. (org-trim (org-element-interpret-data
  3259. `(table nil ,@(org-element-contents table))))))
  3260. ;; Case 2: Matrix.
  3261. ((or (string= type "math") (string= type "inline-math"))
  3262. (org-latex--math-table table info))
  3263. ;; Case 3: Tabbing
  3264. ((string= type "tabbing")
  3265. (org-table--org-tabbing table contents info))
  3266. ;; Case 4: Standard table.
  3267. (t (concat (org-latex--org-table table contents info)
  3268. ;; When there are footnote references within the
  3269. ;; table, insert their definition just after it.
  3270. (org-latex--delayed-footnotes-definitions table info)))))))
  3271. (defun org-latex--align-string (table info &optional math?)
  3272. "Return an appropriate LaTeX alignment string.
  3273. TABLE is the considered table. INFO is a plist used as
  3274. a communication channel. When optional argument MATH? is
  3275. non-nil, TABLE is meant to be a matrix, where all cells are
  3276. centered."
  3277. (or (org-export-read-attribute :attr_latex table :align)
  3278. (let (align)
  3279. ;; Extract column groups and alignment from first (non-rule)
  3280. ;; row.
  3281. (org-element-map
  3282. (org-element-map table 'table-row
  3283. (lambda (row)
  3284. (and (eq (org-element-property :type row) 'standard) row))
  3285. info 'first-match)
  3286. 'table-cell
  3287. (lambda (cell)
  3288. (let ((borders (org-export-table-cell-borders cell info)))
  3289. ;; Check left border for the first cell only.
  3290. (when (and (memq 'left borders) (not align))
  3291. (push "|" align))
  3292. (push (if math? "c" ;center cells in matrices
  3293. (cl-case (org-export-table-cell-alignment cell info)
  3294. (left "l")
  3295. (right "r")
  3296. (center "c")))
  3297. align)
  3298. (when (memq 'right borders) (push "|" align))))
  3299. info)
  3300. (apply 'concat (nreverse align)))))
  3301. (defun org-latex--align-string-tabbing (table info)
  3302. "Return LaTeX alignment string using tabbing environment.
  3303. TABLE is the considered table. INFO is a plist used as
  3304. a communication channel."
  3305. (or (org-export-read-attribute :attr_latex table :align)
  3306. (let* ((count
  3307. ;; Count the number of cells in the first row.
  3308. (length
  3309. (org-element-map
  3310. (org-element-map table 'table-row
  3311. (lambda (row)
  3312. (and (eq (org-element-property :type row)
  3313. 'standard)
  3314. row))
  3315. info 'first-match)
  3316. 'table-cell #'identity)))
  3317. ;; Calculate the column width, using a proportion of
  3318. ;; the document's textwidth.
  3319. (separator
  3320. (format "\\hspace{%s\\textwidth} \\= "
  3321. (- (/ 1.0 count) 0.01))))
  3322. (concat (apply 'concat (make-list count separator))
  3323. "\\kill"))))
  3324. (defun org-latex--decorate-table (table attributes caption above? info)
  3325. "Decorate TABLE string with caption and float environment.
  3326. ATTRIBUTES is the plist containing LaTeX attributes. CAPTION is
  3327. its caption, as a string or nil. It is located above the table
  3328. if ABOVE? is non-nil. INFO is the plist containing current
  3329. export parameters.
  3330. Return new environment, as a string."
  3331. (let* ((float-environment
  3332. (let ((float (plist-get attributes :float)))
  3333. (cond ((and (not float) (plist-member attributes :float)) nil)
  3334. ((member float '("sidewaystable" "sideways")) "sidewaystable")
  3335. ((equal float "multicolumn") "table*")
  3336. ((string= float "t") "table")
  3337. (float float)
  3338. ((org-string-nw-p caption) "table")
  3339. (t nil))))
  3340. (placement
  3341. (or (plist-get attributes :placement)
  3342. (format "[%s]" (plist-get info :latex-default-figure-position))))
  3343. (center? (if (plist-member attributes :center)
  3344. (plist-get attributes :center)
  3345. (plist-get info :latex-tables-centered)))
  3346. (fontsize (let ((font (plist-get attributes :font)))
  3347. (and font (concat font "\n")))))
  3348. (concat (cond
  3349. (float-environment
  3350. (concat (format "\\begin{%s}%s\n" float-environment placement)
  3351. (if above? caption "")
  3352. (when center? "\\centering\n")
  3353. fontsize))
  3354. (caption
  3355. (concat (and center? "\\begin{center}\n" )
  3356. (if above? caption "")
  3357. (cond ((and fontsize center?) fontsize)
  3358. (fontsize (concat "{" fontsize))
  3359. (t nil))))
  3360. (center? (concat "\\begin{center}\n" fontsize))
  3361. (fontsize (concat "{" fontsize)))
  3362. table
  3363. (cond
  3364. (float-environment
  3365. (concat (if above? "" (concat "\n" caption))
  3366. (format "\n\\end{%s}" float-environment)))
  3367. (caption
  3368. (concat (if above? "" (concat "\n" caption))
  3369. (and center? "\n\\end{center}")
  3370. (and fontsize (not center?) "}")))
  3371. (center? "\n\\end{center}")
  3372. (fontsize "}")))))
  3373. (defun org-latex--org-table (table contents info)
  3374. "Return appropriate LaTeX code for an Org table.
  3375. TABLE is the table type element to transcode. CONTENTS is its
  3376. contents, as a string. INFO is a plist used as a communication
  3377. channel.
  3378. This function assumes TABLE has `org' as its `:type' property and
  3379. `table' as its `:mode' attribute."
  3380. (let* ((attr (org-export-read-attribute :attr_latex table))
  3381. (alignment (org-latex--align-string table info))
  3382. (opt (org-export-read-attribute :attr_latex table :options))
  3383. (table-env (or (plist-get attr :environment)
  3384. (plist-get info :latex-default-table-environment)))
  3385. (width
  3386. (let ((w (plist-get attr :width)))
  3387. (cond ((not w) "")
  3388. ((member table-env '("tabular" "longtable")) "")
  3389. ((member table-env '("tabu" "longtabu"))
  3390. (format (if (plist-get attr :spread) " spread %s "
  3391. " to %s ")
  3392. w))
  3393. (t (format "{%s}" w)))))
  3394. (caption (org-latex--caption/label-string table info))
  3395. (above? (org-latex--caption-above-p table info)))
  3396. (cond
  3397. ((member table-env '("longtable" "longtabu"))
  3398. (let ((fontsize (let ((font (plist-get attr :font)))
  3399. (and font (concat font "\n")))))
  3400. (concat (and fontsize (concat "{" fontsize))
  3401. (format "\\begin{%s}%s{%s}\n" table-env width alignment)
  3402. (and above?
  3403. (org-string-nw-p caption)
  3404. (concat caption "\\\\\n"))
  3405. contents
  3406. (and (not above?)
  3407. (org-string-nw-p caption)
  3408. (concat caption "\\\\\n"))
  3409. (format "\\end{%s}" table-env)
  3410. (and fontsize "}"))))
  3411. (t
  3412. (let ((output (format "\\begin{%s}%s%s{%s}\n%s\\end{%s}"
  3413. table-env
  3414. (if opt (format "[%s]" opt) "")
  3415. width
  3416. alignment
  3417. contents
  3418. table-env)))
  3419. (org-latex--decorate-table output attr caption above? info))))))
  3420. (defun org-table--org-tabbing (table contents info)
  3421. "Return tabbing environment LaTeX code for Org table.
  3422. TABLE is the table type element to transcode. CONTENTS is its
  3423. contents, as a string. INFO is a plist used as a communication
  3424. channel.
  3425. This function assumes TABLE has `org' as its `:type' property and
  3426. `tabbing' as its `:mode' attribute."
  3427. (format "\\begin{%s}\n%s\n%s\\end{%s}"
  3428. "tabbing"
  3429. (org-latex--align-string-tabbing table info)
  3430. contents
  3431. "tabbing"))
  3432. (defun org-latex--table.el-table (table info)
  3433. "Return appropriate LaTeX code for a table.el table.
  3434. TABLE is the table type element to transcode. INFO is a plist
  3435. used as a communication channel.
  3436. This function assumes TABLE has `table.el' as its `:type'
  3437. property."
  3438. (require 'table)
  3439. ;; Ensure "*org-export-table*" buffer is empty.
  3440. (with-current-buffer (get-buffer-create "*org-export-table*")
  3441. (erase-buffer))
  3442. (let ((output
  3443. (replace-regexp-in-string
  3444. "^%.*\n" "" ;remove comments
  3445. (with-temp-buffer
  3446. (save-excursion (insert (org-element-property :value table)))
  3447. (re-search-forward "^[ \t]*|[^|]" nil t)
  3448. (table-generate-source 'latex "*org-export-table*")
  3449. (with-current-buffer "*org-export-table*"
  3450. (org-trim (buffer-string))))
  3451. t t)))
  3452. (kill-buffer (get-buffer "*org-export-table*"))
  3453. (let ((attr (org-export-read-attribute :attr_latex table))
  3454. (caption (org-latex--caption/label-string table info))
  3455. (above? (org-latex--caption-above-p table info)))
  3456. (when (plist-get attr :rmlines)
  3457. ;; When the "rmlines" attribute is provided, remove all hlines
  3458. ;; but the one separating heading from the table body.
  3459. (let ((n 0) (pos 0))
  3460. (while (and (< (length output) pos)
  3461. (setq pos (string-match "^\\\\hline\n?" output pos)))
  3462. (cl-incf n)
  3463. (unless (= n 2) (setq output (replace-match "" nil nil output))))))
  3464. (org-latex--decorate-table output attr caption above? info))))
  3465. (defun org-latex--math-table (table info)
  3466. "Return appropriate LaTeX code for a matrix.
  3467. TABLE is the table type element to transcode. INFO is a plist
  3468. used as a communication channel.
  3469. This function assumes TABLE has `org' as its `:type' property and
  3470. `inline-math' or `math' as its `:mode' attribute."
  3471. (let* ((attr (org-export-read-attribute :attr_latex table))
  3472. (env (or (plist-get attr :environment)
  3473. (plist-get info :latex-default-table-environment)))
  3474. (contents
  3475. (mapconcat
  3476. (lambda (row)
  3477. (if (eq (org-element-property :type row) 'rule) "\\hline"
  3478. ;; Return each cell unmodified.
  3479. (concat
  3480. (mapconcat
  3481. (lambda (cell)
  3482. (substring (org-element-interpret-data cell) 0 -1))
  3483. (org-element-map row 'table-cell #'identity info) "&")
  3484. (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
  3485. "\n")))
  3486. (org-element-map table 'table-row #'identity info) "")))
  3487. (concat
  3488. ;; Prefix.
  3489. (plist-get attr :math-prefix)
  3490. ;; Environment. Also treat special cases.
  3491. (cond ((member env '("array" "tabular"))
  3492. (format "\\begin{%s}{%s}\n%s\\end{%s}"
  3493. env (org-latex--align-string table info t) contents env))
  3494. ((assoc env org-latex-table-matrix-macros)
  3495. (format "\\%s%s{\n%s}"
  3496. env
  3497. (or (plist-get attr :math-arguments) "")
  3498. contents))
  3499. (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
  3500. ;; Suffix.
  3501. (plist-get attr :math-suffix))))
  3502. ;;;; Table Cell
  3503. (defun org-latex-table-cell (table-cell contents info)
  3504. "Transcode a TABLE-CELL element from Org to LaTeX.
  3505. CONTENTS is the cell contents. INFO is a plist used as
  3506. a communication channel."
  3507. (let ((type (org-export-read-attribute
  3508. :attr_latex (org-export-get-parent-table table-cell) :mode))
  3509. (scientific-format (plist-get info :latex-table-scientific-notation)))
  3510. (concat
  3511. (if (and contents
  3512. scientific-format
  3513. (string-match orgtbl-exp-regexp contents))
  3514. ;; Use appropriate format string for scientific
  3515. ;; notation.
  3516. (format scientific-format
  3517. (match-string 1 contents)
  3518. (match-string 2 contents))
  3519. contents)
  3520. (when (org-export-get-next-element table-cell info)
  3521. (if (string= type "tabbing") " \\> " " & ")))))
  3522. ;;;; Table Row
  3523. (defun org-latex-table-row (table-row contents info)
  3524. "Transcode a TABLE-ROW element from Org to LaTeX.
  3525. CONTENTS is the contents of the row. INFO is a plist used as
  3526. a communication channel."
  3527. (let* ((attr (org-export-read-attribute :attr_latex
  3528. (org-export-get-parent table-row)))
  3529. (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
  3530. (plist-get info :latex-tables-booktabs)))
  3531. (longtablep
  3532. (member (or (plist-get attr :environment)
  3533. (plist-get info :latex-default-table-environment))
  3534. '("longtable" "longtabu"))))
  3535. (if (eq (org-element-property :type table-row) 'rule)
  3536. (cond
  3537. ((not booktabsp) "\\hline")
  3538. ((not (org-export-get-previous-element table-row info)) "\\toprule")
  3539. ((not (org-export-get-next-element table-row info)) "\\bottomrule")
  3540. ((and longtablep
  3541. (org-export-table-row-ends-header-p
  3542. (org-export-get-previous-element table-row info) info))
  3543. "")
  3544. (t "\\midrule"))
  3545. (concat
  3546. ;; When BOOKTABS are activated enforce top-rule even when no
  3547. ;; hline was specifically marked.
  3548. (and booktabsp (not (org-export-get-previous-element table-row info))
  3549. "\\toprule\n")
  3550. contents "\\\\\n"
  3551. (cond
  3552. ;; Special case for long tables. Define header and footers.
  3553. ((and longtablep (org-export-table-row-ends-header-p table-row info))
  3554. (let ((columns (cdr (org-export-table-dimensions
  3555. (org-export-get-parent-table table-row) info))))
  3556. (format "%s
  3557. \\endfirsthead
  3558. \\multicolumn{%d}{l}{%s} \\\\
  3559. %s
  3560. %s \\\\\n
  3561. %s
  3562. \\endhead
  3563. %s\\multicolumn{%d}{r}{%s} \\\\
  3564. \\endfoot
  3565. \\endlastfoot"
  3566. (if booktabsp "\\midrule" "\\hline")
  3567. columns
  3568. (org-latex--translate "Continued from previous page" info)
  3569. (cond
  3570. ((not (org-export-table-row-starts-header-p table-row info))
  3571. "")
  3572. (booktabsp "\\toprule\n")
  3573. (t "\\hline\n"))
  3574. contents
  3575. (if booktabsp "\\midrule" "\\hline")
  3576. (if booktabsp "\\midrule" "\\hline")
  3577. columns
  3578. (org-latex--translate "Continued on next page" info))))
  3579. ;; When BOOKTABS are activated enforce bottom rule even when
  3580. ;; no hline was specifically marked.
  3581. ((and booktabsp (not (org-export-get-next-element table-row info)))
  3582. "\\bottomrule"))))))
  3583. ;;;; Target
  3584. (defun org-latex-target (target _contents info)
  3585. "Transcode a TARGET object from Org to LaTeX.
  3586. CONTENTS is nil. INFO is a plist holding contextual
  3587. information."
  3588. (format "\\label{%s}" (org-latex--label target info)))
  3589. ;;;; Timestamp
  3590. (defun org-latex-timestamp (timestamp _contents info)
  3591. "Transcode a TIMESTAMP object from Org to LaTeX.
  3592. CONTENTS is nil. INFO is a plist holding contextual
  3593. information."
  3594. (let ((value (org-latex-plain-text (org-timestamp-translate timestamp) info)))
  3595. (format
  3596. (plist-get info
  3597. (cl-case (org-element-property :type timestamp)
  3598. ((active active-range) :latex-active-timestamp-format)
  3599. ((inactive inactive-range) :latex-inactive-timestamp-format)
  3600. (otherwise :latex-diary-timestamp-format)))
  3601. value)))
  3602. ;;;; Underline
  3603. (defun org-latex-underline (_underline contents info)
  3604. "Transcode UNDERLINE from Org to LaTeX.
  3605. CONTENTS is the text with underline markup. INFO is a plist
  3606. holding contextual information."
  3607. (org-latex--text-markup contents 'underline info))
  3608. ;;;; Verbatim
  3609. (defun org-latex-verbatim (verbatim _contents info)
  3610. "Transcode a VERBATIM object from Org to LaTeX.
  3611. CONTENTS is nil. INFO is a plist used as a communication
  3612. channel."
  3613. (org-latex--text-markup
  3614. (org-element-property :value verbatim) 'verbatim info))
  3615. ;;;; Verse Block
  3616. (defun org-latex-verse-block (verse-block contents info)
  3617. "Transcode a VERSE-BLOCK element from Org to LaTeX.
  3618. CONTENTS is verse block contents. INFO is a plist holding
  3619. contextual information."
  3620. (let* ((lin (org-export-read-attribute :attr_latex verse-block :lines))
  3621. (latcode (org-export-read-attribute :attr_latex verse-block :latexcode))
  3622. (cent (org-export-read-attribute :attr_latex verse-block :center))
  3623. (attr (concat
  3624. (if cent "[\\versewidth]" "")
  3625. (if lin (format "\n\\poemlines{%s}" lin) "")
  3626. (if latcode (format "\n%s" latcode) "")))
  3627. (versewidth (org-export-read-attribute :attr_latex verse-block :versewidth))
  3628. (vwidth (if versewidth (format "\\settowidth{\\versewidth}{%s}\n" versewidth) ""))
  3629. (linreset (if lin "\n\\poemlines{0}" "")))
  3630. (concat
  3631. (org-latex--wrap-label
  3632. verse-block
  3633. ;; In a verse environment, add a line break to each newline
  3634. ;; character and change each white space at beginning of a line
  3635. ;; into a space of 1 em. Also change each blank line with
  3636. ;; a vertical space of 1 em.
  3637. (format "%s\\begin{verse}%s\n%s\\end{verse}%s"
  3638. vwidth
  3639. attr
  3640. (replace-regexp-in-string
  3641. "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
  3642. (replace-regexp-in-string
  3643. "^[ \t]*\\\\\\\\$" "\\vspace*{1em}"
  3644. (replace-regexp-in-string
  3645. "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n"
  3646. contents nil t) nil t) nil t) linreset)
  3647. info)
  3648. ;; Insert footnote definitions, if any, after the environment, so
  3649. ;; the special formatting above is not applied to them.
  3650. (org-latex--delayed-footnotes-definitions verse-block info))))
  3651. ;;; End-user functions
  3652. ;;;###autoload
  3653. (defun org-latex-export-as-latex
  3654. (&optional async subtreep visible-only body-only ext-plist)
  3655. "Export current buffer as a LaTeX buffer.
  3656. If narrowing is active in the current buffer, only export its
  3657. narrowed part.
  3658. If a region is active, export that region.
  3659. A non-nil optional argument ASYNC means the process should happen
  3660. asynchronously. The resulting buffer should be accessible
  3661. through the `org-export-stack' interface.
  3662. When optional argument SUBTREEP is non-nil, export the sub-tree
  3663. at point, extracting information from the headline properties
  3664. first.
  3665. When optional argument VISIBLE-ONLY is non-nil, don't export
  3666. contents of hidden elements.
  3667. When optional argument BODY-ONLY is non-nil, only write code
  3668. between \"\\begin{document}\" and \"\\end{document}\".
  3669. EXT-PLIST, when provided, is a property list with external
  3670. parameters overriding Org default settings, but still inferior to
  3671. file-local settings.
  3672. Export is done in a buffer named \"*Org LATEX Export*\", which
  3673. will be displayed when `org-export-show-temporary-export-buffer'
  3674. is non-nil."
  3675. (interactive)
  3676. (org-export-to-buffer 'latex "*Org LATEX Export*"
  3677. async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
  3678. ;;;###autoload
  3679. (defun org-latex-convert-region-to-latex ()
  3680. "Assume the current region has Org syntax, and convert it to LaTeX.
  3681. This can be used in any buffer. For example, you can write an
  3682. itemized list in Org syntax in an LaTeX buffer and use this
  3683. command to convert it."
  3684. (interactive)
  3685. (org-export-replace-region-by 'latex))
  3686. ;;;###autoload
  3687. (defun org-latex-export-to-latex
  3688. (&optional async subtreep visible-only body-only ext-plist)
  3689. "Export current buffer to a LaTeX file.
  3690. If narrowing is active in the current buffer, only export its
  3691. narrowed part.
  3692. If a region is active, export that region.
  3693. A non-nil optional argument ASYNC means the process should happen
  3694. asynchronously. The resulting file should be accessible through
  3695. the `org-export-stack' interface.
  3696. When optional argument SUBTREEP is non-nil, export the sub-tree
  3697. at point, extracting information from the headline properties
  3698. first.
  3699. When optional argument VISIBLE-ONLY is non-nil, don't export
  3700. contents of hidden elements.
  3701. When optional argument BODY-ONLY is non-nil, only write code
  3702. between \"\\begin{document}\" and \"\\end{document}\".
  3703. EXT-PLIST, when provided, is a property list with external
  3704. parameters overriding Org default settings, but still inferior to
  3705. file-local settings."
  3706. (interactive)
  3707. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  3708. (org-export-to-file 'latex outfile
  3709. async subtreep visible-only body-only ext-plist)))
  3710. ;;;###autoload
  3711. (defun org-latex-export-to-pdf
  3712. (&optional async subtreep visible-only body-only ext-plist)
  3713. "Export current buffer to LaTeX then process through to PDF.
  3714. If narrowing is active in the current buffer, only export its
  3715. narrowed part.
  3716. If a region is active, export that region.
  3717. A non-nil optional argument ASYNC means the process should happen
  3718. asynchronously. The resulting file should be accessible through
  3719. the `org-export-stack' interface.
  3720. When optional argument SUBTREEP is non-nil, export the sub-tree
  3721. at point, extracting information from the headline properties
  3722. first.
  3723. When optional argument VISIBLE-ONLY is non-nil, don't export
  3724. contents of hidden elements.
  3725. When optional argument BODY-ONLY is non-nil, only write code
  3726. between \"\\begin{document}\" and \"\\end{document}\".
  3727. EXT-PLIST, when provided, is a property list with external
  3728. parameters overriding Org default settings, but still inferior to
  3729. file-local settings.
  3730. Return PDF file's name."
  3731. (interactive)
  3732. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  3733. (org-export-to-file 'latex outfile
  3734. async subtreep visible-only body-only ext-plist
  3735. #'org-latex-compile)))
  3736. (defun org-latex-compile (texfile &optional snippet)
  3737. "Compile a TeX file.
  3738. TEXFILE is the name of the file being compiled. Processing is
  3739. done through the command specified in `org-latex-pdf-process',
  3740. which see. Output is redirected to \"*Org PDF LaTeX Output*\"
  3741. buffer.
  3742. When optional argument SNIPPET is non-nil, TEXFILE is a temporary
  3743. file used to preview a LaTeX snippet. In this case, do not
  3744. create a log buffer and do not remove log files.
  3745. Return PDF file name or raise an error if it couldn't be
  3746. produced."
  3747. (unless snippet (message "Processing LaTeX file %s..." texfile))
  3748. (let* ((compiler
  3749. (or (with-temp-buffer
  3750. (save-excursion (insert-file-contents texfile))
  3751. (and (search-forward-regexp (regexp-opt org-latex-compilers)
  3752. (line-end-position 2)
  3753. t)
  3754. (progn (beginning-of-line) (looking-at-p "%"))
  3755. (match-string 0)))
  3756. ;; Cannot find the compiler inserted by
  3757. ;; `org-latex-template' -> `org-latex--insert-compiler'.
  3758. ;; Use a fallback.
  3759. "pdflatex"))
  3760. (process (if (functionp org-latex-pdf-process) org-latex-pdf-process
  3761. ;; Replace "%latex" with "%L" and "%bib" and
  3762. ;; "%bibtex" with "%B" to adhere to `format-spec'
  3763. ;; specifications.
  3764. (mapcar (lambda (command)
  3765. (replace-regexp-in-string
  3766. "%\\(?:\\(?:bib\\|la\\)tex\\|bib\\)\\>"
  3767. (lambda (m) (upcase (substring m 0 2)))
  3768. command))
  3769. org-latex-pdf-process)))
  3770. (spec `((?B . ,(shell-quote-argument org-latex-bib-compiler))
  3771. (?L . ,(shell-quote-argument compiler))))
  3772. (log-buf-name "*Org PDF LaTeX Output*")
  3773. (log-buf (and (not snippet) (get-buffer-create log-buf-name)))
  3774. (outfile (org-compile-file texfile process "pdf"
  3775. (format "See %S for details" log-buf-name)
  3776. log-buf spec)))
  3777. (unless snippet
  3778. (when org-latex-remove-logfiles
  3779. (mapc #'delete-file
  3780. (directory-files
  3781. (file-name-directory outfile)
  3782. t
  3783. (concat (regexp-quote (file-name-base outfile))
  3784. "\\(?:\\.[0-9]+\\)?\\."
  3785. (regexp-opt org-latex-logfiles-extensions))
  3786. t)))
  3787. (let ((warnings (org-latex--collect-warnings log-buf)))
  3788. (message (concat "PDF file produced"
  3789. (cond
  3790. ((eq warnings 'error) " with errors.")
  3791. (warnings (concat " with warnings: " warnings))
  3792. (t "."))))))
  3793. ;; Return output file name.
  3794. outfile))
  3795. (defun org-latex--collect-warnings (buffer)
  3796. "Collect some warnings from \"pdflatex\" command output.
  3797. BUFFER is the buffer containing output. Return collected
  3798. warnings types as a string, `error' if a LaTeX error was
  3799. encountered or nil if there was none."
  3800. (with-current-buffer buffer
  3801. (save-excursion
  3802. (goto-char (point-max))
  3803. (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
  3804. (if (re-search-forward "^!" nil t) 'error
  3805. (let ((case-fold-search t)
  3806. (warnings ""))
  3807. (dolist (warning org-latex-known-warnings)
  3808. (when (save-excursion (re-search-forward (car warning) nil t))
  3809. (setq warnings (concat warnings " " (cdr warning)))))
  3810. (org-string-nw-p (org-trim warnings))))))))
  3811. ;;;###autoload
  3812. (defun org-latex-publish-to-latex (plist filename pub-dir)
  3813. "Publish an Org file to LaTeX.
  3814. FILENAME is the filename of the Org file to be published. PLIST
  3815. is the property list for the given project. PUB-DIR is the
  3816. publishing directory.
  3817. Return output file name."
  3818. (org-publish-org-to 'latex filename ".tex" plist pub-dir))
  3819. ;;;###autoload
  3820. (defun org-latex-publish-to-pdf (plist filename pub-dir)
  3821. "Publish an Org file to PDF (via LaTeX).
  3822. FILENAME is the filename of the Org file to be published. PLIST
  3823. is the property list for the given project. PUB-DIR is the
  3824. publishing directory.
  3825. Return output file name."
  3826. ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
  3827. ;; in working directory and then moved to publishing directory.
  3828. (org-publish-attachment
  3829. plist
  3830. ;; Default directory could be anywhere when this function is
  3831. ;; called. We ensure it is set to source file directory during
  3832. ;; compilation so as to not break links to external documents.
  3833. (let ((default-directory (file-name-directory filename)))
  3834. (org-latex-compile
  3835. (org-publish-org-to
  3836. 'latex filename ".tex" plist (file-name-directory filename))))
  3837. pub-dir))
  3838. (provide 'ox-latex)
  3839. ;; Local variables:
  3840. ;; generated-autoload-file: "org-loaddefs.el"
  3841. ;; End:
  3842. ;;; ox-latex.el ends here