ox-latex.el 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340
  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. (format "\\date{%s}\n" (org-export-data date info)))
  1710. ;; Title and subtitle.
  1711. (let* ((subtitle (plist-get info :subtitle))
  1712. (formatted-subtitle
  1713. (when subtitle
  1714. (format (plist-get info :latex-subtitle-format)
  1715. (org-export-data subtitle info))))
  1716. (separate (plist-get info :latex-subtitle-separate)))
  1717. (concat
  1718. (format "\\title{%s%s}\n" title
  1719. (if separate "" (or formatted-subtitle "")))
  1720. (when (and separate subtitle)
  1721. (concat formatted-subtitle "\n"))))
  1722. ;; Hyperref options.
  1723. (let ((template (plist-get info :latex-hyperref-template)))
  1724. (and (stringp template)
  1725. (format-spec template spec)))
  1726. ;; engrave-faces-latex preamble
  1727. (when (and (eq org-latex-src-block-backend 'engraved)
  1728. (org-element-map (plist-get info :parse-tree)
  1729. '(src-block inline-src-block) #'identity
  1730. info t))
  1731. (org-latex-generate-engraved-preamble info t))
  1732. ;; Document start.
  1733. "\\begin{document}\n\n"
  1734. ;; Title command.
  1735. (let* ((title-command (plist-get info :latex-title-command))
  1736. (command (and (stringp title-command)
  1737. (format-spec title-command spec))))
  1738. (org-element-normalize-string
  1739. (cond ((not (plist-get info :with-title)) nil)
  1740. ((string= "" title) nil)
  1741. ((not (stringp command)) nil)
  1742. ((string-match "\\(?:[^%]\\|^\\)%s" command)
  1743. (format command title))
  1744. (t command))))
  1745. ;; Table of contents.
  1746. (let ((depth (plist-get info :with-toc)))
  1747. (when depth
  1748. (concat (when (integerp depth)
  1749. (format "\\setcounter{tocdepth}{%d}\n" depth))
  1750. (plist-get info :latex-toc-command))))
  1751. ;; Document's body.
  1752. contents
  1753. ;; Creator.
  1754. (and (plist-get info :with-creator)
  1755. (concat (plist-get info :creator) "\n"))
  1756. ;; Document end.
  1757. "\\end{document}")))
  1758. ;;; Transcode Functions
  1759. ;;;; Bold
  1760. (defun org-latex-bold (_bold contents info)
  1761. "Transcode BOLD from Org to LaTeX.
  1762. CONTENTS is the text with bold markup. INFO is a plist holding
  1763. contextual information."
  1764. (org-latex--text-markup contents 'bold info))
  1765. ;;;; Center Block
  1766. (defun org-latex-center-block (center-block contents info)
  1767. "Transcode a CENTER-BLOCK element from Org to LaTeX.
  1768. CONTENTS holds the contents of the center block. INFO is a plist
  1769. holding contextual information."
  1770. (org-latex--wrap-label
  1771. center-block (format "\\begin{center}\n%s\\end{center}" contents) info))
  1772. ;;;; Clock
  1773. (defun org-latex-clock (clock _contents info)
  1774. "Transcode a CLOCK element from Org to LaTeX.
  1775. CONTENTS is nil. INFO is a plist holding contextual
  1776. information."
  1777. (concat
  1778. "\\noindent"
  1779. (format "\\textbf{%s} " org-clock-string)
  1780. (format (plist-get info :latex-inactive-timestamp-format)
  1781. (concat (org-timestamp-translate (org-element-property :value clock))
  1782. (let ((time (org-element-property :duration clock)))
  1783. (and time (format " (%s)" time)))))
  1784. "\\\\"))
  1785. ;;;; Code
  1786. (defun org-latex-code (code _contents info)
  1787. "Transcode a CODE object from Org to LaTeX.
  1788. CONTENTS is nil. INFO is a plist used as a communication
  1789. channel."
  1790. (org-latex--text-markup (org-element-property :value code) 'code info))
  1791. ;;;; Drawer
  1792. (defun org-latex-drawer (drawer contents info)
  1793. "Transcode a DRAWER element from Org to LaTeX.
  1794. CONTENTS holds the contents of the block. INFO is a plist
  1795. holding contextual information."
  1796. (let* ((name (org-element-property :drawer-name drawer))
  1797. (output (funcall (plist-get info :latex-format-drawer-function)
  1798. name contents)))
  1799. (org-latex--wrap-label drawer output info)))
  1800. ;;;; Dynamic Block
  1801. (defun org-latex-dynamic-block (dynamic-block contents info)
  1802. "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
  1803. CONTENTS holds the contents of the block. INFO is a plist
  1804. holding contextual information. See `org-export-data'."
  1805. (org-latex--wrap-label dynamic-block contents info))
  1806. ;;;; Entity
  1807. (defun org-latex-entity (entity _contents _info)
  1808. "Transcode an ENTITY object from Org to LaTeX.
  1809. CONTENTS are the definition itself. INFO is a plist holding
  1810. contextual information."
  1811. (org-element-property :latex entity))
  1812. ;;;; Example Block
  1813. (defun org-latex-example-block (example-block _contents info)
  1814. "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
  1815. CONTENTS is nil. INFO is a plist holding contextual
  1816. information."
  1817. (when (org-string-nw-p (org-element-property :value example-block))
  1818. (let ((environment (or (org-export-read-attribute
  1819. :attr_latex example-block :environment)
  1820. "verbatim")))
  1821. (org-latex--wrap-label
  1822. example-block
  1823. (format "\\begin{%s}\n%s\\end{%s}"
  1824. environment
  1825. (org-export-format-code-default example-block info)
  1826. environment)
  1827. info))))
  1828. ;;;; Export Block
  1829. (defun org-latex-export-block (export-block _contents _info)
  1830. "Transcode a EXPORT-BLOCK element from Org to LaTeX.
  1831. CONTENTS is nil. INFO is a plist holding contextual information."
  1832. (when (member (org-element-property :type export-block) '("LATEX" "TEX"))
  1833. (org-remove-indentation (org-element-property :value export-block))))
  1834. ;;;; Export Snippet
  1835. (defun org-latex-export-snippet (export-snippet _contents _info)
  1836. "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
  1837. CONTENTS is nil. INFO is a plist holding contextual information."
  1838. (when (eq (org-export-snippet-backend export-snippet) 'latex)
  1839. (org-element-property :value export-snippet)))
  1840. ;;;; Fixed Width
  1841. (defun org-latex-fixed-width (fixed-width _contents info)
  1842. "Transcode a FIXED-WIDTH element from Org to LaTeX.
  1843. CONTENTS is nil. INFO is a plist holding contextual information."
  1844. (org-latex--wrap-label
  1845. fixed-width
  1846. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  1847. (org-remove-indentation
  1848. (org-element-property :value fixed-width)))
  1849. info))
  1850. ;;;; Footnote Reference
  1851. (defun org-latex-footnote-reference (footnote-reference _contents info)
  1852. "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
  1853. CONTENTS is nil. INFO is a plist holding contextual information."
  1854. (let ((label (org-element-property :label footnote-reference)))
  1855. (concat
  1856. ;; Insert separator between two footnotes in a row.
  1857. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1858. (when (eq (org-element-type prev) 'footnote-reference)
  1859. (plist-get info :latex-footnote-separator)))
  1860. (cond
  1861. ;; Use `:latex-footnote-defined-format' if the footnote has
  1862. ;; already been defined.
  1863. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1864. (format (plist-get info :latex-footnote-defined-format)
  1865. (org-latex--label
  1866. (org-export-get-footnote-definition footnote-reference info)
  1867. info t)))
  1868. ;; Use \footnotemark if reference is within another footnote
  1869. ;; reference, footnote definition, table cell, verse block, or
  1870. ;; item's tag.
  1871. ((or (org-element-lineage footnote-reference
  1872. '(footnote-reference footnote-definition
  1873. table-cell verse-block))
  1874. (eq 'item (org-element-type
  1875. (org-export-get-parent-element footnote-reference))))
  1876. "\\footnotemark")
  1877. ;; Otherwise, define it with \footnote command.
  1878. (t
  1879. (let ((def (org-export-get-footnote-definition footnote-reference info)))
  1880. (concat
  1881. (format "\\footnote{%s%s}" (org-trim (org-export-data def info))
  1882. ;; Only insert a \label if there exist another
  1883. ;; reference to def.
  1884. (cond ((not label) "")
  1885. ((org-element-map (plist-get info :parse-tree)
  1886. 'footnote-reference
  1887. (lambda (f)
  1888. (and (not (eq f footnote-reference))
  1889. (equal (org-element-property :label f) label)
  1890. (org-trim (org-latex--label def info t t))))
  1891. info t))
  1892. (t "")))
  1893. ;; Retrieve all footnote references within the footnote and
  1894. ;; add their definition after it, since LaTeX doesn't support
  1895. ;; them inside.
  1896. (org-latex--delayed-footnotes-definitions def info))))))))
  1897. ;;;; Headline
  1898. (defun org-latex-headline (headline contents info)
  1899. "Transcode a HEADLINE element from Org to LaTeX.
  1900. CONTENTS holds the contents of the headline. INFO is a plist
  1901. holding contextual information."
  1902. (unless (org-element-property :footnote-section-p headline)
  1903. (let* ((class (plist-get info :latex-class))
  1904. (level (org-export-get-relative-level headline info))
  1905. (numberedp (org-export-numbered-headline-p headline info))
  1906. (class-sectioning (assoc class (plist-get info :latex-classes)))
  1907. ;; Section formatting will set two placeholders: one for
  1908. ;; the title and the other for the contents.
  1909. (section-fmt
  1910. (let ((sec (if (functionp (nth 2 class-sectioning))
  1911. (funcall (nth 2 class-sectioning) level numberedp)
  1912. (nth (1+ level) class-sectioning))))
  1913. (cond
  1914. ;; No section available for that LEVEL.
  1915. ((not sec) nil)
  1916. ;; Section format directly returned by a function. Add
  1917. ;; placeholder for contents.
  1918. ((stringp sec) (concat sec "\n%s"))
  1919. ;; (numbered-section . unnumbered-section)
  1920. ((not (consp (cdr sec)))
  1921. (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
  1922. ;; (numbered-open numbered-close)
  1923. ((= (length sec) 2)
  1924. (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
  1925. ;; (num-in num-out no-num-in no-num-out)
  1926. ((= (length sec) 4)
  1927. (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
  1928. (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
  1929. ;; Create a temporary export back-end that hard-codes
  1930. ;; "\underline" within "\section" and alike.
  1931. (section-back-end
  1932. (org-export-create-backend
  1933. :parent 'latex
  1934. :transcoders
  1935. '((underline . (lambda (o c i) (format "\\underline{%s}" c)))
  1936. ;; LaTeX isn't happy when you try to use \verb inside the argument of other
  1937. ;; commands (like \section, etc.), and this causes compilation to fail.
  1938. ;; So, within headings it's a good idea to replace any instances of \verb
  1939. ;; with \texttt.
  1940. (code . (lambda (o _ _) (org-latex--protect-texttt (org-element-property :value o))))
  1941. (verbatim . (lambda (o _ _) (org-latex--protect-texttt (org-element-property :value o)))))))
  1942. (text
  1943. (org-export-data-with-backend
  1944. (org-element-property :title headline) section-back-end info))
  1945. (todo
  1946. (and (plist-get info :with-todo-keywords)
  1947. (let ((todo (org-element-property :todo-keyword headline)))
  1948. (and todo (org-export-data todo info)))))
  1949. (todo-type (and todo (org-element-property :todo-type headline)))
  1950. (tags (and (plist-get info :with-tags)
  1951. (org-export-get-tags headline info)))
  1952. (priority (and (plist-get info :with-priority)
  1953. (org-element-property :priority headline)))
  1954. ;; Create the headline text along with a no-tag version.
  1955. ;; The latter is required to remove tags from toc.
  1956. (full-text (funcall (plist-get info :latex-format-headline-function)
  1957. todo todo-type priority text tags info))
  1958. ;; Associate \label to the headline for internal links.
  1959. (headline-label (org-latex--label headline info t t))
  1960. (pre-blanks
  1961. (make-string (org-element-property :pre-blank headline) ?\n)))
  1962. (if (or (not section-fmt) (org-export-low-level-p headline info))
  1963. ;; This is a deep sub-tree: export it as a list item. Also
  1964. ;; export as items headlines for which no section format has
  1965. ;; been found.
  1966. (let ((low-level-body
  1967. (concat
  1968. ;; If headline is the first sibling, start a list.
  1969. (when (org-export-first-sibling-p headline info)
  1970. (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
  1971. ;; Itemize headline
  1972. "\\item"
  1973. (and full-text
  1974. (string-match-p "\\`[ \t]*\\[" full-text)
  1975. "\\relax")
  1976. " " full-text "\n"
  1977. headline-label
  1978. pre-blanks
  1979. contents)))
  1980. ;; If headline is not the last sibling simply return
  1981. ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
  1982. ;; any blank line.
  1983. (if (not (org-export-last-sibling-p headline info)) low-level-body
  1984. (replace-regexp-in-string
  1985. "[ \t\n]*\\'"
  1986. (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
  1987. low-level-body)))
  1988. ;; This is a standard headline. Export it as a section. Add
  1989. ;; an alternative heading when possible, and when this is not
  1990. ;; identical to the usual heading.
  1991. (let ((opt-title
  1992. (funcall (plist-get info :latex-format-headline-function)
  1993. todo todo-type priority
  1994. (org-export-data-with-backend
  1995. (org-export-get-alt-title headline info)
  1996. section-back-end info)
  1997. (and (eq (plist-get info :with-tags) t) tags)
  1998. info))
  1999. ;; Maybe end local TOC (see `org-latex-keyword').
  2000. (contents
  2001. (concat
  2002. contents
  2003. (let ((case-fold-search t)
  2004. (section
  2005. (let ((first (car (org-element-contents headline))))
  2006. (and (eq (org-element-type first) 'section) first))))
  2007. (org-element-map section 'keyword
  2008. (lambda (k)
  2009. (and (equal (org-element-property :key k) "TOC")
  2010. (let ((v (org-element-property :value k)))
  2011. (and (string-match-p "\\<headlines\\>" v)
  2012. (string-match-p "\\<local\\>" v)
  2013. (format "\\stopcontents[level-%d]" level)))))
  2014. info t)))))
  2015. (if (and opt-title
  2016. (not (equal opt-title full-text))
  2017. (string-match "\\`\\\\\\(.+?\\){" section-fmt))
  2018. (format (replace-match "\\1[%s]" nil nil section-fmt 1)
  2019. ;; Replace square brackets with parenthesis
  2020. ;; since square brackets are not supported in
  2021. ;; optional arguments.
  2022. (replace-regexp-in-string
  2023. "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
  2024. full-text
  2025. (concat headline-label pre-blanks contents))
  2026. ;; Impossible to add an alternative heading. Fallback to
  2027. ;; regular sectioning format string.
  2028. (format section-fmt full-text
  2029. (concat headline-label pre-blanks contents))))))))
  2030. (defun org-latex-format-headline-default-function
  2031. (todo _todo-type priority text tags _info)
  2032. "Default format function for a headline.
  2033. See `org-latex-format-headline-function' for details."
  2034. (concat
  2035. (and todo (format "{\\bfseries\\sffamily %s} " todo))
  2036. (and priority (format "\\framebox{\\#%c} " priority))
  2037. text
  2038. (and tags
  2039. (format "\\hfill{}\\textsc{%s}"
  2040. (mapconcat #'org-latex--protect-text tags ":")))))
  2041. ;;;; Horizontal Rule
  2042. (defun org-latex-horizontal-rule (horizontal-rule _contents info)
  2043. "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
  2044. CONTENTS is nil. INFO is a plist holding contextual information."
  2045. (let ((attr (org-export-read-attribute :attr_latex horizontal-rule))
  2046. (prev (org-export-get-previous-element horizontal-rule info)))
  2047. (concat
  2048. ;; Make sure the rule doesn't start at the end of the current
  2049. ;; line by separating it with a blank line from previous element.
  2050. (when (and prev
  2051. (let ((prev-blank (org-element-property :post-blank prev)))
  2052. (or (not prev-blank) (zerop prev-blank))))
  2053. "\n")
  2054. (org-latex--wrap-label
  2055. horizontal-rule
  2056. (format "\\noindent\\rule{%s}{%s}"
  2057. (or (plist-get attr :width) "\\textwidth")
  2058. (or (plist-get attr :thickness) "0.5pt"))
  2059. info))))
  2060. ;;;; Inline Src Block
  2061. (defun org-latex-inline-src-block (inline-src-block _contents info)
  2062. "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
  2063. CONTENTS holds the contents of the item. INFO is a plist holding
  2064. contextual information."
  2065. (let ((code (org-element-property :value inline-src-block))
  2066. (lang (org-element-property :language inline-src-block)))
  2067. (pcase (plist-get info :latex-src-block-backend)
  2068. (`verbatim (org-latex--text-markup code 'code info))
  2069. (`minted (org-latex-inline-src-block--minted info code lang))
  2070. (`engraved (org-latex-inline-src-block--engraved info code lang))
  2071. (`listings (org-latex-inline-src-block--listings info code lang))
  2072. (oldval
  2073. (message "Please update the LaTeX src-block-backend to %s"
  2074. (if oldval "listings" "verbatim"))
  2075. (if oldval
  2076. (org-latex-inline-src-block--listings info code lang)
  2077. (org-latex--text-markup code 'code info))))))
  2078. (defun org-latex-inline-src-block--minted (info code lang)
  2079. "Transcode an inline src block's content from Org to LaTeX, using minted.
  2080. INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
  2081. (let ((mint-lang (or (cadr (assq (intern lang)
  2082. (plist-get info :latex-minted-langs)))
  2083. (downcase lang)))
  2084. (options (org-latex--make-option-string
  2085. (plist-get info :latex-minted-options))))
  2086. (format "\\mintinline%s{%s}{%s}"
  2087. (if (string= options "") "" (format "[%s]" options))
  2088. mint-lang
  2089. code)))
  2090. (defun org-latex-inline-src-block--engraved (info code lang)
  2091. "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
  2092. INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
  2093. (org-latex-src--engrave-code
  2094. code lang nil (plist-get info :latex-engraved-options) t))
  2095. (defun org-latex-inline-src-block--listings (info code lang)
  2096. "Transcode an inline src block's content from Org to LaTeX, using lstlistings.
  2097. INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
  2098. (let* ((lst-lang (or (cadr (assq (intern lang)
  2099. (plist-get info :latex-listings-langs)))
  2100. lang))
  2101. (separator (org-latex--find-verb-separator code))
  2102. (options (org-latex--make-option-string
  2103. (append (plist-get info :latex-listings-options)
  2104. `(("language" ,lst-lang))))))
  2105. (concat (format "\\lstinline[%s]" options)
  2106. separator code separator)))
  2107. ;;;; Inlinetask
  2108. (defun org-latex-inlinetask (inlinetask contents info)
  2109. "Transcode an INLINETASK element from Org to LaTeX.
  2110. CONTENTS holds the contents of the block. INFO is a plist
  2111. holding contextual information."
  2112. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  2113. (todo (and (plist-get info :with-todo-keywords)
  2114. (let ((todo (org-element-property :todo-keyword inlinetask)))
  2115. (and todo (org-export-data todo info)))))
  2116. (todo-type (org-element-property :todo-type inlinetask))
  2117. (tags (and (plist-get info :with-tags)
  2118. (org-export-get-tags inlinetask info)))
  2119. (priority (and (plist-get info :with-priority)
  2120. (org-element-property :priority inlinetask)))
  2121. (contents (concat (org-latex--label inlinetask info) contents)))
  2122. (funcall (plist-get info :latex-format-inlinetask-function)
  2123. todo todo-type priority title tags contents info)))
  2124. (defun org-latex-format-inlinetask-default-function
  2125. (todo _todo-type priority title tags contents _info)
  2126. "Default format function for inlinetasks.
  2127. See `org-latex-format-inlinetask-function' for details."
  2128. (let ((full-title
  2129. (concat (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2130. (when priority (format "\\framebox{\\#%c} " priority))
  2131. title
  2132. (when tags
  2133. (format "\\hfill{}\\textsc{%s}"
  2134. (org-make-tag-string
  2135. (mapcar #'org-latex--protect-text tags)))))))
  2136. (concat "\\begin{center}\n"
  2137. "\\fbox{\n"
  2138. "\\begin{minipage}[c]{.6\\linewidth}\n"
  2139. full-title "\n\n"
  2140. (and (org-string-nw-p contents)
  2141. (concat "\\rule[.8em]{\\linewidth}{2pt}\n\n" contents))
  2142. "\\end{minipage}\n"
  2143. "}\n"
  2144. "\\end{center}")))
  2145. ;;;; Italic
  2146. (defun org-latex-italic (_italic contents info)
  2147. "Transcode ITALIC from Org to LaTeX.
  2148. CONTENTS is the text with italic markup. INFO is a plist holding
  2149. contextual information."
  2150. (org-latex--text-markup contents 'italic info))
  2151. ;;;; Item
  2152. (defun org-latex-item (item contents info)
  2153. "Transcode an ITEM element from Org to LaTeX.
  2154. CONTENTS holds the contents of the item. INFO is a plist holding
  2155. contextual information."
  2156. (let* ((orderedp (eq (org-element-property
  2157. :type (org-export-get-parent item))
  2158. 'ordered))
  2159. (level
  2160. ;; Determine level of current item to determine the
  2161. ;; correct LaTeX counter to use (enumi, enumii...).
  2162. (let ((parent item) (level 0))
  2163. (while (memq (org-element-type
  2164. (setq parent (org-export-get-parent parent)))
  2165. '(plain-list item))
  2166. (when (and (eq (org-element-type parent) 'plain-list)
  2167. (eq (org-element-property :type parent)
  2168. 'ordered))
  2169. (cl-incf level)))
  2170. level))
  2171. (count (org-element-property :counter item))
  2172. (counter (and count
  2173. (< level 5)
  2174. (format "\\setcounter{enum%s}{%s}\n"
  2175. (nth (1- level) '("i" "ii" "iii" "iv"))
  2176. (1- count))))
  2177. (checkbox (cl-case (org-element-property :checkbox item)
  2178. (on "$\\boxtimes$")
  2179. (off "$\\square$")
  2180. (trans "$\\boxminus$")))
  2181. (tag (let ((tag (org-element-property :tag item)))
  2182. (and tag (org-export-data tag info))))
  2183. ;; If there are footnotes references in tag, be sure to add
  2184. ;; their definition at the end of the item. This workaround
  2185. ;; is necessary since "\footnote{}" command is not supported
  2186. ;; in tags.
  2187. (tag-footnotes
  2188. (or (and tag (org-latex--delayed-footnotes-definitions
  2189. (org-element-property :tag item) info))
  2190. "")))
  2191. (concat counter
  2192. "\\item"
  2193. (cond
  2194. ((and checkbox tag)
  2195. (format (if orderedp "{%s %s} %s" "[{%s %s}] %s")
  2196. checkbox tag tag-footnotes))
  2197. ((or checkbox tag)
  2198. (format (if orderedp "{%s} %s" "[{%s}] %s")
  2199. (or checkbox tag) tag-footnotes))
  2200. ;; Without a tag or a check-box, if CONTENTS starts with
  2201. ;; an opening square bracket, add "\relax" to "\item",
  2202. ;; unless the brackets comes from an initial export
  2203. ;; snippet (i.e. it is inserted willingly by the user).
  2204. ((and contents
  2205. (string-match-p "\\`[ \t]*\\[" contents)
  2206. (not (let ((e (car (org-element-contents item))))
  2207. (and (eq (org-element-type e) 'paragraph)
  2208. (let ((o (car (org-element-contents e))))
  2209. (and (eq (org-element-type o) 'export-snippet)
  2210. (eq (org-export-snippet-backend o)
  2211. 'latex)))))))
  2212. "\\relax ")
  2213. (t " "))
  2214. (and contents (org-trim contents)))))
  2215. ;;;; Keyword
  2216. (defun org-latex-keyword (keyword _contents info)
  2217. "Transcode a KEYWORD element from Org to LaTeX.
  2218. CONTENTS is nil. INFO is a plist holding contextual information."
  2219. (let ((key (org-element-property :key keyword))
  2220. (value (org-element-property :value keyword)))
  2221. (cond
  2222. ((string= key "LATEX") value)
  2223. ((string= key "INDEX") (format "\\index{%s}" value))
  2224. ((string= key "TOC")
  2225. (let ((case-fold-search t))
  2226. (cond
  2227. ((string-match-p "\\<headlines\\>" value)
  2228. (let* ((localp (string-match-p "\\<local\\>" value))
  2229. (parent (org-element-lineage keyword '(headline)))
  2230. (level (if (not (and localp parent)) 0
  2231. (org-export-get-relative-level parent info)))
  2232. (depth
  2233. (and (string-match "\\<[0-9]+\\>" value)
  2234. (format
  2235. "\\setcounter{tocdepth}{%d}"
  2236. (+ (string-to-number (match-string 0 value)) level)))))
  2237. (if (and localp parent)
  2238. ;; Start local TOC, assuming package "titletoc" is
  2239. ;; required.
  2240. (format "\\startcontents[level-%d]
  2241. \\printcontents[level-%d]{}{0}{%s}"
  2242. level level (or depth ""))
  2243. (concat depth (and depth "\n") "\\tableofcontents"))))
  2244. ((string-match-p "\\<tables\\>" value) "\\listoftables")
  2245. ((string-match-p "\\<listings\\>" value)
  2246. (cl-case (plist-get info :latex-src-block-backend)
  2247. ((nil) "\\listoffigures")
  2248. (minted "\\listoflistings")
  2249. (engraved "\\listoflistings")
  2250. (otherwise "\\lstlistoflistings")))))))))
  2251. ;;;; Latex Environment
  2252. (defun org-latex--environment-type (latex-environment)
  2253. "Return the TYPE of LATEX-ENVIRONMENT.
  2254. The TYPE is determined from the actual latex environment, and
  2255. could be a member of `org-latex-caption-above' or `math'."
  2256. (let* ((latex-begin-re "\\\\begin{\\([A-Za-z0-9*]+\\)}")
  2257. (value (org-remove-indentation
  2258. (org-element-property :value latex-environment)))
  2259. (env (or (and (string-match latex-begin-re value)
  2260. (match-string 1 value))
  2261. "")))
  2262. (cond
  2263. ((string-match-p org-latex-math-environments-re value) 'math)
  2264. ((string-match-p
  2265. (eval-when-compile
  2266. (regexp-opt '("table" "longtable" "tabular" "tabu" "longtabu")))
  2267. env)
  2268. 'table)
  2269. ((string-match-p "figure" env) 'image)
  2270. ((string-match-p
  2271. (eval-when-compile
  2272. (regexp-opt '("lstlisting" "listing" "verbatim" "minted")))
  2273. env)
  2274. 'src-block)
  2275. (t 'special-block))))
  2276. (defun org-latex-latex-environment (latex-environment _contents info)
  2277. "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
  2278. CONTENTS is nil. INFO is a plist holding contextual information."
  2279. (when (plist-get info :with-latex)
  2280. (let* ((value (org-remove-indentation
  2281. (org-element-property :value latex-environment)))
  2282. (type (org-latex--environment-type latex-environment))
  2283. (caption (if (eq type 'math)
  2284. (org-latex--label latex-environment info nil t)
  2285. (org-latex--caption/label-string latex-environment info)))
  2286. (caption-above-p
  2287. (memq type (append (plist-get info :latex-caption-above) '(math)))))
  2288. (if (not (or (org-element-property :name latex-environment)
  2289. (org-element-property :caption latex-environment)))
  2290. value
  2291. ;; Environment is labeled: label must be within the environment
  2292. ;; (otherwise, a reference pointing to that element will count
  2293. ;; the section instead). Also insert caption if `latex-environment'
  2294. ;; is not a math environment.
  2295. (with-temp-buffer
  2296. (insert value)
  2297. (if caption-above-p
  2298. (progn
  2299. (goto-char (point-min))
  2300. (forward-line))
  2301. (goto-char (point-max))
  2302. (forward-line -1))
  2303. (insert caption)
  2304. (buffer-string))))))
  2305. ;;;; Latex Fragment
  2306. (defun org-latex-latex-fragment (latex-fragment _contents _info)
  2307. "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
  2308. CONTENTS is nil. INFO is a plist holding contextual information."
  2309. (let ((value (org-element-property :value latex-fragment)))
  2310. ;; Trim math markers since the fragment is enclosed within
  2311. ;; a latex-math-block object anyway.
  2312. (cond ((string-match-p "\\`\\$[^$]" value) (substring value 1 -1))
  2313. ((string-prefix-p "\\(" value) (substring value 2 -2))
  2314. (t value))))
  2315. ;;;; Line Break
  2316. (defun org-latex-line-break (_line-break _contents _info)
  2317. "Transcode a LINE-BREAK object from Org to LaTeX.
  2318. CONTENTS is nil. INFO is a plist holding contextual information."
  2319. "\\\\\n")
  2320. ;;;; Link
  2321. (defun org-latex-image-link-filter (data _backend info)
  2322. (org-export-insert-image-links data info org-latex-inline-image-rules))
  2323. (defun org-latex--inline-image (link info)
  2324. "Return LaTeX code for an inline image.
  2325. LINK is the link pointing to the inline image. INFO is a plist
  2326. used as a communication channel."
  2327. (let* ((parent (org-export-get-parent-element link))
  2328. (path (let ((raw-path (org-element-property :path link)))
  2329. (if (not (file-name-absolute-p raw-path)) raw-path
  2330. (expand-file-name raw-path))))
  2331. (filetype (file-name-extension path))
  2332. (caption (org-latex--caption/label-string parent info))
  2333. (caption-above-p (org-latex--caption-above-p link info))
  2334. ;; Retrieve latex attributes from the element around.
  2335. (attr (org-export-read-attribute :attr_latex parent))
  2336. (float (let ((float (plist-get attr :float)))
  2337. (cond ((string= float "wrap") 'wrap)
  2338. ((string= float "sideways") 'sideways)
  2339. ((string= float "multicolumn") 'multicolumn)
  2340. ((string= float "t") 'figure)
  2341. ((and (plist-member attr :float) (not float)) 'nonfloat)
  2342. (float float)
  2343. ((or (org-element-property :caption parent)
  2344. (org-string-nw-p (plist-get attr :caption)))
  2345. 'figure)
  2346. (t 'nonfloat))))
  2347. (placement
  2348. (let ((place (plist-get attr :placement)))
  2349. (cond
  2350. (place (format "%s" place))
  2351. ((eq float 'wrap) "{l}{0.5\\textwidth}")
  2352. ((eq float 'figure)
  2353. (format "[%s]" (plist-get info :latex-default-figure-position)))
  2354. (t ""))))
  2355. (center
  2356. (cond
  2357. ;; If link is an image link, do not center.
  2358. ((eq 'link (org-element-type (org-export-get-parent link))) nil)
  2359. ((plist-member attr :center) (plist-get attr :center))
  2360. (t (plist-get info :latex-images-centered))))
  2361. (comment-include (if (plist-get attr :comment-include) "%" ""))
  2362. ;; It is possible to specify scale or width and height in
  2363. ;; the ATTR_LATEX line, and also via default variables.
  2364. (scale (cond ((eq float 'wrap) "")
  2365. ((plist-get attr :scale))
  2366. (t (plist-get info :latex-image-default-scale))))
  2367. (width (cond ((org-string-nw-p scale) "")
  2368. ((plist-get attr :width))
  2369. ((plist-get attr :height) "")
  2370. ((eq float 'wrap) "0.48\\textwidth")
  2371. (t (plist-get info :latex-image-default-width))))
  2372. (height (cond ((org-string-nw-p scale) "")
  2373. ((plist-get attr :height))
  2374. ((or (plist-get attr :width)
  2375. (memq float '(figure wrap))) "")
  2376. (t (plist-get info :latex-image-default-height))))
  2377. (options (let ((opt (or (plist-get attr :options)
  2378. (plist-get info :latex-image-default-option))))
  2379. (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
  2380. (match-string 1 opt))))
  2381. image-code)
  2382. (if (member filetype '("tikz" "pgf"))
  2383. ;; For tikz images:
  2384. ;; - use \input to read in image file.
  2385. ;; - if options are present, wrap in a tikzpicture environment.
  2386. ;; - if width or height are present, use \resizebox to change
  2387. ;; the image size.
  2388. (progn
  2389. (setq image-code (format "\\input{%s}" path))
  2390. (when (org-string-nw-p options)
  2391. (setq image-code
  2392. (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
  2393. options
  2394. image-code)))
  2395. (setq image-code
  2396. (cond ((org-string-nw-p scale)
  2397. (format "\\scalebox{%s}{%s}" scale image-code))
  2398. ((or (org-string-nw-p width) (org-string-nw-p height))
  2399. (format "\\resizebox{%s}{%s}{%s}"
  2400. (if (org-string-nw-p width) width "!")
  2401. (if (org-string-nw-p height) height "!")
  2402. image-code))
  2403. (t image-code))))
  2404. ;; For other images:
  2405. ;; - add scale, or width and height to options.
  2406. ;; - include the image with \includegraphics.
  2407. (if (org-string-nw-p scale)
  2408. (setq options (concat options ",scale=" scale))
  2409. (when (org-string-nw-p width) (setq options (concat options ",width=" width)))
  2410. (when (org-string-nw-p height) (setq options (concat options ",height=" height))))
  2411. (let ((search-option (org-element-property :search-option link)))
  2412. (when (and search-option
  2413. (equal filetype "pdf")
  2414. (string-match-p "\\`[0-9]+\\'" search-option)
  2415. (not (string-match-p "page=" options)))
  2416. (setq options (concat options ",page=" search-option))))
  2417. (setq image-code
  2418. (format "\\includegraphics%s{%s}"
  2419. (cond ((not (org-string-nw-p options)) "")
  2420. ((string-prefix-p "," options)
  2421. (format "[%s]" (substring options 1)))
  2422. (t (format "[%s]" options)))
  2423. ;; While \includegraphics is fine with unicode in the path,
  2424. ;; \includesvg is prone to producing errors.
  2425. (if (and (string-match-p "[^[:ascii:]]" path)
  2426. (equal filetype "svg"))
  2427. (concat "\\detokenize{" path "}")
  2428. path)))
  2429. (when (equal filetype "svg")
  2430. (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
  2431. "\\includesvg"
  2432. image-code
  2433. nil t))
  2434. (setq image-code (replace-regexp-in-string "\\.svg}"
  2435. "}"
  2436. image-code
  2437. nil t))))
  2438. ;; Return proper string, depending on FLOAT.
  2439. (pcase float
  2440. ((and (pred stringp) env-string)
  2441. (format "\\begin{%s}%s
  2442. %s%s
  2443. %s%s
  2444. %s\\end{%s}"
  2445. env-string
  2446. placement
  2447. (if caption-above-p caption "")
  2448. (if center "\\centering" "")
  2449. comment-include image-code
  2450. (if caption-above-p "" caption)
  2451. env-string))
  2452. (`wrap (format "\\begin{wrapfigure}%s
  2453. %s%s
  2454. %s%s
  2455. %s\\end{wrapfigure}"
  2456. placement
  2457. (if caption-above-p caption "")
  2458. (if center "\\centering" "")
  2459. comment-include image-code
  2460. (if caption-above-p "" caption)))
  2461. (`sideways (format "\\begin{sidewaysfigure}
  2462. %s%s
  2463. %s%s
  2464. %s\\end{sidewaysfigure}"
  2465. (if caption-above-p caption "")
  2466. (if center "\\centering" "")
  2467. comment-include image-code
  2468. (if caption-above-p "" caption)))
  2469. (`multicolumn (format "\\begin{figure*}%s
  2470. %s%s
  2471. %s%s
  2472. %s\\end{figure*}"
  2473. placement
  2474. (if caption-above-p caption "")
  2475. (if center "\\centering" "")
  2476. comment-include image-code
  2477. (if caption-above-p "" caption)))
  2478. (`figure (format "\\begin{figure}%s
  2479. %s%s
  2480. %s%s
  2481. %s\\end{figure}"
  2482. placement
  2483. (if caption-above-p caption "")
  2484. (if center "\\centering" "")
  2485. comment-include image-code
  2486. (if caption-above-p "" caption)))
  2487. ((guard center)
  2488. (format "\\begin{center}
  2489. %s%s
  2490. %s\\end{center}"
  2491. (if caption-above-p caption "")
  2492. image-code
  2493. (if caption-above-p "" caption)))
  2494. (_
  2495. (concat (if caption-above-p caption "")
  2496. image-code
  2497. (if caption-above-p caption ""))))))
  2498. (defun org-latex-link (link desc info)
  2499. "Transcode a LINK object from Org to LaTeX.
  2500. DESC is the description part of the link, or the empty string.
  2501. INFO is a plist holding contextual information. See
  2502. `org-export-data'."
  2503. (let* ((type (org-element-property :type link))
  2504. (raw-path (org-element-property :path link))
  2505. ;; Ensure DESC really exists, or set it to nil.
  2506. (desc (and (not (string= desc "")) desc))
  2507. (imagep (org-export-inline-image-p
  2508. link (plist-get info :latex-inline-image-rules)))
  2509. (path (org-latex--protect-text
  2510. (pcase type
  2511. ((or "http" "https" "ftp" "mailto" "doi")
  2512. (concat type ":" raw-path))
  2513. ("file"
  2514. (org-export-file-uri raw-path))
  2515. (_
  2516. raw-path)))))
  2517. (cond
  2518. ;; Link type is handled by a special function.
  2519. ((org-export-custom-protocol-maybe link desc 'latex info))
  2520. ;; Image file.
  2521. (imagep (org-latex--inline-image (org-export-link-localise link) info))
  2522. ;; Radio link: Transcode target's contents and use them as link's
  2523. ;; description.
  2524. ((string= type "radio")
  2525. (let ((destination (org-export-resolve-radio-link link info)))
  2526. (if (not destination) desc
  2527. (format "\\hyperref[%s]{%s}"
  2528. (org-export-get-reference destination info)
  2529. desc))))
  2530. ;; Links pointing to a headline: Find destination and build
  2531. ;; appropriate referencing command.
  2532. ((member type '("custom-id" "fuzzy" "id"))
  2533. (let ((destination
  2534. (if (string= type "fuzzy")
  2535. (org-export-resolve-fuzzy-link link info 'latex-matrices)
  2536. (org-export-resolve-id-link link info))))
  2537. (cl-case (org-element-type destination)
  2538. ;; Id link points to an external file.
  2539. (plain-text
  2540. (if desc (format "\\href{%s}{%s}" destination desc)
  2541. (format "\\url{%s}" destination)))
  2542. ;; Fuzzy link points nowhere.
  2543. ((nil)
  2544. (format (plist-get info :latex-link-with-unknown-path-format)
  2545. (or desc
  2546. (org-export-data
  2547. (org-element-property :raw-link link) info))))
  2548. ;; LINK points to a headline. If headlines are numbered
  2549. ;; and the link has no description, display headline's
  2550. ;; number. Otherwise, display description or headline's
  2551. ;; title.
  2552. (headline
  2553. (let ((label (org-latex--label destination info t)))
  2554. (if (and (not desc)
  2555. (org-export-numbered-headline-p destination info))
  2556. (format org-latex-reference-command label)
  2557. (format "\\hyperref[%s]{%s}" label
  2558. (or desc
  2559. (org-export-data
  2560. (org-element-property :title destination) info))))))
  2561. ;; Fuzzy link points to a target. Do as above.
  2562. (otherwise
  2563. (let ((ref (org-latex--label destination info t)))
  2564. (if (not desc) (format org-latex-reference-command ref)
  2565. (format "\\hyperref[%s]{%s}" ref desc)))))))
  2566. ;; Coderef: replace link with the reference name or the
  2567. ;; equivalent line number.
  2568. ((string= type "coderef")
  2569. (format (org-export-get-coderef-format path desc)
  2570. ;; Resolve with RAW-PATH since PATH could be tainted
  2571. ;; with `org-latex--protect-text' call above.
  2572. (org-export-resolve-coderef raw-path info)))
  2573. ;; External link with a description part.
  2574. ((and path desc) (format "\\href{%s}{%s}" path desc))
  2575. ;; External link without a description part.
  2576. (path (format "\\url{%s}" path))
  2577. ;; No path, only description. Try to do something useful.
  2578. (t (format (plist-get info :latex-link-with-unknown-path-format) desc)))))
  2579. ;;;; Node Property
  2580. (defun org-latex-node-property (node-property _contents _info)
  2581. "Transcode a NODE-PROPERTY element from Org to LaTeX.
  2582. CONTENTS is nil. INFO is a plist holding contextual
  2583. information."
  2584. (format "%s:%s"
  2585. (org-element-property :key node-property)
  2586. (let ((value (org-element-property :value node-property)))
  2587. (if value (concat " " value) ""))))
  2588. ;;;; Paragraph
  2589. (defun org-latex-paragraph (_paragraph contents _info)
  2590. "Transcode a PARAGRAPH element from Org to LaTeX.
  2591. CONTENTS is the contents of the paragraph, as a string. INFO is
  2592. the plist used as a communication channel."
  2593. contents)
  2594. ;;;; Plain List
  2595. (defun org-latex-plain-list (plain-list contents info)
  2596. "Transcode a PLAIN-LIST element from Org to LaTeX.
  2597. CONTENTS is the contents of the list. INFO is a plist holding
  2598. contextual information."
  2599. (let* ((type (org-element-property :type plain-list))
  2600. (attr (org-export-read-attribute :attr_latex plain-list))
  2601. (latex-type (let ((env (plist-get attr :environment)))
  2602. (cond (env (format "%s" env))
  2603. ((eq type 'ordered) "enumerate")
  2604. ((eq type 'descriptive) "description")
  2605. (t "itemize")))))
  2606. (org-latex--wrap-label
  2607. plain-list
  2608. (format "\\begin{%s}%s\n%s\\end{%s}"
  2609. latex-type
  2610. (or (plist-get attr :options) "")
  2611. contents
  2612. latex-type)
  2613. info)))
  2614. ;;;; Plain Text
  2615. (defun org-latex-plain-text (text info)
  2616. "Transcode a TEXT string from Org to LaTeX.
  2617. TEXT is the string to transcode. INFO is a plist holding
  2618. contextual information."
  2619. (let* ((specialp (plist-get info :with-special-strings))
  2620. (output
  2621. ;; Turn LaTeX into \LaTeX{} and TeX into \TeX{}.
  2622. (let ((case-fold-search nil))
  2623. (replace-regexp-in-string
  2624. "\\<\\(?:La\\)?TeX\\>" "\\\\\\&{}"
  2625. ;; Protect ^, ~, %, #, &, $, _, { and }. Also protect \.
  2626. ;; However, if special strings are used, be careful not
  2627. ;; to protect "\" in "\-" constructs.
  2628. (replace-regexp-in-string
  2629. (concat "[%$#&{}_~^]\\|\\\\" (and specialp "\\([^-]\\|$\\)"))
  2630. (lambda (m)
  2631. (cl-case (string-to-char m)
  2632. (?\\ "$\\\\backslash$\\1")
  2633. (?~ "\\\\textasciitilde{}")
  2634. (?^ "\\\\^{}")
  2635. (t "\\\\\\&")))
  2636. text)))))
  2637. ;; Activate smart quotes. Be sure to provide original TEXT string
  2638. ;; since OUTPUT may have been modified.
  2639. (when (plist-get info :with-smart-quotes)
  2640. (setq output (org-export-activate-smart-quotes output :latex info text)))
  2641. ;; Convert special strings.
  2642. (when specialp
  2643. (setq output (replace-regexp-in-string "\\.\\.\\." "\\\\ldots{}" output)))
  2644. ;; Handle break preservation if required.
  2645. (when (plist-get info :preserve-breaks)
  2646. (setq output (replace-regexp-in-string
  2647. "\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n" output nil t)))
  2648. ;; Return value.
  2649. output))
  2650. ;;;; Planning
  2651. (defun org-latex-planning (planning _contents info)
  2652. "Transcode a PLANNING element from Org to LaTeX.
  2653. CONTENTS is nil. INFO is a plist holding contextual
  2654. information."
  2655. (concat
  2656. "\\noindent"
  2657. (mapconcat
  2658. 'identity
  2659. (delq nil
  2660. (list
  2661. (let ((closed (org-element-property :closed planning)))
  2662. (when closed
  2663. (concat
  2664. (format "\\textbf{%s} " org-closed-string)
  2665. (format (plist-get info :latex-inactive-timestamp-format)
  2666. (org-timestamp-translate closed)))))
  2667. (let ((deadline (org-element-property :deadline planning)))
  2668. (when deadline
  2669. (concat
  2670. (format "\\textbf{%s} " org-deadline-string)
  2671. (format (plist-get info :latex-active-timestamp-format)
  2672. (org-timestamp-translate deadline)))))
  2673. (let ((scheduled (org-element-property :scheduled planning)))
  2674. (when scheduled
  2675. (concat
  2676. (format "\\textbf{%s} " org-scheduled-string)
  2677. (format (plist-get info :latex-active-timestamp-format)
  2678. (org-timestamp-translate scheduled)))))))
  2679. " ")
  2680. "\\\\"))
  2681. ;;;; Property Drawer
  2682. (defun org-latex-property-drawer (_property-drawer contents _info)
  2683. "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
  2684. CONTENTS holds the contents of the drawer. INFO is a plist
  2685. holding contextual information."
  2686. (and (org-string-nw-p contents)
  2687. (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
  2688. ;;;; Pseudo Element: LaTeX Matrices
  2689. ;; `latex-matrices' elements have the following properties:
  2690. ;; `:caption', `:post-blank' and `:markup' (`inline', `equation' or
  2691. ;; `math').
  2692. (defun org-latex--wrap-latex-matrices (data info)
  2693. "Merge contiguous tables with the same mode within a pseudo-element.
  2694. DATA is a parse tree or a secondary string. INFO is a plist
  2695. containing export options. Modify DATA by side-effect and return
  2696. it."
  2697. (org-element-map data 'table
  2698. (lambda (table)
  2699. (when (eq (org-element-property :type table) 'org)
  2700. (let ((mode (or (org-export-read-attribute :attr_latex table :mode)
  2701. (plist-get info :latex-default-table-mode))))
  2702. (when (and (member mode '("inline-math" "math"))
  2703. ;; Do not wrap twice the same table.
  2704. (not (eq (org-element-type
  2705. (org-element-property :parent table))
  2706. 'latex-matrices)))
  2707. (let* ((caption (and (not (string= mode "inline-math"))
  2708. (org-element-property :caption table)))
  2709. (name (and (not (string= mode "inline-math"))
  2710. (org-element-property :name table)))
  2711. (matrices
  2712. (list 'latex-matrices
  2713. ;; Inherit name from the first table.
  2714. (list :name name
  2715. ;; FIXME: what syntax for captions?
  2716. ;;
  2717. ;; :caption caption
  2718. :markup
  2719. (cond ((string= mode "inline-math") 'inline)
  2720. ((or caption name) 'equation)
  2721. (t 'math)))))
  2722. (previous table)
  2723. (next (org-export-get-next-element table info)))
  2724. (org-element-insert-before matrices table)
  2725. ;; Swallow all contiguous tables sharing the same mode.
  2726. (while (and
  2727. (zerop (or (org-element-property :post-blank previous) 0))
  2728. (setq next (org-export-get-next-element previous info))
  2729. (eq (org-element-type next) 'table)
  2730. (eq (org-element-property :type next) 'org)
  2731. (string= (or (org-export-read-attribute
  2732. :attr_latex next :mode)
  2733. (plist-get info :latex-default-table-mode))
  2734. mode))
  2735. (org-element-put-property table :name nil)
  2736. (org-element-put-property table :caption nil)
  2737. (org-element-extract-element previous)
  2738. (org-element-adopt-elements matrices previous)
  2739. (setq previous next))
  2740. ;; Inherit `:post-blank' from the value of the last
  2741. ;; swallowed table. Set the latter's `:post-blank'
  2742. ;; value to 0 so as to not duplicate empty lines.
  2743. (org-element-put-property
  2744. matrices :post-blank (org-element-property :post-blank previous))
  2745. (org-element-put-property previous :post-blank 0)
  2746. (org-element-put-property table :name nil)
  2747. (org-element-put-property table :caption nil)
  2748. (org-element-extract-element previous)
  2749. (org-element-adopt-elements matrices previous))))))
  2750. info)
  2751. data)
  2752. (defun org-latex-matrices (matrices contents info)
  2753. "Transcode a MATRICES element from Org to LaTeX.
  2754. CONTENTS is a string. INFO is a plist used as a communication
  2755. channel."
  2756. (pcase (org-element-property :markup matrices)
  2757. (`inline (format "\\(%s\\)" contents))
  2758. (`equation
  2759. (let ((caption (org-latex--caption/label-string matrices info))
  2760. (caption-above? (org-latex--caption-above-p matrices info)))
  2761. (concat "\\begin{equation}\n"
  2762. (and caption-above? caption)
  2763. contents
  2764. (and (not caption-above?) caption)
  2765. "\\end{equation}")))
  2766. (_
  2767. (format "\\[\n%s\\]" contents))))
  2768. ;;;; Pseudo Object: LaTeX Math Block
  2769. ;; `latex-math-block' objects have the following property:
  2770. ;; `:post-blank'.
  2771. (defun org-latex--wrap-latex-math-block (data info)
  2772. "Merge contiguous math objects in a pseudo-object container.
  2773. DATA is a parse tree or a secondary string. INFO is a plist
  2774. containing export options. Modify DATA by side-effect and return it."
  2775. (let ((valid-object-p
  2776. ;; Non-nil when OBJECT can be added to a latex math block.
  2777. (lambda (object)
  2778. (pcase (org-element-type object)
  2779. (`entity (org-element-property :latex-math-p object))
  2780. (`latex-fragment
  2781. (let ((value (org-element-property :value object)))
  2782. (or (string-prefix-p "\\(" value)
  2783. (string-match-p "\\`\\$[^$]" value))))))))
  2784. (org-element-map data '(entity latex-fragment)
  2785. (lambda (object)
  2786. ;; Skip objects already wrapped.
  2787. (when (and (not (eq (org-element-type
  2788. (org-element-property :parent object))
  2789. 'latex-math-block))
  2790. (funcall valid-object-p object))
  2791. (let ((math-block (list 'latex-math-block nil))
  2792. (next-elements (org-export-get-next-element object info t))
  2793. (last object))
  2794. ;; Wrap MATH-BLOCK around OBJECT in DATA.
  2795. (org-element-insert-before math-block object)
  2796. (org-element-extract-element object)
  2797. (org-element-adopt-elements math-block object)
  2798. (when (zerop (or (org-element-property :post-blank object) 0))
  2799. ;; MATH-BLOCK swallows consecutive math objects.
  2800. (catch 'exit
  2801. (dolist (next next-elements)
  2802. (unless (funcall valid-object-p next) (throw 'exit nil))
  2803. (org-element-extract-element next)
  2804. (org-element-adopt-elements math-block next)
  2805. ;; Eschew the case: \beta$x$ -> \(\betax\).
  2806. (org-element-put-property last :post-blank 1)
  2807. (setq last next)
  2808. (when (> (or (org-element-property :post-blank next) 0) 0)
  2809. (throw 'exit nil)))))
  2810. (org-element-put-property
  2811. math-block :post-blank (org-element-property :post-blank last)))))
  2812. info nil '(latex-math-block) t)
  2813. ;; Return updated DATA.
  2814. data))
  2815. (defun org-latex-math-block (_math-block contents _info)
  2816. "Transcode a MATH-BLOCK object from Org to LaTeX.
  2817. CONTENTS is a string. INFO is a plist used as a communication
  2818. channel."
  2819. (when (org-string-nw-p contents)
  2820. (format "\\(%s\\)" (org-trim contents))))
  2821. ;;;; Quote Block
  2822. (defun org-latex-quote-block (quote-block contents info)
  2823. "Transcode a QUOTE-BLOCK element from Org to LaTeX.
  2824. CONTENTS holds the contents of the block. INFO is a plist
  2825. holding contextual information."
  2826. (let ((environment
  2827. (or (org-export-read-attribute :attr_latex quote-block :environment)
  2828. (plist-get info :latex-default-quote-environment)))
  2829. (options
  2830. (or (org-export-read-attribute :attr_latex quote-block :options)
  2831. "")))
  2832. (org-latex--wrap-label
  2833. quote-block (format "\\begin{%s}%s\n%s\\end{%s}"
  2834. environment
  2835. options
  2836. contents
  2837. environment)
  2838. info)))
  2839. ;;;; Radio Target
  2840. (defun org-latex-radio-target (radio-target text info)
  2841. "Transcode a RADIO-TARGET object from Org to LaTeX.
  2842. TEXT is the text of the target. INFO is a plist holding
  2843. contextual information."
  2844. (format "\\label{%s}%s" (org-export-get-reference radio-target info) text))
  2845. ;;;; Section
  2846. (defun org-latex-section (_section contents _info)
  2847. "Transcode a SECTION element from Org to LaTeX.
  2848. CONTENTS holds the contents of the section. INFO is a plist
  2849. holding contextual information."
  2850. contents)
  2851. ;;;; Special Block
  2852. (defun org-latex-special-block (special-block contents info)
  2853. "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
  2854. CONTENTS holds the contents of the block. INFO is a plist
  2855. holding contextual information."
  2856. (let ((type (org-element-property :type special-block))
  2857. (opt (org-export-read-attribute :attr_latex special-block :options))
  2858. (caption (org-latex--caption/label-string special-block info))
  2859. (caption-above-p (org-latex--caption-above-p special-block info)))
  2860. (concat (format "\\begin{%s}%s\n" type (or opt ""))
  2861. (and caption-above-p caption)
  2862. contents
  2863. (and (not caption-above-p) caption)
  2864. (format "\\end{%s}" type))))
  2865. ;;;; Src Block
  2866. (defun org-latex-src-block (src-block _contents info)
  2867. "Transcode a SRC-BLOCK element from Org to LaTeX.
  2868. CONTENTS holds the contents of the item. INFO is a plist holding
  2869. contextual information."
  2870. (when (org-string-nw-p (org-element-property :value src-block))
  2871. (let* ((lang (org-element-property :language src-block))
  2872. (caption (org-element-property :caption src-block))
  2873. (caption-above-p (org-latex--caption-above-p src-block info))
  2874. (label (org-element-property :name src-block))
  2875. (custom-env (and lang
  2876. (cadr (assq (intern lang)
  2877. org-latex-custom-lang-environments))))
  2878. (num-start (org-export-get-loc src-block info))
  2879. (retain-labels (org-element-property :retain-labels src-block))
  2880. (attributes (org-export-read-attribute :attr_latex src-block))
  2881. (float (plist-get attributes :float)))
  2882. (funcall
  2883. (pcase (plist-get info :latex-src-block-backend)
  2884. ((or `verbatim (guard (not lang))) #'org-latex-src-block--verbatim)
  2885. (`minted #'org-latex-src-block--minted)
  2886. (`engraved #'org-latex-src-block--engraved)
  2887. (`listings #'org-latex-src-block--listings)
  2888. ((guard custom-env) #'org-latex-src-block--custom)
  2889. (oldval
  2890. (message "Please update the LaTeX src-block-backend to %s"
  2891. (if oldval "listings" "verbatim"))
  2892. (if oldval
  2893. #'org-latex-src-block--listings
  2894. #'org-latex-src-block--verbatim)))
  2895. :src-block src-block
  2896. :info info
  2897. :lang lang
  2898. :caption caption
  2899. :caption-above-p caption-above-p
  2900. :label label
  2901. :num-start num-start
  2902. :retain-labels retain-labels
  2903. :attributes attributes
  2904. :float float
  2905. :custom-env custom-env))))
  2906. (cl-defun org-latex-src-block--verbatim
  2907. (&key src-block info caption caption-above-p float &allow-other-keys)
  2908. "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
  2909. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  2910. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  2911. (let ((caption-str (org-latex--caption/label-string src-block info))
  2912. (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
  2913. (org-export-format-code-default src-block info))))
  2914. (cond ((string= "multicolumn" float)
  2915. (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
  2916. (plist-get info :latex-default-figure-position)
  2917. (if caption-above-p caption-str "")
  2918. verbatim
  2919. (if caption-above-p "" caption-str)))
  2920. (caption (concat
  2921. (if caption-above-p caption-str "")
  2922. verbatim
  2923. (if caption-above-p "" (concat "\n" caption-str))))
  2924. (t verbatim))))
  2925. (cl-defun org-latex-src-block--custom
  2926. (&key src-block info caption caption-above-p attributes float custom-env &allow-other-keys)
  2927. "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
  2928. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  2929. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  2930. (let ((caption-str (org-latex--caption/label-string src-block info))
  2931. (formatted-src (org-export-format-code-default src-block info)))
  2932. (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
  2933. (format "\\begin{%s}\n%s\\end{%s}\n"
  2934. custom-env
  2935. (concat (and caption-above-p caption-str)
  2936. formatted-src
  2937. (and (not caption-above-p) caption-str))
  2938. custom-env)
  2939. (format-spec custom-env
  2940. `((?s . ,formatted-src)
  2941. (?c . ,caption)
  2942. (?f . ,float)
  2943. (?l . ,(org-latex--label src-block info))
  2944. (?o . ,(or (plist-get attributes :options) "")))))))
  2945. (cl-defun org-latex-src-block--minted
  2946. (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
  2947. "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
  2948. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  2949. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  2950. (let* ((caption-str (org-latex--caption/label-string src-block info))
  2951. (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
  2952. (plist-get info :latex-default-figure-position)))
  2953. (multicolumn-p (string= "multicolumn" float))
  2954. (float-env
  2955. (cond
  2956. ((or caption multicolumn-p)
  2957. (cons
  2958. (concat "\\begin{listing" (when multicolumn-p "*")
  2959. "}[" placement "]\n"
  2960. (if caption-above-p caption-str ""))
  2961. (concat "\n" (if caption-above-p "" caption-str)
  2962. "\\end{listing" (when multicolumn-p "*") "}")))
  2963. ((string= "t" float)
  2964. (cons
  2965. (concat "\\begin{listing}[" placement "]\n")
  2966. "\n\\end{listing}"))))
  2967. (options (plist-get info :latex-minted-options))
  2968. (body
  2969. (format
  2970. "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
  2971. ;; Options.
  2972. (concat
  2973. (org-latex--make-option-string
  2974. (if (or (not num-start) (assoc "linenos" options))
  2975. options
  2976. (append
  2977. `(("linenos")
  2978. ("firstnumber" ,(number-to-string (1+ num-start))))
  2979. options)))
  2980. (let ((local-options (plist-get attributes :options)))
  2981. (and local-options (concat "," local-options))))
  2982. ;; Language.
  2983. (or (cadr (assq (intern lang)
  2984. (plist-get info :latex-minted-langs)))
  2985. (downcase lang))
  2986. ;; Source code.
  2987. (let* ((code-info (org-export-unravel-code src-block))
  2988. (max-width
  2989. (apply 'max
  2990. (mapcar 'string-width
  2991. (org-split-string (car code-info)
  2992. "\n")))))
  2993. (org-export-format-code
  2994. (car code-info)
  2995. (lambda (loc _num ref)
  2996. (concat
  2997. loc
  2998. (when ref
  2999. ;; Ensure references are flushed to the right,
  3000. ;; separated with 6 spaces from the widest line
  3001. ;; of code.
  3002. (concat (make-string (+ (- max-width (length loc)) 6)
  3003. ?\s)
  3004. (format "(%s)" ref)))))
  3005. nil (and retain-labels (cdr code-info)))))))
  3006. (concat (car float-env) body (cdr float-env))))
  3007. (defun org-latex-src--engrave-mathescape-p (info options)
  3008. "From the export INFO plist, and the per-block OPTIONS, determine mathescape."
  3009. (let ((default-options (plist-get info :latex-engraved-options))
  3010. (mathescape-status
  3011. (lambda (opts)
  3012. (cl-some
  3013. (lambda (opt)
  3014. (or (and
  3015. (null (cdr opt))
  3016. (cond
  3017. ((string-match-p
  3018. "\\(?:^\\|,\\)mathescape=false\\(?:,\\|$\\)"
  3019. (car opt))
  3020. 'no)
  3021. ((or (string-match-p
  3022. "\\(?:^\\|,\\)mathescape\\(?:=true\\)?\\(?:,\\|$\\)"
  3023. (car opt))
  3024. (string= "mathescape" (car opt)))
  3025. 'yes)))
  3026. (and
  3027. (string= (car opt) "mathescape")
  3028. (cond
  3029. ((or (and (stringp (cdr opt)) (string= (cdr opt) "true"))
  3030. (equal '("true") (cdr opt)))
  3031. 'yes)
  3032. ((or (and (stringp (cdr opt)) (string= "false" (cdr opt)))
  3033. (equal '("false") (cdr opt)))
  3034. 'no)))))
  3035. opts))))
  3036. (let ((mathescape (or (funcall mathescape-status default-options)
  3037. (funcall mathescape-status options))))
  3038. (when (eq mathescape 'yes)
  3039. (or engrave-faces-latex-mathescape t)))))
  3040. (defun org-latex-src--engrave-code (content lang &optional theme options inline)
  3041. "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
  3042. When the THEME symbol is non-nil, that theme will be used.
  3043. When INLINE is nil, a Verbatim environment wrapped in a Code
  3044. environment will be used. When t, a Verb command will be used.
  3045. When OPTIONS is provided, as either a string or list of key-value
  3046. pairs accepted by `org-latex--make-option-string', it is passed
  3047. to the Verbatim environment or Verb command."
  3048. (if (require 'engrave-faces-latex nil t)
  3049. (let* ((lang-mode (and lang (org-src-get-lang-mode lang)))
  3050. (engrave-faces-current-preset-style
  3051. (if theme
  3052. (engrave-faces-get-theme theme)
  3053. engrave-faces-current-preset-style))
  3054. (engraved-buffer
  3055. (with-temp-buffer
  3056. (insert (replace-regexp-in-string "\n\\'" "" content))
  3057. (when lang-mode
  3058. (if (functionp lang-mode)
  3059. (funcall lang-mode)
  3060. (message "Cannot engrave code as %s. %s is undefined."
  3061. lang lang-mode)))
  3062. (engrave-faces-latex-buffer)))
  3063. (engraved-code
  3064. (with-current-buffer engraved-buffer
  3065. (buffer-string)))
  3066. (engraved-options
  3067. (when options
  3068. (concat "["
  3069. (if (listp options)
  3070. (org-latex--make-option-string options)
  3071. options)
  3072. "]")))
  3073. (engraved-wrapped
  3074. (if inline
  3075. (concat "\\Verb" engraved-options "{" engraved-code "}")
  3076. (concat "\\begin{Code}\n\\begin{Verbatim}" engraved-options "\n"
  3077. engraved-code "\n\\end{Verbatim}\n\\end{Code}"))))
  3078. (kill-buffer engraved-buffer)
  3079. (if theme
  3080. (concat "{\\engravedtheme"
  3081. (replace-regexp-in-string "[^A-Za-z]" ""
  3082. (symbol-name theme))
  3083. engraved-wrapped
  3084. "}")
  3085. engraved-wrapped))
  3086. (user-error "Cannot engrave code as `engrave-faces-latex' is unavailable.")))
  3087. (cl-defun org-latex-src-block--engraved
  3088. (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
  3089. "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
  3090. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  3091. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  3092. (let* ((caption-str (org-latex--caption/label-string src-block info))
  3093. (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
  3094. (plist-get info :latex-default-figure-position)))
  3095. (multicolumn-p (string= "multicolumn" float))
  3096. (float-env
  3097. (cond
  3098. ((or caption multicolumn-p)
  3099. (cons
  3100. (concat "\\begin{listing" (when multicolumn-p "*")
  3101. "}[" placement "]\n"
  3102. (if caption-above-p caption-str ""))
  3103. (concat "\n" (if caption-above-p "" caption-str)
  3104. "\\end{listing" (when multicolumn-p "*") "}")))
  3105. ((string= "t" float)
  3106. (cons
  3107. (concat "\\begin{listing}[" placement "]\n")
  3108. "\n\\end{listing}"))))
  3109. (options
  3110. (let ((engraved-options (plist-get info :latex-engraved-options))
  3111. (local-options (plist-get attributes :options)))
  3112. (append
  3113. (when (and num-start (not (assoc "linenos" engraved-options)))
  3114. `(("linenos")
  3115. ("firstnumber" ,(number-to-string (1+ num-start)))))
  3116. (and local-options `((,local-options))))))
  3117. (engraved-theme (plist-get attributes :engraved-theme))
  3118. (content
  3119. (let* ((code-info (org-export-unravel-code src-block))
  3120. (max-width
  3121. (apply 'max
  3122. (mapcar 'string-width
  3123. (org-split-string (car code-info)
  3124. "\n")))))
  3125. (org-export-format-code
  3126. (car code-info)
  3127. (lambda (loc _num ref)
  3128. (concat
  3129. loc
  3130. (when ref
  3131. ;; Ensure references are flushed to the right,
  3132. ;; separated with 6 spaces from the widest line
  3133. ;; of code.
  3134. (concat (make-string (+ (- max-width (length loc)) 6)
  3135. ?\s)
  3136. (format "(%s)" ref)))))
  3137. nil (and retain-labels (cdr code-info)))))
  3138. (body
  3139. (let ((engrave-faces-latex-mathescape
  3140. (org-latex-src--engrave-mathescape-p info options)))
  3141. (org-latex-src--engrave-code
  3142. content lang
  3143. (when engraved-theme (intern engraved-theme))
  3144. options))))
  3145. (concat (car float-env) body (cdr float-env))))
  3146. (cl-defun org-latex-src-block--listings
  3147. (&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
  3148. "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
  3149. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
  3150. and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  3151. (let ((lst-lang
  3152. (or (cadr (assq (intern lang)
  3153. (plist-get info :latex-listings-langs)))
  3154. lang))
  3155. (caption-str
  3156. (when caption
  3157. (let ((main (org-export-get-caption src-block))
  3158. (secondary (org-export-get-caption src-block t)))
  3159. (if (not secondary)
  3160. (format "{%s}" (org-export-data main info))
  3161. (format "{[%s]%s}"
  3162. (org-export-data secondary info)
  3163. (org-export-data main info))))))
  3164. (lst-opt (plist-get info :latex-listings-options)))
  3165. (concat
  3166. ;; Options.
  3167. (format
  3168. "\\lstset{%s}\n"
  3169. (concat
  3170. (org-latex--make-option-string
  3171. (append
  3172. lst-opt
  3173. (cond
  3174. ((and (not float) (plist-member attributes :float)) nil)
  3175. ((string= "multicolumn" float) '(("float" "*")))
  3176. ((and float (not (assoc "float" lst-opt)))
  3177. `(("float" ,(plist-get info :latex-default-figure-position)))))
  3178. `(("language" ,lst-lang))
  3179. (if label
  3180. `(("label" ,(org-latex--label src-block info)))
  3181. '(("label" " ")))
  3182. (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
  3183. `(("captionpos" ,(if caption-above-p "t" "b")))
  3184. (cond ((assoc "numbers" lst-opt) nil)
  3185. ((not num-start) '(("numbers" "none")))
  3186. (t `(("firstnumber" ,(number-to-string (1+ num-start)))
  3187. ("numbers" "left"))))))
  3188. (let ((local-options (plist-get attributes :options)))
  3189. (and local-options (concat "," local-options)))))
  3190. ;; Source code.
  3191. (format
  3192. "\\begin{lstlisting}\n%s\\end{lstlisting}"
  3193. (let* ((code-info (org-export-unravel-code src-block))
  3194. (max-width
  3195. (apply 'max
  3196. (mapcar 'string-width
  3197. (org-split-string (car code-info) "\n")))))
  3198. (org-export-format-code
  3199. (car code-info)
  3200. (lambda (loc _num ref)
  3201. (concat
  3202. loc
  3203. (when ref
  3204. ;; Ensure references are flushed to the right,
  3205. ;; separated with 6 spaces from the widest line of
  3206. ;; code
  3207. (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
  3208. (format "(%s)" ref)))))
  3209. nil (and retain-labels (cdr code-info))))))))
  3210. ;;;; Statistics Cookie
  3211. (defun org-latex-statistics-cookie (statistics-cookie _contents _info)
  3212. "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
  3213. CONTENTS is nil. INFO is a plist holding contextual information."
  3214. (replace-regexp-in-string
  3215. "%" "\\%" (org-element-property :value statistics-cookie) nil t))
  3216. ;;;; Strike-Through
  3217. (defun org-latex-strike-through (_strike-through contents info)
  3218. "Transcode STRIKE-THROUGH from Org to LaTeX.
  3219. CONTENTS is the text with strike-through markup. INFO is a plist
  3220. holding contextual information."
  3221. (org-latex--text-markup contents 'strike-through info))
  3222. ;;;; Subscript
  3223. (defun org-latex-subscript (_subscript contents _info)
  3224. "Transcode a SUBSCRIPT object from Org to LaTeX.
  3225. CONTENTS is the contents of the object."
  3226. (format "\\textsubscript{%s}" contents))
  3227. ;;;; Superscript
  3228. (defun org-latex-superscript (_superscript contents _info)
  3229. "Transcode a SUPERSCRIPT object from Org to LaTeX.
  3230. CONTENTS is the contents of the object."
  3231. (format "\\textsuperscript{%s}" contents))
  3232. ;;;; Table
  3233. ;;
  3234. ;; `org-latex-table' is the entry point for table transcoding. It
  3235. ;; takes care of tables with a "verbatim" mode. Otherwise, it
  3236. ;; delegates the job to either `org-latex--table.el-table',
  3237. ;; `org-latex--org-table', `org-latex--math-table' or
  3238. ;; `org-latex--org-tabbing' functions,
  3239. ;; depending of the type of the table and the mode requested.
  3240. ;;
  3241. ;; `org-latex--align-string' is a subroutine used to build alignment
  3242. ;; string for Org tables.
  3243. (defun org-latex-table (table contents info)
  3244. "Transcode a TABLE element from Org to LaTeX.
  3245. CONTENTS is the contents of the table. INFO is a plist holding
  3246. contextual information."
  3247. (if (eq (org-element-property :type table) 'table.el)
  3248. ;; "table.el" table. Convert it using appropriate tools.
  3249. (org-latex--table.el-table table info)
  3250. (let ((type (or (org-export-read-attribute :attr_latex table :mode)
  3251. (plist-get info :latex-default-table-mode))))
  3252. (cond
  3253. ;; Case 1: Verbatim table.
  3254. ((string= type "verbatim")
  3255. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  3256. ;; Re-create table, without affiliated keywords.
  3257. (org-trim (org-element-interpret-data
  3258. `(table nil ,@(org-element-contents table))))))
  3259. ;; Case 2: Matrix.
  3260. ((or (string= type "math") (string= type "inline-math"))
  3261. (org-latex--math-table table info))
  3262. ;; Case 3: Tabbing
  3263. ((string= type "tabbing")
  3264. (org-table--org-tabbing table contents info))
  3265. ;; Case 4: Standard table.
  3266. (t (concat (org-latex--org-table table contents info)
  3267. ;; When there are footnote references within the
  3268. ;; table, insert their definition just after it.
  3269. (org-latex--delayed-footnotes-definitions table info)))))))
  3270. (defun org-latex--align-string (table info &optional math?)
  3271. "Return an appropriate LaTeX alignment string.
  3272. TABLE is the considered table. INFO is a plist used as
  3273. a communication channel. When optional argument MATH? is
  3274. non-nil, TABLE is meant to be a matrix, where all cells are
  3275. centered."
  3276. (or (org-export-read-attribute :attr_latex table :align)
  3277. (let (align)
  3278. ;; Extract column groups and alignment from first (non-rule)
  3279. ;; row.
  3280. (org-element-map
  3281. (org-element-map table 'table-row
  3282. (lambda (row)
  3283. (and (eq (org-element-property :type row) 'standard) row))
  3284. info 'first-match)
  3285. 'table-cell
  3286. (lambda (cell)
  3287. (let ((borders (org-export-table-cell-borders cell info)))
  3288. ;; Check left border for the first cell only.
  3289. (when (and (memq 'left borders) (not align))
  3290. (push "|" align))
  3291. (push (if math? "c" ;center cells in matrices
  3292. (cl-case (org-export-table-cell-alignment cell info)
  3293. (left "l")
  3294. (right "r")
  3295. (center "c")))
  3296. align)
  3297. (when (memq 'right borders) (push "|" align))))
  3298. info)
  3299. (apply 'concat (nreverse align)))))
  3300. (defun org-latex--align-string-tabbing (table info)
  3301. "Return LaTeX alignment string using tabbing environment.
  3302. TABLE is the considered table. INFO is a plist used as
  3303. a communication channel."
  3304. (or (org-export-read-attribute :attr_latex table :align)
  3305. (let* ((count
  3306. ;; Count the number of cells in the first row.
  3307. (length
  3308. (org-element-map
  3309. (org-element-map table 'table-row
  3310. (lambda (row)
  3311. (and (eq (org-element-property :type row)
  3312. 'standard)
  3313. row))
  3314. info 'first-match)
  3315. 'table-cell #'identity)))
  3316. ;; Calculate the column width, using a proportion of
  3317. ;; the document's textwidth.
  3318. (separator
  3319. (format "\\hspace{%s\\textwidth} \\= "
  3320. (- (/ 1.0 count) 0.01))))
  3321. (concat (apply 'concat (make-list count separator))
  3322. "\\kill"))))
  3323. (defun org-latex--decorate-table (table attributes caption above? info)
  3324. "Decorate TABLE string with caption and float environment.
  3325. ATTRIBUTES is the plist containing LaTeX attributes. CAPTION is
  3326. its caption, as a string or nil. It is located above the table
  3327. if ABOVE? is non-nil. INFO is the plist containing current
  3328. export parameters.
  3329. Return new environment, as a string."
  3330. (let* ((float-environment
  3331. (let ((float (plist-get attributes :float)))
  3332. (cond ((and (not float) (plist-member attributes :float)) nil)
  3333. ((member float '("sidewaystable" "sideways")) "sidewaystable")
  3334. ((equal float "multicolumn") "table*")
  3335. ((string= float "t") "table")
  3336. (float float)
  3337. ((org-string-nw-p caption) "table")
  3338. (t nil))))
  3339. (placement
  3340. (or (plist-get attributes :placement)
  3341. (format "[%s]" (plist-get info :latex-default-figure-position))))
  3342. (center? (if (plist-member attributes :center)
  3343. (plist-get attributes :center)
  3344. (plist-get info :latex-tables-centered)))
  3345. (fontsize (let ((font (plist-get attributes :font)))
  3346. (and font (concat font "\n")))))
  3347. (concat (cond
  3348. (float-environment
  3349. (concat (format "\\begin{%s}%s\n" float-environment placement)
  3350. (if above? caption "")
  3351. (when center? "\\centering\n")
  3352. fontsize))
  3353. (caption
  3354. (concat (and center? "\\begin{center}\n" )
  3355. (if above? caption "")
  3356. (cond ((and fontsize center?) fontsize)
  3357. (fontsize (concat "{" fontsize))
  3358. (t nil))))
  3359. (center? (concat "\\begin{center}\n" fontsize))
  3360. (fontsize (concat "{" fontsize)))
  3361. table
  3362. (cond
  3363. (float-environment
  3364. (concat (if above? "" (concat "\n" caption))
  3365. (format "\n\\end{%s}" float-environment)))
  3366. (caption
  3367. (concat (if above? "" (concat "\n" caption))
  3368. (and center? "\n\\end{center}")
  3369. (and fontsize (not center?) "}")))
  3370. (center? "\n\\end{center}")
  3371. (fontsize "}")))))
  3372. (defun org-latex--org-table (table contents info)
  3373. "Return appropriate LaTeX code for an Org table.
  3374. TABLE is the table type element to transcode. CONTENTS is its
  3375. contents, as a string. INFO is a plist used as a communication
  3376. channel.
  3377. This function assumes TABLE has `org' as its `:type' property and
  3378. `table' as its `:mode' attribute."
  3379. (let* ((attr (org-export-read-attribute :attr_latex table))
  3380. (alignment (org-latex--align-string table info))
  3381. (opt (org-export-read-attribute :attr_latex table :options))
  3382. (table-env (or (plist-get attr :environment)
  3383. (plist-get info :latex-default-table-environment)))
  3384. (width
  3385. (let ((w (plist-get attr :width)))
  3386. (cond ((not w) "")
  3387. ((member table-env '("tabular" "longtable")) "")
  3388. ((member table-env '("tabu" "longtabu"))
  3389. (format (if (plist-get attr :spread) " spread %s "
  3390. " to %s ")
  3391. w))
  3392. (t (format "{%s}" w)))))
  3393. (caption (org-latex--caption/label-string table info))
  3394. (above? (org-latex--caption-above-p table info)))
  3395. (cond
  3396. ((member table-env '("longtable" "longtabu"))
  3397. (let ((fontsize (let ((font (plist-get attr :font)))
  3398. (and font (concat font "\n")))))
  3399. (concat (and fontsize (concat "{" fontsize))
  3400. (format "\\begin{%s}%s{%s}\n" table-env width alignment)
  3401. (and above?
  3402. (org-string-nw-p caption)
  3403. (concat caption "\\\\\n"))
  3404. contents
  3405. (and (not above?)
  3406. (org-string-nw-p caption)
  3407. (concat caption "\\\\\n"))
  3408. (format "\\end{%s}" table-env)
  3409. (and fontsize "}"))))
  3410. (t
  3411. (let ((output (format "\\begin{%s}%s%s{%s}\n%s\\end{%s}"
  3412. table-env
  3413. (if opt (format "[%s]" opt) "")
  3414. width
  3415. alignment
  3416. contents
  3417. table-env)))
  3418. (org-latex--decorate-table output attr caption above? info))))))
  3419. (defun org-table--org-tabbing (table contents info)
  3420. "Return tabbing environment LaTeX code for Org table.
  3421. TABLE is the table type element to transcode. CONTENTS is its
  3422. contents, as a string. INFO is a plist used as a communication
  3423. channel.
  3424. This function assumes TABLE has `org' as its `:type' property and
  3425. `tabbing' as its `:mode' attribute."
  3426. (format "\\begin{%s}\n%s\n%s\\end{%s}"
  3427. "tabbing"
  3428. (org-latex--align-string-tabbing table info)
  3429. contents
  3430. "tabbing"))
  3431. (defun org-latex--table.el-table (table info)
  3432. "Return appropriate LaTeX code for a table.el table.
  3433. TABLE is the table type element to transcode. INFO is a plist
  3434. used as a communication channel.
  3435. This function assumes TABLE has `table.el' as its `:type'
  3436. property."
  3437. (require 'table)
  3438. ;; Ensure "*org-export-table*" buffer is empty.
  3439. (with-current-buffer (get-buffer-create "*org-export-table*")
  3440. (erase-buffer))
  3441. (let ((output
  3442. (replace-regexp-in-string
  3443. "^%.*\n" "" ;remove comments
  3444. (with-temp-buffer
  3445. (save-excursion (insert (org-element-property :value table)))
  3446. (re-search-forward "^[ \t]*|[^|]" nil t)
  3447. (table-generate-source 'latex "*org-export-table*")
  3448. (with-current-buffer "*org-export-table*"
  3449. (org-trim (buffer-string))))
  3450. t t)))
  3451. (kill-buffer (get-buffer "*org-export-table*"))
  3452. (let ((attr (org-export-read-attribute :attr_latex table))
  3453. (caption (org-latex--caption/label-string table info))
  3454. (above? (org-latex--caption-above-p table info)))
  3455. (when (plist-get attr :rmlines)
  3456. ;; When the "rmlines" attribute is provided, remove all hlines
  3457. ;; but the one separating heading from the table body.
  3458. (let ((n 0) (pos 0))
  3459. (while (and (< (length output) pos)
  3460. (setq pos (string-match "^\\\\hline\n?" output pos)))
  3461. (cl-incf n)
  3462. (unless (= n 2) (setq output (replace-match "" nil nil output))))))
  3463. (org-latex--decorate-table output attr caption above? info))))
  3464. (defun org-latex--math-table (table info)
  3465. "Return appropriate LaTeX code for a matrix.
  3466. TABLE is the table type element to transcode. INFO is a plist
  3467. used as a communication channel.
  3468. This function assumes TABLE has `org' as its `:type' property and
  3469. `inline-math' or `math' as its `:mode' attribute."
  3470. (let* ((attr (org-export-read-attribute :attr_latex table))
  3471. (env (or (plist-get attr :environment)
  3472. (plist-get info :latex-default-table-environment)))
  3473. (contents
  3474. (mapconcat
  3475. (lambda (row)
  3476. (if (eq (org-element-property :type row) 'rule) "\\hline"
  3477. ;; Return each cell unmodified.
  3478. (concat
  3479. (mapconcat
  3480. (lambda (cell)
  3481. (substring (org-element-interpret-data cell) 0 -1))
  3482. (org-element-map row 'table-cell #'identity info) "&")
  3483. (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
  3484. "\n")))
  3485. (org-element-map table 'table-row #'identity info) "")))
  3486. (concat
  3487. ;; Prefix.
  3488. (plist-get attr :math-prefix)
  3489. ;; Environment. Also treat special cases.
  3490. (cond ((member env '("array" "tabular"))
  3491. (format "\\begin{%s}{%s}\n%s\\end{%s}"
  3492. env (org-latex--align-string table info t) contents env))
  3493. ((assoc env org-latex-table-matrix-macros)
  3494. (format "\\%s%s{\n%s}"
  3495. env
  3496. (or (plist-get attr :math-arguments) "")
  3497. contents))
  3498. (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
  3499. ;; Suffix.
  3500. (plist-get attr :math-suffix))))
  3501. ;;;; Table Cell
  3502. (defun org-latex-table-cell (table-cell contents info)
  3503. "Transcode a TABLE-CELL element from Org to LaTeX.
  3504. CONTENTS is the cell contents. INFO is a plist used as
  3505. a communication channel."
  3506. (let ((type (org-export-read-attribute
  3507. :attr_latex (org-export-get-parent-table table-cell) :mode))
  3508. (scientific-format (plist-get info :latex-table-scientific-notation)))
  3509. (concat
  3510. (if (and contents
  3511. scientific-format
  3512. (string-match orgtbl-exp-regexp contents))
  3513. ;; Use appropriate format string for scientific
  3514. ;; notation.
  3515. (format scientific-format
  3516. (match-string 1 contents)
  3517. (match-string 2 contents))
  3518. contents)
  3519. (when (org-export-get-next-element table-cell info)
  3520. (if (string= type "tabbing") " \\> " " & ")))))
  3521. ;;;; Table Row
  3522. (defun org-latex-table-row (table-row contents info)
  3523. "Transcode a TABLE-ROW element from Org to LaTeX.
  3524. CONTENTS is the contents of the row. INFO is a plist used as
  3525. a communication channel."
  3526. (let* ((attr (org-export-read-attribute :attr_latex
  3527. (org-export-get-parent table-row)))
  3528. (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
  3529. (plist-get info :latex-tables-booktabs)))
  3530. (longtablep
  3531. (member (or (plist-get attr :environment)
  3532. (plist-get info :latex-default-table-environment))
  3533. '("longtable" "longtabu"))))
  3534. (if (eq (org-element-property :type table-row) 'rule)
  3535. (cond
  3536. ((not booktabsp) "\\hline")
  3537. ((not (org-export-get-previous-element table-row info)) "\\toprule")
  3538. ((not (org-export-get-next-element table-row info)) "\\bottomrule")
  3539. ((and longtablep
  3540. (org-export-table-row-ends-header-p
  3541. (org-export-get-previous-element table-row info) info))
  3542. "")
  3543. (t "\\midrule"))
  3544. (concat
  3545. ;; When BOOKTABS are activated enforce top-rule even when no
  3546. ;; hline was specifically marked.
  3547. (and booktabsp (not (org-export-get-previous-element table-row info))
  3548. "\\toprule\n")
  3549. contents "\\\\\n"
  3550. (cond
  3551. ;; Special case for long tables. Define header and footers.
  3552. ((and longtablep (org-export-table-row-ends-header-p table-row info))
  3553. (let ((columns (cdr (org-export-table-dimensions
  3554. (org-export-get-parent-table table-row) info))))
  3555. (format "%s
  3556. \\endfirsthead
  3557. \\multicolumn{%d}{l}{%s} \\\\
  3558. %s
  3559. %s \\\\\n
  3560. %s
  3561. \\endhead
  3562. %s\\multicolumn{%d}{r}{%s} \\\\
  3563. \\endfoot
  3564. \\endlastfoot"
  3565. (if booktabsp "\\midrule" "\\hline")
  3566. columns
  3567. (org-latex--translate "Continued from previous page" info)
  3568. (cond
  3569. ((not (org-export-table-row-starts-header-p table-row info))
  3570. "")
  3571. (booktabsp "\\toprule\n")
  3572. (t "\\hline\n"))
  3573. contents
  3574. (if booktabsp "\\midrule" "\\hline")
  3575. (if booktabsp "\\midrule" "\\hline")
  3576. columns
  3577. (org-latex--translate "Continued on next page" info))))
  3578. ;; When BOOKTABS are activated enforce bottom rule even when
  3579. ;; no hline was specifically marked.
  3580. ((and booktabsp (not (org-export-get-next-element table-row info)))
  3581. "\\bottomrule"))))))
  3582. ;;;; Target
  3583. (defun org-latex-target (target _contents info)
  3584. "Transcode a TARGET object from Org to LaTeX.
  3585. CONTENTS is nil. INFO is a plist holding contextual
  3586. information."
  3587. (format "\\label{%s}" (org-latex--label target info)))
  3588. ;;;; Timestamp
  3589. (defun org-latex-timestamp (timestamp _contents info)
  3590. "Transcode a TIMESTAMP object from Org to LaTeX.
  3591. CONTENTS is nil. INFO is a plist holding contextual
  3592. information."
  3593. (let ((value (org-latex-plain-text (org-timestamp-translate timestamp) info)))
  3594. (format
  3595. (plist-get info
  3596. (cl-case (org-element-property :type timestamp)
  3597. ((active active-range) :latex-active-timestamp-format)
  3598. ((inactive inactive-range) :latex-inactive-timestamp-format)
  3599. (otherwise :latex-diary-timestamp-format)))
  3600. value)))
  3601. ;;;; Underline
  3602. (defun org-latex-underline (_underline contents info)
  3603. "Transcode UNDERLINE from Org to LaTeX.
  3604. CONTENTS is the text with underline markup. INFO is a plist
  3605. holding contextual information."
  3606. (org-latex--text-markup contents 'underline info))
  3607. ;;;; Verbatim
  3608. (defun org-latex-verbatim (verbatim _contents info)
  3609. "Transcode a VERBATIM object from Org to LaTeX.
  3610. CONTENTS is nil. INFO is a plist used as a communication
  3611. channel."
  3612. (org-latex--text-markup
  3613. (org-element-property :value verbatim) 'verbatim info))
  3614. ;;;; Verse Block
  3615. (defun org-latex-verse-block (verse-block contents info)
  3616. "Transcode a VERSE-BLOCK element from Org to LaTeX.
  3617. CONTENTS is verse block contents. INFO is a plist holding
  3618. contextual information."
  3619. (let* ((lin (org-export-read-attribute :attr_latex verse-block :lines))
  3620. (latcode (org-export-read-attribute :attr_latex verse-block :latexcode))
  3621. (cent (org-export-read-attribute :attr_latex verse-block :center))
  3622. (attr (concat
  3623. (if cent "[\\versewidth]" "")
  3624. (if lin (format "\n\\poemlines{%s}" lin) "")
  3625. (if latcode (format "\n%s" latcode) "")))
  3626. (versewidth (org-export-read-attribute :attr_latex verse-block :versewidth))
  3627. (vwidth (if versewidth (format "\\settowidth{\\versewidth}{%s}\n" versewidth) ""))
  3628. (linreset (if lin "\n\\poemlines{0}" "")))
  3629. (concat
  3630. (org-latex--wrap-label
  3631. verse-block
  3632. ;; In a verse environment, add a line break to each newline
  3633. ;; character and change each white space at beginning of a line
  3634. ;; into a space of 1 em. Also change each blank line with
  3635. ;; a vertical space of 1 em.
  3636. (format "%s\\begin{verse}%s\n%s\\end{verse}%s"
  3637. vwidth
  3638. attr
  3639. (replace-regexp-in-string
  3640. "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
  3641. (replace-regexp-in-string
  3642. "^[ \t]*\\\\\\\\$" "\\vspace*{1em}"
  3643. (replace-regexp-in-string
  3644. "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n"
  3645. contents nil t) nil t) nil t) linreset)
  3646. info)
  3647. ;; Insert footnote definitions, if any, after the environment, so
  3648. ;; the special formatting above is not applied to them.
  3649. (org-latex--delayed-footnotes-definitions verse-block info))))
  3650. ;;; End-user functions
  3651. ;;;###autoload
  3652. (defun org-latex-export-as-latex
  3653. (&optional async subtreep visible-only body-only ext-plist)
  3654. "Export current buffer as a LaTeX buffer.
  3655. If narrowing is active in the current buffer, only export its
  3656. narrowed part.
  3657. If a region is active, export that region.
  3658. A non-nil optional argument ASYNC means the process should happen
  3659. asynchronously. The resulting buffer should be accessible
  3660. through the `org-export-stack' interface.
  3661. When optional argument SUBTREEP is non-nil, export the sub-tree
  3662. at point, extracting information from the headline properties
  3663. first.
  3664. When optional argument VISIBLE-ONLY is non-nil, don't export
  3665. contents of hidden elements.
  3666. When optional argument BODY-ONLY is non-nil, only write code
  3667. between \"\\begin{document}\" and \"\\end{document}\".
  3668. EXT-PLIST, when provided, is a property list with external
  3669. parameters overriding Org default settings, but still inferior to
  3670. file-local settings.
  3671. Export is done in a buffer named \"*Org LATEX Export*\", which
  3672. will be displayed when `org-export-show-temporary-export-buffer'
  3673. is non-nil."
  3674. (interactive)
  3675. (org-export-to-buffer 'latex "*Org LATEX Export*"
  3676. async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
  3677. ;;;###autoload
  3678. (defun org-latex-convert-region-to-latex ()
  3679. "Assume the current region has Org syntax, and convert it to LaTeX.
  3680. This can be used in any buffer. For example, you can write an
  3681. itemized list in Org syntax in an LaTeX buffer and use this
  3682. command to convert it."
  3683. (interactive)
  3684. (org-export-replace-region-by 'latex))
  3685. ;;;###autoload
  3686. (defun org-latex-export-to-latex
  3687. (&optional async subtreep visible-only body-only ext-plist)
  3688. "Export current buffer to a LaTeX file.
  3689. If narrowing is active in the current buffer, only export its
  3690. narrowed part.
  3691. If a region is active, export that region.
  3692. A non-nil optional argument ASYNC means the process should happen
  3693. asynchronously. The resulting file should be accessible through
  3694. the `org-export-stack' interface.
  3695. When optional argument SUBTREEP is non-nil, export the sub-tree
  3696. at point, extracting information from the headline properties
  3697. first.
  3698. When optional argument VISIBLE-ONLY is non-nil, don't export
  3699. contents of hidden elements.
  3700. When optional argument BODY-ONLY is non-nil, only write code
  3701. between \"\\begin{document}\" and \"\\end{document}\".
  3702. EXT-PLIST, when provided, is a property list with external
  3703. parameters overriding Org default settings, but still inferior to
  3704. file-local settings."
  3705. (interactive)
  3706. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  3707. (org-export-to-file 'latex outfile
  3708. async subtreep visible-only body-only ext-plist)))
  3709. ;;;###autoload
  3710. (defun org-latex-export-to-pdf
  3711. (&optional async subtreep visible-only body-only ext-plist)
  3712. "Export current buffer to LaTeX then process through to PDF.
  3713. If narrowing is active in the current buffer, only export its
  3714. narrowed part.
  3715. If a region is active, export that region.
  3716. A non-nil optional argument ASYNC means the process should happen
  3717. asynchronously. The resulting file should be accessible through
  3718. the `org-export-stack' interface.
  3719. When optional argument SUBTREEP is non-nil, export the sub-tree
  3720. at point, extracting information from the headline properties
  3721. first.
  3722. When optional argument VISIBLE-ONLY is non-nil, don't export
  3723. contents of hidden elements.
  3724. When optional argument BODY-ONLY is non-nil, only write code
  3725. between \"\\begin{document}\" and \"\\end{document}\".
  3726. EXT-PLIST, when provided, is a property list with external
  3727. parameters overriding Org default settings, but still inferior to
  3728. file-local settings.
  3729. Return PDF file's name."
  3730. (interactive)
  3731. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  3732. (org-export-to-file 'latex outfile
  3733. async subtreep visible-only body-only ext-plist
  3734. #'org-latex-compile)))
  3735. (defun org-latex-compile (texfile &optional snippet)
  3736. "Compile a TeX file.
  3737. TEXFILE is the name of the file being compiled. Processing is
  3738. done through the command specified in `org-latex-pdf-process',
  3739. which see. Output is redirected to \"*Org PDF LaTeX Output*\"
  3740. buffer.
  3741. When optional argument SNIPPET is non-nil, TEXFILE is a temporary
  3742. file used to preview a LaTeX snippet. In this case, do not
  3743. create a log buffer and do not remove log files.
  3744. Return PDF file name or raise an error if it couldn't be
  3745. produced."
  3746. (unless snippet (message "Processing LaTeX file %s..." texfile))
  3747. (let* ((compiler
  3748. (or (with-temp-buffer
  3749. (save-excursion (insert-file-contents texfile))
  3750. (and (search-forward-regexp (regexp-opt org-latex-compilers)
  3751. (line-end-position 2)
  3752. t)
  3753. (progn (beginning-of-line) (looking-at-p "%"))
  3754. (match-string 0)))
  3755. ;; Cannot find the compiler inserted by
  3756. ;; `org-latex-template' -> `org-latex--insert-compiler'.
  3757. ;; Use a fallback.
  3758. "pdflatex"))
  3759. (process (if (functionp org-latex-pdf-process) org-latex-pdf-process
  3760. ;; Replace "%latex" with "%L" and "%bib" and
  3761. ;; "%bibtex" with "%B" to adhere to `format-spec'
  3762. ;; specifications.
  3763. (mapcar (lambda (command)
  3764. (replace-regexp-in-string
  3765. "%\\(?:\\(?:bib\\|la\\)tex\\|bib\\)\\>"
  3766. (lambda (m) (upcase (substring m 0 2)))
  3767. command))
  3768. org-latex-pdf-process)))
  3769. (spec `((?B . ,(shell-quote-argument org-latex-bib-compiler))
  3770. (?L . ,(shell-quote-argument compiler))))
  3771. (log-buf-name "*Org PDF LaTeX Output*")
  3772. (log-buf (and (not snippet) (get-buffer-create log-buf-name)))
  3773. (outfile (org-compile-file texfile process "pdf"
  3774. (format "See %S for details" log-buf-name)
  3775. log-buf spec)))
  3776. (unless snippet
  3777. (when org-latex-remove-logfiles
  3778. (mapc #'delete-file
  3779. (directory-files
  3780. (file-name-directory outfile)
  3781. t
  3782. (concat (regexp-quote (file-name-base outfile))
  3783. "\\(?:\\.[0-9]+\\)?\\."
  3784. (regexp-opt org-latex-logfiles-extensions))
  3785. t)))
  3786. (let ((warnings (org-latex--collect-warnings log-buf)))
  3787. (message (concat "PDF file produced"
  3788. (cond
  3789. ((eq warnings 'error) " with errors.")
  3790. (warnings (concat " with warnings: " warnings))
  3791. (t "."))))))
  3792. ;; Return output file name.
  3793. outfile))
  3794. (defun org-latex--collect-warnings (buffer)
  3795. "Collect some warnings from \"pdflatex\" command output.
  3796. BUFFER is the buffer containing output. Return collected
  3797. warnings types as a string, `error' if a LaTeX error was
  3798. encountered or nil if there was none."
  3799. (with-current-buffer buffer
  3800. (save-excursion
  3801. (goto-char (point-max))
  3802. (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
  3803. (if (re-search-forward "^!" nil t) 'error
  3804. (let ((case-fold-search t)
  3805. (warnings ""))
  3806. (dolist (warning org-latex-known-warnings)
  3807. (when (save-excursion (re-search-forward (car warning) nil t))
  3808. (setq warnings (concat warnings " " (cdr warning)))))
  3809. (org-string-nw-p (org-trim warnings))))))))
  3810. ;;;###autoload
  3811. (defun org-latex-publish-to-latex (plist filename pub-dir)
  3812. "Publish an Org file to LaTeX.
  3813. FILENAME is the filename of the Org file to be published. PLIST
  3814. is the property list for the given project. PUB-DIR is the
  3815. publishing directory.
  3816. Return output file name."
  3817. (org-publish-org-to 'latex filename ".tex" plist pub-dir))
  3818. ;;;###autoload
  3819. (defun org-latex-publish-to-pdf (plist filename pub-dir)
  3820. "Publish an Org file to PDF (via LaTeX).
  3821. FILENAME is the filename of the Org file to be published. PLIST
  3822. is the property list for the given project. PUB-DIR is the
  3823. publishing directory.
  3824. Return output file name."
  3825. ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
  3826. ;; in working directory and then moved to publishing directory.
  3827. (org-publish-attachment
  3828. plist
  3829. ;; Default directory could be anywhere when this function is
  3830. ;; called. We ensure it is set to source file directory during
  3831. ;; compilation so as to not break links to external documents.
  3832. (let ((default-directory (file-name-directory filename)))
  3833. (org-latex-compile
  3834. (org-publish-org-to
  3835. 'latex filename ".tex" plist (file-name-directory filename))))
  3836. pub-dir))
  3837. (provide 'ox-latex)
  3838. ;; Local variables:
  3839. ;; generated-autoload-file: "org-loaddefs.el"
  3840. ;; End:
  3841. ;;; ox-latex.el ends here