org-e-latex.el 97 KB

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