ox-latex.el 118 KB

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