ox-latex.el 158 KB

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