ox-latex.el 117 KB

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