ox-latex.el 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319
  1. ;;; ox-latex.el --- LaTeX Back-End for Org Export Engine
  2. ;; Copyright (C) 2011-2015 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; See Org manual for details.
  19. ;;; Code:
  20. (eval-when-compile (require 'cl))
  21. (require 'ox)
  22. (require 'ox-publish)
  23. (defvar org-latex-default-packages-alist)
  24. (defvar org-latex-packages-alist)
  25. (defvar orgtbl-exp-regexp)
  26. ;;; Define Back-End
  27. (org-export-define-backend 'latex
  28. '((bold . org-latex-bold)
  29. (center-block . org-latex-center-block)
  30. (clock . org-latex-clock)
  31. (code . org-latex-code)
  32. (drawer . org-latex-drawer)
  33. (dynamic-block . org-latex-dynamic-block)
  34. (entity . org-latex-entity)
  35. (example-block . org-latex-example-block)
  36. (export-block . org-latex-export-block)
  37. (export-snippet . org-latex-export-snippet)
  38. (fixed-width . org-latex-fixed-width)
  39. (footnote-definition . org-latex-footnote-definition)
  40. (footnote-reference . org-latex-footnote-reference)
  41. (headline . org-latex-headline)
  42. (horizontal-rule . org-latex-horizontal-rule)
  43. (inline-src-block . org-latex-inline-src-block)
  44. (inlinetask . org-latex-inlinetask)
  45. (italic . org-latex-italic)
  46. (item . org-latex-item)
  47. (keyword . org-latex-keyword)
  48. (latex-environment . org-latex-latex-environment)
  49. (latex-fragment . org-latex-latex-fragment)
  50. (line-break . org-latex-line-break)
  51. (link . org-latex-link)
  52. (node-property . org-latex-node-property)
  53. (paragraph . org-latex-paragraph)
  54. (plain-list . org-latex-plain-list)
  55. (plain-text . org-latex-plain-text)
  56. (planning . org-latex-planning)
  57. (property-drawer . org-latex-property-drawer)
  58. (quote-block . org-latex-quote-block)
  59. (radio-target . org-latex-radio-target)
  60. (section . org-latex-section)
  61. (special-block . org-latex-special-block)
  62. (src-block . org-latex-src-block)
  63. (statistics-cookie . org-latex-statistics-cookie)
  64. (strike-through . org-latex-strike-through)
  65. (subscript . org-latex-subscript)
  66. (superscript . org-latex-superscript)
  67. (table . org-latex-table)
  68. (table-cell . org-latex-table-cell)
  69. (table-row . org-latex-table-row)
  70. (target . org-latex-target)
  71. (template . org-latex-template)
  72. (timestamp . org-latex-timestamp)
  73. (underline . org-latex-underline)
  74. (verbatim . org-latex-verbatim)
  75. (verse-block . org-latex-verse-block)
  76. ;; Pseudo objects and elements.
  77. (latex-math-block . org-latex-math-block)
  78. (latex-matrices . org-latex-matrices))
  79. :export-block '("LATEX" "TEX")
  80. :menu-entry
  81. '(?l "Export to LaTeX"
  82. ((?L "As LaTeX buffer" org-latex-export-as-latex)
  83. (?l "As LaTeX file" org-latex-export-to-latex)
  84. (?p "As PDF file" org-latex-export-to-pdf)
  85. (?o "As PDF file and open"
  86. (lambda (a s v b)
  87. (if a (org-latex-export-to-pdf t s v b)
  88. (org-open-file (org-latex-export-to-pdf nil s v b)))))))
  89. :filters-alist '((:filter-options . org-latex-math-block-options-filter)
  90. (:filter-parse-tree org-latex-math-block-tree-filter
  91. org-latex-matrices-tree-filter))
  92. :options-alist
  93. '((:latex-class "LATEX_CLASS" nil org-latex-default-class t)
  94. (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
  95. (:latex-header "LATEX_HEADER" nil nil newline)
  96. (:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline)
  97. (:description "DESCRIPTION" nil nil parse)
  98. (:keywords "KEYWORDS" nil nil parse)
  99. (:subtitle "SUBTITLE" nil nil parse)
  100. ;; Other variables.
  101. (:latex-active-timestamp-format nil nil org-latex-active-timestamp-format)
  102. (:latex-caption-above nil nil org-latex-caption-above)
  103. (:latex-classes nil nil org-latex-classes)
  104. (:latex-custom-id-labels nil nil org-latex-custom-id-as-label)
  105. (:latex-default-figure-position nil nil org-latex-default-figure-position)
  106. (:latex-default-table-environment nil nil org-latex-default-table-environment)
  107. (:latex-default-table-mode nil nil org-latex-default-table-mode)
  108. (:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
  109. (:latex-footnote-separator nil nil org-latex-footnote-separator)
  110. (:latex-format-drawer-function nil nil org-latex-format-drawer-function)
  111. (:latex-format-headline-function nil nil org-latex-format-headline-function)
  112. (:latex-format-inlinetask-function nil nil org-latex-format-inlinetask-function)
  113. (:latex-hyperref-template nil nil org-latex-hyperref-template t)
  114. (:latex-image-default-height nil nil org-latex-image-default-height)
  115. (:latex-image-default-option nil nil org-latex-image-default-option)
  116. (:latex-image-default-width nil nil org-latex-image-default-width)
  117. (:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
  118. (:latex-inline-image-rules nil nil org-latex-inline-image-rules)
  119. (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
  120. (:latex-listings nil nil org-latex-listings)
  121. (:latex-listings-langs nil nil org-latex-listings-langs)
  122. (:latex-listings-options nil nil org-latex-listings-options)
  123. (:latex-minted-langs nil nil org-latex-minted-langs)
  124. (:latex-minted-options nil nil org-latex-minted-options)
  125. (:latex-subtitle-format nil nil org-latex-subtitle-format)
  126. (:latex-subtitle-separate nil nil org-latex-subtitle-separate)
  127. (:latex-table-scientific-notation nil nil org-latex-table-scientific-notation)
  128. (:latex-tables-booktabs nil nil org-latex-tables-booktabs)
  129. (:latex-tables-centered nil nil org-latex-tables-centered)
  130. (:latex-text-markup-alist nil nil org-latex-text-markup-alist)
  131. (:latex-title-command nil nil org-latex-title-command)
  132. (:latex-toc-command nil nil org-latex-toc-command)
  133. ;; Redefine regular options.
  134. (:date "DATE" nil "\\today" parse)))
  135. ;;; Internal Variables
  136. (defconst org-latex-babel-language-alist
  137. '(("af" . "afrikaans")
  138. ("bg" . "bulgarian")
  139. ("bt-br" . "brazilian")
  140. ("ca" . "catalan")
  141. ("cs" . "czech")
  142. ("cy" . "welsh")
  143. ("da" . "danish")
  144. ("de" . "germanb")
  145. ("de-at" . "naustrian")
  146. ("de-de" . "ngerman")
  147. ("el" . "greek")
  148. ("en" . "english")
  149. ("en-au" . "australian")
  150. ("en-ca" . "canadian")
  151. ("en-gb" . "british")
  152. ("en-ie" . "irish")
  153. ("en-nz" . "newzealand")
  154. ("en-us" . "american")
  155. ("es" . "spanish")
  156. ("et" . "estonian")
  157. ("eu" . "basque")
  158. ("fi" . "finnish")
  159. ("fr" . "frenchb")
  160. ("fr-ca" . "canadien")
  161. ("gl" . "galician")
  162. ("hr" . "croatian")
  163. ("hu" . "hungarian")
  164. ("id" . "indonesian")
  165. ("is" . "icelandic")
  166. ("it" . "italian")
  167. ("la" . "latin")
  168. ("ms" . "malay")
  169. ("nl" . "dutch")
  170. ("nb" . "norsk")
  171. ("nn" . "nynorsk")
  172. ("no" . "norsk")
  173. ("pl" . "polish")
  174. ("pt" . "portuguese")
  175. ("ro" . "romanian")
  176. ("ru" . "russian")
  177. ("sa" . "sanskrit")
  178. ("sb" . "uppersorbian")
  179. ("sk" . "slovak")
  180. ("sl" . "slovene")
  181. ("sq" . "albanian")
  182. ("sr" . "serbian")
  183. ("sv" . "swedish")
  184. ("ta" . "tamil")
  185. ("tr" . "turkish")
  186. ("uk" . "ukrainian"))
  187. "Alist between language code and corresponding Babel option.")
  188. (defconst org-latex-table-matrix-macros '(("bordermatrix" . "\\cr")
  189. ("qbordermatrix" . "\\cr")
  190. ("kbordermatrix" . "\\\\"))
  191. "Alist between matrix macros and their row ending.")
  192. ;;; User Configurable Variables
  193. (defgroup org-export-latex nil
  194. "Options for exporting Org mode files to LaTeX."
  195. :tag "Org Export LaTeX"
  196. :group 'org-export)
  197. ;;;; Generic
  198. (defcustom org-latex-caption-above '(table)
  199. "When non-nil, place caption string at the beginning of elements.
  200. Otherwise, place it near the end. When value is a list of
  201. symbols, put caption above selected elements only. Allowed
  202. symbols are: `image', `table', `src-block' and `special-block'."
  203. :group 'org-export-latex
  204. :version "25.1"
  205. :package-version '(Org . "8.3")
  206. :type '(choice
  207. (const :tag "For all elements" t)
  208. (const :tag "For no element" nil)
  209. (set :tag "For the following elements only" :greedy t
  210. (const :tag "Images" image)
  211. (const :tag "Tables" table)
  212. (const :tag "Source code" src-block)
  213. (const :tag "Special blocks" special-block))))
  214. ;;;; Preamble
  215. (defcustom org-latex-default-class "article"
  216. "The default LaTeX class."
  217. :group 'org-export-latex
  218. :type '(string :tag "LaTeX class"))
  219. (defcustom org-latex-classes
  220. '(("article"
  221. "\\documentclass[11pt]{article}"
  222. ("\\section{%s}" . "\\section*{%s}")
  223. ("\\subsection{%s}" . "\\subsection*{%s}")
  224. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  225. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  226. ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
  227. ("report"
  228. "\\documentclass[11pt]{report}"
  229. ("\\part{%s}" . "\\part*{%s}")
  230. ("\\chapter{%s}" . "\\chapter*{%s}")
  231. ("\\section{%s}" . "\\section*{%s}")
  232. ("\\subsection{%s}" . "\\subsection*{%s}")
  233. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
  234. ("book"
  235. "\\documentclass[11pt]{book}"
  236. ("\\part{%s}" . "\\part*{%s}")
  237. ("\\chapter{%s}" . "\\chapter*{%s}")
  238. ("\\section{%s}" . "\\section*{%s}")
  239. ("\\subsection{%s}" . "\\subsection*{%s}")
  240. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
  241. "Alist of LaTeX classes and associated header and structure.
  242. If #+LATEX_CLASS is set in the buffer, use its value and the
  243. associated information. Here is the structure of each cell:
  244. \(class-name
  245. header-string
  246. \(numbered-section . unnumbered-section)
  247. ...)
  248. The header string
  249. -----------------
  250. The HEADER-STRING is the header that will be inserted into the
  251. LaTeX file. It should contain the \\documentclass macro, and
  252. anything else that is needed for this setup. To this header, the
  253. following commands will be added:
  254. - Calls to \\usepackage for all packages mentioned in the
  255. variables `org-latex-default-packages-alist' and
  256. `org-latex-packages-alist'. Thus, your header definitions
  257. should avoid to also request these packages.
  258. - Lines specified via \"#+LATEX_HEADER:\" and
  259. \"#+LATEX_HEADER_EXTRA:\" keywords.
  260. If you need more control about the sequence in which the header
  261. is built up, or if you want to exclude one of these building
  262. blocks for a particular class, you can use the following
  263. macro-like placeholders.
  264. [DEFAULT-PACKAGES] \\usepackage statements for default packages
  265. [NO-DEFAULT-PACKAGES] do not include any of the default packages
  266. [PACKAGES] \\usepackage statements for packages
  267. [NO-PACKAGES] do not include the packages
  268. [EXTRA] the stuff from #+LATEX_HEADER(_EXTRA)
  269. [NO-EXTRA] do not include #+LATEX_HEADER(_EXTRA) stuff
  270. So a header like
  271. \\documentclass{article}
  272. [NO-DEFAULT-PACKAGES]
  273. [EXTRA]
  274. \\providecommand{\\alert}[1]{\\textbf{#1}}
  275. [PACKAGES]
  276. will omit the default packages, and will include the
  277. #+LATEX_HEADER and #+LATEX_HEADER_EXTRA lines, then have a call
  278. to \\providecommand, and then place \\usepackage commands based
  279. on the content of `org-latex-packages-alist'.
  280. If your header, `org-latex-default-packages-alist' or
  281. `org-latex-packages-alist' inserts \"\\usepackage[AUTO]{inputenc}\",
  282. AUTO will automatically be replaced with a coding system derived
  283. from `buffer-file-coding-system'. See also the variable
  284. `org-latex-inputenc-alist' for a way to influence this mechanism.
  285. Likewise, if your header contains \"\\usepackage[AUTO]{babel}\",
  286. AUTO will be replaced with the language related to the language
  287. code specified by `org-export-default-language', which see. Note
  288. that constructions such as \"\\usepackage[french,AUTO,english]{babel}\"
  289. are permitted.
  290. The sectioning structure
  291. ------------------------
  292. The sectioning structure of the class is given by the elements
  293. following the header string. For each sectioning level, a number
  294. of strings is specified. A %s formatter is mandatory in each
  295. section string and will be replaced by the title of the section.
  296. Instead of a cons cell (numbered . unnumbered), you can also
  297. provide a list of 2 or 4 elements,
  298. \(numbered-open numbered-close)
  299. or
  300. \(numbered-open numbered-close unnumbered-open unnumbered-close)
  301. providing opening and closing strings for a LaTeX environment
  302. that should represent the document section. The opening clause
  303. should have a %s to represent the section title.
  304. Instead of a list of sectioning commands, you can also specify
  305. a function name. That function will be called with two
  306. parameters, the (reduced) level of the headline, and a predicate
  307. non-nil when the headline should be numbered. It must return
  308. a format string in which the section title will be added."
  309. :group 'org-export-latex
  310. :type '(repeat
  311. (list (string :tag "LaTeX class")
  312. (string :tag "LaTeX header")
  313. (repeat :tag "Levels" :inline t
  314. (choice
  315. (cons :tag "Heading"
  316. (string :tag " numbered")
  317. (string :tag "unnumbered"))
  318. (list :tag "Environment"
  319. (string :tag "Opening (numbered)")
  320. (string :tag "Closing (numbered)")
  321. (string :tag "Opening (unnumbered)")
  322. (string :tag "Closing (unnumbered)"))
  323. (function :tag "Hook computing sectioning"))))))
  324. (defcustom org-latex-inputenc-alist nil
  325. "Alist of inputenc coding system names, and what should really be used.
  326. For example, adding an entry
  327. (\"utf8\" . \"utf8x\")
  328. will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
  329. are written as utf8 files."
  330. :group 'org-export-latex
  331. :type '(repeat
  332. (cons
  333. (string :tag "Derived from buffer")
  334. (string :tag "Use this instead"))))
  335. (defcustom org-latex-title-command "\\maketitle"
  336. "The command used to insert the title just after \\begin{document}.
  337. This format string may contain these elements:
  338. %a for AUTHOR keyword
  339. %t for TITLE keyword
  340. %s for SUBTITLE keyword
  341. %k for KEYWORDS line
  342. %d for DESCRIPTION line
  343. %c for CREATOR line
  344. %l for Language keyword
  345. %L for capitalized language keyword
  346. %D for DATE keyword
  347. If you need to use a \"%\" character, you need to escape it
  348. like that: \"%%\".
  349. Setting :latex-title-command in publishing projects will take
  350. precedence over this variable."
  351. :group 'org-export-latex
  352. :type '(string :tag "Format string"))
  353. (defcustom org-latex-subtitle-format "\\\\\\medskip\n\\large %s"
  354. "Format string used for transcoded subtitle.
  355. The format string should have at most one \"%s\"-expression,
  356. which is replaced with the subtitle."
  357. :group 'org-export-latex
  358. :version "25.1"
  359. :package-version '(Org . "8.3")
  360. :type '(string :tag "Format string"))
  361. (defcustom org-latex-subtitle-separate nil
  362. "Non-nil means the subtitle is not typeset as part of title."
  363. :group 'org-export-latex
  364. :version "25.1"
  365. :package-version '(Org . "8.3")
  366. :type 'boolean)
  367. (defcustom org-latex-toc-command "\\tableofcontents\n\n"
  368. "LaTeX command to set the table of contents, list of figures, etc.
  369. This command only applies to the table of contents generated with
  370. the toc:nil option, not to those generated with #+TOC keyword."
  371. :group 'org-export-latex
  372. :type 'string)
  373. (defcustom org-latex-hyperref-template
  374. "\\hypersetup{\n pdfauthor={%a},\n pdftitle={%t},\n pdfkeywords={%k},
  375. pdfsubject={%d},\n pdfcreator={%c}, \n pdflang={%L}}\n"
  376. "Template for hyperref package options.
  377. This format string may contain these elements:
  378. %a for AUTHOR keyword
  379. %t for TITLE keyword
  380. %s for SUBTITLE keyword
  381. %k for KEYWORDS line
  382. %d for DESCRIPTION line
  383. %c for CREATOR line
  384. %l for Language keyword
  385. %L for capitalized language keyword
  386. %D for DATE keyword
  387. If you need to use a \"%\" character, you need to escape it
  388. like that: \"%%\".
  389. Setting :latex-hyperref-template in publishing projects will take
  390. precedence over this variable."
  391. :group 'org-export-latex
  392. :version "25.1"
  393. :package-version '(Org . "8.3")
  394. :type '(string :tag "Format string"))
  395. ;;;; Headline
  396. (defcustom org-latex-format-headline-function
  397. 'org-latex-format-headline-default-function
  398. "Function for formatting the headline's text.
  399. This function will be called with six arguments:
  400. TODO the todo keyword (string or nil)
  401. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  402. PRIORITY the priority of the headline (integer or nil)
  403. TEXT the main headline text (string)
  404. TAGS the tags (list of strings or nil)
  405. INFO the export options (plist)
  406. The function result will be used in the section format string."
  407. :group 'org-export-latex
  408. :version "24.4"
  409. :package-version '(Org . "8.0")
  410. :type 'function)
  411. (defcustom org-latex-custom-id-as-label nil
  412. "Toggle use of CUSTOM_ID properties for generating section labels.
  413. When this variable is non-nil, Org will use the value of a
  414. headline's CUSTOM_ID property as the key for the \\label command
  415. for the LaTeX section corresponding to the headline.
  416. By default, Org generates its own internal section labels for all
  417. headlines during LaTeX export. This process ensures that the
  418. \\label keys are unique and valid, but it means the keys are not
  419. available in advance of the export process.
  420. Setting this variable gives you control over how Org generates
  421. labels for sections during LaTeX export, so that you may know
  422. their keys in advance. One reason to do this is that it allows
  423. you to refer to headlines using a single label both in Org's link
  424. syntax and in embedded LaTeX code.
  425. For example, when this variable is non-nil, a headline like this:
  426. ** Some section
  427. :PROPERTIES:
  428. :CUSTOM_ID: sec:foo
  429. :END:
  430. This is section [[#sec:foo]].
  431. #+BEGIN_LATEX
  432. And this is still section \\ref{sec:foo}.
  433. #+END_LATEX
  434. will be exported to LaTeX as:
  435. \\subsection{Some section}
  436. \\label{sec:foo}
  437. This is section \\ref{sec:foo}.
  438. And this is still section \\ref{sec:foo}.
  439. Note, however, that setting this variable introduces a limitation
  440. on the possible values for CUSTOM_ID. When this variable is
  441. non-nil and a headline defines a CUSTOM_ID value, Org simply
  442. passes this value to \\label unchanged. You are responsible for
  443. ensuring that the value is a valid LaTeX \\label key, and that no
  444. other \\label commands with the same key appear elsewhere in your
  445. document. (Keys may contain letters, numbers, and the following
  446. punctuation: '_' '.' '-' ':'.) There are no such limitations on
  447. CUSTOM_ID when this variable is nil.
  448. For headlines that do not define the CUSTOM_ID property, Org will
  449. continue to use its default labeling scheme to generate labels
  450. and resolve links into section references."
  451. :group 'org-export-latex
  452. :type 'boolean
  453. :version "25.1"
  454. :package-version '(Org . "8.3"))
  455. ;;;; Footnotes
  456. (defcustom org-latex-footnote-separator "\\textsuperscript{,}\\,"
  457. "Text used to separate footnotes."
  458. :group 'org-export-latex
  459. :type 'string)
  460. ;;;; Timestamps
  461. (defcustom org-latex-active-timestamp-format "\\textit{%s}"
  462. "A printf format string to be applied to active timestamps."
  463. :group 'org-export-latex
  464. :type 'string)
  465. (defcustom org-latex-inactive-timestamp-format "\\textit{%s}"
  466. "A printf format string to be applied to inactive timestamps."
  467. :group 'org-export-latex
  468. :type 'string)
  469. (defcustom org-latex-diary-timestamp-format "\\textit{%s}"
  470. "A printf format string to be applied to diary timestamps."
  471. :group 'org-export-latex
  472. :type 'string)
  473. ;;;; Links
  474. (defcustom org-latex-image-default-option ""
  475. "Default option for images."
  476. :group 'org-export-latex
  477. :version "24.4"
  478. :package-version '(Org . "8.0")
  479. :type 'string)
  480. (defcustom org-latex-image-default-width ".9\\linewidth"
  481. "Default width for images.
  482. This value will not be used if a height is provided."
  483. :group 'org-export-latex
  484. :version "24.4"
  485. :package-version '(Org . "8.0")
  486. :type 'string)
  487. (defcustom org-latex-image-default-height ""
  488. "Default height for images.
  489. This value will not be used if a width is provided, or if the
  490. image is wrapped within a \"figure\" or \"wrapfigure\"
  491. environment."
  492. :group 'org-export-latex
  493. :version "24.4"
  494. :package-version '(Org . "8.0")
  495. :type 'string)
  496. (defcustom org-latex-default-figure-position "htb"
  497. "Default position for latex figures."
  498. :group 'org-export-latex
  499. :type 'string)
  500. (defcustom org-latex-inline-image-rules
  501. '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\|pgf\\|svg\\)\\'"))
  502. "Rules characterizing image files that can be inlined into LaTeX.
  503. A rule consists in an association whose key is the type of link
  504. to consider, and value is a regexp that will be matched against
  505. link's path.
  506. Note that, by default, the image extension *actually* allowed
  507. depend on the way the LaTeX file is processed. When used with
  508. pdflatex, pdf, jpg and png images are OK. When processing
  509. through dvi to Postscript, only ps and eps are allowed. The
  510. default we use here encompasses both."
  511. :group 'org-export-latex
  512. :version "24.4"
  513. :package-version '(Org . "8.0")
  514. :type '(alist :key-type (string :tag "Type")
  515. :value-type (regexp :tag "Path")))
  516. (defcustom org-latex-link-with-unknown-path-format "\\texttt{%s}"
  517. "Format string for links with unknown path type."
  518. :group 'org-export-latex
  519. :type 'string)
  520. ;;;; Tables
  521. (defcustom org-latex-default-table-environment "tabular"
  522. "Default environment used to build tables."
  523. :group 'org-export-latex
  524. :version "24.4"
  525. :package-version '(Org . "8.0")
  526. :type 'string)
  527. (defcustom org-latex-default-table-mode 'table
  528. "Default mode for tables.
  529. Value can be a symbol among:
  530. `table' Regular LaTeX table.
  531. `math' In this mode, every cell is considered as being in math
  532. mode and the complete table will be wrapped within a math
  533. environment. It is particularly useful to write matrices.
  534. `inline-math' This mode is almost the same as `math', but the
  535. math environment will be inlined.
  536. `verbatim' The table is exported as it appears in the Org
  537. buffer, within a verbatim environment.
  538. This value can be overridden locally with, i.e. \":mode math\" in
  539. LaTeX attributes.
  540. When modifying this variable, it may be useful to change
  541. `org-latex-default-table-environment' accordingly."
  542. :group 'org-export-latex
  543. :version "24.4"
  544. :package-version '(Org . "8.0")
  545. :type '(choice (const :tag "Table" table)
  546. (const :tag "Matrix" math)
  547. (const :tag "Inline matrix" inline-math)
  548. (const :tag "Verbatim" verbatim))
  549. :safe (lambda (s) (memq s '(table math inline-math verbatim))))
  550. (defcustom org-latex-tables-centered t
  551. "When non-nil, tables are exported in a center environment."
  552. :group 'org-export-latex
  553. :type 'boolean
  554. :safe #'booleanp)
  555. (defcustom org-latex-tables-booktabs nil
  556. "When non-nil, display tables in a formal \"booktabs\" style.
  557. This option assumes that the \"booktabs\" package is properly
  558. loaded in the header of the document. This value can be ignored
  559. locally with \":booktabs t\" and \":booktabs nil\" LaTeX
  560. attributes."
  561. :group 'org-export-latex
  562. :version "24.4"
  563. :package-version '(Org . "8.0")
  564. :type 'boolean
  565. :safe #'booleanp)
  566. (defcustom org-latex-table-scientific-notation "%s\\,(%s)"
  567. "Format string to display numbers in scientific notation.
  568. The format should have \"%s\" twice, for mantissa and exponent
  569. \(i.e., \"%s\\\\times10^{%s}\").
  570. When nil, no transformation is made."
  571. :group 'org-export-latex
  572. :version "24.4"
  573. :package-version '(Org . "8.0")
  574. :type '(choice
  575. (string :tag "Format string")
  576. (const :tag "No formatting" nil)))
  577. ;;;; Text markup
  578. (defcustom org-latex-text-markup-alist '((bold . "\\textbf{%s}")
  579. (code . verb)
  580. (italic . "\\emph{%s}")
  581. (strike-through . "\\sout{%s}")
  582. (underline . "\\uline{%s}")
  583. (verbatim . protectedtexttt))
  584. "Alist of LaTeX expressions to convert text markup.
  585. The key must be a symbol among `bold', `code', `italic',
  586. `strike-through', `underline' and `verbatim'. The value is
  587. a formatting string to wrap fontified text with.
  588. Value can also be set to the following symbols: `verb' and
  589. `protectedtexttt'. For the former, Org will use \"\\verb\" to
  590. create a format string and select a delimiter character that
  591. isn't in the string. For the latter, Org will use \"\\texttt\"
  592. to typeset and try to protect special characters.
  593. If no association can be found for a given markup, text will be
  594. returned as-is."
  595. :group 'org-export-latex
  596. :type 'alist
  597. :options '(bold code italic strike-through underline verbatim))
  598. ;;;; Drawers
  599. (defcustom org-latex-format-drawer-function
  600. (lambda (name contents) contents)
  601. "Function called to format a drawer in LaTeX code.
  602. The function must accept two parameters:
  603. NAME the drawer name, like \"LOGBOOK\"
  604. CONTENTS the contents of the drawer.
  605. The function should return the string to be exported.
  606. The default function simply returns the value of CONTENTS."
  607. :group 'org-export-latex
  608. :version "24.4"
  609. :package-version '(Org . "8.3")
  610. :type 'function)
  611. ;;;; Inlinetasks
  612. (defcustom org-latex-format-inlinetask-function
  613. 'org-latex-format-inlinetask-default-function
  614. "Function called to format an inlinetask in LaTeX code.
  615. The function must accept seven parameters:
  616. TODO the todo keyword (string or nil)
  617. TODO-TYPE the todo type (symbol: `todo', `done', nil)
  618. PRIORITY the inlinetask priority (integer or nil)
  619. NAME the inlinetask name (string)
  620. TAGS the inlinetask tags (list of strings or nil)
  621. CONTENTS the contents of the inlinetask (string or nil)
  622. INFO the export options (plist)
  623. The function should return the string to be exported."
  624. :group 'org-export-latex
  625. :type 'function
  626. :version "25.1"
  627. :package-version '(Org . "8.3"))
  628. ;; Src blocks
  629. (defcustom org-latex-listings nil
  630. "Non-nil means export source code using the listings package.
  631. This package will fontify source code, possibly even with color.
  632. If you want to use this, you also need to make LaTeX use the
  633. listings package, and if you want to have color, the color
  634. package. Just add these to `org-latex-packages-alist', for
  635. example using customize, or with something like:
  636. \(require 'ox-latex)
  637. \(add-to-list 'org-latex-packages-alist '(\"\" \"listings\"))
  638. \(add-to-list 'org-latex-packages-alist '(\"\" \"color\"))
  639. Alternatively,
  640. \(setq org-latex-listings 'minted)
  641. causes source code to be exported using the minted package as
  642. opposed to listings. If you want to use minted, you need to add
  643. the minted package to `org-latex-packages-alist', for example
  644. using customize, or with
  645. \(require 'ox-latex)
  646. \(add-to-list 'org-latex-packages-alist '(\"\" \"minted\"))
  647. In addition, it is necessary to install pygments
  648. \(http://pygments.org), and to configure the variable
  649. `org-latex-pdf-process' so that the -shell-escape option is
  650. passed to pdflatex.
  651. The minted choice has possible repercussions on the preview of
  652. latex fragments (see `org-preview-latex-fragment'). If you run
  653. into previewing problems, please consult
  654. http://orgmode.org/worg/org-tutorials/org-latex-preview.html"
  655. :group 'org-export-latex
  656. :type '(choice
  657. (const :tag "Use listings" t)
  658. (const :tag "Use minted" minted)
  659. (const :tag "Export verbatim" nil))
  660. :safe (lambda (s) (memq s '(t nil minted))))
  661. (defcustom org-latex-listings-langs
  662. '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
  663. (c "C") (cc "C++")
  664. (fortran "fortran")
  665. (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
  666. (html "HTML") (xml "XML")
  667. (tex "TeX") (latex "[LaTeX]TeX")
  668. (shell-script "bash")
  669. (gnuplot "Gnuplot")
  670. (ocaml "Caml") (caml "Caml")
  671. (sql "SQL") (sqlite "sql")
  672. (makefile "make"))
  673. "Alist mapping languages to their listing language counterpart.
  674. The key is a symbol, the major mode symbol without the \"-mode\".
  675. The value is the string that should be inserted as the language
  676. parameter for the listings package. If the mode name and the
  677. listings name are the same, the language does not need an entry
  678. in this list - but it does not hurt if it is present."
  679. :group 'org-export-latex
  680. :version "24.4"
  681. :package-version '(Org . "8.3")
  682. :type '(repeat
  683. (list
  684. (symbol :tag "Major mode ")
  685. (string :tag "Listings language"))))
  686. (defcustom org-latex-listings-options nil
  687. "Association list of options for the latex listings package.
  688. These options are supplied as a comma-separated list to the
  689. \\lstset command. Each element of the association list should be
  690. a list containing two strings: the name of the option, and the
  691. value. For example,
  692. \(setq org-latex-listings-options
  693. '((\"basicstyle\" \"\\\\small\")
  694. \(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
  695. will typeset the code in a small size font with underlined, bold
  696. black keywords.
  697. Note that the same options will be applied to blocks of all
  698. languages. If you need block-specific options, you may use the
  699. following syntax:
  700. #+ATTR_LATEX: :options key1=value1,key2=value2
  701. #+BEGIN_SRC <LANG>
  702. ...
  703. #+END_SRC"
  704. :group 'org-export-latex
  705. :type '(repeat
  706. (list
  707. (string :tag "Listings option name ")
  708. (string :tag "Listings option value"))))
  709. (defcustom org-latex-minted-langs
  710. '((emacs-lisp "common-lisp")
  711. (cc "c++")
  712. (cperl "perl")
  713. (shell-script "bash")
  714. (caml "ocaml"))
  715. "Alist mapping languages to their minted language counterpart.
  716. The key is a symbol, the major mode symbol without the \"-mode\".
  717. The value is the string that should be inserted as the language
  718. parameter for the minted package. If the mode name and the
  719. listings name are the same, the language does not need an entry
  720. in this list - but it does not hurt if it is present.
  721. Note that minted uses all lower case for language identifiers,
  722. and that the full list of language identifiers can be obtained
  723. with:
  724. pygmentize -L lexers"
  725. :group 'org-export-latex
  726. :type '(repeat
  727. (list
  728. (symbol :tag "Major mode ")
  729. (string :tag "Minted language"))))
  730. (defcustom org-latex-minted-options nil
  731. "Association list of options for the latex minted package.
  732. These options are supplied within square brackets in
  733. \\begin{minted} environments. Each element of the alist should
  734. be a list containing two strings: the name of the option, and the
  735. value. For example,
  736. \(setq org-latex-minted-options
  737. '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
  738. will result in src blocks being exported with
  739. \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
  740. as the start of the minted environment. Note that the same
  741. options will be applied to blocks of all languages. If you need
  742. block-specific options, you may use the following syntax:
  743. #+ATTR_LATEX: :options key1=value1,key2=value2
  744. #+BEGIN_SRC <LANG>
  745. ...
  746. #+END_SRC"
  747. :group 'org-export-latex
  748. :type '(repeat
  749. (list
  750. (string :tag "Minted option name ")
  751. (string :tag "Minted option value"))))
  752. (defvar org-latex-custom-lang-environments nil
  753. "Alist mapping languages to language-specific LaTeX environments.
  754. It is used during export of src blocks by the listings and minted
  755. latex packages. For example,
  756. \(setq org-latex-custom-lang-environments
  757. '\(\(python \"pythoncode\"\)\)\)
  758. would have the effect that if org encounters begin_src python
  759. during latex export it will output
  760. \\begin{pythoncode}
  761. <src block body>
  762. \\end{pythoncode}")
  763. ;;;; Compilation
  764. (defcustom org-latex-pdf-process
  765. '("pdflatex -interaction nonstopmode -output-directory %o %f"
  766. "pdflatex -interaction nonstopmode -output-directory %o %f"
  767. "pdflatex -interaction nonstopmode -output-directory %o %f")
  768. "Commands to process a LaTeX file to a PDF file.
  769. This is a list of strings, each of them will be given to the
  770. shell as a command. %f in the command will be replaced by the
  771. full file name, %b by the file base name (i.e. without directory
  772. and extension parts) and %o by the base directory of the file.
  773. The reason why this is a list is that it usually takes several
  774. runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
  775. does not have a clever mechanism to detect which of these
  776. commands have to be run to get to a stable result, and it also
  777. does not do any error checking.
  778. By default, Org uses 3 runs of `pdflatex' to do the processing.
  779. If you have texi2dvi on your system and if that does not cause
  780. the infamous egrep/locale bug:
  781. http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
  782. then `texi2dvi' is the superior choice as it automates the LaTeX
  783. build process by calling the \"correct\" combinations of
  784. auxiliary programs. Org does offer `texi2dvi' as one of the
  785. customize options. Alternatively, `rubber' and `latexmk' also
  786. provide similar functionality. The latter supports `biber' out
  787. of the box.
  788. Alternatively, this may be a Lisp function that does the
  789. processing, so you could use this to apply the machinery of
  790. AUCTeX or the Emacs LaTeX mode. This function should accept the
  791. file name as its single argument."
  792. :group 'org-export-pdf
  793. :type '(choice
  794. (repeat :tag "Shell command sequence"
  795. (string :tag "Shell command"))
  796. (const :tag "2 runs of pdflatex"
  797. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  798. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  799. (const :tag "3 runs of pdflatex"
  800. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  801. "pdflatex -interaction nonstopmode -output-directory %o %f"
  802. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  803. (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
  804. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  805. "bibtex %b"
  806. "pdflatex -interaction nonstopmode -output-directory %o %f"
  807. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  808. (const :tag "2 runs of xelatex"
  809. ("xelatex -interaction nonstopmode -output-directory %o %f"
  810. "xelatex -interaction nonstopmode -output-directory %o %f"))
  811. (const :tag "3 runs of xelatex"
  812. ("xelatex -interaction nonstopmode -output-directory %o %f"
  813. "xelatex -interaction nonstopmode -output-directory %o %f"
  814. "xelatex -interaction nonstopmode -output-directory %o %f"))
  815. (const :tag "xelatex,bibtex,xelatex,xelatex"
  816. ("xelatex -interaction nonstopmode -output-directory %o %f"
  817. "bibtex %b"
  818. "xelatex -interaction nonstopmode -output-directory %o %f"
  819. "xelatex -interaction nonstopmode -output-directory %o %f"))
  820. (const :tag "texi2dvi"
  821. ("texi2dvi -p -b -V %f"))
  822. (const :tag "rubber"
  823. ("rubber -d --into %o %f"))
  824. (const :tag "latexmk"
  825. ("latexmk -g -pdf %f"))
  826. (function)))
  827. (defcustom org-latex-logfiles-extensions
  828. '("aux" "bcf" "blg" "fdb_latexmk" "fls" "figlist" "idx" "log" "nav" "out"
  829. "ptc" "run.xml" "snm" "toc" "vrb" "xdv")
  830. "The list of file extensions to consider as LaTeX logfiles.
  831. The logfiles will be removed if `org-latex-remove-logfiles' is
  832. non-nil."
  833. :group 'org-export-latex
  834. :version "25.1"
  835. :package-version '(Org . "8.3")
  836. :type '(repeat (string :tag "Extension")))
  837. (defcustom org-latex-remove-logfiles t
  838. "Non-nil means remove the logfiles produced by PDF production.
  839. By default, logfiles are files with these extensions: .aux, .idx,
  840. .log, .out, .toc, .nav, .snm and .vrb. To define the set of
  841. logfiles to remove, set `org-latex-logfiles-extensions'."
  842. :group 'org-export-latex
  843. :type 'boolean)
  844. (defcustom org-latex-known-warnings
  845. '(("Reference.*?undefined" . "[undefined reference]")
  846. ("Runaway argument" . "[runaway argument]")
  847. ("Underfull \\hbox" . "[underfull hbox]")
  848. ("Overfull \\hbox" . "[overfull hbox]")
  849. ("Citation.*?undefined" . "[undefined citation]")
  850. ("Undefined control sequence" . "[undefined control sequence]"))
  851. "Alist of regular expressions and associated messages for the user.
  852. The regular expressions are used to find possible warnings in the
  853. log of a latex-run. These warnings will be reported after
  854. calling `org-latex-compile'."
  855. :group 'org-export-latex
  856. :version "25.1"
  857. :package-version '(Org . "8.3")
  858. :type '(repeat
  859. (cons
  860. (string :tag "Regexp")
  861. (string :tag "Message"))))
  862. ;;; Internal Functions
  863. (defun org-latex--caption-above-p (element info)
  864. "Non nil when caption is expected to be located above ELEMENT.
  865. INFO is a plist holding contextual information."
  866. (let ((above (plist-get info :latex-caption-above)))
  867. (if (symbolp above) above
  868. (let ((type (org-element-type element)))
  869. (memq (if (eq type 'link) 'image type) above)))))
  870. (defun org-latex--caption/label-string (element info)
  871. "Return caption and label LaTeX string for ELEMENT.
  872. INFO is a plist holding contextual information. If there's no
  873. caption nor label, return the empty string.
  874. For non-floats, see `org-latex--wrap-label'."
  875. (let* ((label
  876. (if (not (org-element-property :name element)) ""
  877. (format "\\label{%s}" (org-export-get-reference element info))))
  878. (main (org-export-get-caption element))
  879. (short (org-export-get-caption element t))
  880. (caption-from-attr-latex
  881. (org-export-read-attribute :attr_latex element :caption)))
  882. (cond
  883. ((org-string-nw-p caption-from-attr-latex)
  884. (concat caption-from-attr-latex "\n"))
  885. ((and (not main) (equal label "")) "")
  886. ((not main) (concat label "\n"))
  887. ;; Option caption format with short name.
  888. (short (format "\\caption[%s]{%s%s}\n"
  889. (org-export-data short info)
  890. label
  891. (org-export-data main info)))
  892. ;; Standard caption format.
  893. (t (format "\\caption{%s%s}\n" label (org-export-data main info))))))
  894. (defun org-latex-guess-inputenc (header)
  895. "Set the coding system in inputenc to what the buffer is.
  896. HEADER is the LaTeX header string. This function only applies
  897. when specified inputenc option is \"AUTO\".
  898. Return the new header, as a string."
  899. (let* ((cs (or (ignore-errors
  900. (latexenc-coding-system-to-inputenc
  901. (or org-export-coding-system buffer-file-coding-system)))
  902. "utf8")))
  903. (if (not cs) header
  904. ;; First translate if that is requested.
  905. (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
  906. ;; Then find the \usepackage statement and replace the option.
  907. (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
  908. cs header t nil 1))))
  909. (defun org-latex-guess-babel-language (header info)
  910. "Set Babel's language according to LANGUAGE keyword.
  911. HEADER is the LaTeX header string. INFO is the plist used as
  912. a communication channel.
  913. Insertion of guessed language only happens when Babel package has
  914. explicitly been loaded. Then it is added to the rest of
  915. package's options.
  916. The argument to Babel may be \"AUTO\" which is then replaced with
  917. the language of the document or `org-export-default-language'
  918. unless language in question is already loaded.
  919. Return the new header."
  920. (let ((language-code (plist-get info :language)))
  921. ;; If no language is set or Babel package is not loaded, return
  922. ;; HEADER as-is.
  923. (if (or (not (stringp language-code))
  924. (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
  925. header
  926. (let ((options (save-match-data
  927. (org-split-string (match-string 1 header) ",[ \t]*")))
  928. (language (cdr (assoc language-code
  929. org-latex-babel-language-alist))))
  930. ;; If LANGUAGE is already loaded, return header without AUTO.
  931. ;; Otherwise, replace AUTO with language or append language if
  932. ;; AUTO is not present.
  933. (replace-match
  934. (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
  935. (cond ((member language options) (delete "AUTO" options))
  936. ((member "AUTO" options) options)
  937. (t (append options (list language))))
  938. ", ")
  939. t nil header 1)))))
  940. (defun org-latex--find-verb-separator (s)
  941. "Return a character not used in string S.
  942. This is used to choose a separator for constructs like \\verb."
  943. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  944. (loop for c across ll
  945. when (not (string-match (regexp-quote (char-to-string c)) s))
  946. return (char-to-string c))))
  947. (defun org-latex--make-option-string (options)
  948. "Return a comma separated string of keywords and values.
  949. OPTIONS is an alist where the key is the options keyword as
  950. a string, and the value a list containing the keyword value, or
  951. nil."
  952. (mapconcat (lambda (pair)
  953. (concat (first pair)
  954. (when (> (length (second pair)) 0)
  955. (concat "=" (second pair)))))
  956. options
  957. ","))
  958. (defun org-latex--wrap-label (element output info)
  959. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  960. INFO is the current export state, as a plist. This function
  961. should not be used for floats. See
  962. `org-latex--caption/label-string'."
  963. (if (not (and (org-string-nw-p output) (org-element-property :name element)))
  964. output
  965. (concat (format "\\phantomsection\n\\label{%s}\n"
  966. (org-export-get-reference element info))
  967. output)))
  968. (defun org-latex--text-markup (text markup info)
  969. "Format TEXT depending on MARKUP text markup.
  970. INFO is a plist used as a communication channel. See
  971. `org-latex-text-markup-alist' for details."
  972. (let ((fmt (cdr (assq markup (plist-get info :latex-text-markup-alist)))))
  973. (cond
  974. ;; No format string: Return raw text.
  975. ((not fmt) text)
  976. ;; Handle the `verb' special case: Find an appropriate separator
  977. ;; and use "\\verb" command.
  978. ((eq 'verb fmt)
  979. (let ((separator (org-latex--find-verb-separator text)))
  980. (concat "\\verb" separator
  981. (replace-regexp-in-string "\n" " " text)
  982. separator)))
  983. ;; Handle the `protectedtexttt' special case: Protect some
  984. ;; special chars and use "\texttt{%s}" format string.
  985. ((eq 'protectedtexttt fmt)
  986. (let ((start 0)
  987. (trans '(("\\" . "\\textbackslash{}")
  988. ("~" . "\\textasciitilde{}")
  989. ("^" . "\\textasciicircum{}")))
  990. (rtn "")
  991. char)
  992. (while (string-match "[\\{}$%&_#~^]" text)
  993. (setq char (match-string 0 text))
  994. (if (> (match-beginning 0) 0)
  995. (setq rtn (concat rtn (substring text 0 (match-beginning 0)))))
  996. (setq text (substring text (1+ (match-beginning 0))))
  997. (setq char (or (cdr (assoc char trans)) (concat "\\" char))
  998. rtn (concat rtn char)))
  999. (setq text (concat rtn text)
  1000. fmt "\\texttt{%s}")
  1001. (while (string-match "--" text)
  1002. (setq text (replace-match "-{}-" t t text)))
  1003. (format fmt text)))
  1004. ;; Else use format string.
  1005. (t (format fmt text)))))
  1006. (defun org-latex--delayed-footnotes-definitions (element info)
  1007. "Return footnotes definitions in ELEMENT as a string.
  1008. INFO is a plist used as a communication channel.
  1009. Footnotes definitions are returned within \"\\footnotetxt{}\"
  1010. commands.
  1011. This function is used within constructs that don't support
  1012. \"\\footnote{}\" command (i.e. an item's tag). In that case,
  1013. \"\\footnotemark\" is used within the construct and the function
  1014. just outside of it."
  1015. (mapconcat
  1016. (lambda (ref)
  1017. (format
  1018. "\\footnotetext[%s]{%s}"
  1019. (org-export-get-footnote-number ref info)
  1020. (org-trim
  1021. (org-export-data
  1022. (org-export-get-footnote-definition ref info) info))))
  1023. ;; Find every footnote reference in ELEMENT.
  1024. (let* (all-refs
  1025. search-refs ; For byte-compiler.
  1026. (search-refs
  1027. (function
  1028. (lambda (data)
  1029. ;; Return a list of all footnote references never seen
  1030. ;; before in DATA.
  1031. (org-element-map data 'footnote-reference
  1032. (lambda (ref)
  1033. (when (org-export-footnote-first-reference-p ref info)
  1034. (push ref all-refs)
  1035. (when (eq (org-element-property :type ref) 'standard)
  1036. (funcall search-refs
  1037. (org-export-get-footnote-definition ref info)))))
  1038. info)
  1039. (reverse all-refs)))))
  1040. (funcall search-refs element))
  1041. ""))
  1042. (defun org-latex--translate (s info)
  1043. "Translate string S according to specified language.
  1044. INFO is a plist used as a communication channel."
  1045. (org-export-translate s :latex info))
  1046. (defun org-latex--format-spec (info)
  1047. "Create a format-spec for document meta-data.
  1048. INFO is a plist used as a communication channel."
  1049. (let ((language (let ((lang (plist-get info :language)))
  1050. (or (cdr (assoc lang org-latex-babel-language-alist))
  1051. lang))))
  1052. `((?a . ,(org-export-data (plist-get info :author) info))
  1053. (?t . ,(org-export-data (plist-get info :title) info))
  1054. (?k . ,(org-export-data (org-latex--wrap-latex-math-block
  1055. (plist-get info :keywords) info)
  1056. info))
  1057. (?d . ,(org-export-data (org-latex--wrap-latex-math-block
  1058. (plist-get info :description) info)
  1059. info))
  1060. (?c . ,(plist-get info :creator))
  1061. (?l . ,language)
  1062. (?L . ,(capitalize language))
  1063. (?D . ,(org-export-get-date info)))))
  1064. ;;; Template
  1065. (defun org-latex-template (contents info)
  1066. "Return complete document string after LaTeX conversion.
  1067. CONTENTS is the transcoded contents string. INFO is a plist
  1068. holding export options."
  1069. (let ((title (org-export-data (plist-get info :title) info))
  1070. (spec (org-latex--format-spec info)))
  1071. (concat
  1072. ;; Time-stamp.
  1073. (and (plist-get info :time-stamp-file)
  1074. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  1075. ;; Document class and packages.
  1076. (let* ((class (plist-get info :latex-class))
  1077. (class-options (plist-get info :latex-class-options))
  1078. (header (nth 1 (assoc class (plist-get info :latex-classes))))
  1079. (document-class-string
  1080. (and (stringp header)
  1081. (if (not class-options) header
  1082. (replace-regexp-in-string
  1083. "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
  1084. class-options header t nil 1)))))
  1085. (if (not document-class-string)
  1086. (user-error "Unknown LaTeX class `%s'" class)
  1087. (org-latex-guess-babel-language
  1088. (org-latex-guess-inputenc
  1089. (org-element-normalize-string
  1090. (org-splice-latex-header
  1091. document-class-string
  1092. org-latex-default-packages-alist
  1093. org-latex-packages-alist nil
  1094. (concat (org-element-normalize-string
  1095. (plist-get info :latex-header))
  1096. (plist-get info :latex-header-extra)))))
  1097. info)))
  1098. ;; Possibly limit depth for headline numbering.
  1099. (let ((sec-num (plist-get info :section-numbers)))
  1100. (when (integerp sec-num)
  1101. (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
  1102. ;; Author.
  1103. (let ((author (and (plist-get info :with-author)
  1104. (let ((auth (plist-get info :author)))
  1105. (and auth (org-export-data auth info)))))
  1106. (email (and (plist-get info :with-email)
  1107. (org-export-data (plist-get info :email) info))))
  1108. (cond ((and author email (not (string= "" email)))
  1109. (format "\\author{%s\\thanks{%s}}\n" author email))
  1110. ((or author email) (format "\\author{%s}\n" (or author email)))))
  1111. ;; Date.
  1112. (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
  1113. (format "\\date{%s}\n" (org-export-data date info)))
  1114. ;; Title and subtitle.
  1115. (let* ((subtitle (plist-get info :subtitle))
  1116. (formatted-subtitle
  1117. (when subtitle
  1118. (format (plist-get info :latex-subtitle-format)
  1119. (org-export-data subtitle info))))
  1120. (separate (plist-get info :latex-subtitle-separate)))
  1121. (concat
  1122. (format "\\title{%s%s}\n" title
  1123. (if separate "" (or formatted-subtitle "")))
  1124. (when (and separate subtitle)
  1125. (concat formatted-subtitle "\n"))))
  1126. ;; Hyperref options.
  1127. (let ((template (plist-get info :latex-hyperref-template)))
  1128. (and (stringp template)
  1129. (format-spec template spec)))
  1130. ;; Document start.
  1131. "\\begin{document}\n\n"
  1132. ;; Title command.
  1133. (let* ((title-command (plist-get info :latex-title-command))
  1134. (command (and (stringp title-command)
  1135. (format-spec title-command spec))))
  1136. (org-element-normalize-string
  1137. (cond ((not (plist-get info :with-title)) nil)
  1138. ((string= "" title) nil)
  1139. ((not (stringp command)) nil)
  1140. ((string-match "\\(?:[^%]\\|^\\)%s" command)
  1141. (format command title))
  1142. (t command))))
  1143. ;; Table of contents.
  1144. (let ((depth (plist-get info :with-toc)))
  1145. (when depth
  1146. (concat (when (wholenump depth)
  1147. (format "\\setcounter{tocdepth}{%d}\n" depth))
  1148. (plist-get info :latex-toc-command))))
  1149. ;; Document's body.
  1150. contents
  1151. ;; Creator.
  1152. (and (plist-get info :with-creator)
  1153. (concat (plist-get info :creator) "\n"))
  1154. ;; Document end.
  1155. "\\end{document}")))
  1156. ;;; Transcode Functions
  1157. ;;;; Bold
  1158. (defun org-latex-bold (bold contents info)
  1159. "Transcode BOLD from Org to LaTeX.
  1160. CONTENTS is the text with bold markup. INFO is a plist holding
  1161. contextual information."
  1162. (org-latex--text-markup contents 'bold info))
  1163. ;;;; Center Block
  1164. (defun org-latex-center-block (center-block contents info)
  1165. "Transcode a CENTER-BLOCK element from Org to LaTeX.
  1166. CONTENTS holds the contents of the center block. INFO is a plist
  1167. holding contextual information."
  1168. (org-latex--wrap-label
  1169. center-block (format "\\begin{center}\n%s\\end{center}" contents) info))
  1170. ;;;; Clock
  1171. (defun org-latex-clock (clock contents info)
  1172. "Transcode a CLOCK element from Org to LaTeX.
  1173. CONTENTS is nil. INFO is a plist holding contextual
  1174. information."
  1175. (concat
  1176. "\\noindent"
  1177. (format "\\textbf{%s} " org-clock-string)
  1178. (format (plist-get info :latex-inactive-timestamp-format)
  1179. (concat (org-timestamp-translate (org-element-property :value clock))
  1180. (let ((time (org-element-property :duration clock)))
  1181. (and time (format " (%s)" time)))))
  1182. "\\\\"))
  1183. ;;;; Code
  1184. (defun org-latex-code (code contents info)
  1185. "Transcode a CODE object from Org to LaTeX.
  1186. CONTENTS is nil. INFO is a plist used as a communication
  1187. channel."
  1188. (org-latex--text-markup (org-element-property :value code) 'code info))
  1189. ;;;; Drawer
  1190. (defun org-latex-drawer (drawer contents info)
  1191. "Transcode a DRAWER element from Org to LaTeX.
  1192. CONTENTS holds the contents of the block. INFO is a plist
  1193. holding contextual information."
  1194. (let* ((name (org-element-property :drawer-name drawer))
  1195. (output (funcall (plist-get info :latex-format-drawer-function)
  1196. name contents)))
  1197. (org-latex--wrap-label drawer output info)))
  1198. ;;;; Dynamic Block
  1199. (defun org-latex-dynamic-block (dynamic-block contents info)
  1200. "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
  1201. CONTENTS holds the contents of the block. INFO is a plist
  1202. holding contextual information. See `org-export-data'."
  1203. (org-latex--wrap-label dynamic-block contents info))
  1204. ;;;; Entity
  1205. (defun org-latex-entity (entity contents info)
  1206. "Transcode an ENTITY object from Org to LaTeX.
  1207. CONTENTS are the definition itself. INFO is a plist holding
  1208. contextual information."
  1209. (org-element-property :latex entity))
  1210. ;;;; Example Block
  1211. (defun org-latex-example-block (example-block contents info)
  1212. "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
  1213. CONTENTS is nil. INFO is a plist holding contextual
  1214. information."
  1215. (when (org-string-nw-p (org-element-property :value example-block))
  1216. (org-latex--wrap-label
  1217. example-block
  1218. (format "\\begin{verbatim}\n%s\\end{verbatim}"
  1219. (org-export-format-code-default example-block info))
  1220. info)))
  1221. ;;;; Export Block
  1222. (defun org-latex-export-block (export-block contents info)
  1223. "Transcode a EXPORT-BLOCK element from Org to LaTeX.
  1224. CONTENTS is nil. INFO is a plist holding contextual information."
  1225. (when (member (org-element-property :type export-block) '("LATEX" "TEX"))
  1226. (org-remove-indentation (org-element-property :value export-block))))
  1227. ;;;; Export Snippet
  1228. (defun org-latex-export-snippet (export-snippet contents info)
  1229. "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
  1230. CONTENTS is nil. INFO is a plist holding contextual information."
  1231. (when (eq (org-export-snippet-backend export-snippet) 'latex)
  1232. (org-element-property :value export-snippet)))
  1233. ;;;; Fixed Width
  1234. (defun org-latex-fixed-width (fixed-width contents info)
  1235. "Transcode a FIXED-WIDTH element from Org to LaTeX.
  1236. CONTENTS is nil. INFO is a plist holding contextual information."
  1237. (org-latex--wrap-label
  1238. fixed-width
  1239. (format "\\begin{verbatim}\n%s\\end{verbatim}"
  1240. (org-remove-indentation
  1241. (org-element-property :value fixed-width)))
  1242. info))
  1243. ;;;; Footnote Reference
  1244. (defun org-latex-footnote-reference (footnote-reference contents info)
  1245. "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
  1246. CONTENTS is nil. INFO is a plist holding contextual information."
  1247. (concat
  1248. ;; Insert separator between two footnotes in a row.
  1249. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1250. (when (eq (org-element-type prev) 'footnote-reference)
  1251. (plist-get info :latex-footnote-separator)))
  1252. (cond
  1253. ;; Use \footnotemark if the footnote has already been defined.
  1254. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1255. (format "\\footnotemark[%s]{}"
  1256. (org-export-get-footnote-number footnote-reference info)))
  1257. ;; Use \footnotemark if reference is within another footnote
  1258. ;; reference, footnote definition or table cell.
  1259. ((org-element-lineage footnote-reference
  1260. '(footnote-reference footnote-definition table-cell))
  1261. "\\footnotemark")
  1262. ;; Otherwise, define it with \footnote command.
  1263. (t
  1264. (let ((def (org-export-get-footnote-definition footnote-reference info)))
  1265. (concat
  1266. (format "\\footnote{%s}" (org-trim (org-export-data def info)))
  1267. ;; Retrieve all footnote references within the footnote and
  1268. ;; add their definition after it, since LaTeX doesn't support
  1269. ;; them inside.
  1270. (org-latex--delayed-footnotes-definitions def info)))))))
  1271. ;;;; Headline
  1272. (defun org-latex-headline (headline contents info)
  1273. "Transcode a HEADLINE element from Org to LaTeX.
  1274. CONTENTS holds the contents of the headline. INFO is a plist
  1275. holding contextual information."
  1276. (unless (org-element-property :footnote-section-p headline)
  1277. (let* ((class (plist-get info :latex-class))
  1278. (level (org-export-get-relative-level headline info))
  1279. (numberedp (org-export-numbered-headline-p headline info))
  1280. (class-sectioning (assoc class (plist-get info :latex-classes)))
  1281. ;; Section formatting will set two placeholders: one for
  1282. ;; the title and the other for the contents.
  1283. (section-fmt
  1284. (let ((sec (if (functionp (nth 2 class-sectioning))
  1285. (funcall (nth 2 class-sectioning) level numberedp)
  1286. (nth (1+ level) class-sectioning))))
  1287. (cond
  1288. ;; No section available for that LEVEL.
  1289. ((not sec) nil)
  1290. ;; Section format directly returned by a function. Add
  1291. ;; placeholder for contents.
  1292. ((stringp sec) (concat sec "\n%s"))
  1293. ;; (numbered-section . unnumbered-section)
  1294. ((not (consp (cdr sec)))
  1295. (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
  1296. ;; (numbered-open numbered-close)
  1297. ((= (length sec) 2)
  1298. (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
  1299. ;; (num-in num-out no-num-in no-num-out)
  1300. ((= (length sec) 4)
  1301. (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
  1302. (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
  1303. ;; Create a temporary export back-end that hard-codes
  1304. ;; "\underline" within "\section" and alike.
  1305. (section-back-end
  1306. (org-export-create-backend
  1307. :parent 'latex
  1308. :transcoders
  1309. '((underline . (lambda (o c i) (format "\\underline{%s}" c))))))
  1310. (text
  1311. (org-export-data-with-backend
  1312. (org-element-property :title headline) section-back-end info))
  1313. (todo
  1314. (and (plist-get info :with-todo-keywords)
  1315. (let ((todo (org-element-property :todo-keyword headline)))
  1316. (and todo (org-export-data todo info)))))
  1317. (todo-type (and todo (org-element-property :todo-type headline)))
  1318. (tags (and (plist-get info :with-tags)
  1319. (org-export-get-tags headline info)))
  1320. (priority (and (plist-get info :with-priority)
  1321. (org-element-property :priority headline)))
  1322. ;; Create the headline text along with a no-tag version.
  1323. ;; The latter is required to remove tags from toc.
  1324. (full-text (funcall (plist-get info :latex-format-headline-function)
  1325. todo todo-type priority text tags info))
  1326. ;; Associate \label to the headline for internal links.
  1327. (headline-label
  1328. (format "\\label{%s}\n"
  1329. (or (and (plist-get info :latex-custom-id-labels)
  1330. (org-element-property :CUSTOM_ID headline))
  1331. (org-export-get-reference headline info))))
  1332. (pre-blanks
  1333. (make-string (org-element-property :pre-blank headline) 10)))
  1334. (if (or (not section-fmt) (org-export-low-level-p headline info))
  1335. ;; This is a deep sub-tree: export it as a list item. Also
  1336. ;; export as items headlines for which no section format has
  1337. ;; been found.
  1338. (let ((low-level-body
  1339. (concat
  1340. ;; If headline is the first sibling, start a list.
  1341. (when (org-export-first-sibling-p headline info)
  1342. (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
  1343. ;; Itemize headline
  1344. "\\item"
  1345. (and full-text (org-string-match-p "\\`[ \t]*\\[" full-text)
  1346. "\\relax")
  1347. " " full-text "\n"
  1348. headline-label
  1349. pre-blanks
  1350. contents)))
  1351. ;; If headline is not the last sibling simply return
  1352. ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
  1353. ;; any blank line.
  1354. (if (not (org-export-last-sibling-p headline info)) low-level-body
  1355. (replace-regexp-in-string
  1356. "[ \t\n]*\\'"
  1357. (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
  1358. low-level-body)))
  1359. ;; This is a standard headline. Export it as a section. Add
  1360. ;; an alternative heading when possible, and when this is not
  1361. ;; identical to the usual heading.
  1362. (let ((opt-title
  1363. (funcall (plist-get info :latex-format-headline-function)
  1364. todo todo-type priority
  1365. (org-export-data-with-backend
  1366. (org-export-get-alt-title headline info)
  1367. section-back-end info)
  1368. (and (eq (plist-get info :with-tags) t) tags)
  1369. info))
  1370. ;; Maybe end local TOC (see `org-latex-keyword').
  1371. (contents
  1372. (concat
  1373. contents
  1374. (let ((case-fold-search t)
  1375. (section
  1376. (let ((first (car (org-element-contents headline))))
  1377. (and (eq (org-element-type first) 'section) first))))
  1378. (org-element-map section 'keyword
  1379. (lambda (k)
  1380. (and (equal (org-element-property :key k) "TOC")
  1381. (let ((v (org-element-property :value k)))
  1382. (and (org-string-match-p "\\<headlines\\>" v)
  1383. (org-string-match-p "\\<local\\>" v)
  1384. (format "\\stopcontents[level-%d]" level)))))
  1385. info t)))))
  1386. (if (and opt-title
  1387. (not (equal opt-title full-text))
  1388. (string-match "\\`\\\\\\(.*?[^*]\\){" section-fmt))
  1389. (format (replace-match "\\1[%s]" nil nil section-fmt 1)
  1390. ;; Replace square brackets with parenthesis
  1391. ;; since square brackets are not supported in
  1392. ;; optional arguments.
  1393. (replace-regexp-in-string
  1394. "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
  1395. full-text
  1396. (concat headline-label pre-blanks contents))
  1397. ;; Impossible to add an alternative heading. Fallback to
  1398. ;; regular sectioning format string.
  1399. (format section-fmt full-text
  1400. (concat headline-label pre-blanks contents))))))))
  1401. (defun org-latex-format-headline-default-function
  1402. (todo todo-type priority text tags info)
  1403. "Default format function for a headline.
  1404. See `org-latex-format-headline-function' for details."
  1405. (concat
  1406. (and todo (format "{\\bfseries\\sffamily %s} " todo))
  1407. (and priority (format "\\framebox{\\#%c} " priority))
  1408. text
  1409. (and tags
  1410. (format "\\hfill{}\\textsc{%s}"
  1411. (mapconcat (lambda (tag) (org-latex-plain-text tag info))
  1412. tags ":")))))
  1413. ;;;; Horizontal Rule
  1414. (defun org-latex-horizontal-rule (horizontal-rule contents info)
  1415. "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
  1416. CONTENTS is nil. INFO is a plist holding contextual information."
  1417. (let ((attr (org-export-read-attribute :attr_latex horizontal-rule))
  1418. (prev (org-export-get-previous-element horizontal-rule info)))
  1419. (concat
  1420. ;; Make sure the rule doesn't start at the end of the current
  1421. ;; line by separating it with a blank line from previous element.
  1422. (when (and prev
  1423. (let ((prev-blank (org-element-property :post-blank prev)))
  1424. (or (not prev-blank) (zerop prev-blank))))
  1425. "\n")
  1426. (org-latex--wrap-label
  1427. horizontal-rule
  1428. (format "\\rule{%s}{%s}"
  1429. (or (plist-get attr :width) "\\linewidth")
  1430. (or (plist-get attr :thickness) "0.5pt"))
  1431. info))))
  1432. ;;;; Inline Src Block
  1433. (defun org-latex-inline-src-block (inline-src-block contents info)
  1434. "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
  1435. CONTENTS holds the contents of the item. INFO is a plist holding
  1436. contextual information."
  1437. (let* ((code (org-element-property :value inline-src-block))
  1438. (separator (org-latex--find-verb-separator code)))
  1439. (case (plist-get info :latex-listings)
  1440. ;; Do not use a special package: transcode it verbatim.
  1441. ((nil) (concat "\\verb" separator code separator))
  1442. ;; Use minted package.
  1443. (minted
  1444. (let* ((org-lang (org-element-property :language inline-src-block))
  1445. (mint-lang (or (cadr (assq (intern org-lang)
  1446. (plist-get info :latex-minted-langs)))
  1447. (downcase org-lang)))
  1448. (options (org-latex--make-option-string
  1449. (plist-get info :latex-minted-options))))
  1450. (concat (format "\\mint%s{%s}"
  1451. (if (string= options "") "" (format "[%s]" options))
  1452. mint-lang)
  1453. separator code separator)))
  1454. ;; Use listings package.
  1455. (otherwise
  1456. ;; Maybe translate language's name.
  1457. (let* ((org-lang (org-element-property :language inline-src-block))
  1458. (lst-lang (or (cadr (assq (intern org-lang)
  1459. (plist-get info :latex-listings-langs)))
  1460. org-lang))
  1461. (options (org-latex--make-option-string
  1462. (append (plist-get info :latex-listings-options)
  1463. `(("language" ,lst-lang))))))
  1464. (concat (format "\\lstinline[%s]" options)
  1465. separator code separator))))))
  1466. ;;;; Inlinetask
  1467. (defun org-latex-inlinetask (inlinetask contents info)
  1468. "Transcode an INLINETASK element from Org to LaTeX.
  1469. CONTENTS holds the contents of the block. INFO is a plist
  1470. holding contextual information."
  1471. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  1472. (todo (and (plist-get info :with-todo-keywords)
  1473. (let ((todo (org-element-property :todo-keyword inlinetask)))
  1474. (and todo (org-export-data todo info)))))
  1475. (todo-type (org-element-property :todo-type inlinetask))
  1476. (tags (and (plist-get info :with-tags)
  1477. (org-export-get-tags inlinetask info)))
  1478. (priority (and (plist-get info :with-priority)
  1479. (org-element-property :priority inlinetask)))
  1480. (contents (concat
  1481. (let ((label (org-element-property :CUSTOM_ID inlinetask)))
  1482. (and label (format "\\label{%s}\n" label)))
  1483. contents)))
  1484. (funcall (plist-get info :latex-format-inlinetask-function)
  1485. todo todo-type priority title tags contents info)))
  1486. (defun org-latex-format-inlinetask-default-function
  1487. (todo todo-type priority title tags contents info)
  1488. "Default format function for a inlinetasks.
  1489. See `org-latex-format-inlinetask-function' for details."
  1490. (let ((full-title
  1491. (concat (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  1492. (when priority (format "\\framebox{\\#%c} " priority))
  1493. title
  1494. (when tags
  1495. (format "\\hfill{}\\textsc{:%s:}"
  1496. (mapconcat
  1497. (lambda (tag) (org-latex-plain-text tag info))
  1498. tags ":"))))))
  1499. (concat "\\begin{center}\n"
  1500. "\\fbox{\n"
  1501. "\\begin{minipage}[c]{.6\\textwidth}\n"
  1502. full-title "\n\n"
  1503. (and (org-string-nw-p contents)
  1504. (concat "\\rule[.8em]{\\textwidth}{2pt}\n\n" contents))
  1505. "\\end{minipage}\n"
  1506. "}\n"
  1507. "\\end{center}")))
  1508. ;;;; Italic
  1509. (defun org-latex-italic (italic contents info)
  1510. "Transcode ITALIC from Org to LaTeX.
  1511. CONTENTS is the text with italic markup. INFO is a plist holding
  1512. contextual information."
  1513. (org-latex--text-markup contents 'italic info))
  1514. ;;;; Item
  1515. (defun org-latex-item (item contents info)
  1516. "Transcode an ITEM element from Org to LaTeX.
  1517. CONTENTS holds the contents of the item. INFO is a plist holding
  1518. contextual information."
  1519. (let* ((counter
  1520. (let ((count (org-element-property :counter item))
  1521. (level
  1522. ;; Determine level of current item to determine the
  1523. ;; correct LaTeX counter to use (enumi, enumii...).
  1524. (let ((parent item) (level 0))
  1525. (while (memq (org-element-type
  1526. (setq parent (org-export-get-parent parent)))
  1527. '(plain-list item))
  1528. (when (and (eq (org-element-type parent) 'plain-list)
  1529. (eq (org-element-property :type parent)
  1530. 'ordered))
  1531. (incf level)))
  1532. level)))
  1533. (and count
  1534. (< level 5)
  1535. (format "\\setcounter{enum%s}{%s}\n"
  1536. (nth (1- level) '("i" "ii" "iii" "iv"))
  1537. (1- count)))))
  1538. (checkbox (case (org-element-property :checkbox item)
  1539. (on "$\\boxtimes$ ")
  1540. (off "$\\square$ ")
  1541. (trans "$\\boxminus$ ")))
  1542. (tag (let ((tag (org-element-property :tag item)))
  1543. ;; Check-boxes must belong to the tag.
  1544. (and tag (format "[{%s}] "
  1545. (concat checkbox
  1546. (org-export-data tag info)))))))
  1547. (concat counter
  1548. "\\item"
  1549. (cond
  1550. (tag)
  1551. (checkbox (concat " " checkbox))
  1552. ;; Without a tag or a check-box, if CONTENTS starts with
  1553. ;; an opening square bracket, add "\relax" to "\item",
  1554. ;; unless the brackets comes from an initial export
  1555. ;; snippet (i.e. it is inserted willingly by the user).
  1556. ((and contents
  1557. (org-string-match-p "\\`[ \t]*\\[" contents)
  1558. (not (let ((e (car (org-element-contents item))))
  1559. (and (eq (org-element-type e) 'paragraph)
  1560. (let ((o (car (org-element-contents e))))
  1561. (and (eq (org-element-type o) 'export-snippet)
  1562. (eq (org-export-snippet-backend o)
  1563. 'latex)))))))
  1564. "\\relax ")
  1565. (t " "))
  1566. (and contents (org-trim contents))
  1567. ;; If there are footnotes references in tag, be sure to
  1568. ;; add their definition at the end of the item. This
  1569. ;; workaround is necessary since "\footnote{}" command is
  1570. ;; not supported in tags.
  1571. (and tag
  1572. (org-latex--delayed-footnotes-definitions
  1573. (org-element-property :tag item) info)))))
  1574. ;;;; Keyword
  1575. (defun org-latex-keyword (keyword contents info)
  1576. "Transcode a KEYWORD element from Org to LaTeX.
  1577. CONTENTS is nil. INFO is a plist holding contextual information."
  1578. (let ((key (org-element-property :key keyword))
  1579. (value (org-element-property :value keyword)))
  1580. (cond
  1581. ((string= key "LATEX") value)
  1582. ((string= key "INDEX") (format "\\index{%s}" value))
  1583. ((string= key "TOC")
  1584. (let ((case-fold-search t))
  1585. (cond
  1586. ((org-string-match-p "\\<headlines\\>" value)
  1587. (let* ((localp (org-string-match-p "\\<local\\>" value))
  1588. (parent (org-element-lineage keyword '(headline)))
  1589. (level (if (not (and localp parent)) 0
  1590. (org-export-get-relative-level parent info)))
  1591. (depth
  1592. (and (string-match "\\<[0-9]+\\>" value)
  1593. (format
  1594. "\\setcounter{tocdepth}{%d}"
  1595. (+ (string-to-number (match-string 0 value)) level)))))
  1596. (if (and localp parent)
  1597. ;; Start local TOC, assuming package "titletoc" is
  1598. ;; required.
  1599. (format "\\startcontents[level-%d]
  1600. \\printcontents[level-%d]{}{0}{%s}"
  1601. level level (or depth ""))
  1602. (concat depth (and depth "\n") "\\tableofcontents"))))
  1603. ((org-string-match-p "\\<tables\\>" value) "\\listoftables")
  1604. ((org-string-match-p "\\<listings\\>" value)
  1605. (case (plist-get info :latex-listings)
  1606. ((nil) "\\listoffigures")
  1607. (minted "\\listoflistings")
  1608. (otherwise "\\lstlistoflistings")))))))))
  1609. ;;;; Latex Environment
  1610. (defun org-latex-latex-environment (latex-environment contents info)
  1611. "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
  1612. CONTENTS is nil. INFO is a plist holding contextual information."
  1613. (when (plist-get info :with-latex)
  1614. (let ((value (org-remove-indentation
  1615. (org-element-property :value latex-environment))))
  1616. (if (not (org-element-property :name latex-environment)) value
  1617. ;; Environment is labeled: label must be within the environment
  1618. ;; (otherwise, a reference pointing to that element will count
  1619. ;; the section instead).
  1620. (with-temp-buffer
  1621. (insert value)
  1622. (goto-char (point-min))
  1623. (forward-line)
  1624. (insert
  1625. (format "\\label{%s}\n"
  1626. (org-export-get-reference latex-environment info)))
  1627. (buffer-string))))))
  1628. ;;;; Latex Fragment
  1629. (defun org-latex-latex-fragment (latex-fragment contents info)
  1630. "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
  1631. CONTENTS is nil. INFO is a plist holding contextual information."
  1632. (let ((value (org-element-property :value latex-fragment)))
  1633. ;; Trim math markers since the fragment is enclosed within
  1634. ;; a latex-math-block object anyway.
  1635. (cond ((string-match "\\`\\(\\$\\{1,2\\}\\)\\([^\000]*\\)\\1\\'" value)
  1636. (match-string 2 value))
  1637. ((string-match "\\`\\\\(\\([^\000]*\\)\\\\)\\'" value)
  1638. (match-string 1 value))
  1639. (t value))))
  1640. ;;;; Line Break
  1641. (defun org-latex-line-break (line-break contents info)
  1642. "Transcode a LINE-BREAK object from Org to LaTeX.
  1643. CONTENTS is nil. INFO is a plist holding contextual information."
  1644. "\\\\\n")
  1645. ;;;; Link
  1646. (defun org-latex--inline-image (link info)
  1647. "Return LaTeX code for an inline image.
  1648. LINK is the link pointing to the inline image. INFO is a plist
  1649. used as a communication channel."
  1650. (let* ((parent (org-export-get-parent-element link))
  1651. (path (let ((raw-path (org-element-property :path link)))
  1652. (if (not (file-name-absolute-p raw-path)) raw-path
  1653. (expand-file-name raw-path))))
  1654. (filetype (file-name-extension path))
  1655. (caption (org-latex--caption/label-string parent info))
  1656. (caption-above-p (org-latex--caption-above-p link info))
  1657. ;; Retrieve latex attributes from the element around.
  1658. (attr (org-export-read-attribute :attr_latex parent))
  1659. (float (let ((float (plist-get attr :float)))
  1660. (cond ((and (not float) (plist-member attr :float)) nil)
  1661. ((string= float "wrap") 'wrap)
  1662. ((string= float "sideways") 'sideways)
  1663. ((string= float "multicolumn") 'multicolumn)
  1664. ((or float
  1665. (org-element-property :caption parent)
  1666. (org-string-nw-p (plist-get attr :caption)))
  1667. 'figure))))
  1668. (placement
  1669. (let ((place (plist-get attr :placement)))
  1670. (cond
  1671. (place (format "%s" place))
  1672. ((eq float 'wrap) "{l}{0.5\\textwidth}")
  1673. ((eq float 'figure)
  1674. (format "[%s]" (plist-get info :latex-default-figure-position)))
  1675. (t ""))))
  1676. (comment-include (if (plist-get attr :comment-include) "%" ""))
  1677. ;; It is possible to specify width and height in the
  1678. ;; ATTR_LATEX line, and also via default variables.
  1679. (width (cond ((plist-get attr :width))
  1680. ((plist-get attr :height) "")
  1681. ((eq float 'wrap) "0.48\\textwidth")
  1682. (t (plist-get info :latex-image-default-width))))
  1683. (height (cond ((plist-get attr :height))
  1684. ((or (plist-get attr :width)
  1685. (memq float '(figure wrap))) "")
  1686. (t (plist-get info :latex-image-default-height))))
  1687. (options (let ((opt (or (plist-get attr :options)
  1688. (plist-get info :latex-image-default-option))))
  1689. (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
  1690. (match-string 1 opt))))
  1691. image-code)
  1692. (if (member filetype '("tikz" "pgf"))
  1693. ;; For tikz images:
  1694. ;; - use \input to read in image file.
  1695. ;; - if options are present, wrap in a tikzpicture environment.
  1696. ;; - if width or height are present, use \resizebox to change
  1697. ;; the image size.
  1698. (progn
  1699. (setq image-code (format "\\input{%s}" path))
  1700. (when (org-string-nw-p options)
  1701. (setq image-code
  1702. (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
  1703. options
  1704. image-code)))
  1705. (when (or (org-string-nw-p width) (org-string-nw-p height))
  1706. (setq image-code (format "\\resizebox{%s}{%s}{%s}"
  1707. (if (org-string-nw-p width) width "!")
  1708. (if (org-string-nw-p height) height "!")
  1709. image-code))))
  1710. ;; For other images:
  1711. ;; - add width and height to options.
  1712. ;; - include the image with \includegraphics.
  1713. (when (org-string-nw-p width)
  1714. (setq options (concat options ",width=" width)))
  1715. (when (org-string-nw-p height)
  1716. (setq options (concat options ",height=" height)))
  1717. (let ((search-option (org-element-property :search-option link)))
  1718. (when (and search-option
  1719. (equal filetype "pdf")
  1720. (org-string-match-p "\\`[0-9]+\\'" search-option)
  1721. (not (org-string-match-p "page=" options)))
  1722. (setq options (concat options ",page=" search-option))))
  1723. (setq image-code
  1724. (format "\\includegraphics%s{%s}"
  1725. (cond ((not (org-string-nw-p options)) "")
  1726. ((= (aref options 0) ?,)
  1727. (format "[%s]"(substring options 1)))
  1728. (t (format "[%s]" options)))
  1729. path))
  1730. (when (equal filetype "svg")
  1731. (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
  1732. "\\includesvg"
  1733. image-code
  1734. nil t))
  1735. (setq image-code (replace-regexp-in-string "\\.svg}"
  1736. "}"
  1737. image-code
  1738. nil t))))
  1739. ;; Return proper string, depending on FLOAT.
  1740. (case float
  1741. (wrap (format "\\begin{wrapfigure}%s
  1742. %s\\centering
  1743. %s%s
  1744. %s\\end{wrapfigure}"
  1745. placement
  1746. (if caption-above-p caption "")
  1747. comment-include image-code
  1748. (if caption-above-p "" caption)))
  1749. (sideways (format "\\begin{sidewaysfigure}
  1750. %s\\centering
  1751. %s%s
  1752. %s\\end{sidewaysfigure}"
  1753. (if caption-above-p caption "")
  1754. comment-include image-code
  1755. (if caption-above-p "" caption)))
  1756. (multicolumn (format "\\begin{figure*}%s
  1757. %s\\centering
  1758. %s%s
  1759. %s\\end{figure*}"
  1760. placement
  1761. (if caption-above-p caption "")
  1762. comment-include image-code
  1763. (if caption-above-p "" caption)))
  1764. (figure (format "\\begin{figure}%s
  1765. %s\\centering
  1766. %s%s
  1767. %s\\end{figure}"
  1768. placement
  1769. (if caption-above-p caption "")
  1770. comment-include image-code
  1771. (if caption-above-p "" caption)))
  1772. (otherwise image-code))))
  1773. (defun org-latex-link (link desc info)
  1774. "Transcode a LINK object from Org to LaTeX.
  1775. DESC is the description part of the link, or the empty string.
  1776. INFO is a plist holding contextual information. See
  1777. `org-export-data'."
  1778. (let* ((type (org-element-property :type link))
  1779. (raw-path (replace-regexp-in-string
  1780. "%" "\\%" (org-element-property :path link) nil t))
  1781. ;; Ensure DESC really exists, or set it to nil.
  1782. (desc (and (not (string= desc "")) desc))
  1783. (imagep (org-export-inline-image-p
  1784. link (plist-get info :latex-inline-image-rules)))
  1785. (path (cond
  1786. ((member type '("http" "https" "ftp" "mailto" "doi"))
  1787. (concat type ":" raw-path))
  1788. ((and (string= type "file") (file-name-absolute-p raw-path))
  1789. (concat "file:" raw-path))
  1790. (t raw-path))))
  1791. (cond
  1792. ;; Link type is handled by a special function.
  1793. ((org-export-custom-protocol-maybe link desc 'latex))
  1794. ;; Image file.
  1795. (imagep (org-latex--inline-image link info))
  1796. ;; Radio link: Transcode target's contents and use them as link's
  1797. ;; description.
  1798. ((string= type "radio")
  1799. (let ((destination (org-export-resolve-radio-link link info)))
  1800. (if (not destination) desc
  1801. (format "\\hyperref[%s]{%s}"
  1802. (org-export-get-reference destination info)
  1803. desc))))
  1804. ;; Links pointing to a headline: Find destination and build
  1805. ;; appropriate referencing command.
  1806. ((member type '("custom-id" "fuzzy" "id"))
  1807. (let ((destination (if (string= type "fuzzy")
  1808. (org-export-resolve-fuzzy-link link info)
  1809. (org-export-resolve-id-link link info))))
  1810. (case (org-element-type destination)
  1811. ;; Id link points to an external file.
  1812. (plain-text
  1813. (if desc (format "\\href{%s}{%s}" destination desc)
  1814. (format "\\url{%s}" destination)))
  1815. ;; Fuzzy link points nowhere.
  1816. ((nil)
  1817. (format (plist-get info :latex-link-with-unknown-path-format)
  1818. (or desc
  1819. (org-export-data
  1820. (org-element-property :raw-link link) info))))
  1821. ;; LINK points to a headline. If headlines are numbered
  1822. ;; and the link has no description, display headline's
  1823. ;; number. Otherwise, display description or headline's
  1824. ;; title.
  1825. (headline
  1826. (let* ((custom-label
  1827. (and (plist-get info :latex-custom-id-labels)
  1828. (org-element-property :CUSTOM_ID destination)))
  1829. (label (or custom-label
  1830. (org-export-get-reference destination info))))
  1831. (if (and (not desc)
  1832. (org-export-numbered-headline-p destination info))
  1833. (format "\\ref{%s}" label)
  1834. (format "\\hyperref[%s]{%s}" label
  1835. (or desc
  1836. (org-export-data
  1837. (org-element-property :title destination) info))))))
  1838. ;; Fuzzy link points to a target. Do as above.
  1839. (otherwise
  1840. (let ((ref (org-export-get-reference destination info)))
  1841. (if (not desc) (format "\\ref{%s}" ref)
  1842. (format "\\hyperref[%s]{%s}" ref desc)))))))
  1843. ;; Coderef: replace link with the reference name or the
  1844. ;; equivalent line number.
  1845. ((string= type "coderef")
  1846. (format (org-export-get-coderef-format path desc)
  1847. (org-export-resolve-coderef path info)))
  1848. ;; External link with a description part.
  1849. ((and path desc) (format "\\href{%s}{%s}" path desc))
  1850. ;; External link without a description part.
  1851. (path (format "\\url{%s}" path))
  1852. ;; No path, only description. Try to do something useful.
  1853. (t (format (plist-get info :latex-link-with-unknown-path-format) desc)))))
  1854. ;;;; Node Property
  1855. (defun org-latex-node-property (node-property contents info)
  1856. "Transcode a NODE-PROPERTY element from Org to LaTeX.
  1857. CONTENTS is nil. INFO is a plist holding contextual
  1858. information."
  1859. (format "%s:%s"
  1860. (org-element-property :key node-property)
  1861. (let ((value (org-element-property :value node-property)))
  1862. (if value (concat " " value) ""))))
  1863. ;;;; Paragraph
  1864. (defun org-latex-paragraph (paragraph contents info)
  1865. "Transcode a PARAGRAPH element from Org to LaTeX.
  1866. CONTENTS is the contents of the paragraph, as a string. INFO is
  1867. the plist used as a communication channel."
  1868. contents)
  1869. ;;;; Plain List
  1870. (defun org-latex-plain-list (plain-list contents info)
  1871. "Transcode a PLAIN-LIST element from Org to LaTeX.
  1872. CONTENTS is the contents of the list. INFO is a plist holding
  1873. contextual information."
  1874. (let* ((type (org-element-property :type plain-list))
  1875. (attr (org-export-read-attribute :attr_latex plain-list))
  1876. (latex-type (let ((env (plist-get attr :environment)))
  1877. (cond (env (format "%s" env))
  1878. ((eq type 'ordered) "enumerate")
  1879. ((eq type 'descriptive) "description")
  1880. (t "itemize")))))
  1881. (org-latex--wrap-label
  1882. plain-list
  1883. (format "\\begin{%s}%s\n%s\\end{%s}"
  1884. latex-type
  1885. (or (plist-get attr :options) "")
  1886. contents
  1887. latex-type)
  1888. info)))
  1889. ;;;; Plain Text
  1890. (defun org-latex-plain-text (text info)
  1891. "Transcode a TEXT string from Org to LaTeX.
  1892. TEXT is the string to transcode. INFO is a plist holding
  1893. contextual information."
  1894. (let* ((specialp (plist-get info :with-special-strings))
  1895. (output
  1896. ;; Turn LaTeX into \LaTeX{} and TeX into \TeX{}.
  1897. (let ((case-fold-search nil))
  1898. (replace-regexp-in-string
  1899. "\\<\\(?:La\\)?TeX\\>" "\\\\\\&{}"
  1900. ;; Protect ^, ~, %, #, &, $, _, { and }. Also protect \.
  1901. ;; However, if special strings are used, be careful not
  1902. ;; to protect "\" in "\-" constructs.
  1903. (replace-regexp-in-string
  1904. (concat "[%$#&{}_~^]\\|\\\\" (and specialp "\\(?:[^-]\\|$\\)"))
  1905. (lambda (m)
  1906. (case (aref m 0)
  1907. (?\\ "$\\\\backslash$")
  1908. (?~ "\\\\textasciitilde{}")
  1909. (?^ "\\\\^{}")
  1910. (t "\\\\\\&")))
  1911. text)))))
  1912. ;; Activate smart quotes. Be sure to provide original TEXT string
  1913. ;; since OUTPUT may have been modified.
  1914. (when (plist-get info :with-smart-quotes)
  1915. (setq output (org-export-activate-smart-quotes output :latex info text)))
  1916. ;; Convert special strings.
  1917. (when specialp
  1918. (setq output (replace-regexp-in-string "\\.\\.\\." "\\\\ldots{}" output)))
  1919. ;; Handle break preservation if required.
  1920. (when (plist-get info :preserve-breaks)
  1921. (setq output (replace-regexp-in-string
  1922. "\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n" output nil t)))
  1923. ;; Return value.
  1924. output))
  1925. ;;;; Planning
  1926. (defun org-latex-planning (planning contents info)
  1927. "Transcode a PLANNING element from Org to LaTeX.
  1928. CONTENTS is nil. INFO is a plist holding contextual
  1929. information."
  1930. (concat
  1931. "\\noindent"
  1932. (mapconcat
  1933. 'identity
  1934. (delq nil
  1935. (list
  1936. (let ((closed (org-element-property :closed planning)))
  1937. (when closed
  1938. (concat
  1939. (format "\\textbf{%s} " org-closed-string)
  1940. (format (plist-get info :latex-inactive-timestamp-format)
  1941. (org-timestamp-translate closed)))))
  1942. (let ((deadline (org-element-property :deadline planning)))
  1943. (when deadline
  1944. (concat
  1945. (format "\\textbf{%s} " org-deadline-string)
  1946. (format (plist-get info :latex-active-timestamp-format)
  1947. (org-timestamp-translate deadline)))))
  1948. (let ((scheduled (org-element-property :scheduled planning)))
  1949. (when scheduled
  1950. (concat
  1951. (format "\\textbf{%s} " org-scheduled-string)
  1952. (format (plist-get info :latex-active-timestamp-format)
  1953. (org-timestamp-translate scheduled)))))))
  1954. " ")
  1955. "\\\\"))
  1956. ;;;; Property Drawer
  1957. (defun org-latex-property-drawer (property-drawer contents info)
  1958. "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
  1959. CONTENTS holds the contents of the drawer. INFO is a plist
  1960. holding contextual information."
  1961. (and (org-string-nw-p contents)
  1962. (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
  1963. ;;;; Pseudo Element: LaTeX Matrices
  1964. ;; `latex-matrices' elements have the following properties:
  1965. ;; `:caption', `:post-blank' and `:markup' (`inline', `equation' or
  1966. ;; `math').
  1967. (defun org-latex--wrap-latex-matrices (data info)
  1968. "Merge contiguous tables with the same mode within a pseudo-element.
  1969. DATA is a parse tree or a secondary string. INFO is a plist
  1970. containing export options. Modify DATA by side-effect and return
  1971. it."
  1972. (org-element-map data 'table
  1973. (lambda (table)
  1974. (when (eq (org-element-property :type table) 'org)
  1975. (let ((mode (or (org-export-read-attribute :attr_latex table :mode)
  1976. (plist-get info :latex-default-table-mode))))
  1977. (when (and (member mode '("inline-math" "math"))
  1978. ;; Do not wrap twice the same table.
  1979. (not (eq (org-element-type
  1980. (org-element-property :parent table))
  1981. 'latex-matrices)))
  1982. (let* ((caption (and (not (string= mode "inline-math"))
  1983. (org-element-property :caption table)))
  1984. (matrices
  1985. (list 'latex-matrices
  1986. (list :caption caption
  1987. :markup
  1988. (cond ((string= mode "inline-math") 'inline)
  1989. (caption 'equation)
  1990. (t 'math)))))
  1991. (previous table)
  1992. (next (org-export-get-next-element table info)))
  1993. (org-element-insert-before matrices table)
  1994. ;; Swallow all contiguous tables sharing the same mode.
  1995. (while (and
  1996. (zerop (or (org-element-property :post-blank previous) 0))
  1997. (setq next (org-export-get-next-element previous info))
  1998. (eq (org-element-type next) 'table)
  1999. (eq (org-element-property :type next) 'org)
  2000. (string= (or (org-export-read-attribute
  2001. :attr_latex next :mode)
  2002. (plist-get info :latex-default-table-mode))
  2003. mode))
  2004. (org-element-extract-element previous)
  2005. (org-element-adopt-elements matrices previous)
  2006. (setq previous next))
  2007. (org-element-put-property
  2008. matrices :post-blank (org-element-property :post-blank previous))
  2009. (org-element-extract-element previous)
  2010. (org-element-adopt-elements matrices previous))))))
  2011. info)
  2012. data)
  2013. (defun org-latex-matrices (matrices contents info)
  2014. "Transcode a MATRICES element from Org to LaTeX.
  2015. CONTENTS is a string. INFO is a plist used as a communication
  2016. channel."
  2017. (format (case (org-element-property :markup matrices)
  2018. (inline "\\(%s\\)")
  2019. (equation "\\begin{equation}\n%s\\end{equation}")
  2020. (t "\\[\n%s\\]"))
  2021. contents))
  2022. (defun org-latex-matrices-tree-filter (tree backend info)
  2023. (org-latex--wrap-latex-matrices tree info))
  2024. ;;;; Pseudo Object: LaTeX Math Block
  2025. ;; `latex-math-block' objects have the following property:
  2026. ;; `:post-blank'.
  2027. (defun org-latex--wrap-latex-math-block (data info)
  2028. "Merge contiguous math objects in a pseudo-object container.
  2029. DATA is a parse tree or a secondary string. INFO is a plist
  2030. containing export options. Modify DATA by side-effect and return it."
  2031. (let ((valid-object-p
  2032. (function
  2033. ;; Non-nil when OBJ can be added to the latex math block.
  2034. (lambda (obj)
  2035. (case (org-element-type obj)
  2036. (entity (org-element-property :latex-math-p obj))
  2037. (latex-fragment
  2038. (let ((value (org-element-property :value obj)))
  2039. (or (org-string-match-p "\\`\\\\([^\000]*\\\\)\\'" value)
  2040. (org-string-match-p "\\`\\$[^\000]*\\$\\'" value))))
  2041. ((subscript superscript) t))))))
  2042. (org-element-map data '(entity latex-fragment subscript superscript)
  2043. (lambda (object)
  2044. ;; Skip objects already wrapped.
  2045. (when (and (not (eq (org-element-type
  2046. (org-element-property :parent object))
  2047. 'latex-math-block))
  2048. (funcall valid-object-p object))
  2049. (let ((math-block (list 'latex-math-block nil))
  2050. (next-elements (org-export-get-next-element object info t))
  2051. (last object))
  2052. ;; Wrap MATH-BLOCK around OBJECT in DATA.
  2053. (org-element-insert-before math-block object)
  2054. (org-element-extract-element object)
  2055. (org-element-adopt-elements math-block object)
  2056. (when (zerop (or (org-element-property :post-blank object) 0))
  2057. ;; MATH-BLOCK swallows consecutive math objects.
  2058. (catch 'exit
  2059. (dolist (next next-elements)
  2060. (if (not (funcall valid-object-p next)) (throw 'exit nil)
  2061. (org-element-extract-element next)
  2062. (org-element-adopt-elements math-block next)
  2063. ;; Eschew the case: \beta$x$ -> \(\betax\).
  2064. (unless (memq (org-element-type next)
  2065. '(subscript superscript))
  2066. (org-element-put-property last :post-blank 1))
  2067. (setq last next)
  2068. (when (> (or (org-element-property :post-blank next) 0) 0)
  2069. (throw 'exit nil))))))
  2070. (org-element-put-property
  2071. math-block :post-blank (org-element-property :post-blank last)))))
  2072. info nil '(subscript superscript latex-math-block) t)
  2073. ;; Return updated DATA.
  2074. data))
  2075. (defun org-latex-math-block-tree-filter (tree backend info)
  2076. (org-latex--wrap-latex-math-block tree info))
  2077. (defun org-latex-math-block-options-filter (info backend)
  2078. (dolist (prop '(:author :date :title) info)
  2079. (plist-put info prop
  2080. (org-latex--wrap-latex-math-block (plist-get info prop) info))))
  2081. (defun org-latex-math-block (math-block contents info)
  2082. "Transcode a MATH-BLOCK object from Org to LaTeX.
  2083. CONTENTS is a string. INFO is a plist used as a communication
  2084. channel."
  2085. (when (org-string-nw-p contents)
  2086. (format "\\(%s\\)" (org-trim contents))))
  2087. ;;;; Quote Block
  2088. (defun org-latex-quote-block (quote-block contents info)
  2089. "Transcode a QUOTE-BLOCK element from Org to LaTeX.
  2090. CONTENTS holds the contents of the block. INFO is a plist
  2091. holding contextual information."
  2092. (org-latex--wrap-label
  2093. quote-block (format "\\begin{quote}\n%s\\end{quote}" contents) info))
  2094. ;;;; Radio Target
  2095. (defun org-latex-radio-target (radio-target text info)
  2096. "Transcode a RADIO-TARGET object from Org to LaTeX.
  2097. TEXT is the text of the target. INFO is a plist holding
  2098. contextual information."
  2099. (format "\\label{%s}%s" (org-export-get-reference radio-target info) text))
  2100. ;;;; Section
  2101. (defun org-latex-section (section contents info)
  2102. "Transcode a SECTION element from Org to LaTeX.
  2103. CONTENTS holds the contents of the section. INFO is a plist
  2104. holding contextual information."
  2105. contents)
  2106. ;;;; Special Block
  2107. (defun org-latex-special-block (special-block contents info)
  2108. "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
  2109. CONTENTS holds the contents of the block. INFO is a plist
  2110. holding contextual information."
  2111. (let ((type (org-element-property :type special-block))
  2112. (opt (org-export-read-attribute :attr_latex special-block :options))
  2113. (caption (org-latex--caption/label-string special-block info))
  2114. (caption-above-p (org-latex--caption-above-p special-block info)))
  2115. (concat (format "\\begin{%s}%s\n" type (or opt ""))
  2116. (and caption-above-p caption)
  2117. contents
  2118. (and (not caption-above-p) caption)
  2119. (format "\\end{%s}" type))))
  2120. ;;;; Src Block
  2121. (defun org-latex-src-block (src-block contents info)
  2122. "Transcode a SRC-BLOCK element from Org to LaTeX.
  2123. CONTENTS holds the contents of the item. INFO is a plist holding
  2124. contextual information."
  2125. (when (org-string-nw-p (org-element-property :value src-block))
  2126. (let* ((lang (org-element-property :language src-block))
  2127. (caption (org-element-property :caption src-block))
  2128. (caption-above-p (org-latex--caption-above-p src-block info))
  2129. (label (org-element-property :name src-block))
  2130. (custom-env (and lang
  2131. (cadr (assq (intern lang)
  2132. org-latex-custom-lang-environments))))
  2133. (num-start (case (org-element-property :number-lines src-block)
  2134. (continued (org-export-get-loc src-block info))
  2135. (new 0)))
  2136. (retain-labels (org-element-property :retain-labels src-block))
  2137. (attributes (org-export-read-attribute :attr_latex src-block))
  2138. (float (plist-get attributes :float))
  2139. (listings (plist-get info :latex-listings)))
  2140. (cond
  2141. ;; Case 1. No source fontification.
  2142. ((not listings)
  2143. (let* ((caption-str (org-latex--caption/label-string src-block info))
  2144. (float-env
  2145. (cond ((and (not float) (plist-member attributes :float)) "%s")
  2146. ((string= "multicolumn" float)
  2147. (format "\\begin{figure*}[%s]\n%s%%s\n%s\\end{figure*}"
  2148. (plist-get info :latex-default-figure-position)
  2149. (if caption-above-p caption-str "")
  2150. (if caption-above-p "" caption-str)))
  2151. ((or caption float)
  2152. (format "\\begin{figure}[H]\n%%s\n%s\\end{figure}"
  2153. caption-str))
  2154. (t "%s"))))
  2155. (format
  2156. float-env
  2157. (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
  2158. (org-export-format-code-default src-block info))))))
  2159. ;; Case 2. Custom environment.
  2160. (custom-env
  2161. (let ((caption-str (org-latex--caption/label-string src-block info)))
  2162. (format "\\begin{%s}\n%s\\end{%s}\n"
  2163. custom-env
  2164. (concat (and caption-above-p caption-str)
  2165. (org-export-format-code-default src-block info)
  2166. (and (not caption-above-p) caption-str))
  2167. custom-env)))
  2168. ;; Case 3. Use minted package.
  2169. ((eq listings 'minted)
  2170. (let* ((caption-str (org-latex--caption/label-string src-block info))
  2171. (float-env
  2172. (cond
  2173. ((and (not float) (plist-member attributes :float) caption)
  2174. (let ((caption
  2175. (replace-regexp-in-string
  2176. "\\\\caption" "\\captionof{listing}" caption-str
  2177. t t)))
  2178. (concat (and caption-above-p caption)
  2179. "%%s"
  2180. (and (not caption-above-p) (concat "\n" caption)))))
  2181. ((and (not float) (plist-member attributes :float)) "%s")
  2182. ((string= "multicolumn" float)
  2183. (format "\\begin{listing*}\n%s%%s\n%s\\end{listing*}"
  2184. (if caption-above-p caption-str "")
  2185. (if caption-above-p "" caption-str)))
  2186. ((or caption float)
  2187. (format "\\begin{listing}[H]\n%s%%s\n%s\\end{listing}"
  2188. (if caption-above-p caption-str "")
  2189. (if caption-above-p "" caption-str)))
  2190. (t "%s")))
  2191. (options (plist-get info :latex-minted-options))
  2192. (body
  2193. (format
  2194. "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
  2195. ;; Options.
  2196. (concat
  2197. (org-latex--make-option-string
  2198. (if (or (not num-start) (assoc "linenos" options))
  2199. options
  2200. (append
  2201. `(("linenos")
  2202. ("firstnumber" ,(number-to-string (1+ num-start))))
  2203. options)))
  2204. (let ((local-options (plist-get attributes :options)))
  2205. (and local-options (concat "," local-options))))
  2206. ;; Language.
  2207. (or (cadr (assq (intern lang)
  2208. (plist-get info :latex-minted-langs)))
  2209. (downcase lang))
  2210. ;; Source code.
  2211. (let* ((code-info (org-export-unravel-code src-block))
  2212. (max-width
  2213. (apply 'max
  2214. (mapcar 'length
  2215. (org-split-string (car code-info)
  2216. "\n")))))
  2217. (org-export-format-code
  2218. (car code-info)
  2219. (lambda (loc num ref)
  2220. (concat
  2221. loc
  2222. (when ref
  2223. ;; Ensure references are flushed to the right,
  2224. ;; separated with 6 spaces from the widest line
  2225. ;; of code.
  2226. (concat (make-string (+ (- max-width (length loc)) 6)
  2227. ?\s)
  2228. (format "(%s)" ref)))))
  2229. nil (and retain-labels (cdr code-info)))))))
  2230. ;; Return value.
  2231. (format float-env body)))
  2232. ;; Case 4. Use listings package.
  2233. (t
  2234. (let ((lst-lang
  2235. (or (cadr (assq (intern lang)
  2236. (plist-get info :latex-listings-langs)))
  2237. lang))
  2238. (caption-str
  2239. (when caption
  2240. (let ((main (org-export-get-caption src-block))
  2241. (secondary (org-export-get-caption src-block t)))
  2242. (if (not secondary)
  2243. (format "{%s}" (org-export-data main info))
  2244. (format "{[%s]%s}"
  2245. (org-export-data secondary info)
  2246. (org-export-data main info))))))
  2247. (lst-opt (plist-get info :latex-listings-options)))
  2248. (concat
  2249. ;; Options.
  2250. (format
  2251. "\\lstset{%s}\n"
  2252. (concat
  2253. (org-latex--make-option-string
  2254. (append
  2255. lst-opt
  2256. (cond
  2257. ((and (not float) (plist-member attributes :float)) nil)
  2258. ((string= "multicolumn" float) '(("float" "*")))
  2259. ((and float (not (assoc "float" lst-opt)))
  2260. `(("float" ,(plist-get info :latex-default-figure-position)))))
  2261. `(("language" ,lst-lang))
  2262. (if label `(("label" ,label)) '(("label" " ")))
  2263. (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
  2264. `(("captionpos" ,(if caption-above-p "t" "b")))
  2265. (cond ((assoc "numbers" lst-opt) nil)
  2266. ((not num-start) '(("numbers" "none")))
  2267. ((zerop num-start) '(("numbers" "left")))
  2268. (t `(("firstnumber" ,(number-to-string (1+ num-start)))
  2269. ("numbers" "left"))))))
  2270. (let ((local-options (plist-get attributes :options)))
  2271. (and local-options (concat "," local-options)))))
  2272. ;; Source code.
  2273. (format
  2274. "\\begin{lstlisting}\n%s\\end{lstlisting}"
  2275. (let* ((code-info (org-export-unravel-code src-block))
  2276. (max-width
  2277. (apply 'max
  2278. (mapcar 'length
  2279. (org-split-string (car code-info) "\n")))))
  2280. (org-export-format-code
  2281. (car code-info)
  2282. (lambda (loc num ref)
  2283. (concat
  2284. loc
  2285. (when ref
  2286. ;; Ensure references are flushed to the right,
  2287. ;; separated with 6 spaces from the widest line of
  2288. ;; code
  2289. (concat (make-string (+ (- max-width (length loc)) 6) ? )
  2290. (format "(%s)" ref)))))
  2291. nil (and retain-labels (cdr code-info))))))))))))
  2292. ;;;; Statistics Cookie
  2293. (defun org-latex-statistics-cookie (statistics-cookie contents info)
  2294. "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
  2295. CONTENTS is nil. INFO is a plist holding contextual information."
  2296. (replace-regexp-in-string
  2297. "%" "\\%" (org-element-property :value statistics-cookie) nil t))
  2298. ;;;; Strike-Through
  2299. (defun org-latex-strike-through (strike-through contents info)
  2300. "Transcode STRIKE-THROUGH from Org to LaTeX.
  2301. CONTENTS is the text with strike-through markup. INFO is a plist
  2302. holding contextual information."
  2303. (org-latex--text-markup contents 'strike-through info))
  2304. ;;;; Subscript
  2305. (defun org-latex--script-size (object info)
  2306. "Transcode a subscript or superscript object.
  2307. OBJECT is an Org object. INFO is a plist used as a communication
  2308. channel."
  2309. (let ((type (org-element-type object))
  2310. (output ""))
  2311. (org-element-map (org-element-contents object)
  2312. (cons 'plain-text org-element-all-objects)
  2313. (lambda (obj)
  2314. (case (org-element-type obj)
  2315. ((entity latex-fragment)
  2316. (let ((data (org-trim (org-export-data obj info))))
  2317. (string-match
  2318. "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
  2319. data)
  2320. (setq output
  2321. (concat output
  2322. (match-string 1 data)
  2323. (let ((blank (org-element-property :post-blank obj)))
  2324. (and blank (> blank 0) "\\ "))))))
  2325. (plain-text
  2326. (setq output
  2327. (format "%s\\text{%s}" output (org-export-data obj info))))
  2328. (otherwise
  2329. (setq output
  2330. (concat output
  2331. (org-export-data obj info)
  2332. (let ((blank (org-element-property :post-blank obj)))
  2333. (and blank (> blank 0) "\\ ")))))))
  2334. info nil org-element-recursive-objects)
  2335. ;; Result. Do not wrap into curly brackets if OUTPUT is a single
  2336. ;; character.
  2337. (concat (if (eq (org-element-type object) 'subscript) "_" "^")
  2338. (and (> (length output) 1) "{")
  2339. output
  2340. (and (> (length output) 1) "}"))))
  2341. (defun org-latex-subscript (subscript contents info)
  2342. "Transcode a SUBSCRIPT object from Org to LaTeX.
  2343. CONTENTS is the contents of the object. INFO is a plist holding
  2344. contextual information."
  2345. (org-latex--script-size subscript info))
  2346. ;;;; Superscript
  2347. (defun org-latex-superscript (superscript contents info)
  2348. "Transcode a SUPERSCRIPT object from Org to LaTeX.
  2349. CONTENTS is the contents of the object. INFO is a plist holding
  2350. contextual information."
  2351. (org-latex--script-size superscript info))
  2352. ;;;; Table
  2353. ;;
  2354. ;; `org-latex-table' is the entry point for table transcoding. It
  2355. ;; takes care of tables with a "verbatim" mode. Otherwise, it
  2356. ;; delegates the job to either `org-latex--table.el-table',
  2357. ;; `org-latex--org-table' or `org-latex--math-table' functions,
  2358. ;; depending of the type of the table and the mode requested.
  2359. ;;
  2360. ;; `org-latex--align-string' is a subroutine used to build alignment
  2361. ;; string for Org tables.
  2362. (defun org-latex-table (table contents info)
  2363. "Transcode a TABLE element from Org to LaTeX.
  2364. CONTENTS is the contents of the table. INFO is a plist holding
  2365. contextual information."
  2366. (if (eq (org-element-property :type table) 'table.el)
  2367. ;; "table.el" table. Convert it using appropriate tools.
  2368. (org-latex--table.el-table table info)
  2369. (let ((type (or (org-export-read-attribute :attr_latex table :mode)
  2370. (plist-get info :latex-default-table-mode))))
  2371. (cond
  2372. ;; Case 1: Verbatim table.
  2373. ((string= type "verbatim")
  2374. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  2375. ;; Re-create table, without affiliated keywords.
  2376. (org-trim (org-element-interpret-data
  2377. `(table nil ,@(org-element-contents table))))))
  2378. ;; Case 2: Matrix.
  2379. ((or (string= type "math") (string= type "inline-math"))
  2380. (org-latex--math-table table info))
  2381. ;; Case 3: Standard table.
  2382. (t (concat (org-latex--org-table table contents info)
  2383. ;; When there are footnote references within the
  2384. ;; table, insert their definition just after it.
  2385. (org-latex--delayed-footnotes-definitions table info)))))))
  2386. (defun org-latex--align-string (table info)
  2387. "Return an appropriate LaTeX alignment string.
  2388. TABLE is the considered table. INFO is a plist used as
  2389. a communication channel."
  2390. (or (org-export-read-attribute :attr_latex table :align)
  2391. (let (align)
  2392. ;; Extract column groups and alignment from first (non-rule)
  2393. ;; row.
  2394. (org-element-map
  2395. (org-element-map table 'table-row
  2396. (lambda (row)
  2397. (and (eq (org-element-property :type row) 'standard) row))
  2398. info 'first-match)
  2399. 'table-cell
  2400. (lambda (cell)
  2401. (let ((borders (org-export-table-cell-borders cell info)))
  2402. ;; Check left border for the first cell only.
  2403. (when (and (memq 'left borders) (not align))
  2404. (push "|" align))
  2405. (push (case (org-export-table-cell-alignment cell info)
  2406. (left "l")
  2407. (right "r")
  2408. (center "c"))
  2409. align)
  2410. (when (memq 'right borders) (push "|" align))))
  2411. info)
  2412. (apply 'concat (nreverse align)))))
  2413. (defun org-latex--org-table (table contents info)
  2414. "Return appropriate LaTeX code for an Org table.
  2415. TABLE is the table type element to transcode. CONTENTS is its
  2416. contents, as a string. INFO is a plist used as a communication
  2417. channel.
  2418. This function assumes TABLE has `org' as its `:type' property and
  2419. `table' as its `:mode' attribute."
  2420. (let* ((caption (org-latex--caption/label-string table info))
  2421. (attr (org-export-read-attribute :attr_latex table))
  2422. ;; Determine alignment string.
  2423. (alignment (org-latex--align-string table info))
  2424. ;; Determine environment for the table: longtable, tabular...
  2425. (table-env (or (plist-get attr :environment)
  2426. (plist-get info :latex-default-table-environment)))
  2427. ;; If table is a float, determine environment: table, table*
  2428. ;; or sidewaystable.
  2429. (float-env (unless (member table-env '("longtable" "longtabu"))
  2430. (let ((float (plist-get attr :float)))
  2431. (cond
  2432. ((and (not float) (plist-member attr :float)) nil)
  2433. ((or (string= float "sidewaystable")
  2434. (string= float "sideways")) "sidewaystable")
  2435. ((string= float "multicolumn") "table*")
  2436. ((or float
  2437. (org-element-property :caption table)
  2438. (org-string-nw-p (plist-get attr :caption)))
  2439. "table")))))
  2440. ;; Extract others display options.
  2441. (fontsize (let ((font (plist-get attr :font)))
  2442. (and font (concat font "\n"))))
  2443. ;; "tabular" environment doesn't allow to define a width.
  2444. (width (and (not (equal table-env "tabular")) (plist-get attr :width)))
  2445. (spreadp (plist-get attr :spread))
  2446. (placement
  2447. (or (plist-get attr :placement)
  2448. (format "[%s]" (plist-get info :latex-default-figure-position))))
  2449. (centerp (if (plist-member attr :center) (plist-get attr :center)
  2450. (plist-get info :latex-tables-centered)))
  2451. (caption-above-p (org-latex--caption-above-p table info)))
  2452. ;; Prepare the final format string for the table.
  2453. (cond
  2454. ;; Longtable.
  2455. ((equal "longtable" table-env)
  2456. (concat (and fontsize (concat "{" fontsize))
  2457. (format "\\begin{longtable}{%s}\n" alignment)
  2458. (and caption-above-p
  2459. (org-string-nw-p caption)
  2460. (concat caption "\\\\\n"))
  2461. contents
  2462. (and (not caption-above-p)
  2463. (org-string-nw-p caption)
  2464. (concat caption "\\\\\n"))
  2465. "\\end{longtable}\n"
  2466. (and fontsize "}")))
  2467. ;; Longtabu
  2468. ((equal "longtabu" table-env)
  2469. (concat (and fontsize (concat "{" fontsize))
  2470. (format "\\begin{longtabu}%s{%s}\n"
  2471. (if width
  2472. (format " %s %s "
  2473. (if spreadp "spread" "to") width) "")
  2474. alignment)
  2475. (and caption-above-p
  2476. (org-string-nw-p caption)
  2477. (concat caption "\\\\\n"))
  2478. contents
  2479. (and (not caption-above-p)
  2480. (org-string-nw-p caption)
  2481. (concat caption "\\\\\n"))
  2482. "\\end{longtabu}\n"
  2483. (and fontsize "}")))
  2484. ;; Others.
  2485. (t (concat (cond
  2486. (float-env
  2487. (concat (format "\\begin{%s}%s\n" float-env placement)
  2488. (if caption-above-p caption "")
  2489. (when centerp "\\centering\n")
  2490. fontsize))
  2491. (centerp (concat "\\begin{center}\n" fontsize))
  2492. (fontsize (concat "{" fontsize)))
  2493. (cond ((equal "tabu" table-env)
  2494. (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
  2495. (if width (format
  2496. (if spreadp " spread %s " " to %s ")
  2497. width) "")
  2498. alignment
  2499. contents))
  2500. (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
  2501. table-env
  2502. (if width (format "{%s}" width) "")
  2503. alignment
  2504. contents
  2505. table-env)))
  2506. (cond
  2507. (float-env
  2508. (concat (if caption-above-p "" caption)
  2509. (format "\n\\end{%s}" float-env)))
  2510. (centerp "\n\\end{center}")
  2511. (fontsize "}")))))))
  2512. (defun org-latex--table.el-table (table info)
  2513. "Return appropriate LaTeX code for a table.el table.
  2514. TABLE is the table type element to transcode. INFO is a plist
  2515. used as a communication channel.
  2516. This function assumes TABLE has `table.el' as its `:type'
  2517. property."
  2518. (require 'table)
  2519. ;; Ensure "*org-export-table*" buffer is empty.
  2520. (with-current-buffer (get-buffer-create "*org-export-table*")
  2521. (erase-buffer))
  2522. (let ((output (with-temp-buffer
  2523. (insert (org-element-property :value table))
  2524. (goto-char 1)
  2525. (re-search-forward "^[ \t]*|[^|]" nil t)
  2526. (table-generate-source 'latex "*org-export-table*")
  2527. (with-current-buffer "*org-export-table*"
  2528. (org-trim (buffer-string))))))
  2529. (kill-buffer (get-buffer "*org-export-table*"))
  2530. ;; Remove left out comments.
  2531. (while (string-match "^%.*\n" output)
  2532. (setq output (replace-match "" t t output)))
  2533. (let ((attr (org-export-read-attribute :attr_latex table)))
  2534. (when (plist-get attr :rmlines)
  2535. ;; When the "rmlines" attribute is provided, remove all hlines
  2536. ;; but the the one separating heading from the table body.
  2537. (let ((n 0) (pos 0))
  2538. (while (and (< (length output) pos)
  2539. (setq pos (string-match "^\\\\hline\n?" output pos)))
  2540. (incf n)
  2541. (unless (= n 2) (setq output (replace-match "" nil nil output))))))
  2542. (let ((centerp (if (plist-member attr :center) (plist-get attr :center)
  2543. (plist-get info :latex-tables-centered))))
  2544. (if (not centerp) output
  2545. (format "\\begin{center}\n%s\n\\end{center}" output))))))
  2546. (defun org-latex--math-table (table info)
  2547. "Return appropriate LaTeX code for a matrix.
  2548. TABLE is the table type element to transcode. INFO is a plist
  2549. used as a communication channel.
  2550. This function assumes TABLE has `org' as its `:type' property and
  2551. `inline-math' or `math' as its `:mode' attribute."
  2552. (let* ((attr (org-export-read-attribute :attr_latex table))
  2553. (env (or (plist-get attr :environment)
  2554. (plist-get info :latex-default-table-environment)))
  2555. (contents
  2556. (mapconcat
  2557. (lambda (row)
  2558. ;; Ignore horizontal rules.
  2559. (when (eq (org-element-property :type row) 'standard)
  2560. ;; Return each cell unmodified.
  2561. (concat
  2562. (mapconcat
  2563. (lambda (cell)
  2564. (substring (org-element-interpret-data cell) 0 -1))
  2565. (org-element-map row 'table-cell #'identity info) "&")
  2566. (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
  2567. "\n")))
  2568. (org-element-map table 'table-row #'identity info) "")))
  2569. (concat
  2570. ;; Prefix.
  2571. (plist-get attr :math-prefix)
  2572. ;; Environment. Also treat special cases.
  2573. (cond ((member env '("array" "tabular"))
  2574. (let ((align (make-string
  2575. (cdr (org-export-table-dimensions table info)) ?c)))
  2576. (format "\\begin{%s}{%s}\n%s\\end{%s}" env align contents env)))
  2577. ((assoc env org-latex-table-matrix-macros)
  2578. (format "\\%s%s{\n%s}"
  2579. env
  2580. (or (plist-get attr :math-arguments) "")
  2581. contents))
  2582. (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
  2583. ;; Suffix.
  2584. (plist-get attr :math-suffix))))
  2585. ;;;; Table Cell
  2586. (defun org-latex-table-cell (table-cell contents info)
  2587. "Transcode a TABLE-CELL element from Org to LaTeX.
  2588. CONTENTS is the cell contents. INFO is a plist used as
  2589. a communication channel."
  2590. (concat
  2591. (let ((scientific-format (plist-get info :latex-table-scientific-notation)))
  2592. (if (and contents
  2593. scientific-format
  2594. (string-match orgtbl-exp-regexp contents))
  2595. ;; Use appropriate format string for scientific
  2596. ;; notation.
  2597. (format scientific-format
  2598. (match-string 1 contents)
  2599. (match-string 2 contents))
  2600. contents))
  2601. (when (org-export-get-next-element table-cell info) " & ")))
  2602. ;;;; Table Row
  2603. (defun org-latex-table-row (table-row contents info)
  2604. "Transcode a TABLE-ROW element from Org to LaTeX.
  2605. CONTENTS is the contents of the row. INFO is a plist used as
  2606. a communication channel."
  2607. (let* ((attr (org-export-read-attribute :attr_latex
  2608. (org-export-get-parent table-row)))
  2609. (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
  2610. (plist-get info :latex-tables-booktabs)))
  2611. (longtablep
  2612. (member (or (plist-get attr :environment)
  2613. (plist-get info :latex-default-table-environment))
  2614. '("longtable" "longtabu"))))
  2615. (if (eq (org-element-property :type table-row) 'rule)
  2616. (cond
  2617. ((not booktabsp) "\\hline")
  2618. ((not (org-export-get-previous-element table-row info)) "\\toprule")
  2619. ((not (org-export-get-next-element table-row info)) "\\bottomrule")
  2620. ((and longtablep
  2621. (org-export-table-row-ends-header-p
  2622. (org-export-get-previous-element table-row info) info))
  2623. "")
  2624. (t "\\midrule"))
  2625. (concat
  2626. ;; When BOOKTABS are activated enforce top-rule even when no
  2627. ;; hline was specifically marked.
  2628. (and booktabsp (not (org-export-get-previous-element table-row info))
  2629. "\\toprule\n")
  2630. contents "\\\\\n"
  2631. (cond
  2632. ;; Special case for long tables. Define header and footers.
  2633. ((and longtablep (org-export-table-row-ends-header-p table-row info))
  2634. (let ((columns (cdr (org-export-table-dimensions
  2635. (org-export-get-parent-table table-row) info))))
  2636. (format "%s
  2637. \\endfirsthead
  2638. \\multicolumn{%d}{l}{%s} \\\\
  2639. %s
  2640. %s \\\\\n
  2641. %s
  2642. \\endhead
  2643. %s\\multicolumn{%d}{r}{%s} \\\\
  2644. \\endfoot
  2645. \\endlastfoot"
  2646. (if booktabsp "\\midrule" "\\hline")
  2647. columns
  2648. (org-latex--translate "Continued from previous page" info)
  2649. (cond
  2650. ((not (org-export-table-row-starts-header-p table-row info))
  2651. "")
  2652. (booktabsp "\\toprule\n")
  2653. (t "\\hline\n"))
  2654. contents
  2655. (if booktabsp "\\midrule" "\\hline")
  2656. (if booktabsp "\\midrule" "\\hline")
  2657. columns
  2658. (org-latex--translate "Continued on next page" info))))
  2659. ;; When BOOKTABS are activated enforce bottom rule even when
  2660. ;; no hline was specifically marked.
  2661. ((and booktabsp (not (org-export-get-next-element table-row info)))
  2662. "\\bottomrule"))))))
  2663. ;;;; Target
  2664. (defun org-latex-target (target contents info)
  2665. "Transcode a TARGET object from Org to LaTeX.
  2666. CONTENTS is nil. INFO is a plist holding contextual
  2667. information."
  2668. (format "\\label{%s}" (org-export-get-reference target info)))
  2669. ;;;; Timestamp
  2670. (defun org-latex-timestamp (timestamp contents info)
  2671. "Transcode a TIMESTAMP object from Org to LaTeX.
  2672. CONTENTS is nil. INFO is a plist holding contextual
  2673. information."
  2674. (let ((value (org-latex-plain-text (org-timestamp-translate timestamp) info)))
  2675. (format
  2676. (plist-get info
  2677. (case (org-element-property :type timestamp)
  2678. ((active active-range) :latex-active-timestamp-format)
  2679. ((inactive inactive-range) :latex-inactive-timestamp-format)
  2680. (otherwise :latex-diary-timestamp-format)))
  2681. value)))
  2682. ;;;; Underline
  2683. (defun org-latex-underline (underline contents info)
  2684. "Transcode UNDERLINE from Org to LaTeX.
  2685. CONTENTS is the text with underline markup. INFO is a plist
  2686. holding contextual information."
  2687. (org-latex--text-markup contents 'underline info))
  2688. ;;;; Verbatim
  2689. (defun org-latex-verbatim (verbatim contents info)
  2690. "Transcode a VERBATIM object from Org to LaTeX.
  2691. CONTENTS is nil. INFO is a plist used as a communication
  2692. channel."
  2693. (org-latex--text-markup
  2694. (org-element-property :value verbatim) 'verbatim info))
  2695. ;;;; Verse Block
  2696. (defun org-latex-verse-block (verse-block contents info)
  2697. "Transcode a VERSE-BLOCK element from Org to LaTeX.
  2698. CONTENTS is verse block contents. INFO is a plist holding
  2699. contextual information."
  2700. (org-latex--wrap-label
  2701. verse-block
  2702. ;; In a verse environment, add a line break to each newline
  2703. ;; character and change each white space at beginning of a line
  2704. ;; into a space of 1 em. Also change each blank line with
  2705. ;; a vertical space of 1 em.
  2706. (format "\\begin{verse}\n%s\\end{verse}"
  2707. (replace-regexp-in-string
  2708. "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
  2709. (replace-regexp-in-string
  2710. "^[ \t]*\\\\\\\\$" "\\vspace*{1em}"
  2711. (replace-regexp-in-string
  2712. "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n"
  2713. contents nil t) nil t) nil t))
  2714. info))
  2715. ;;; End-user functions
  2716. ;;;###autoload
  2717. (defun org-latex-export-as-latex
  2718. (&optional async subtreep visible-only body-only ext-plist)
  2719. "Export current buffer as a LaTeX buffer.
  2720. If narrowing is active in the current buffer, only export its
  2721. narrowed part.
  2722. If a region is active, export that region.
  2723. A non-nil optional argument ASYNC means the process should happen
  2724. asynchronously. The resulting buffer should be accessible
  2725. through the `org-export-stack' interface.
  2726. When optional argument SUBTREEP is non-nil, export the sub-tree
  2727. at point, extracting information from the headline properties
  2728. first.
  2729. When optional argument VISIBLE-ONLY is non-nil, don't export
  2730. contents of hidden elements.
  2731. When optional argument BODY-ONLY is non-nil, only write code
  2732. between \"\\begin{document}\" and \"\\end{document}\".
  2733. EXT-PLIST, when provided, is a property list with external
  2734. parameters overriding Org default settings, but still inferior to
  2735. file-local settings.
  2736. Export is done in a buffer named \"*Org LATEX Export*\", which
  2737. will be displayed when `org-export-show-temporary-export-buffer'
  2738. is non-nil."
  2739. (interactive)
  2740. (org-export-to-buffer 'latex "*Org LATEX Export*"
  2741. async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
  2742. ;;;###autoload
  2743. (defun org-latex-convert-region-to-latex ()
  2744. "Assume the current region has org-mode syntax, and convert it to LaTeX.
  2745. This can be used in any buffer. For example, you can write an
  2746. itemized list in org-mode syntax in an LaTeX buffer and use this
  2747. command to convert it."
  2748. (interactive)
  2749. (org-export-replace-region-by 'latex))
  2750. ;;;###autoload
  2751. (defun org-latex-export-to-latex
  2752. (&optional async subtreep visible-only body-only ext-plist)
  2753. "Export current buffer to a LaTeX file.
  2754. If narrowing is active in the current buffer, only export its
  2755. narrowed part.
  2756. If a region is active, export that region.
  2757. A non-nil optional argument ASYNC means the process should happen
  2758. asynchronously. The resulting file should be accessible through
  2759. the `org-export-stack' interface.
  2760. When optional argument SUBTREEP is non-nil, export the sub-tree
  2761. at point, extracting information from the headline properties
  2762. first.
  2763. When optional argument VISIBLE-ONLY is non-nil, don't export
  2764. contents of hidden elements.
  2765. When optional argument BODY-ONLY is non-nil, only write code
  2766. between \"\\begin{document}\" and \"\\end{document}\".
  2767. EXT-PLIST, when provided, is a property list with external
  2768. parameters overriding Org default settings, but still inferior to
  2769. file-local settings."
  2770. (interactive)
  2771. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  2772. (org-export-to-file 'latex outfile
  2773. async subtreep visible-only body-only ext-plist)))
  2774. ;;;###autoload
  2775. (defun org-latex-export-to-pdf
  2776. (&optional async subtreep visible-only body-only ext-plist)
  2777. "Export current buffer to LaTeX then process through to PDF.
  2778. If narrowing is active in the current buffer, only export its
  2779. narrowed part.
  2780. If a region is active, export that region.
  2781. A non-nil optional argument ASYNC means the process should happen
  2782. asynchronously. The resulting file should be accessible through
  2783. the `org-export-stack' interface.
  2784. When optional argument SUBTREEP is non-nil, export the sub-tree
  2785. at point, extracting information from the headline properties
  2786. first.
  2787. When optional argument VISIBLE-ONLY is non-nil, don't export
  2788. contents of hidden elements.
  2789. When optional argument BODY-ONLY is non-nil, only write code
  2790. between \"\\begin{document}\" and \"\\end{document}\".
  2791. EXT-PLIST, when provided, is a property list with external
  2792. parameters overriding Org default settings, but still inferior to
  2793. file-local settings.
  2794. Return PDF file's name."
  2795. (interactive)
  2796. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  2797. (org-export-to-file 'latex outfile
  2798. async subtreep visible-only body-only ext-plist
  2799. (lambda (file) (org-latex-compile file)))))
  2800. (defun org-latex-compile (texfile &optional snippet)
  2801. "Compile a TeX file.
  2802. TEXFILE is the name of the file being compiled. Processing is
  2803. done through the command specified in `org-latex-pdf-process'.
  2804. When optional argument SNIPPET is non-nil, TEXFILE is a temporary
  2805. file used to preview a LaTeX snippet. In this case, do not
  2806. create a log buffer and do not bother removing log files.
  2807. Return PDF file name or an error if it couldn't be produced."
  2808. (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile)))
  2809. (full-name (file-truename texfile))
  2810. (out-dir (file-name-directory texfile))
  2811. ;; Properly set working directory for compilation.
  2812. (default-directory (if (file-name-absolute-p texfile)
  2813. (file-name-directory full-name)
  2814. default-directory))
  2815. (time (current-time))
  2816. warnings)
  2817. (unless snippet (message (format "Processing LaTeX file %s..." texfile)))
  2818. (save-window-excursion
  2819. (cond
  2820. ;; A function is provided: Apply it.
  2821. ((functionp org-latex-pdf-process)
  2822. (funcall org-latex-pdf-process (shell-quote-argument texfile)))
  2823. ;; A list is provided: Replace %b, %f and %o with appropriate
  2824. ;; values in each command before applying it. Output is
  2825. ;; redirected to "*Org PDF LaTeX Output*" buffer.
  2826. ((consp org-latex-pdf-process)
  2827. (let ((outbuf (and (not snippet)
  2828. (get-buffer-create "*Org PDF LaTeX Output*"))))
  2829. (dolist (command org-latex-pdf-process)
  2830. (shell-command
  2831. (replace-regexp-in-string
  2832. "%b" (shell-quote-argument base-name)
  2833. (replace-regexp-in-string
  2834. "%f" (shell-quote-argument full-name)
  2835. (replace-regexp-in-string
  2836. "%o" (shell-quote-argument out-dir) command t t) t t) t t)
  2837. outbuf))
  2838. ;; Collect standard errors from output buffer.
  2839. (setq warnings (and (not snippet)
  2840. (org-latex--collect-warnings outbuf)))))
  2841. (t (error "No valid command to process to PDF")))
  2842. (let ((pdffile (concat out-dir base-name ".pdf")))
  2843. ;; Check for process failure. Provide collected errors if
  2844. ;; possible.
  2845. (if (or (not (file-exists-p pdffile))
  2846. (time-less-p (nth 5 (file-attributes pdffile)) time))
  2847. (error (format "PDF file %s wasn't produced" pdffile))
  2848. ;; Else remove log files, when specified, and signal end of
  2849. ;; process to user, along with any error encountered.
  2850. (unless snippet
  2851. (when org-latex-remove-logfiles
  2852. (dolist (file (directory-files
  2853. out-dir t
  2854. (concat (regexp-quote base-name)
  2855. "\\(?:\\.[0-9]+\\)?"
  2856. "\\."
  2857. (regexp-opt org-latex-logfiles-extensions))))
  2858. (delete-file file)))
  2859. (message (concat "PDF file produced"
  2860. (cond
  2861. ((eq warnings 'error) " with errors.")
  2862. (warnings (concat " with warnings: " warnings))
  2863. (t "."))))))
  2864. ;; Return output file name.
  2865. pdffile))))
  2866. (defun org-latex--collect-warnings (buffer)
  2867. "Collect some warnings from \"pdflatex\" command output.
  2868. BUFFER is the buffer containing output. Return collected
  2869. warnings types as a string, `error' if a LaTeX error was
  2870. encountered or nil if there was none."
  2871. (with-current-buffer buffer
  2872. (save-excursion
  2873. (goto-char (point-max))
  2874. (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
  2875. (if (re-search-forward "^!" nil t) 'error
  2876. (let ((case-fold-search t)
  2877. (warnings ""))
  2878. (dolist (warning org-latex-known-warnings)
  2879. (when (save-excursion (re-search-forward (car warning) nil t))
  2880. (setq warnings (concat warnings " " (cdr warning)))))
  2881. (org-string-nw-p (org-trim warnings))))))))
  2882. ;;;###autoload
  2883. (defun org-latex-publish-to-latex (plist filename pub-dir)
  2884. "Publish an Org file to LaTeX.
  2885. FILENAME is the filename of the Org file to be published. PLIST
  2886. is the property list for the given project. PUB-DIR is the
  2887. publishing directory.
  2888. Return output file name."
  2889. (org-publish-org-to 'latex filename ".tex" plist pub-dir))
  2890. ;;;###autoload
  2891. (defun org-latex-publish-to-pdf (plist filename pub-dir)
  2892. "Publish an Org file to PDF (via LaTeX).
  2893. FILENAME is the filename of the Org file to be published. PLIST
  2894. is the property list for the given project. PUB-DIR is the
  2895. publishing directory.
  2896. Return output file name."
  2897. ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
  2898. ;; in working directory and then moved to publishing directory.
  2899. (org-publish-attachment
  2900. plist
  2901. (org-latex-compile
  2902. (org-publish-org-to
  2903. 'latex filename ".tex" plist (file-name-directory filename)))
  2904. pub-dir))
  2905. (provide 'ox-latex)
  2906. ;; Local variables:
  2907. ;; generated-autoload-file: "org-loaddefs.el"
  2908. ;; End:
  2909. ;;; ox-latex.el ends here