ox-latex.el 118 KB

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