ox-latex.el 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330
  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 affiliated keyword or no
  875. CUSTOM_ID property, unless FORCE is non-nil. In this case always
  876. return a unique label.
  877. Eventually, if FULL is non-nil, wrap label within \"\\label{}\"."
  878. (let* ((user-label
  879. (org-element-property
  880. (if (memq (org-element-type element) '(headline inlinetask))
  881. :CUSTOM_ID
  882. :name)
  883. element))
  884. (label
  885. (and (or user-label force)
  886. (if (and user-label (plist-get info :latex-prefer-user-labels))
  887. user-label
  888. (org-export-get-reference element info)))))
  889. (cond ((not full) label)
  890. (label (format "\\label{%s}\n" label))
  891. (t ""))))
  892. (defun org-latex--caption/label-string (element info)
  893. "Return caption and label LaTeX string for ELEMENT.
  894. INFO is a plist holding contextual information. If there's no
  895. caption nor label, return the empty string.
  896. For non-floats, see `org-latex--wrap-label'."
  897. (let* ((label (org-latex--label element info nil t))
  898. (main (org-export-get-caption element))
  899. (short (org-export-get-caption element t))
  900. (caption-from-attr-latex
  901. (org-export-read-attribute :attr_latex element :caption)))
  902. (cond
  903. ((org-string-nw-p caption-from-attr-latex)
  904. (concat caption-from-attr-latex "\n"))
  905. ((and (not main) (equal label "")) "")
  906. ((not main) (concat label "\n"))
  907. ;; Option caption format with short name.
  908. (short (format "\\caption[%s]{%s%s}\n"
  909. (org-export-data short info)
  910. label
  911. (org-export-data main info)))
  912. ;; Standard caption format.
  913. (t (format "\\caption{%s%s}\n" label (org-export-data main info))))))
  914. (defun org-latex-guess-inputenc (header)
  915. "Set the coding system in inputenc to what the buffer is.
  916. HEADER is the LaTeX header string. This function only applies
  917. when specified inputenc option is \"AUTO\".
  918. Return the new header, as a string."
  919. (let* ((cs (or (ignore-errors
  920. (latexenc-coding-system-to-inputenc
  921. (or org-export-coding-system buffer-file-coding-system)))
  922. "utf8")))
  923. (if (not cs) header
  924. ;; First translate if that is requested.
  925. (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
  926. ;; Then find the \usepackage statement and replace the option.
  927. (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
  928. cs header t nil 1))))
  929. (defun org-latex-guess-babel-language (header info)
  930. "Set Babel's language according to LANGUAGE keyword.
  931. HEADER is the LaTeX header string. INFO is the plist used as
  932. a communication channel.
  933. Insertion of guessed language only happens when Babel package has
  934. explicitly been loaded. Then it is added to the rest of
  935. package's options.
  936. The argument to Babel may be \"AUTO\" which is then replaced with
  937. the language of the document or `org-export-default-language'
  938. unless language in question is already loaded.
  939. Return the new header."
  940. (let ((language-code (plist-get info :language)))
  941. ;; If no language is set or Babel package is not loaded, return
  942. ;; HEADER as-is.
  943. (if (or (not (stringp language-code))
  944. (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
  945. header
  946. (let ((options (save-match-data
  947. (org-split-string (match-string 1 header) ",[ \t]*")))
  948. (language (cdr (assoc language-code
  949. org-latex-babel-language-alist))))
  950. ;; If LANGUAGE is already loaded, return header without AUTO.
  951. ;; Otherwise, replace AUTO with language or append language if
  952. ;; AUTO is not present.
  953. (replace-match
  954. (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
  955. (cond ((member language options) (delete "AUTO" options))
  956. ((member "AUTO" options) options)
  957. (t (append options (list language))))
  958. ", ")
  959. t nil header 1)))))
  960. (defun org-latex--find-verb-separator (s)
  961. "Return a character not used in string S.
  962. This is used to choose a separator for constructs like \\verb."
  963. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  964. (loop for c across ll
  965. when (not (string-match (regexp-quote (char-to-string c)) s))
  966. return (char-to-string c))))
  967. (defun org-latex--make-option-string (options)
  968. "Return a comma separated string of keywords and values.
  969. OPTIONS is an alist where the key is the options keyword as
  970. a string, and the value a list containing the keyword value, or
  971. nil."
  972. (mapconcat (lambda (pair)
  973. (concat (first pair)
  974. (when (> (length (second pair)) 0)
  975. (concat "=" (second pair)))))
  976. options
  977. ","))
  978. (defun org-latex--wrap-label (element output info)
  979. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  980. INFO is the current export state, as a plist. This function
  981. should not be used for floats. See
  982. `org-latex--caption/label-string'."
  983. (if (not (and (org-string-nw-p output) (org-element-property :name element)))
  984. output
  985. (concat (format "\\phantomsection\n\\label{%s}\n"
  986. (org-export-get-reference element info))
  987. output)))
  988. (defun org-latex--text-markup (text markup info)
  989. "Format TEXT depending on MARKUP text markup.
  990. INFO is a plist used as a communication channel. See
  991. `org-latex-text-markup-alist' for details."
  992. (let ((fmt (cdr (assq markup (plist-get info :latex-text-markup-alist)))))
  993. (cond
  994. ;; No format string: Return raw text.
  995. ((not fmt) text)
  996. ;; Handle the `verb' special case: Find an appropriate separator
  997. ;; and use "\\verb" command.
  998. ((eq 'verb fmt)
  999. (let ((separator (org-latex--find-verb-separator text)))
  1000. (concat "\\verb" separator
  1001. (replace-regexp-in-string "\n" " " text)
  1002. separator)))
  1003. ;; Handle the `protectedtexttt' special case: Protect some
  1004. ;; special chars and use "\texttt{%s}" format string.
  1005. ((eq 'protectedtexttt fmt)
  1006. (let ((start 0)
  1007. (trans '(("\\" . "\\textbackslash{}")
  1008. ("~" . "\\textasciitilde{}")
  1009. ("^" . "\\textasciicircum{}")))
  1010. (rtn "")
  1011. char)
  1012. (while (string-match "[\\{}$%&_#~^]" text)
  1013. (setq char (match-string 0 text))
  1014. (if (> (match-beginning 0) 0)
  1015. (setq rtn (concat rtn (substring text 0 (match-beginning 0)))))
  1016. (setq text (substring text (1+ (match-beginning 0))))
  1017. (setq char (or (cdr (assoc char trans)) (concat "\\" char))
  1018. rtn (concat rtn char)))
  1019. (setq text (concat rtn text)
  1020. fmt "\\texttt{%s}")
  1021. (while (string-match "--" text)
  1022. (setq text (replace-match "-{}-" t t text)))
  1023. (format fmt text)))
  1024. ;; Else use format string.
  1025. (t (format fmt text)))))
  1026. (defun org-latex--delayed-footnotes-definitions (element info)
  1027. "Return footnotes definitions in ELEMENT as a string.
  1028. INFO is a plist used as a communication channel.
  1029. Footnotes definitions are returned within \"\\footnotetxt{}\"
  1030. commands.
  1031. This function is used within constructs that don't support
  1032. \"\\footnote{}\" command (i.e. an item's tag). In that case,
  1033. \"\\footnotemark\" is used within the construct and the function
  1034. just outside of it."
  1035. (mapconcat
  1036. (lambda (ref)
  1037. (format
  1038. "\\footnotetext[%s]{%s}"
  1039. (org-export-get-footnote-number ref info)
  1040. (org-trim
  1041. (org-export-data
  1042. (org-export-get-footnote-definition ref info) info))))
  1043. ;; Find every footnote reference in ELEMENT.
  1044. (let* (all-refs
  1045. search-refs ; For byte-compiler.
  1046. (search-refs
  1047. (function
  1048. (lambda (data)
  1049. ;; Return a list of all footnote references never seen
  1050. ;; before in DATA.
  1051. (org-element-map data 'footnote-reference
  1052. (lambda (ref)
  1053. (when (org-export-footnote-first-reference-p ref info)
  1054. (push ref all-refs)
  1055. (when (eq (org-element-property :type ref) 'standard)
  1056. (funcall search-refs
  1057. (org-export-get-footnote-definition ref info)))))
  1058. info)
  1059. (reverse all-refs)))))
  1060. (funcall search-refs element))
  1061. ""))
  1062. (defun org-latex--translate (s info)
  1063. "Translate string S according to specified language.
  1064. INFO is a plist used as a communication channel."
  1065. (org-export-translate s :latex info))
  1066. (defun org-latex--format-spec (info)
  1067. "Create a format-spec for document meta-data.
  1068. INFO is a plist used as a communication channel."
  1069. (let ((language (let ((lang (plist-get info :language)))
  1070. (or (cdr (assoc lang org-latex-babel-language-alist))
  1071. lang))))
  1072. `((?a . ,(org-export-data (plist-get info :author) info))
  1073. (?t . ,(org-export-data (plist-get info :title) info))
  1074. (?k . ,(org-export-data (org-latex--wrap-latex-math-block
  1075. (plist-get info :keywords) info)
  1076. info))
  1077. (?d . ,(org-export-data (org-latex--wrap-latex-math-block
  1078. (plist-get info :description) info)
  1079. info))
  1080. (?c . ,(plist-get info :creator))
  1081. (?l . ,language)
  1082. (?L . ,(capitalize language))
  1083. (?D . ,(org-export-get-date info)))))
  1084. ;;; Template
  1085. (defun org-latex-template (contents info)
  1086. "Return complete document string after LaTeX conversion.
  1087. CONTENTS is the transcoded contents string. INFO is a plist
  1088. holding export options."
  1089. (let ((title (org-export-data (plist-get info :title) info))
  1090. (spec (org-latex--format-spec info)))
  1091. (concat
  1092. ;; Time-stamp.
  1093. (and (plist-get info :time-stamp-file)
  1094. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  1095. ;; Document class and packages.
  1096. (let* ((class (plist-get info :latex-class))
  1097. (class-options (plist-get info :latex-class-options))
  1098. (header (nth 1 (assoc class (plist-get info :latex-classes))))
  1099. (document-class-string
  1100. (and (stringp header)
  1101. (if (not class-options) header
  1102. (replace-regexp-in-string
  1103. "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
  1104. class-options header t nil 1)))))
  1105. (if (not document-class-string)
  1106. (user-error "Unknown LaTeX class `%s'" class)
  1107. (org-latex-guess-babel-language
  1108. (org-latex-guess-inputenc
  1109. (org-element-normalize-string
  1110. (org-splice-latex-header
  1111. document-class-string
  1112. org-latex-default-packages-alist
  1113. org-latex-packages-alist nil
  1114. (concat (org-element-normalize-string
  1115. (plist-get info :latex-header))
  1116. (plist-get info :latex-header-extra)))))
  1117. info)))
  1118. ;; Possibly limit depth for headline numbering.
  1119. (let ((sec-num (plist-get info :section-numbers)))
  1120. (when (integerp sec-num)
  1121. (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
  1122. ;; Author.
  1123. (let ((author (and (plist-get info :with-author)
  1124. (let ((auth (plist-get info :author)))
  1125. (and auth (org-export-data auth info)))))
  1126. (email (and (plist-get info :with-email)
  1127. (org-export-data (plist-get info :email) info))))
  1128. (cond ((and author email (not (string= "" email)))
  1129. (format "\\author{%s\\thanks{%s}}\n" author email))
  1130. ((or author email) (format "\\author{%s}\n" (or author email)))))
  1131. ;; Date.
  1132. (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
  1133. (format "\\date{%s}\n" (org-export-data date info)))
  1134. ;; Title and subtitle.
  1135. (let* ((subtitle (plist-get info :subtitle))
  1136. (formatted-subtitle
  1137. (when subtitle
  1138. (format (plist-get info :latex-subtitle-format)
  1139. (org-export-data subtitle info))))
  1140. (separate (plist-get info :latex-subtitle-separate)))
  1141. (concat
  1142. (format "\\title{%s%s}\n" title
  1143. (if separate "" (or formatted-subtitle "")))
  1144. (when (and separate subtitle)
  1145. (concat formatted-subtitle "\n"))))
  1146. ;; Hyperref options.
  1147. (let ((template (plist-get info :latex-hyperref-template)))
  1148. (and (stringp template)
  1149. (format-spec template spec)))
  1150. ;; Document start.
  1151. "\\begin{document}\n\n"
  1152. ;; Title command.
  1153. (let* ((title-command (plist-get info :latex-title-command))
  1154. (command (and (stringp title-command)
  1155. (format-spec title-command spec))))
  1156. (org-element-normalize-string
  1157. (cond ((not (plist-get info :with-title)) nil)
  1158. ((string= "" title) nil)
  1159. ((not (stringp command)) nil)
  1160. ((string-match "\\(?:[^%]\\|^\\)%s" command)
  1161. (format command title))
  1162. (t command))))
  1163. ;; Table of contents.
  1164. (let ((depth (plist-get info :with-toc)))
  1165. (when depth
  1166. (concat (when (wholenump depth)
  1167. (format "\\setcounter{tocdepth}{%d}\n" depth))
  1168. (plist-get info :latex-toc-command))))
  1169. ;; Document's body.
  1170. contents
  1171. ;; Creator.
  1172. (and (plist-get info :with-creator)
  1173. (concat (plist-get info :creator) "\n"))
  1174. ;; Document end.
  1175. "\\end{document}")))
  1176. ;;; Transcode Functions
  1177. ;;;; Bold
  1178. (defun org-latex-bold (bold contents info)
  1179. "Transcode BOLD from Org to LaTeX.
  1180. CONTENTS is the text with bold markup. INFO is a plist holding
  1181. contextual information."
  1182. (org-latex--text-markup contents 'bold info))
  1183. ;;;; Center Block
  1184. (defun org-latex-center-block (center-block contents info)
  1185. "Transcode a CENTER-BLOCK element from Org to LaTeX.
  1186. CONTENTS holds the contents of the center block. INFO is a plist
  1187. holding contextual information."
  1188. (org-latex--wrap-label
  1189. center-block (format "\\begin{center}\n%s\\end{center}" contents) info))
  1190. ;;;; Clock
  1191. (defun org-latex-clock (clock contents info)
  1192. "Transcode a CLOCK element from Org to LaTeX.
  1193. CONTENTS is nil. INFO is a plist holding contextual
  1194. information."
  1195. (concat
  1196. "\\noindent"
  1197. (format "\\textbf{%s} " org-clock-string)
  1198. (format (plist-get info :latex-inactive-timestamp-format)
  1199. (concat (org-timestamp-translate (org-element-property :value clock))
  1200. (let ((time (org-element-property :duration clock)))
  1201. (and time (format " (%s)" time)))))
  1202. "\\\\"))
  1203. ;;;; Code
  1204. (defun org-latex-code (code contents info)
  1205. "Transcode a CODE object from Org to LaTeX.
  1206. CONTENTS is nil. INFO is a plist used as a communication
  1207. channel."
  1208. (org-latex--text-markup (org-element-property :value code) 'code info))
  1209. ;;;; Drawer
  1210. (defun org-latex-drawer (drawer contents info)
  1211. "Transcode a DRAWER element from Org to LaTeX.
  1212. CONTENTS holds the contents of the block. INFO is a plist
  1213. holding contextual information."
  1214. (let* ((name (org-element-property :drawer-name drawer))
  1215. (output (funcall (plist-get info :latex-format-drawer-function)
  1216. name contents)))
  1217. (org-latex--wrap-label drawer output info)))
  1218. ;;;; Dynamic Block
  1219. (defun org-latex-dynamic-block (dynamic-block contents info)
  1220. "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
  1221. CONTENTS holds the contents of the block. INFO is a plist
  1222. holding contextual information. See `org-export-data'."
  1223. (org-latex--wrap-label dynamic-block contents info))
  1224. ;;;; Entity
  1225. (defun org-latex-entity (entity contents info)
  1226. "Transcode an ENTITY object from Org to LaTeX.
  1227. CONTENTS are the definition itself. INFO is a plist holding
  1228. contextual information."
  1229. (org-element-property :latex entity))
  1230. ;;;; Example Block
  1231. (defun org-latex-example-block (example-block contents info)
  1232. "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
  1233. CONTENTS is nil. INFO is a plist holding contextual
  1234. information."
  1235. (when (org-string-nw-p (org-element-property :value example-block))
  1236. (org-latex--wrap-label
  1237. example-block
  1238. (format "\\begin{verbatim}\n%s\\end{verbatim}"
  1239. (org-export-format-code-default example-block info))
  1240. info)))
  1241. ;;;; Export Block
  1242. (defun org-latex-export-block (export-block contents info)
  1243. "Transcode a EXPORT-BLOCK element from Org to LaTeX.
  1244. CONTENTS is nil. INFO is a plist holding contextual information."
  1245. (when (member (org-element-property :type export-block) '("LATEX" "TEX"))
  1246. (org-remove-indentation (org-element-property :value export-block))))
  1247. ;;;; Export Snippet
  1248. (defun org-latex-export-snippet (export-snippet contents info)
  1249. "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
  1250. CONTENTS is nil. INFO is a plist holding contextual information."
  1251. (when (eq (org-export-snippet-backend export-snippet) 'latex)
  1252. (org-element-property :value export-snippet)))
  1253. ;;;; Fixed Width
  1254. (defun org-latex-fixed-width (fixed-width contents info)
  1255. "Transcode a FIXED-WIDTH element from Org to LaTeX.
  1256. CONTENTS is nil. INFO is a plist holding contextual information."
  1257. (org-latex--wrap-label
  1258. fixed-width
  1259. (format "\\begin{verbatim}\n%s\\end{verbatim}"
  1260. (org-remove-indentation
  1261. (org-element-property :value fixed-width)))
  1262. info))
  1263. ;;;; Footnote Reference
  1264. (defun org-latex-footnote-reference (footnote-reference contents info)
  1265. "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
  1266. CONTENTS is nil. INFO is a plist holding contextual information."
  1267. (concat
  1268. ;; Insert separator between two footnotes in a row.
  1269. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1270. (when (eq (org-element-type prev) 'footnote-reference)
  1271. (plist-get info :latex-footnote-separator)))
  1272. (cond
  1273. ;; Use \footnotemark if the footnote has already been defined.
  1274. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1275. (format "\\footnotemark[%s]{}"
  1276. (org-export-get-footnote-number footnote-reference info)))
  1277. ;; Use \footnotemark if reference is within another footnote
  1278. ;; reference, footnote definition or table cell.
  1279. ((org-element-lineage footnote-reference
  1280. '(footnote-reference footnote-definition table-cell))
  1281. "\\footnotemark")
  1282. ;; Otherwise, define it with \footnote command.
  1283. (t
  1284. (let ((def (org-export-get-footnote-definition footnote-reference info)))
  1285. (concat
  1286. (format "\\footnote{%s}" (org-trim (org-export-data def info)))
  1287. ;; Retrieve all footnote references within the footnote and
  1288. ;; add their definition after it, since LaTeX doesn't support
  1289. ;; them inside.
  1290. (org-latex--delayed-footnotes-definitions def info)))))))
  1291. ;;;; Headline
  1292. (defun org-latex-headline (headline contents info)
  1293. "Transcode a HEADLINE element from Org to LaTeX.
  1294. CONTENTS holds the contents of the headline. INFO is a plist
  1295. holding contextual information."
  1296. (unless (org-element-property :footnote-section-p headline)
  1297. (let* ((class (plist-get info :latex-class))
  1298. (level (org-export-get-relative-level headline info))
  1299. (numberedp (org-export-numbered-headline-p headline info))
  1300. (class-sectioning (assoc class (plist-get info :latex-classes)))
  1301. ;; Section formatting will set two placeholders: one for
  1302. ;; the title and the other for the contents.
  1303. (section-fmt
  1304. (let ((sec (if (functionp (nth 2 class-sectioning))
  1305. (funcall (nth 2 class-sectioning) level numberedp)
  1306. (nth (1+ level) class-sectioning))))
  1307. (cond
  1308. ;; No section available for that LEVEL.
  1309. ((not sec) nil)
  1310. ;; Section format directly returned by a function. Add
  1311. ;; placeholder for contents.
  1312. ((stringp sec) (concat sec "\n%s"))
  1313. ;; (numbered-section . unnumbered-section)
  1314. ((not (consp (cdr sec)))
  1315. (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
  1316. ;; (numbered-open numbered-close)
  1317. ((= (length sec) 2)
  1318. (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
  1319. ;; (num-in num-out no-num-in no-num-out)
  1320. ((= (length sec) 4)
  1321. (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
  1322. (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
  1323. ;; Create a temporary export back-end that hard-codes
  1324. ;; "\underline" within "\section" and alike.
  1325. (section-back-end
  1326. (org-export-create-backend
  1327. :parent 'latex
  1328. :transcoders
  1329. '((underline . (lambda (o c i) (format "\\underline{%s}" c))))))
  1330. (text
  1331. (org-export-data-with-backend
  1332. (org-element-property :title headline) section-back-end info))
  1333. (todo
  1334. (and (plist-get info :with-todo-keywords)
  1335. (let ((todo (org-element-property :todo-keyword headline)))
  1336. (and todo (org-export-data todo info)))))
  1337. (todo-type (and todo (org-element-property :todo-type headline)))
  1338. (tags (and (plist-get info :with-tags)
  1339. (org-export-get-tags headline info)))
  1340. (priority (and (plist-get info :with-priority)
  1341. (org-element-property :priority headline)))
  1342. ;; Create the headline text along with a no-tag version.
  1343. ;; The latter is required to remove tags from toc.
  1344. (full-text (funcall (plist-get info :latex-format-headline-function)
  1345. todo todo-type priority text tags info))
  1346. ;; Associate \label to the headline for internal links.
  1347. (headline-label (org-latex--label headline info t t))
  1348. (pre-blanks
  1349. (make-string (org-element-property :pre-blank headline) ?\n)))
  1350. (if (or (not section-fmt) (org-export-low-level-p headline info))
  1351. ;; This is a deep sub-tree: export it as a list item. Also
  1352. ;; export as items headlines for which no section format has
  1353. ;; been found.
  1354. (let ((low-level-body
  1355. (concat
  1356. ;; If headline is the first sibling, start a list.
  1357. (when (org-export-first-sibling-p headline info)
  1358. (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
  1359. ;; Itemize headline
  1360. "\\item"
  1361. (and full-text (org-string-match-p "\\`[ \t]*\\[" full-text)
  1362. "\\relax")
  1363. " " full-text "\n"
  1364. headline-label
  1365. pre-blanks
  1366. contents)))
  1367. ;; If headline is not the last sibling simply return
  1368. ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
  1369. ;; any blank line.
  1370. (if (not (org-export-last-sibling-p headline info)) low-level-body
  1371. (replace-regexp-in-string
  1372. "[ \t\n]*\\'"
  1373. (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
  1374. low-level-body)))
  1375. ;; This is a standard headline. Export it as a section. Add
  1376. ;; an alternative heading when possible, and when this is not
  1377. ;; identical to the usual heading.
  1378. (let ((opt-title
  1379. (funcall (plist-get info :latex-format-headline-function)
  1380. todo todo-type priority
  1381. (org-export-data-with-backend
  1382. (org-export-get-alt-title headline info)
  1383. section-back-end info)
  1384. (and (eq (plist-get info :with-tags) t) tags)
  1385. info))
  1386. ;; Maybe end local TOC (see `org-latex-keyword').
  1387. (contents
  1388. (concat
  1389. contents
  1390. (let ((case-fold-search t)
  1391. (section
  1392. (let ((first (car (org-element-contents headline))))
  1393. (and (eq (org-element-type first) 'section) first))))
  1394. (org-element-map section 'keyword
  1395. (lambda (k)
  1396. (and (equal (org-element-property :key k) "TOC")
  1397. (let ((v (org-element-property :value k)))
  1398. (and (org-string-match-p "\\<headlines\\>" v)
  1399. (org-string-match-p "\\<local\\>" v)
  1400. (format "\\stopcontents[level-%d]" level)))))
  1401. info t)))))
  1402. (if (and opt-title
  1403. (not (equal opt-title full-text))
  1404. (string-match "\\`\\\\\\(.*?[^*]\\){" section-fmt))
  1405. (format (replace-match "\\1[%s]" nil nil section-fmt 1)
  1406. ;; Replace square brackets with parenthesis
  1407. ;; since square brackets are not supported in
  1408. ;; optional arguments.
  1409. (replace-regexp-in-string
  1410. "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
  1411. full-text
  1412. (concat headline-label pre-blanks contents))
  1413. ;; Impossible to add an alternative heading. Fallback to
  1414. ;; regular sectioning format string.
  1415. (format section-fmt full-text
  1416. (concat headline-label pre-blanks contents))))))))
  1417. (defun org-latex-format-headline-default-function
  1418. (todo todo-type priority text tags info)
  1419. "Default format function for a headline.
  1420. See `org-latex-format-headline-function' for details."
  1421. (concat
  1422. (and todo (format "{\\bfseries\\sffamily %s} " todo))
  1423. (and priority (format "\\framebox{\\#%c} " priority))
  1424. text
  1425. (and tags
  1426. (format "\\hfill{}\\textsc{%s}"
  1427. (mapconcat (lambda (tag) (org-latex-plain-text tag info))
  1428. tags ":")))))
  1429. ;;;; Horizontal Rule
  1430. (defun org-latex-horizontal-rule (horizontal-rule contents info)
  1431. "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
  1432. CONTENTS is nil. INFO is a plist holding contextual information."
  1433. (let ((attr (org-export-read-attribute :attr_latex horizontal-rule))
  1434. (prev (org-export-get-previous-element horizontal-rule info)))
  1435. (concat
  1436. ;; Make sure the rule doesn't start at the end of the current
  1437. ;; line by separating it with a blank line from previous element.
  1438. (when (and prev
  1439. (let ((prev-blank (org-element-property :post-blank prev)))
  1440. (or (not prev-blank) (zerop prev-blank))))
  1441. "\n")
  1442. (org-latex--wrap-label
  1443. horizontal-rule
  1444. (format "\\rule{%s}{%s}"
  1445. (or (plist-get attr :width) "\\linewidth")
  1446. (or (plist-get attr :thickness) "0.5pt"))
  1447. info))))
  1448. ;;;; Inline Src Block
  1449. (defun org-latex-inline-src-block (inline-src-block contents info)
  1450. "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
  1451. CONTENTS holds the contents of the item. INFO is a plist holding
  1452. contextual information."
  1453. (let* ((code (org-element-property :value inline-src-block))
  1454. (separator (org-latex--find-verb-separator code)))
  1455. (case (plist-get info :latex-listings)
  1456. ;; Do not use a special package: transcode it verbatim.
  1457. ((nil) (concat "\\verb" separator code separator))
  1458. ;; Use minted package.
  1459. (minted
  1460. (let* ((org-lang (org-element-property :language inline-src-block))
  1461. (mint-lang (or (cadr (assq (intern org-lang)
  1462. (plist-get info :latex-minted-langs)))
  1463. (downcase org-lang)))
  1464. (options (org-latex--make-option-string
  1465. (plist-get info :latex-minted-options))))
  1466. (concat (format "\\mint%s{%s}"
  1467. (if (string= options "") "" (format "[%s]" options))
  1468. mint-lang)
  1469. separator code separator)))
  1470. ;; Use listings package.
  1471. (otherwise
  1472. ;; Maybe translate language's name.
  1473. (let* ((org-lang (org-element-property :language inline-src-block))
  1474. (lst-lang (or (cadr (assq (intern org-lang)
  1475. (plist-get info :latex-listings-langs)))
  1476. org-lang))
  1477. (options (org-latex--make-option-string
  1478. (append (plist-get info :latex-listings-options)
  1479. `(("language" ,lst-lang))))))
  1480. (concat (format "\\lstinline[%s]" options)
  1481. separator code separator))))))
  1482. ;;;; Inlinetask
  1483. (defun org-latex-inlinetask (inlinetask contents info)
  1484. "Transcode an INLINETASK element from Org to LaTeX.
  1485. CONTENTS holds the contents of the block. INFO is a plist
  1486. holding contextual information."
  1487. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  1488. (todo (and (plist-get info :with-todo-keywords)
  1489. (let ((todo (org-element-property :todo-keyword inlinetask)))
  1490. (and todo (org-export-data todo info)))))
  1491. (todo-type (org-element-property :todo-type inlinetask))
  1492. (tags (and (plist-get info :with-tags)
  1493. (org-export-get-tags inlinetask info)))
  1494. (priority (and (plist-get info :with-priority)
  1495. (org-element-property :priority inlinetask)))
  1496. (contents (concat (org-latex--label inlinetask info) contents)))
  1497. (funcall (plist-get info :latex-format-inlinetask-function)
  1498. todo todo-type priority title tags contents info)))
  1499. (defun org-latex-format-inlinetask-default-function
  1500. (todo todo-type priority title tags contents info)
  1501. "Default format function for a inlinetasks.
  1502. See `org-latex-format-inlinetask-function' for details."
  1503. (let ((full-title
  1504. (concat (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  1505. (when priority (format "\\framebox{\\#%c} " priority))
  1506. title
  1507. (when tags
  1508. (format "\\hfill{}\\textsc{:%s:}"
  1509. (mapconcat
  1510. (lambda (tag) (org-latex-plain-text tag info))
  1511. tags ":"))))))
  1512. (concat "\\begin{center}\n"
  1513. "\\fbox{\n"
  1514. "\\begin{minipage}[c]{.6\\textwidth}\n"
  1515. full-title "\n\n"
  1516. (and (org-string-nw-p contents)
  1517. (concat "\\rule[.8em]{\\textwidth}{2pt}\n\n" contents))
  1518. "\\end{minipage}\n"
  1519. "}\n"
  1520. "\\end{center}")))
  1521. ;;;; Italic
  1522. (defun org-latex-italic (italic contents info)
  1523. "Transcode ITALIC from Org to LaTeX.
  1524. CONTENTS is the text with italic markup. INFO is a plist holding
  1525. contextual information."
  1526. (org-latex--text-markup contents 'italic info))
  1527. ;;;; Item
  1528. (defun org-latex-item (item contents info)
  1529. "Transcode an ITEM element from Org to LaTeX.
  1530. CONTENTS holds the contents of the item. INFO is a plist holding
  1531. contextual information."
  1532. (let* ((counter
  1533. (let ((count (org-element-property :counter item))
  1534. (level
  1535. ;; Determine level of current item to determine the
  1536. ;; correct LaTeX counter to use (enumi, enumii...).
  1537. (let ((parent item) (level 0))
  1538. (while (memq (org-element-type
  1539. (setq parent (org-export-get-parent parent)))
  1540. '(plain-list item))
  1541. (when (and (eq (org-element-type parent) 'plain-list)
  1542. (eq (org-element-property :type parent)
  1543. 'ordered))
  1544. (incf level)))
  1545. level)))
  1546. (and count
  1547. (< level 5)
  1548. (format "\\setcounter{enum%s}{%s}\n"
  1549. (nth (1- level) '("i" "ii" "iii" "iv"))
  1550. (1- count)))))
  1551. (checkbox (case (org-element-property :checkbox item)
  1552. (on "$\\boxtimes$ ")
  1553. (off "$\\square$ ")
  1554. (trans "$\\boxminus$ ")))
  1555. (tag (let ((tag (org-element-property :tag item)))
  1556. ;; Check-boxes must belong to the tag.
  1557. (and tag (format "[{%s}] "
  1558. (concat checkbox
  1559. (org-export-data tag info)))))))
  1560. (concat counter
  1561. "\\item"
  1562. (cond
  1563. (tag)
  1564. (checkbox (concat " " checkbox))
  1565. ;; Without a tag or a check-box, if CONTENTS starts with
  1566. ;; an opening square bracket, add "\relax" to "\item",
  1567. ;; unless the brackets comes from an initial export
  1568. ;; snippet (i.e. it is inserted willingly by the user).
  1569. ((and contents
  1570. (org-string-match-p "\\`[ \t]*\\[" contents)
  1571. (not (let ((e (car (org-element-contents item))))
  1572. (and (eq (org-element-type e) 'paragraph)
  1573. (let ((o (car (org-element-contents e))))
  1574. (and (eq (org-element-type o) 'export-snippet)
  1575. (eq (org-export-snippet-backend o)
  1576. 'latex)))))))
  1577. "\\relax ")
  1578. (t " "))
  1579. (and contents (org-trim contents))
  1580. ;; If there are footnotes references in tag, be sure to
  1581. ;; add their definition at the end of the item. This
  1582. ;; workaround is necessary since "\footnote{}" command is
  1583. ;; not supported in tags.
  1584. (and tag
  1585. (org-latex--delayed-footnotes-definitions
  1586. (org-element-property :tag item) info)))))
  1587. ;;;; Keyword
  1588. (defun org-latex-keyword (keyword contents info)
  1589. "Transcode a KEYWORD element from Org to LaTeX.
  1590. CONTENTS is nil. INFO is a plist holding contextual information."
  1591. (let ((key (org-element-property :key keyword))
  1592. (value (org-element-property :value keyword)))
  1593. (cond
  1594. ((string= key "LATEX") value)
  1595. ((string= key "INDEX") (format "\\index{%s}" value))
  1596. ((string= key "TOC")
  1597. (let ((case-fold-search t))
  1598. (cond
  1599. ((org-string-match-p "\\<headlines\\>" value)
  1600. (let* ((localp (org-string-match-p "\\<local\\>" value))
  1601. (parent (org-element-lineage keyword '(headline)))
  1602. (level (if (not (and localp parent)) 0
  1603. (org-export-get-relative-level parent info)))
  1604. (depth
  1605. (and (string-match "\\<[0-9]+\\>" value)
  1606. (format
  1607. "\\setcounter{tocdepth}{%d}"
  1608. (+ (string-to-number (match-string 0 value)) level)))))
  1609. (if (and localp parent)
  1610. ;; Start local TOC, assuming package "titletoc" is
  1611. ;; required.
  1612. (format "\\startcontents[level-%d]
  1613. \\printcontents[level-%d]{}{0}{%s}"
  1614. level level (or depth ""))
  1615. (concat depth (and depth "\n") "\\tableofcontents"))))
  1616. ((org-string-match-p "\\<tables\\>" value) "\\listoftables")
  1617. ((org-string-match-p "\\<listings\\>" value)
  1618. (case (plist-get info :latex-listings)
  1619. ((nil) "\\listoffigures")
  1620. (minted "\\listoflistings")
  1621. (otherwise "\\lstlistoflistings")))))))))
  1622. ;;;; Latex Environment
  1623. (defun org-latex-latex-environment (latex-environment contents info)
  1624. "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
  1625. CONTENTS is nil. INFO is a plist holding contextual information."
  1626. (when (plist-get info :with-latex)
  1627. (let ((value (org-remove-indentation
  1628. (org-element-property :value latex-environment))))
  1629. (if (not (org-element-property :name latex-environment)) value
  1630. ;; Environment is labeled: label must be within the environment
  1631. ;; (otherwise, a reference pointing to that element will count
  1632. ;; the section instead).
  1633. (with-temp-buffer
  1634. (insert value)
  1635. (goto-char (point-min))
  1636. (forward-line)
  1637. (insert (org-latex--label latex-environment info nil t))
  1638. (buffer-string))))))
  1639. ;;;; Latex Fragment
  1640. (defun org-latex-latex-fragment (latex-fragment contents info)
  1641. "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
  1642. CONTENTS is nil. INFO is a plist holding contextual information."
  1643. (let ((value (org-element-property :value latex-fragment)))
  1644. ;; Trim math markers since the fragment is enclosed within
  1645. ;; a latex-math-block object anyway.
  1646. (cond ((string-match "\\`\\(\\$\\{1,2\\}\\)\\([^\000]*\\)\\1\\'" value)
  1647. (match-string 2 value))
  1648. ((string-match "\\`\\\\(\\([^\000]*\\)\\\\)\\'" value)
  1649. (match-string 1 value))
  1650. (t value))))
  1651. ;;;; Line Break
  1652. (defun org-latex-line-break (line-break contents info)
  1653. "Transcode a LINE-BREAK object from Org to LaTeX.
  1654. CONTENTS is nil. INFO is a plist holding contextual information."
  1655. "\\\\\n")
  1656. ;;;; Link
  1657. (defun org-latex--inline-image (link info)
  1658. "Return LaTeX code for an inline image.
  1659. LINK is the link pointing to the inline image. INFO is a plist
  1660. used as a communication channel."
  1661. (let* ((parent (org-export-get-parent-element link))
  1662. (path (let ((raw-path (org-element-property :path link)))
  1663. (if (not (file-name-absolute-p raw-path)) raw-path
  1664. (expand-file-name raw-path))))
  1665. (filetype (file-name-extension path))
  1666. (caption (org-latex--caption/label-string parent info))
  1667. (caption-above-p (org-latex--caption-above-p link info))
  1668. ;; Retrieve latex attributes from the element around.
  1669. (attr (org-export-read-attribute :attr_latex parent))
  1670. (float (let ((float (plist-get attr :float)))
  1671. (cond ((and (not float) (plist-member attr :float)) nil)
  1672. ((string= float "wrap") 'wrap)
  1673. ((string= float "sideways") 'sideways)
  1674. ((string= float "multicolumn") 'multicolumn)
  1675. ((or float
  1676. (org-element-property :caption parent)
  1677. (org-string-nw-p (plist-get attr :caption)))
  1678. 'figure))))
  1679. (placement
  1680. (let ((place (plist-get attr :placement)))
  1681. (cond
  1682. (place (format "%s" place))
  1683. ((eq float 'wrap) "{l}{0.5\\textwidth}")
  1684. ((eq float 'figure)
  1685. (format "[%s]" (plist-get info :latex-default-figure-position)))
  1686. (t ""))))
  1687. (comment-include (if (plist-get attr :comment-include) "%" ""))
  1688. ;; It is possible to specify width and height in the
  1689. ;; ATTR_LATEX line, and also via default variables.
  1690. (width (cond ((plist-get attr :width))
  1691. ((plist-get attr :height) "")
  1692. ((eq float 'wrap) "0.48\\textwidth")
  1693. (t (plist-get info :latex-image-default-width))))
  1694. (height (cond ((plist-get attr :height))
  1695. ((or (plist-get attr :width)
  1696. (memq float '(figure wrap))) "")
  1697. (t (plist-get info :latex-image-default-height))))
  1698. (options (let ((opt (or (plist-get attr :options)
  1699. (plist-get info :latex-image-default-option))))
  1700. (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
  1701. (match-string 1 opt))))
  1702. image-code)
  1703. (if (member filetype '("tikz" "pgf"))
  1704. ;; For tikz images:
  1705. ;; - use \input to read in image file.
  1706. ;; - if options are present, wrap in a tikzpicture environment.
  1707. ;; - if width or height are present, use \resizebox to change
  1708. ;; the image size.
  1709. (progn
  1710. (setq image-code (format "\\input{%s}" path))
  1711. (when (org-string-nw-p options)
  1712. (setq image-code
  1713. (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
  1714. options
  1715. image-code)))
  1716. (when (or (org-string-nw-p width) (org-string-nw-p height))
  1717. (setq image-code (format "\\resizebox{%s}{%s}{%s}"
  1718. (if (org-string-nw-p width) width "!")
  1719. (if (org-string-nw-p height) height "!")
  1720. image-code))))
  1721. ;; For other images:
  1722. ;; - add width and height to options.
  1723. ;; - include the image with \includegraphics.
  1724. (when (org-string-nw-p width)
  1725. (setq options (concat options ",width=" width)))
  1726. (when (org-string-nw-p height)
  1727. (setq options (concat options ",height=" height)))
  1728. (let ((search-option (org-element-property :search-option link)))
  1729. (when (and search-option
  1730. (equal filetype "pdf")
  1731. (org-string-match-p "\\`[0-9]+\\'" search-option)
  1732. (not (org-string-match-p "page=" options)))
  1733. (setq options (concat options ",page=" search-option))))
  1734. (setq image-code
  1735. (format "\\includegraphics%s{%s}"
  1736. (cond ((not (org-string-nw-p options)) "")
  1737. ((= (aref options 0) ?,)
  1738. (format "[%s]"(substring options 1)))
  1739. (t (format "[%s]" options)))
  1740. path))
  1741. (when (equal filetype "svg")
  1742. (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
  1743. "\\includesvg"
  1744. image-code
  1745. nil t))
  1746. (setq image-code (replace-regexp-in-string "\\.svg}"
  1747. "}"
  1748. image-code
  1749. nil t))))
  1750. ;; Return proper string, depending on FLOAT.
  1751. (case float
  1752. (wrap (format "\\begin{wrapfigure}%s
  1753. %s\\centering
  1754. %s%s
  1755. %s\\end{wrapfigure}"
  1756. placement
  1757. (if caption-above-p caption "")
  1758. comment-include image-code
  1759. (if caption-above-p "" caption)))
  1760. (sideways (format "\\begin{sidewaysfigure}
  1761. %s\\centering
  1762. %s%s
  1763. %s\\end{sidewaysfigure}"
  1764. (if caption-above-p caption "")
  1765. comment-include image-code
  1766. (if caption-above-p "" caption)))
  1767. (multicolumn (format "\\begin{figure*}%s
  1768. %s\\centering
  1769. %s%s
  1770. %s\\end{figure*}"
  1771. placement
  1772. (if caption-above-p caption "")
  1773. comment-include image-code
  1774. (if caption-above-p "" caption)))
  1775. (figure (format "\\begin{figure}%s
  1776. %s\\centering
  1777. %s%s
  1778. %s\\end{figure}"
  1779. placement
  1780. (if caption-above-p caption "")
  1781. comment-include image-code
  1782. (if caption-above-p "" caption)))
  1783. (otherwise image-code))))
  1784. (defun org-latex-link (link desc info)
  1785. "Transcode a LINK object from Org to LaTeX.
  1786. DESC is the description part of the link, or the empty string.
  1787. INFO is a plist holding contextual information. See
  1788. `org-export-data'."
  1789. (let* ((type (org-element-property :type link))
  1790. (raw-path (replace-regexp-in-string
  1791. "%" "\\%" (org-element-property :path link) nil t))
  1792. ;; Ensure DESC really exists, or set it to nil.
  1793. (desc (and (not (string= desc "")) desc))
  1794. (imagep (org-export-inline-image-p
  1795. link (plist-get info :latex-inline-image-rules)))
  1796. (path (cond
  1797. ((member type '("http" "https" "ftp" "mailto" "doi"))
  1798. (concat type ":" raw-path))
  1799. ((and (string= type "file") (file-name-absolute-p raw-path))
  1800. (concat "file:" raw-path))
  1801. (t raw-path))))
  1802. (cond
  1803. ;; Link type is handled by a special function.
  1804. ((org-export-custom-protocol-maybe link desc 'latex))
  1805. ;; Image file.
  1806. (imagep (org-latex--inline-image link info))
  1807. ;; Radio link: Transcode target's contents and use them as link's
  1808. ;; description.
  1809. ((string= type "radio")
  1810. (let ((destination (org-export-resolve-radio-link link info)))
  1811. (if (not destination) desc
  1812. (format "\\hyperref[%s]{%s}"
  1813. (org-export-get-reference destination info)
  1814. desc))))
  1815. ;; Links pointing to a headline: Find destination and build
  1816. ;; appropriate referencing command.
  1817. ((member type '("custom-id" "fuzzy" "id"))
  1818. (let ((destination (if (string= type "fuzzy")
  1819. (org-export-resolve-fuzzy-link link info)
  1820. (org-export-resolve-id-link link info))))
  1821. (case (org-element-type destination)
  1822. ;; Id link points to an external file.
  1823. (plain-text
  1824. (if desc (format "\\href{%s}{%s}" destination desc)
  1825. (format "\\url{%s}" destination)))
  1826. ;; Fuzzy link points nowhere.
  1827. ((nil)
  1828. (format (plist-get info :latex-link-with-unknown-path-format)
  1829. (or desc
  1830. (org-export-data
  1831. (org-element-property :raw-link link) info))))
  1832. ;; LINK points to a headline. If headlines are numbered
  1833. ;; and the link has no description, display headline's
  1834. ;; number. Otherwise, display description or headline's
  1835. ;; title.
  1836. (headline
  1837. (let ((label (org-latex--label destination info t)))
  1838. (if (and (not desc)
  1839. (org-export-numbered-headline-p destination info))
  1840. (format "\\ref{%s}" label)
  1841. (format "\\hyperref[%s]{%s}" label
  1842. (or desc
  1843. (org-export-data
  1844. (org-element-property :title destination) info))))))
  1845. ;; Fuzzy link points to a target. Do as above.
  1846. (otherwise
  1847. (let ((ref (org-latex--label destination info t)))
  1848. (if (not desc) (format "\\ref{%s}" ref)
  1849. (format "\\hyperref[%s]{%s}" ref desc)))))))
  1850. ;; Coderef: replace link with the reference name or the
  1851. ;; equivalent line number.
  1852. ((string= type "coderef")
  1853. (format (org-export-get-coderef-format path desc)
  1854. (org-export-resolve-coderef path info)))
  1855. ;; External link with a description part.
  1856. ((and path desc) (format "\\href{%s}{%s}" path desc))
  1857. ;; External link without a description part.
  1858. (path (format "\\url{%s}" path))
  1859. ;; No path, only description. Try to do something useful.
  1860. (t (format (plist-get info :latex-link-with-unknown-path-format) desc)))))
  1861. ;;;; Node Property
  1862. (defun org-latex-node-property (node-property contents info)
  1863. "Transcode a NODE-PROPERTY element from Org to LaTeX.
  1864. CONTENTS is nil. INFO is a plist holding contextual
  1865. information."
  1866. (format "%s:%s"
  1867. (org-element-property :key node-property)
  1868. (let ((value (org-element-property :value node-property)))
  1869. (if value (concat " " value) ""))))
  1870. ;;;; Paragraph
  1871. (defun org-latex-paragraph (paragraph contents info)
  1872. "Transcode a PARAGRAPH element from Org to LaTeX.
  1873. CONTENTS is the contents of the paragraph, as a string. INFO is
  1874. the plist used as a communication channel."
  1875. contents)
  1876. ;;;; Plain List
  1877. (defun org-latex-plain-list (plain-list contents info)
  1878. "Transcode a PLAIN-LIST element from Org to LaTeX.
  1879. CONTENTS is the contents of the list. INFO is a plist holding
  1880. contextual information."
  1881. (let* ((type (org-element-property :type plain-list))
  1882. (attr (org-export-read-attribute :attr_latex plain-list))
  1883. (latex-type (let ((env (plist-get attr :environment)))
  1884. (cond (env (format "%s" env))
  1885. ((eq type 'ordered) "enumerate")
  1886. ((eq type 'descriptive) "description")
  1887. (t "itemize")))))
  1888. (org-latex--wrap-label
  1889. plain-list
  1890. (format "\\begin{%s}%s\n%s\\end{%s}"
  1891. latex-type
  1892. (or (plist-get attr :options) "")
  1893. contents
  1894. latex-type)
  1895. info)))
  1896. ;;;; Plain Text
  1897. (defun org-latex-plain-text (text info)
  1898. "Transcode a TEXT string from Org to LaTeX.
  1899. TEXT is the string to transcode. INFO is a plist holding
  1900. contextual information."
  1901. (let* ((specialp (plist-get info :with-special-strings))
  1902. (output
  1903. ;; Turn LaTeX into \LaTeX{} and TeX into \TeX{}.
  1904. (let ((case-fold-search nil))
  1905. (replace-regexp-in-string
  1906. "\\<\\(?:La\\)?TeX\\>" "\\\\\\&{}"
  1907. ;; Protect ^, ~, %, #, &, $, _, { and }. Also protect \.
  1908. ;; However, if special strings are used, be careful not
  1909. ;; to protect "\" in "\-" constructs.
  1910. (replace-regexp-in-string
  1911. (concat "[%$#&{}_~^]\\|\\\\" (and specialp "\\(?:[^-]\\|$\\)"))
  1912. (lambda (m)
  1913. (case (aref m 0)
  1914. (?\\ "$\\\\backslash$")
  1915. (?~ "\\\\textasciitilde{}")
  1916. (?^ "\\\\^{}")
  1917. (t "\\\\\\&")))
  1918. text)))))
  1919. ;; Activate smart quotes. Be sure to provide original TEXT string
  1920. ;; since OUTPUT may have been modified.
  1921. (when (plist-get info :with-smart-quotes)
  1922. (setq output (org-export-activate-smart-quotes output :latex info text)))
  1923. ;; Convert special strings.
  1924. (when specialp
  1925. (setq output (replace-regexp-in-string "\\.\\.\\." "\\\\ldots{}" output)))
  1926. ;; Handle break preservation if required.
  1927. (when (plist-get info :preserve-breaks)
  1928. (setq output (replace-regexp-in-string
  1929. "\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n" output nil t)))
  1930. ;; Return value.
  1931. output))
  1932. ;;;; Planning
  1933. (defun org-latex-planning (planning contents info)
  1934. "Transcode a PLANNING element from Org to LaTeX.
  1935. CONTENTS is nil. INFO is a plist holding contextual
  1936. information."
  1937. (concat
  1938. "\\noindent"
  1939. (mapconcat
  1940. 'identity
  1941. (delq nil
  1942. (list
  1943. (let ((closed (org-element-property :closed planning)))
  1944. (when closed
  1945. (concat
  1946. (format "\\textbf{%s} " org-closed-string)
  1947. (format (plist-get info :latex-inactive-timestamp-format)
  1948. (org-timestamp-translate closed)))))
  1949. (let ((deadline (org-element-property :deadline planning)))
  1950. (when deadline
  1951. (concat
  1952. (format "\\textbf{%s} " org-deadline-string)
  1953. (format (plist-get info :latex-active-timestamp-format)
  1954. (org-timestamp-translate deadline)))))
  1955. (let ((scheduled (org-element-property :scheduled planning)))
  1956. (when scheduled
  1957. (concat
  1958. (format "\\textbf{%s} " org-scheduled-string)
  1959. (format (plist-get info :latex-active-timestamp-format)
  1960. (org-timestamp-translate scheduled)))))))
  1961. " ")
  1962. "\\\\"))
  1963. ;;;; Property Drawer
  1964. (defun org-latex-property-drawer (property-drawer contents info)
  1965. "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
  1966. CONTENTS holds the contents of the drawer. INFO is a plist
  1967. holding contextual information."
  1968. (and (org-string-nw-p contents)
  1969. (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
  1970. ;;;; Pseudo Element: LaTeX Matrices
  1971. ;; `latex-matrices' elements have the following properties:
  1972. ;; `:caption', `:post-blank' and `:markup' (`inline', `equation' or
  1973. ;; `math').
  1974. (defun org-latex--wrap-latex-matrices (data info)
  1975. "Merge contiguous tables with the same mode within a pseudo-element.
  1976. DATA is a parse tree or a secondary string. INFO is a plist
  1977. containing export options. Modify DATA by side-effect and return
  1978. it."
  1979. (org-element-map data 'table
  1980. (lambda (table)
  1981. (when (eq (org-element-property :type table) 'org)
  1982. (let ((mode (or (org-export-read-attribute :attr_latex table :mode)
  1983. (plist-get info :latex-default-table-mode))))
  1984. (when (and (member mode '("inline-math" "math"))
  1985. ;; Do not wrap twice the same table.
  1986. (not (eq (org-element-type
  1987. (org-element-property :parent table))
  1988. 'latex-matrices)))
  1989. (let* ((caption (and (not (string= mode "inline-math"))
  1990. (org-element-property :caption table)))
  1991. (matrices
  1992. (list 'latex-matrices
  1993. (list :caption caption
  1994. :markup
  1995. (cond ((string= mode "inline-math") 'inline)
  1996. (caption 'equation)
  1997. (t 'math)))))
  1998. (previous table)
  1999. (next (org-export-get-next-element table info)))
  2000. (org-element-insert-before matrices table)
  2001. ;; Swallow all contiguous tables sharing the same mode.
  2002. (while (and
  2003. (zerop (or (org-element-property :post-blank previous) 0))
  2004. (setq next (org-export-get-next-element previous info))
  2005. (eq (org-element-type next) 'table)
  2006. (eq (org-element-property :type next) 'org)
  2007. (string= (or (org-export-read-attribute
  2008. :attr_latex next :mode)
  2009. (plist-get info :latex-default-table-mode))
  2010. mode))
  2011. (org-element-extract-element previous)
  2012. (org-element-adopt-elements matrices previous)
  2013. (setq previous next))
  2014. (org-element-put-property
  2015. matrices :post-blank (org-element-property :post-blank previous))
  2016. (org-element-extract-element previous)
  2017. (org-element-adopt-elements matrices previous))))))
  2018. info)
  2019. data)
  2020. (defun org-latex-matrices (matrices contents info)
  2021. "Transcode a MATRICES element from Org to LaTeX.
  2022. CONTENTS is a string. INFO is a plist used as a communication
  2023. channel."
  2024. (format (case (org-element-property :markup matrices)
  2025. (inline "\\(%s\\)")
  2026. (equation "\\begin{equation}\n%s\\end{equation}")
  2027. (t "\\[\n%s\\]"))
  2028. contents))
  2029. (defun org-latex-matrices-tree-filter (tree backend info)
  2030. (org-latex--wrap-latex-matrices tree info))
  2031. ;;;; Pseudo Object: LaTeX Math Block
  2032. ;; `latex-math-block' objects have the following property:
  2033. ;; `:post-blank'.
  2034. (defun org-latex--wrap-latex-math-block (data info)
  2035. "Merge contiguous math objects in a pseudo-object container.
  2036. DATA is a parse tree or a secondary string. INFO is a plist
  2037. containing export options. Modify DATA by side-effect and return it."
  2038. (let ((valid-object-p
  2039. (function
  2040. ;; Non-nil when OBJ can be added to the latex math block.
  2041. (lambda (obj)
  2042. (case (org-element-type obj)
  2043. (entity (org-element-property :latex-math-p obj))
  2044. (latex-fragment
  2045. (let ((value (org-element-property :value obj)))
  2046. (or (org-string-match-p "\\`\\\\([^\000]*\\\\)\\'" value)
  2047. (org-string-match-p "\\`\\$[^\000]*\\$\\'" value))))
  2048. ((subscript superscript) t))))))
  2049. (org-element-map data '(entity latex-fragment subscript superscript)
  2050. (lambda (object)
  2051. ;; Skip objects already wrapped.
  2052. (when (and (not (eq (org-element-type
  2053. (org-element-property :parent object))
  2054. 'latex-math-block))
  2055. (funcall valid-object-p object))
  2056. (let ((math-block (list 'latex-math-block nil))
  2057. (next-elements (org-export-get-next-element object info t))
  2058. (last object))
  2059. ;; Wrap MATH-BLOCK around OBJECT in DATA.
  2060. (org-element-insert-before math-block object)
  2061. (org-element-extract-element object)
  2062. (org-element-adopt-elements math-block object)
  2063. (when (zerop (or (org-element-property :post-blank object) 0))
  2064. ;; MATH-BLOCK swallows consecutive math objects.
  2065. (catch 'exit
  2066. (dolist (next next-elements)
  2067. (if (not (funcall valid-object-p next)) (throw 'exit nil)
  2068. (org-element-extract-element next)
  2069. (org-element-adopt-elements math-block next)
  2070. ;; Eschew the case: \beta$x$ -> \(\betax\).
  2071. (unless (memq (org-element-type next)
  2072. '(subscript superscript))
  2073. (org-element-put-property last :post-blank 1))
  2074. (setq last next)
  2075. (when (> (or (org-element-property :post-blank next) 0) 0)
  2076. (throw 'exit nil))))))
  2077. (org-element-put-property
  2078. math-block :post-blank (org-element-property :post-blank last)))))
  2079. info nil '(subscript superscript latex-math-block) t)
  2080. ;; Return updated DATA.
  2081. data))
  2082. (defun org-latex-math-block-tree-filter (tree backend info)
  2083. (org-latex--wrap-latex-math-block tree info))
  2084. (defun org-latex-math-block-options-filter (info backend)
  2085. (dolist (prop '(:author :date :title) info)
  2086. (plist-put info prop
  2087. (org-latex--wrap-latex-math-block (plist-get info prop) info))))
  2088. (defun org-latex-math-block (math-block contents info)
  2089. "Transcode a MATH-BLOCK object from Org to LaTeX.
  2090. CONTENTS is a string. INFO is a plist used as a communication
  2091. channel."
  2092. (when (org-string-nw-p contents)
  2093. (format "\\(%s\\)" (org-trim contents))))
  2094. ;;;; Quote Block
  2095. (defun org-latex-quote-block (quote-block contents info)
  2096. "Transcode a QUOTE-BLOCK element from Org to LaTeX.
  2097. CONTENTS holds the contents of the block. INFO is a plist
  2098. holding contextual information."
  2099. (org-latex--wrap-label
  2100. quote-block (format "\\begin{quote}\n%s\\end{quote}" contents) info))
  2101. ;;;; Radio Target
  2102. (defun org-latex-radio-target (radio-target text info)
  2103. "Transcode a RADIO-TARGET object from Org to LaTeX.
  2104. TEXT is the text of the target. INFO is a plist holding
  2105. contextual information."
  2106. (format "\\label{%s}%s" (org-export-get-reference radio-target info) text))
  2107. ;;;; Section
  2108. (defun org-latex-section (section contents info)
  2109. "Transcode a SECTION element from Org to LaTeX.
  2110. CONTENTS holds the contents of the section. INFO is a plist
  2111. holding contextual information."
  2112. contents)
  2113. ;;;; Special Block
  2114. (defun org-latex-special-block (special-block contents info)
  2115. "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
  2116. CONTENTS holds the contents of the block. INFO is a plist
  2117. holding contextual information."
  2118. (let ((type (org-element-property :type special-block))
  2119. (opt (org-export-read-attribute :attr_latex special-block :options))
  2120. (caption (org-latex--caption/label-string special-block info))
  2121. (caption-above-p (org-latex--caption-above-p special-block info)))
  2122. (concat (format "\\begin{%s}%s\n" type (or opt ""))
  2123. (and caption-above-p caption)
  2124. contents
  2125. (and (not caption-above-p) caption)
  2126. (format "\\end{%s}" type))))
  2127. ;;;; Src Block
  2128. (defun org-latex-src-block (src-block contents info)
  2129. "Transcode a SRC-BLOCK element from Org to LaTeX.
  2130. CONTENTS holds the contents of the item. INFO is a plist holding
  2131. contextual information."
  2132. (when (org-string-nw-p (org-element-property :value src-block))
  2133. (let* ((lang (org-element-property :language src-block))
  2134. (caption (org-element-property :caption src-block))
  2135. (caption-above-p (org-latex--caption-above-p src-block info))
  2136. (label (org-element-property :name src-block))
  2137. (custom-env (and lang
  2138. (cadr (assq (intern lang)
  2139. org-latex-custom-lang-environments))))
  2140. (num-start (case (org-element-property :number-lines src-block)
  2141. (continued (org-export-get-loc src-block info))
  2142. (new 0)))
  2143. (retain-labels (org-element-property :retain-labels src-block))
  2144. (attributes (org-export-read-attribute :attr_latex src-block))
  2145. (float (plist-get attributes :float))
  2146. (listings (plist-get info :latex-listings)))
  2147. (cond
  2148. ;; Case 1. No source fontification.
  2149. ((not listings)
  2150. (let* ((caption-str (org-latex--caption/label-string src-block info))
  2151. (float-env
  2152. (cond ((and (not float) (plist-member attributes :float)) "%s")
  2153. ((string= "multicolumn" float)
  2154. (format "\\begin{figure*}[%s]\n%s%%s\n%s\\end{figure*}"
  2155. (plist-get info :latex-default-figure-position)
  2156. (if caption-above-p caption-str "")
  2157. (if caption-above-p "" caption-str)))
  2158. ((or caption float)
  2159. (format "\\begin{figure}[H]\n%%s\n%s\\end{figure}"
  2160. caption-str))
  2161. (t "%s"))))
  2162. (format
  2163. float-env
  2164. (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
  2165. (org-export-format-code-default src-block info))))))
  2166. ;; Case 2. Custom environment.
  2167. (custom-env
  2168. (let ((caption-str (org-latex--caption/label-string src-block info)))
  2169. (format "\\begin{%s}\n%s\\end{%s}\n"
  2170. custom-env
  2171. (concat (and caption-above-p caption-str)
  2172. (org-export-format-code-default src-block info)
  2173. (and (not caption-above-p) caption-str))
  2174. custom-env)))
  2175. ;; Case 3. Use minted package.
  2176. ((eq listings 'minted)
  2177. (let* ((caption-str (org-latex--caption/label-string src-block info))
  2178. (float-env
  2179. (cond
  2180. ((and (not float) (plist-member attributes :float) caption)
  2181. (let ((caption
  2182. (replace-regexp-in-string
  2183. "\\\\caption" "\\captionof{listing}" caption-str
  2184. t t)))
  2185. (concat (and caption-above-p caption)
  2186. "%%s"
  2187. (and (not caption-above-p) (concat "\n" caption)))))
  2188. ((and (not float) (plist-member attributes :float)) "%s")
  2189. ((string= "multicolumn" float)
  2190. (format "\\begin{listing*}\n%s%%s\n%s\\end{listing*}"
  2191. (if caption-above-p caption-str "")
  2192. (if caption-above-p "" caption-str)))
  2193. ((or caption float)
  2194. (format "\\begin{listing}[H]\n%s%%s\n%s\\end{listing}"
  2195. (if caption-above-p caption-str "")
  2196. (if caption-above-p "" caption-str)))
  2197. (t "%s")))
  2198. (options (plist-get info :latex-minted-options))
  2199. (body
  2200. (format
  2201. "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
  2202. ;; Options.
  2203. (concat
  2204. (org-latex--make-option-string
  2205. (if (or (not num-start) (assoc "linenos" options))
  2206. options
  2207. (append
  2208. `(("linenos")
  2209. ("firstnumber" ,(number-to-string (1+ num-start))))
  2210. options)))
  2211. (let ((local-options (plist-get attributes :options)))
  2212. (and local-options (concat "," local-options))))
  2213. ;; Language.
  2214. (or (cadr (assq (intern lang)
  2215. (plist-get info :latex-minted-langs)))
  2216. (downcase lang))
  2217. ;; Source code.
  2218. (let* ((code-info (org-export-unravel-code src-block))
  2219. (max-width
  2220. (apply 'max
  2221. (mapcar 'length
  2222. (org-split-string (car code-info)
  2223. "\n")))))
  2224. (org-export-format-code
  2225. (car code-info)
  2226. (lambda (loc num ref)
  2227. (concat
  2228. loc
  2229. (when ref
  2230. ;; Ensure references are flushed to the right,
  2231. ;; separated with 6 spaces from the widest line
  2232. ;; of code.
  2233. (concat (make-string (+ (- max-width (length loc)) 6)
  2234. ?\s)
  2235. (format "(%s)" ref)))))
  2236. nil (and retain-labels (cdr code-info)))))))
  2237. ;; Return value.
  2238. (format float-env body)))
  2239. ;; Case 4. Use listings package.
  2240. (t
  2241. (let ((lst-lang
  2242. (or (cadr (assq (intern lang)
  2243. (plist-get info :latex-listings-langs)))
  2244. lang))
  2245. (caption-str
  2246. (when caption
  2247. (let ((main (org-export-get-caption src-block))
  2248. (secondary (org-export-get-caption src-block t)))
  2249. (if (not secondary)
  2250. (format "{%s}" (org-export-data main info))
  2251. (format "{[%s]%s}"
  2252. (org-export-data secondary info)
  2253. (org-export-data main info))))))
  2254. (lst-opt (plist-get info :latex-listings-options)))
  2255. (concat
  2256. ;; Options.
  2257. (format
  2258. "\\lstset{%s}\n"
  2259. (concat
  2260. (org-latex--make-option-string
  2261. (append
  2262. lst-opt
  2263. (cond
  2264. ((and (not float) (plist-member attributes :float)) nil)
  2265. ((string= "multicolumn" float) '(("float" "*")))
  2266. ((and float (not (assoc "float" lst-opt)))
  2267. `(("float" ,(plist-get info :latex-default-figure-position)))))
  2268. `(("language" ,lst-lang))
  2269. (if label `(("label" ,label)) '(("label" " ")))
  2270. (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
  2271. `(("captionpos" ,(if caption-above-p "t" "b")))
  2272. (cond ((assoc "numbers" lst-opt) nil)
  2273. ((not num-start) '(("numbers" "none")))
  2274. ((zerop num-start) '(("numbers" "left")))
  2275. (t `(("firstnumber" ,(number-to-string (1+ num-start)))
  2276. ("numbers" "left"))))))
  2277. (let ((local-options (plist-get attributes :options)))
  2278. (and local-options (concat "," local-options)))))
  2279. ;; Source code.
  2280. (format
  2281. "\\begin{lstlisting}\n%s\\end{lstlisting}"
  2282. (let* ((code-info (org-export-unravel-code src-block))
  2283. (max-width
  2284. (apply 'max
  2285. (mapcar 'length
  2286. (org-split-string (car code-info) "\n")))))
  2287. (org-export-format-code
  2288. (car code-info)
  2289. (lambda (loc num ref)
  2290. (concat
  2291. loc
  2292. (when ref
  2293. ;; Ensure references are flushed to the right,
  2294. ;; separated with 6 spaces from the widest line of
  2295. ;; code
  2296. (concat (make-string (+ (- max-width (length loc)) 6) ? )
  2297. (format "(%s)" ref)))))
  2298. nil (and retain-labels (cdr code-info))))))))))))
  2299. ;;;; Statistics Cookie
  2300. (defun org-latex-statistics-cookie (statistics-cookie contents info)
  2301. "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
  2302. CONTENTS is nil. INFO is a plist holding contextual information."
  2303. (replace-regexp-in-string
  2304. "%" "\\%" (org-element-property :value statistics-cookie) nil t))
  2305. ;;;; Strike-Through
  2306. (defun org-latex-strike-through (strike-through contents info)
  2307. "Transcode STRIKE-THROUGH from Org to LaTeX.
  2308. CONTENTS is the text with strike-through markup. INFO is a plist
  2309. holding contextual information."
  2310. (org-latex--text-markup contents 'strike-through info))
  2311. ;;;; Subscript
  2312. (defun org-latex--script-size (object info)
  2313. "Transcode a subscript or superscript object.
  2314. OBJECT is an Org object. INFO is a plist used as a communication
  2315. channel."
  2316. (let ((type (org-element-type object))
  2317. (output ""))
  2318. (org-element-map (org-element-contents object)
  2319. (cons 'plain-text org-element-all-objects)
  2320. (lambda (obj)
  2321. (case (org-element-type obj)
  2322. ((entity latex-fragment)
  2323. (let ((data (org-trim (org-export-data obj info))))
  2324. (string-match
  2325. "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
  2326. data)
  2327. (setq output
  2328. (concat output
  2329. (match-string 1 data)
  2330. (let ((blank (org-element-property :post-blank obj)))
  2331. (and blank (> blank 0) "\\ "))))))
  2332. (plain-text
  2333. (setq output
  2334. (format "%s\\text{%s}" output (org-export-data obj info))))
  2335. (otherwise
  2336. (setq output
  2337. (concat output
  2338. (org-export-data obj info)
  2339. (let ((blank (org-element-property :post-blank obj)))
  2340. (and blank (> blank 0) "\\ ")))))))
  2341. info nil org-element-recursive-objects)
  2342. ;; Result. Do not wrap into curly brackets if OUTPUT is a single
  2343. ;; character.
  2344. (concat (if (eq (org-element-type object) 'subscript) "_" "^")
  2345. (and (> (length output) 1) "{")
  2346. output
  2347. (and (> (length output) 1) "}"))))
  2348. (defun org-latex-subscript (subscript contents info)
  2349. "Transcode a SUBSCRIPT object from Org to LaTeX.
  2350. CONTENTS is the contents of the object. INFO is a plist holding
  2351. contextual information."
  2352. (org-latex--script-size subscript info))
  2353. ;;;; Superscript
  2354. (defun org-latex-superscript (superscript contents info)
  2355. "Transcode a SUPERSCRIPT object from Org to LaTeX.
  2356. CONTENTS is the contents of the object. INFO is a plist holding
  2357. contextual information."
  2358. (org-latex--script-size superscript info))
  2359. ;;;; Table
  2360. ;;
  2361. ;; `org-latex-table' is the entry point for table transcoding. It
  2362. ;; takes care of tables with a "verbatim" mode. Otherwise, it
  2363. ;; delegates the job to either `org-latex--table.el-table',
  2364. ;; `org-latex--org-table' or `org-latex--math-table' functions,
  2365. ;; depending of the type of the table and the mode requested.
  2366. ;;
  2367. ;; `org-latex--align-string' is a subroutine used to build alignment
  2368. ;; string for Org tables.
  2369. (defun org-latex-table (table contents info)
  2370. "Transcode a TABLE element from Org to LaTeX.
  2371. CONTENTS is the contents of the table. INFO is a plist holding
  2372. contextual information."
  2373. (if (eq (org-element-property :type table) 'table.el)
  2374. ;; "table.el" table. Convert it using appropriate tools.
  2375. (org-latex--table.el-table table info)
  2376. (let ((type (or (org-export-read-attribute :attr_latex table :mode)
  2377. (plist-get info :latex-default-table-mode))))
  2378. (cond
  2379. ;; Case 1: Verbatim table.
  2380. ((string= type "verbatim")
  2381. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  2382. ;; Re-create table, without affiliated keywords.
  2383. (org-trim (org-element-interpret-data
  2384. `(table nil ,@(org-element-contents table))))))
  2385. ;; Case 2: Matrix.
  2386. ((or (string= type "math") (string= type "inline-math"))
  2387. (org-latex--math-table table info))
  2388. ;; Case 3: Standard table.
  2389. (t (concat (org-latex--org-table table contents info)
  2390. ;; When there are footnote references within the
  2391. ;; table, insert their definition just after it.
  2392. (org-latex--delayed-footnotes-definitions table info)))))))
  2393. (defun org-latex--align-string (table info)
  2394. "Return an appropriate LaTeX alignment string.
  2395. TABLE is the considered table. INFO is a plist used as
  2396. a communication channel."
  2397. (or (org-export-read-attribute :attr_latex table :align)
  2398. (let (align)
  2399. ;; Extract column groups and alignment from first (non-rule)
  2400. ;; row.
  2401. (org-element-map
  2402. (org-element-map table 'table-row
  2403. (lambda (row)
  2404. (and (eq (org-element-property :type row) 'standard) row))
  2405. info 'first-match)
  2406. 'table-cell
  2407. (lambda (cell)
  2408. (let ((borders (org-export-table-cell-borders cell info)))
  2409. ;; Check left border for the first cell only.
  2410. (when (and (memq 'left borders) (not align))
  2411. (push "|" align))
  2412. (push (case (org-export-table-cell-alignment cell info)
  2413. (left "l")
  2414. (right "r")
  2415. (center "c"))
  2416. align)
  2417. (when (memq 'right borders) (push "|" align))))
  2418. info)
  2419. (apply 'concat (nreverse align)))))
  2420. (defun org-latex--org-table (table contents info)
  2421. "Return appropriate LaTeX code for an Org table.
  2422. TABLE is the table type element to transcode. CONTENTS is its
  2423. contents, as a string. INFO is a plist used as a communication
  2424. channel.
  2425. This function assumes TABLE has `org' as its `:type' property and
  2426. `table' as its `:mode' attribute."
  2427. (let* ((caption (org-latex--caption/label-string table info))
  2428. (attr (org-export-read-attribute :attr_latex table))
  2429. ;; Determine alignment string.
  2430. (alignment (org-latex--align-string table info))
  2431. ;; Determine environment for the table: longtable, tabular...
  2432. (table-env (or (plist-get attr :environment)
  2433. (plist-get info :latex-default-table-environment)))
  2434. ;; If table is a float, determine environment: table, table*
  2435. ;; or sidewaystable.
  2436. (float-env (unless (member table-env '("longtable" "longtabu"))
  2437. (let ((float (plist-get attr :float)))
  2438. (cond
  2439. ((and (not float) (plist-member attr :float)) nil)
  2440. ((or (string= float "sidewaystable")
  2441. (string= float "sideways")) "sidewaystable")
  2442. ((string= float "multicolumn") "table*")
  2443. ((or float
  2444. (org-element-property :caption table)
  2445. (org-string-nw-p (plist-get attr :caption)))
  2446. "table")))))
  2447. ;; Extract others display options.
  2448. (fontsize (let ((font (plist-get attr :font)))
  2449. (and font (concat font "\n"))))
  2450. ;; "tabular" environment doesn't allow to define a width.
  2451. (width (and (not (equal table-env "tabular")) (plist-get attr :width)))
  2452. (spreadp (plist-get attr :spread))
  2453. (placement
  2454. (or (plist-get attr :placement)
  2455. (format "[%s]" (plist-get info :latex-default-figure-position))))
  2456. (centerp (if (plist-member attr :center) (plist-get attr :center)
  2457. (plist-get info :latex-tables-centered)))
  2458. (caption-above-p (org-latex--caption-above-p table info)))
  2459. ;; Prepare the final format string for the table.
  2460. (cond
  2461. ;; Longtable.
  2462. ((equal "longtable" table-env)
  2463. (concat (and fontsize (concat "{" fontsize))
  2464. (format "\\begin{longtable}{%s}\n" alignment)
  2465. (and caption-above-p
  2466. (org-string-nw-p caption)
  2467. (concat caption "\\\\\n"))
  2468. contents
  2469. (and (not caption-above-p)
  2470. (org-string-nw-p caption)
  2471. (concat caption "\\\\\n"))
  2472. "\\end{longtable}\n"
  2473. (and fontsize "}")))
  2474. ;; Longtabu
  2475. ((equal "longtabu" table-env)
  2476. (concat (and fontsize (concat "{" fontsize))
  2477. (format "\\begin{longtabu}%s{%s}\n"
  2478. (if width
  2479. (format " %s %s "
  2480. (if spreadp "spread" "to") width) "")
  2481. alignment)
  2482. (and caption-above-p
  2483. (org-string-nw-p caption)
  2484. (concat caption "\\\\\n"))
  2485. contents
  2486. (and (not caption-above-p)
  2487. (org-string-nw-p caption)
  2488. (concat caption "\\\\\n"))
  2489. "\\end{longtabu}\n"
  2490. (and fontsize "}")))
  2491. ;; Others.
  2492. (t (concat (cond
  2493. (float-env
  2494. (concat (format "\\begin{%s}%s\n" float-env placement)
  2495. (if caption-above-p caption "")
  2496. (when centerp "\\centering\n")
  2497. fontsize))
  2498. (centerp (concat "\\begin{center}\n" fontsize))
  2499. (fontsize (concat "{" fontsize)))
  2500. (cond ((equal "tabu" table-env)
  2501. (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
  2502. (if width (format
  2503. (if spreadp " spread %s " " to %s ")
  2504. width) "")
  2505. alignment
  2506. contents))
  2507. (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
  2508. table-env
  2509. (if width (format "{%s}" width) "")
  2510. alignment
  2511. contents
  2512. table-env)))
  2513. (cond
  2514. (float-env
  2515. (concat (if caption-above-p "" caption)
  2516. (format "\n\\end{%s}" float-env)))
  2517. (centerp "\n\\end{center}")
  2518. (fontsize "}")))))))
  2519. (defun org-latex--table.el-table (table info)
  2520. "Return appropriate LaTeX code for a table.el table.
  2521. TABLE is the table type element to transcode. INFO is a plist
  2522. used as a communication channel.
  2523. This function assumes TABLE has `table.el' as its `:type'
  2524. property."
  2525. (require 'table)
  2526. ;; Ensure "*org-export-table*" buffer is empty.
  2527. (with-current-buffer (get-buffer-create "*org-export-table*")
  2528. (erase-buffer))
  2529. (let ((output (with-temp-buffer
  2530. (insert (org-element-property :value table))
  2531. (goto-char 1)
  2532. (re-search-forward "^[ \t]*|[^|]" nil t)
  2533. (table-generate-source 'latex "*org-export-table*")
  2534. (with-current-buffer "*org-export-table*"
  2535. (org-trim (buffer-string))))))
  2536. (kill-buffer (get-buffer "*org-export-table*"))
  2537. ;; Remove left out comments.
  2538. (while (string-match "^%.*\n" output)
  2539. (setq output (replace-match "" t t output)))
  2540. (let ((attr (org-export-read-attribute :attr_latex table)))
  2541. (when (plist-get attr :rmlines)
  2542. ;; When the "rmlines" attribute is provided, remove all hlines
  2543. ;; but the the one separating heading from the table body.
  2544. (let ((n 0) (pos 0))
  2545. (while (and (< (length output) pos)
  2546. (setq pos (string-match "^\\\\hline\n?" output pos)))
  2547. (incf n)
  2548. (unless (= n 2) (setq output (replace-match "" nil nil output))))))
  2549. (let ((centerp (if (plist-member attr :center) (plist-get attr :center)
  2550. (plist-get info :latex-tables-centered))))
  2551. (if (not centerp) output
  2552. (format "\\begin{center}\n%s\n\\end{center}" output))))))
  2553. (defun org-latex--math-table (table info)
  2554. "Return appropriate LaTeX code for a matrix.
  2555. TABLE is the table type element to transcode. INFO is a plist
  2556. used as a communication channel.
  2557. This function assumes TABLE has `org' as its `:type' property and
  2558. `inline-math' or `math' as its `:mode' attribute."
  2559. (let* ((attr (org-export-read-attribute :attr_latex table))
  2560. (env (or (plist-get attr :environment)
  2561. (plist-get info :latex-default-table-environment)))
  2562. (contents
  2563. (mapconcat
  2564. (lambda (row)
  2565. ;; Ignore horizontal rules.
  2566. (when (eq (org-element-property :type row) 'standard)
  2567. ;; Return each cell unmodified.
  2568. (concat
  2569. (mapconcat
  2570. (lambda (cell)
  2571. (substring (org-element-interpret-data cell) 0 -1))
  2572. (org-element-map row 'table-cell #'identity info) "&")
  2573. (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
  2574. "\n")))
  2575. (org-element-map table 'table-row #'identity info) "")))
  2576. (concat
  2577. ;; Prefix.
  2578. (plist-get attr :math-prefix)
  2579. ;; Environment. Also treat special cases.
  2580. (cond ((member env '("array" "tabular"))
  2581. (let ((align (make-string
  2582. (cdr (org-export-table-dimensions table info)) ?c)))
  2583. (format "\\begin{%s}{%s}\n%s\\end{%s}" env align contents env)))
  2584. ((assoc env org-latex-table-matrix-macros)
  2585. (format "\\%s%s{\n%s}"
  2586. env
  2587. (or (plist-get attr :math-arguments) "")
  2588. contents))
  2589. (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
  2590. ;; Suffix.
  2591. (plist-get attr :math-suffix))))
  2592. ;;;; Table Cell
  2593. (defun org-latex-table-cell (table-cell contents info)
  2594. "Transcode a TABLE-CELL element from Org to LaTeX.
  2595. CONTENTS is the cell contents. INFO is a plist used as
  2596. a communication channel."
  2597. (concat
  2598. (let ((scientific-format (plist-get info :latex-table-scientific-notation)))
  2599. (if (and contents
  2600. scientific-format
  2601. (string-match orgtbl-exp-regexp contents))
  2602. ;; Use appropriate format string for scientific
  2603. ;; notation.
  2604. (format scientific-format
  2605. (match-string 1 contents)
  2606. (match-string 2 contents))
  2607. contents))
  2608. (when (org-export-get-next-element table-cell info) " & ")))
  2609. ;;;; Table Row
  2610. (defun org-latex-table-row (table-row contents info)
  2611. "Transcode a TABLE-ROW element from Org to LaTeX.
  2612. CONTENTS is the contents of the row. INFO is a plist used as
  2613. a communication channel."
  2614. (let* ((attr (org-export-read-attribute :attr_latex
  2615. (org-export-get-parent table-row)))
  2616. (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
  2617. (plist-get info :latex-tables-booktabs)))
  2618. (longtablep
  2619. (member (or (plist-get attr :environment)
  2620. (plist-get info :latex-default-table-environment))
  2621. '("longtable" "longtabu"))))
  2622. (if (eq (org-element-property :type table-row) 'rule)
  2623. (cond
  2624. ((not booktabsp) "\\hline")
  2625. ((not (org-export-get-previous-element table-row info)) "\\toprule")
  2626. ((not (org-export-get-next-element table-row info)) "\\bottomrule")
  2627. ((and longtablep
  2628. (org-export-table-row-ends-header-p
  2629. (org-export-get-previous-element table-row info) info))
  2630. "")
  2631. (t "\\midrule"))
  2632. (concat
  2633. ;; When BOOKTABS are activated enforce top-rule even when no
  2634. ;; hline was specifically marked.
  2635. (and booktabsp (not (org-export-get-previous-element table-row info))
  2636. "\\toprule\n")
  2637. contents "\\\\\n"
  2638. (cond
  2639. ;; Special case for long tables. Define header and footers.
  2640. ((and longtablep (org-export-table-row-ends-header-p table-row info))
  2641. (let ((columns (cdr (org-export-table-dimensions
  2642. (org-export-get-parent-table table-row) info))))
  2643. (format "%s
  2644. \\endfirsthead
  2645. \\multicolumn{%d}{l}{%s} \\\\
  2646. %s
  2647. %s \\\\\n
  2648. %s
  2649. \\endhead
  2650. %s\\multicolumn{%d}{r}{%s} \\\\
  2651. \\endfoot
  2652. \\endlastfoot"
  2653. (if booktabsp "\\midrule" "\\hline")
  2654. columns
  2655. (org-latex--translate "Continued from previous page" info)
  2656. (cond
  2657. ((not (org-export-table-row-starts-header-p table-row info))
  2658. "")
  2659. (booktabsp "\\toprule\n")
  2660. (t "\\hline\n"))
  2661. contents
  2662. (if booktabsp "\\midrule" "\\hline")
  2663. (if booktabsp "\\midrule" "\\hline")
  2664. columns
  2665. (org-latex--translate "Continued on next page" info))))
  2666. ;; When BOOKTABS are activated enforce bottom rule even when
  2667. ;; no hline was specifically marked.
  2668. ((and booktabsp (not (org-export-get-next-element table-row info)))
  2669. "\\bottomrule"))))))
  2670. ;;;; Target
  2671. (defun org-latex-target (target contents info)
  2672. "Transcode a TARGET object from Org to LaTeX.
  2673. CONTENTS is nil. INFO is a plist holding contextual
  2674. information."
  2675. (format "\\label{%s}" (org-export-get-reference target info)))
  2676. ;;;; Timestamp
  2677. (defun org-latex-timestamp (timestamp contents info)
  2678. "Transcode a TIMESTAMP object from Org to LaTeX.
  2679. CONTENTS is nil. INFO is a plist holding contextual
  2680. information."
  2681. (let ((value (org-latex-plain-text (org-timestamp-translate timestamp) info)))
  2682. (format
  2683. (plist-get info
  2684. (case (org-element-property :type timestamp)
  2685. ((active active-range) :latex-active-timestamp-format)
  2686. ((inactive inactive-range) :latex-inactive-timestamp-format)
  2687. (otherwise :latex-diary-timestamp-format)))
  2688. value)))
  2689. ;;;; Underline
  2690. (defun org-latex-underline (underline contents info)
  2691. "Transcode UNDERLINE from Org to LaTeX.
  2692. CONTENTS is the text with underline markup. INFO is a plist
  2693. holding contextual information."
  2694. (org-latex--text-markup contents 'underline info))
  2695. ;;;; Verbatim
  2696. (defun org-latex-verbatim (verbatim contents info)
  2697. "Transcode a VERBATIM object from Org to LaTeX.
  2698. CONTENTS is nil. INFO is a plist used as a communication
  2699. channel."
  2700. (org-latex--text-markup
  2701. (org-element-property :value verbatim) 'verbatim info))
  2702. ;;;; Verse Block
  2703. (defun org-latex-verse-block (verse-block contents info)
  2704. "Transcode a VERSE-BLOCK element from Org to LaTeX.
  2705. CONTENTS is verse block contents. INFO is a plist holding
  2706. contextual information."
  2707. (org-latex--wrap-label
  2708. verse-block
  2709. ;; In a verse environment, add a line break to each newline
  2710. ;; character and change each white space at beginning of a line
  2711. ;; into a space of 1 em. Also change each blank line with
  2712. ;; a vertical space of 1 em.
  2713. (format "\\begin{verse}\n%s\\end{verse}"
  2714. (replace-regexp-in-string
  2715. "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
  2716. (replace-regexp-in-string
  2717. "^[ \t]*\\\\\\\\$" "\\vspace*{1em}"
  2718. (replace-regexp-in-string
  2719. "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n"
  2720. contents nil t) nil t) nil t))
  2721. info))
  2722. ;;; End-user functions
  2723. ;;;###autoload
  2724. (defun org-latex-export-as-latex
  2725. (&optional async subtreep visible-only body-only ext-plist)
  2726. "Export current buffer as a LaTeX buffer.
  2727. If narrowing is active in the current buffer, only export its
  2728. narrowed part.
  2729. If a region is active, export that region.
  2730. A non-nil optional argument ASYNC means the process should happen
  2731. asynchronously. The resulting buffer should be accessible
  2732. through the `org-export-stack' interface.
  2733. When optional argument SUBTREEP is non-nil, export the sub-tree
  2734. at point, extracting information from the headline properties
  2735. first.
  2736. When optional argument VISIBLE-ONLY is non-nil, don't export
  2737. contents of hidden elements.
  2738. When optional argument BODY-ONLY is non-nil, only write code
  2739. between \"\\begin{document}\" and \"\\end{document}\".
  2740. EXT-PLIST, when provided, is a property list with external
  2741. parameters overriding Org default settings, but still inferior to
  2742. file-local settings.
  2743. Export is done in a buffer named \"*Org LATEX Export*\", which
  2744. will be displayed when `org-export-show-temporary-export-buffer'
  2745. is non-nil."
  2746. (interactive)
  2747. (org-export-to-buffer 'latex "*Org LATEX Export*"
  2748. async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
  2749. ;;;###autoload
  2750. (defun org-latex-convert-region-to-latex ()
  2751. "Assume the current region has org-mode syntax, and convert it to LaTeX.
  2752. This can be used in any buffer. For example, you can write an
  2753. itemized list in org-mode syntax in an LaTeX buffer and use this
  2754. command to convert it."
  2755. (interactive)
  2756. (org-export-replace-region-by 'latex))
  2757. ;;;###autoload
  2758. (defun org-latex-export-to-latex
  2759. (&optional async subtreep visible-only body-only ext-plist)
  2760. "Export current buffer to a LaTeX file.
  2761. If narrowing is active in the current buffer, only export its
  2762. narrowed part.
  2763. If a region is active, export that region.
  2764. A non-nil optional argument ASYNC means the process should happen
  2765. asynchronously. The resulting file should be accessible through
  2766. the `org-export-stack' interface.
  2767. When optional argument SUBTREEP is non-nil, export the sub-tree
  2768. at point, extracting information from the headline properties
  2769. first.
  2770. When optional argument VISIBLE-ONLY is non-nil, don't export
  2771. contents of hidden elements.
  2772. When optional argument BODY-ONLY is non-nil, only write code
  2773. between \"\\begin{document}\" and \"\\end{document}\".
  2774. EXT-PLIST, when provided, is a property list with external
  2775. parameters overriding Org default settings, but still inferior to
  2776. file-local settings."
  2777. (interactive)
  2778. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  2779. (org-export-to-file 'latex outfile
  2780. async subtreep visible-only body-only ext-plist)))
  2781. ;;;###autoload
  2782. (defun org-latex-export-to-pdf
  2783. (&optional async subtreep visible-only body-only ext-plist)
  2784. "Export current buffer to LaTeX then process through to PDF.
  2785. If narrowing is active in the current buffer, only export its
  2786. narrowed part.
  2787. If a region is active, export that region.
  2788. A non-nil optional argument ASYNC means the process should happen
  2789. asynchronously. The resulting file should be accessible through
  2790. the `org-export-stack' interface.
  2791. When optional argument SUBTREEP is non-nil, export the sub-tree
  2792. at point, extracting information from the headline properties
  2793. first.
  2794. When optional argument VISIBLE-ONLY is non-nil, don't export
  2795. contents of hidden elements.
  2796. When optional argument BODY-ONLY is non-nil, only write code
  2797. between \"\\begin{document}\" and \"\\end{document}\".
  2798. EXT-PLIST, when provided, is a property list with external
  2799. parameters overriding Org default settings, but still inferior to
  2800. file-local settings.
  2801. Return PDF file's name."
  2802. (interactive)
  2803. (let ((outfile (org-export-output-file-name ".tex" subtreep)))
  2804. (org-export-to-file 'latex outfile
  2805. async subtreep visible-only body-only ext-plist
  2806. (lambda (file) (org-latex-compile file)))))
  2807. (defun org-latex-compile (texfile &optional snippet)
  2808. "Compile a TeX file.
  2809. TEXFILE is the name of the file being compiled. Processing is
  2810. done through the command specified in `org-latex-pdf-process'.
  2811. When optional argument SNIPPET is non-nil, TEXFILE is a temporary
  2812. file used to preview a LaTeX snippet. In this case, do not
  2813. create a log buffer and do not bother removing log files.
  2814. Return PDF file name or an error if it couldn't be produced."
  2815. (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile)))
  2816. (full-name (file-truename texfile))
  2817. (out-dir (file-name-directory texfile))
  2818. ;; Properly set working directory for compilation.
  2819. (default-directory (if (file-name-absolute-p texfile)
  2820. (file-name-directory full-name)
  2821. default-directory))
  2822. (time (current-time))
  2823. warnings)
  2824. (unless snippet (message (format "Processing LaTeX file %s..." texfile)))
  2825. (save-window-excursion
  2826. (cond
  2827. ;; A function is provided: Apply it.
  2828. ((functionp org-latex-pdf-process)
  2829. (funcall org-latex-pdf-process (shell-quote-argument texfile)))
  2830. ;; A list is provided: Replace %b, %f and %o with appropriate
  2831. ;; values in each command before applying it. Output is
  2832. ;; redirected to "*Org PDF LaTeX Output*" buffer.
  2833. ((consp org-latex-pdf-process)
  2834. (let ((outbuf (and (not snippet)
  2835. (get-buffer-create "*Org PDF LaTeX Output*"))))
  2836. (dolist (command org-latex-pdf-process)
  2837. (shell-command
  2838. (replace-regexp-in-string
  2839. "%b" (shell-quote-argument base-name)
  2840. (replace-regexp-in-string
  2841. "%f" (shell-quote-argument full-name)
  2842. (replace-regexp-in-string
  2843. "%o" (shell-quote-argument out-dir) command t t) t t) t t)
  2844. outbuf))
  2845. ;; Collect standard errors from output buffer.
  2846. (setq warnings (and (not snippet)
  2847. (org-latex--collect-warnings outbuf)))))
  2848. (t (error "No valid command to process to PDF")))
  2849. (let ((pdffile (concat out-dir base-name ".pdf")))
  2850. ;; Check for process failure. Provide collected errors if
  2851. ;; possible.
  2852. (if (or (not (file-exists-p pdffile))
  2853. (time-less-p (nth 5 (file-attributes pdffile)) time))
  2854. (error (format "PDF file %s wasn't produced" pdffile))
  2855. ;; Else remove log files, when specified, and signal end of
  2856. ;; process to user, along with any error encountered.
  2857. (unless snippet
  2858. (when org-latex-remove-logfiles
  2859. (dolist (file (directory-files
  2860. out-dir t
  2861. (concat (regexp-quote base-name)
  2862. "\\(?:\\.[0-9]+\\)?"
  2863. "\\."
  2864. (regexp-opt org-latex-logfiles-extensions))))
  2865. (delete-file file)))
  2866. (message (concat "PDF file produced"
  2867. (cond
  2868. ((eq warnings 'error) " with errors.")
  2869. (warnings (concat " with warnings: " warnings))
  2870. (t "."))))))
  2871. ;; Return output file name.
  2872. pdffile))))
  2873. (defun org-latex--collect-warnings (buffer)
  2874. "Collect some warnings from \"pdflatex\" command output.
  2875. BUFFER is the buffer containing output. Return collected
  2876. warnings types as a string, `error' if a LaTeX error was
  2877. encountered or nil if there was none."
  2878. (with-current-buffer buffer
  2879. (save-excursion
  2880. (goto-char (point-max))
  2881. (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
  2882. (if (re-search-forward "^!" nil t) 'error
  2883. (let ((case-fold-search t)
  2884. (warnings ""))
  2885. (dolist (warning org-latex-known-warnings)
  2886. (when (save-excursion (re-search-forward (car warning) nil t))
  2887. (setq warnings (concat warnings " " (cdr warning)))))
  2888. (org-string-nw-p (org-trim warnings))))))))
  2889. ;;;###autoload
  2890. (defun org-latex-publish-to-latex (plist filename pub-dir)
  2891. "Publish an Org file to LaTeX.
  2892. FILENAME is the filename of the Org file to be published. PLIST
  2893. is the property list for the given project. PUB-DIR is the
  2894. publishing directory.
  2895. Return output file name."
  2896. (org-publish-org-to 'latex filename ".tex" plist pub-dir))
  2897. ;;;###autoload
  2898. (defun org-latex-publish-to-pdf (plist filename pub-dir)
  2899. "Publish an Org file to PDF (via LaTeX).
  2900. FILENAME is the filename of the Org file to be published. PLIST
  2901. is the property list for the given project. PUB-DIR is the
  2902. publishing directory.
  2903. Return output file name."
  2904. ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
  2905. ;; in working directory and then moved to publishing directory.
  2906. (org-publish-attachment
  2907. plist
  2908. (org-latex-compile
  2909. (org-publish-org-to
  2910. 'latex filename ".tex" plist (file-name-directory filename)))
  2911. pub-dir))
  2912. (provide 'ox-latex)
  2913. ;; Local variables:
  2914. ;; generated-autoload-file: "org-loaddefs.el"
  2915. ;; End:
  2916. ;;; ox-latex.el ends here