org-latex.el 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098
  1. ;;; org-latex.el --- LaTeX exporter for org-mode
  2. ;;
  3. ;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
  4. ;;
  5. ;; Emacs Lisp Archive Entry
  6. ;; Filename: org-latex.el
  7. ;; Version: 6.33trans
  8. ;; Author: Bastien Guerry <bzg AT altern DOT org>
  9. ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
  10. ;; Keywords: org, wp, tex
  11. ;; Description: Converts an org-mode buffer into LaTeX
  12. ;; This file is part of GNU Emacs.
  13. ;; GNU Emacs is free software: you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation, either version 3 of the License, or
  16. ;; (at your option) any later version.
  17. ;; GNU Emacs is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;; GNU General Public License for more details.
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  23. ;;; Commentary:
  24. ;;
  25. ;; This library implements a LaTeX exporter for org-mode.
  26. ;;
  27. ;; It is part of Org and will be autoloaded
  28. ;;
  29. ;; The interactive functions are similar to those of the HTML exporter:
  30. ;;
  31. ;; M-x `org-export-as-latex'
  32. ;; M-x `org-export-as-pdf'
  33. ;; M-x `org-export-as-pdf-and-open'
  34. ;; M-x `org-export-as-latex-batch'
  35. ;; M-x `org-export-as-latex-to-buffer'
  36. ;; M-x `org-export-region-as-latex'
  37. ;; M-x `org-replace-region-by-latex'
  38. ;;
  39. ;;; Code:
  40. (eval-when-compile
  41. (require 'cl))
  42. (require 'footnote)
  43. (require 'org)
  44. (require 'org-exp)
  45. (require 'org-macs)
  46. ;;; Variables:
  47. (defvar org-export-latex-class nil)
  48. (defvar org-export-latex-class-options nil)
  49. (defvar org-export-latex-header nil)
  50. (defvar org-export-latex-append-header nil)
  51. (defvar org-export-latex-options-plist nil)
  52. (defvar org-export-latex-todo-keywords-1 nil)
  53. (defvar org-export-latex-complex-heading-re nil)
  54. (defvar org-export-latex-not-done-keywords nil)
  55. (defvar org-export-latex-done-keywords nil)
  56. (defvar org-export-latex-display-custom-times nil)
  57. (defvar org-export-latex-all-targets-re nil)
  58. (defvar org-export-latex-add-level 0)
  59. (defvar org-export-latex-sectioning "")
  60. (defvar org-export-latex-sectioning-depth 0)
  61. (defvar org-export-latex-special-keyword-regexp
  62. (concat "\\<\\(" org-scheduled-string "\\|"
  63. org-deadline-string "\\|"
  64. org-closed-string"\\)")
  65. "Regexp matching special time planning keywords plus the time after it.")
  66. (defvar latexp) ; dynamically scoped from org.el
  67. (defvar re-quote) ; dynamically scoped from org.el
  68. (defvar commentsp) ; dynamically scoped from org.el
  69. ;;; User variables:
  70. (defgroup org-export-latex nil
  71. "Options for exporting Org-mode files to LaTeX."
  72. :tag "Org Export LaTeX"
  73. :group 'org-export)
  74. (defcustom org-export-latex-default-class "article"
  75. "The default LaTeX class."
  76. :group 'org-export-latex
  77. :type '(string :tag "LaTeX class"))
  78. (defcustom org-export-latex-classes
  79. '(("article"
  80. "\\documentclass[11pt]{article}
  81. \\usepackage[utf8]{inputenc}
  82. \\usepackage[T1]{fontenc}
  83. \\usepackage{graphicx}
  84. \\usepackage{longtable}
  85. \\usepackage{float}
  86. \\usepackage{wrapfig}
  87. \\usepackage{soul}
  88. \\usepackage{amssymb}
  89. \\usepackage{hyperref}"
  90. ("\\section{%s}" . "\\section*{%s}")
  91. ("\\subsection{%s}" . "\\subsection*{%s}")
  92. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  93. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  94. ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
  95. ("report"
  96. "\\documentclass[11pt]{report}
  97. \\usepackage[utf8]{inputenc}
  98. \\usepackage[T1]{fontenc}
  99. \\usepackage{graphicx}
  100. \\usepackage{longtable}
  101. \\usepackage{float}
  102. \\usepackage{wrapfig}
  103. \\usepackage{soul}
  104. \\usepackage{amssymb}
  105. \\usepackage{hyperref}"
  106. ("\\part{%s}" . "\\part*{%s}")
  107. ("\\chapter{%s}" . "\\chapter*{%s}")
  108. ("\\section{%s}" . "\\section*{%s}")
  109. ("\\subsection{%s}" . "\\subsection*{%s}")
  110. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
  111. ("book"
  112. "\\documentclass[11pt]{book}
  113. \\usepackage[utf8]{inputenc}
  114. \\usepackage[T1]{fontenc}
  115. \\usepackage{graphicx}
  116. \\usepackage{longtable}
  117. \\usepackage{float}
  118. \\usepackage{wrapfig}
  119. \\usepackage{soul}
  120. \\usepackage{amssymb}
  121. \\usepackage{hyperref}"
  122. ("\\part{%s}" . "\\part*{%s}")
  123. ("\\chapter{%s}" . "\\chapter*{%s}")
  124. ("\\section{%s}" . "\\section*{%s}")
  125. ("\\subsection{%s}" . "\\subsection*{%s}")
  126. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
  127. "Alist of LaTeX classes and associated header and structure.
  128. If #+LaTeX_CLASS is set in the buffer, use its value and the
  129. associated information. Here is the structure of each cell:
  130. \(class-name
  131. header-string
  132. (numbered-section . unnumbered-section\)
  133. ...\)
  134. A %s formatter is mandatory in each section string and will be
  135. replaced by the title of the section.
  136. Instead of a cons cell (numbered . unnumbered), you can also provide a list
  137. of 2-4 elements,
  138. (numbered-open numbered-close)
  139. or
  140. (numbered-open numbered-close unnumbered-open unnumbered-close)
  141. providing opening and closing strings for an environment that should
  142. represent the document section. The opening clause should have a %s
  143. to represent the section title."
  144. :group 'org-export-latex
  145. :type '(repeat
  146. (list (string :tag "LaTeX class")
  147. (string :tag "LaTeX header")
  148. (repeat :tag "Levels" :inline t
  149. (choice
  150. (cons :tag "Heading"
  151. (string :tag "numbered")
  152. (string :tag "unnumbered)"))
  153. (list :tag "Environment"
  154. (string :tag "Opening (numbered) ")
  155. (string :tag "Closing (numbered) ")
  156. (string :tag "Opening (unnumbered)")
  157. (string :tag "Closing (unnumbered)")))))))
  158. (defcustom org-export-latex-emphasis-alist
  159. '(("*" "\\textbf{%s}" nil)
  160. ("/" "\\emph{%s}" nil)
  161. ("_" "\\underline{%s}" nil)
  162. ("+" "\\st{%s}" nil)
  163. ("=" "\\verb" t)
  164. ("~" "\\verb" t))
  165. "Alist of LaTeX expressions to convert emphasis fontifiers.
  166. Each element of the list is a list of three elements.
  167. The first element is the character used as a marker for fontification.
  168. The second element is a formatting string to wrap fontified text with.
  169. If it is \"\\verb\", Org will automatically select a delimiter
  170. character that is not in the string.
  171. The third element decides whether to protect converted text from other
  172. conversions."
  173. :group 'org-export-latex
  174. :type 'alist)
  175. (defcustom org-export-latex-title-command "\\maketitle"
  176. "The command used to insert the title just after \\begin{document}.
  177. If this string contains the formatting specification \"%s\" then
  178. it will be used as a formatting string, passing the title as an
  179. argument."
  180. :group 'org-export-latex
  181. :type 'string)
  182. (defcustom org-export-latex-import-inbuffer-stuff nil
  183. "Non-nil means define TeX macros for Org's inbuffer definitions.
  184. For example \orgTITLE for #+TITLE."
  185. :group 'org-export-latex
  186. :type 'boolean)
  187. (defcustom org-export-latex-date-format
  188. "%d %B %Y"
  189. "Format string for \\date{...}."
  190. :group 'org-export-latex
  191. :type 'string)
  192. (defcustom org-export-latex-todo-keyword-markup "\\textbf{%s}"
  193. "Markup for TODO keywords, as a printf format.
  194. This can be a single format for all keywords, a cons cell with separate
  195. formats for not-done and done states, or an association list with setup
  196. for individual keywords. If a keyword shows up for which there is no
  197. markup defined, the first one in the association list will be used."
  198. :group 'org-export-latex
  199. :type '(choice
  200. (string :tag "Default")
  201. (cons :tag "Distinguish undone and done"
  202. (string :tag "Not-DONE states")
  203. (string :tag "DONE states"))
  204. (repeat :tag "Per keyword markup"
  205. (cons
  206. (string :tag "Keyword")
  207. (string :tag "Markup")))))
  208. (defcustom org-export-latex-timestamp-markup "\\textit{%s}"
  209. "A printf format string to be applied to time stamps."
  210. :group 'org-export-latex
  211. :type 'string)
  212. (defcustom org-export-latex-timestamp-keyword-markup "\\texttt{%s}"
  213. "A printf format string to be applied to time stamps."
  214. :group 'org-export-latex
  215. :type 'string)
  216. (defcustom org-export-latex-tables-verbatim nil
  217. "When non-nil, tables are exported verbatim."
  218. :group 'org-export-latex
  219. :type 'boolean)
  220. (defcustom org-export-latex-tables-centered t
  221. "When non-nil, tables are exported in a center environment."
  222. :group 'org-export-latex
  223. :type 'boolean)
  224. (defcustom org-export-latex-tables-column-borders nil
  225. "When non-nil, grouping columns can cause outer vertical lines in tables.
  226. When nil, grouping causes only separation lines between groups."
  227. :group 'org-export-latex
  228. :type 'boolean)
  229. (defcustom org-export-latex-low-levels 'itemize
  230. "How to convert sections below the current level of sectioning.
  231. This is specified by the `org-export-headline-levels' option or the
  232. value of \"H:\" in Org's #+OPTION line.
  233. This can be either nil (skip the sections), `description', `itemize',
  234. or `enumerate' (convert the sections as the corresponding list type), or
  235. a string to be used instead of \\section{%s}. In this latter case,
  236. the %s stands here for the inserted headline and is mandatory.
  237. It may also be a list of three string to define a user-defined environment
  238. that should be used. The first string should be the like
  239. \"\\begin{itemize}\", the second should be like \"\\item %s %s\" with up
  240. to two occurrences of %s for the title and a label, respectively. The third
  241. string should be like \"\\end{itemize\"."
  242. :group 'org-export-latex
  243. :type '(choice (const :tag "Ignore" nil)
  244. (const :tag "Convert as descriptive list" description)
  245. (const :tag "Convert as itemized list" itemize)
  246. (const :tag "Convert as enumerated list" enumerate)
  247. (list :tag "User-defined environment"
  248. :value ("\\begin{itemize}" "\\end{itemize}" "\\item %s")
  249. (string :tag "Start")
  250. (string :tag "End")
  251. (string :tag "item"))
  252. (string :tag "Use a section string" :value "\\subparagraph{%s}")))
  253. (defcustom org-export-latex-list-parameters
  254. '(:cbon "$\\boxtimes$" :cboff "$\\Box$")
  255. "Parameters for the LaTeX list exporter.
  256. These parameters will be passed on to `org-list-to-latex', which in turn
  257. will pass them (combined with the LaTeX default list parameters) to
  258. `org-list-to-generic'."
  259. :group 'org-export-latex
  260. :type 'plist)
  261. (defcustom org-export-latex-verbatim-wrap
  262. '("\\begin{verbatim}\n" . "\\end{verbatim}\n")
  263. "Environment to be wrapped around a fixed-width section in LaTeX export.
  264. This is a cons with two strings, to be added before and after the
  265. fixed-with text.
  266. Defaults to \\begin{verbatim} and \\end{verbatim}."
  267. :group 'org-export-translation
  268. :group 'org-export-latex
  269. :type '(cons (string :tag "Open")
  270. (string :tag "Close")))
  271. (defcustom org-export-latex-listings nil
  272. "Non-nil means, export source code using the listings package.
  273. This package will fontify source code, possibly even with color.
  274. If you want to use this, you also need to make LaTeX use the
  275. listings package, and if you want to have color, the color
  276. package. Just add these to `org-export-latex-packages-alist',
  277. for example using customize, or with something like
  278. (require 'org-latex)
  279. (add-to-list 'org-export-latex-packages-alist '(\"\" \"listings\"))
  280. (add-to-list 'org-export-latex-packages-alist '(\"\" \"color\"))"
  281. :group 'org-export-latex
  282. :type 'boolean)
  283. (defcustom org-export-latex-listings-langs
  284. '((emacs-lisp "Lisp") (lisp "Lisp")
  285. (c "C") (cc "C++")
  286. (fortran "fortran")
  287. (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
  288. (html "HTML") (xml "XML")
  289. (tex "TeX") (latex "TeX")
  290. (shell-script "bash")
  291. (gnuplot "Gnuplot")
  292. (ocaml "Caml") (caml "Caml")
  293. (sql "SQL"))
  294. "Alist mapping languages to their listing language counterpart.
  295. The key is a symbol, the major mode symbol without the \"-mode\".
  296. The value is the string that should be inserted as the language parameter
  297. for the listings package. If the mode name and the listings name are
  298. the same, the language does not need an entry in this list - but it does not
  299. hurt if it is present."
  300. :group 'org-export-latex
  301. :type '(repeat
  302. (list
  303. (symbol :tag "Major mode ")
  304. (string :tag "Listings language"))))
  305. (defcustom org-export-latex-remove-from-headlines
  306. '(:todo nil :priority nil :tags nil)
  307. "A plist of keywords to remove from headlines. OBSOLETE.
  308. Non-nil means remove this keyword type from the headline.
  309. Don't remove the keys, just change their values.
  310. Obsolete, this variable is no longer used. Use the separate
  311. variables `org-export-with-todo-keywords', `org-export-with-priority',
  312. and `org-export-with-tags' instead."
  313. :type 'plist
  314. :group 'org-export-latex)
  315. (defcustom org-export-latex-image-default-option "width=10em"
  316. "Default option for images."
  317. :group 'org-export-latex
  318. :type 'string)
  319. (defcustom org-export-latex-inline-image-extensions
  320. '("pdf" "jpeg" "jpg" "png" "ps" "eps")
  321. "Extensions of image files that can be inlined into LaTeX.
  322. Note that the image extension *actually* allowed depend on the way the
  323. LaTeX file is processed. When used with pdflatex, pdf, jpg and png images
  324. are OK. When processing through dvi to Postscript, only ps and eps are
  325. allowed. The default we use here encompasses both."
  326. :group 'org-export-latex
  327. :type '(repeat (string :tag "Extension")))
  328. (defcustom org-export-latex-coding-system nil
  329. "Coding system for the exported LaTex file."
  330. :group 'org-export-latex
  331. :type 'coding-system)
  332. (defgroup org-export-pdf nil
  333. "Options for exporting Org-mode files to PDF, via LaTeX."
  334. :tag "Org Export PDF"
  335. :group 'org-export-latex
  336. :group 'org-export)
  337. (defcustom org-latex-to-pdf-process
  338. '("pdflatex -interaction nonstopmode %s"
  339. "pdflatex -interaction nonstopmode %s")
  340. "Commands to process a LaTeX file to a PDF file.
  341. This is a list of strings, each of them will be given to the shell
  342. as a command. %s in the command will be replaced by the full file name, %b
  343. by the file base name (i.e. without extension).
  344. The reason why this is a list is that it usually takes several runs of
  345. pdflatex, maybe mixed with a call to bibtex. Org does not have a clever
  346. mechanism to detect which of these commands have to be run to get to a stable
  347. result, and it also does not do any error checking.
  348. Alternatively, this may be a Lisp function that does the processing, so you
  349. could use this to apply the machinery of AUCTeX or the Emacs LaTeX mode.
  350. This function should accept the file name as its single argument."
  351. :group 'org-export-pdf
  352. :type '(choice (repeat :tag "Shell command sequence"
  353. (string :tag "Shell command"))
  354. (function)))
  355. (defcustom org-export-pdf-logfiles
  356. '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
  357. "The list of file extensions to consider as LaTeX logfiles."
  358. :group 'org-export-pdf
  359. :type '(repeat (string :tag "Extension")))
  360. (defcustom org-export-pdf-remove-logfiles t
  361. "Non-nil means, remove the logfiles produced by PDF production.
  362. These are the .aux, .log, .out, and .toc files."
  363. :group 'org-export-pdf
  364. :type 'boolean)
  365. ;;; Hooks
  366. (defvar org-export-latex-after-blockquotes-hook nil
  367. "Hook run during LaTeX export, after blockquote, verse, center are done.")
  368. (defvar org-export-latex-final-hook nil
  369. "Hook run in the finalized LaTeX buffer.")
  370. ;;; Autoload functions:
  371. ;;;###autoload
  372. (defun org-export-as-latex-batch ()
  373. "Call `org-export-as-latex', may be used in batch processing.
  374. For example:
  375. emacs --batch
  376. --load=$HOME/lib/emacs/org.el
  377. --eval \"(setq org-export-headline-levels 2)\"
  378. --visit=MyFile --funcall org-export-as-latex-batch"
  379. (org-export-as-latex org-export-headline-levels 'hidden))
  380. ;;;###autoload
  381. (defun org-export-as-latex-to-buffer (arg)
  382. "Call `org-export-as-latex` with output to a temporary buffer.
  383. No file is created. The prefix ARG is passed through to `org-export-as-latex'."
  384. (interactive "P")
  385. (org-export-as-latex arg nil nil "*Org LaTeX Export*")
  386. (when org-export-show-temporary-export-buffer
  387. (switch-to-buffer-other-window "*Org LaTeX Export*")))
  388. ;;;###autoload
  389. (defun org-replace-region-by-latex (beg end)
  390. "Replace the region from BEG to END with its LaTeX export.
  391. It assumes the region has `org-mode' syntax, and then convert it to
  392. LaTeX. This can be used in any buffer. For example, you could
  393. write an itemized list in `org-mode' syntax in an LaTeX buffer and
  394. then use this command to convert it."
  395. (interactive "r")
  396. (let (reg latex buf)
  397. (save-window-excursion
  398. (if (org-mode-p)
  399. (setq latex (org-export-region-as-latex
  400. beg end t 'string))
  401. (setq reg (buffer-substring beg end)
  402. buf (get-buffer-create "*Org tmp*"))
  403. (with-current-buffer buf
  404. (erase-buffer)
  405. (insert reg)
  406. (org-mode)
  407. (setq latex (org-export-region-as-latex
  408. (point-min) (point-max) t 'string)))
  409. (kill-buffer buf)))
  410. (delete-region beg end)
  411. (insert latex)))
  412. ;;;###autoload
  413. (defun org-export-region-as-latex (beg end &optional body-only buffer)
  414. "Convert region from BEG to END in `org-mode' buffer to LaTeX.
  415. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  416. contents, and only produce the region of converted text, useful for
  417. cut-and-paste operations.
  418. If BUFFER is a buffer or a string, use/create that buffer as a target
  419. of the converted LaTeX. If BUFFER is the symbol `string', return the
  420. produced LaTeX as a string and leave no buffer behind. For example,
  421. a Lisp program could call this function in the following way:
  422. (setq latex (org-export-region-as-latex beg end t 'string))
  423. When called interactively, the output buffer is selected, and shown
  424. in a window. A non-interactive call will only return the buffer."
  425. (interactive "r\nP")
  426. (when (interactive-p)
  427. (setq buffer "*Org LaTeX Export*"))
  428. (let ((transient-mark-mode t) (zmacs-regions t)
  429. ext-plist rtn)
  430. (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
  431. (goto-char end)
  432. (set-mark (point)) ;; to activate the region
  433. (goto-char beg)
  434. (setq rtn (org-export-as-latex
  435. nil nil ext-plist
  436. buffer body-only))
  437. (if (fboundp 'deactivate-mark) (deactivate-mark))
  438. (if (and (interactive-p) (bufferp rtn))
  439. (switch-to-buffer-other-window rtn)
  440. rtn)))
  441. ;;;###autoload
  442. (defun org-export-as-latex (arg &optional hidden ext-plist
  443. to-buffer body-only pub-dir)
  444. "Export current buffer to a LaTeX file.
  445. If there is an active region, export only the region. The prefix
  446. ARG specifies how many levels of the outline should become
  447. headlines. The default is 3. Lower levels will be exported
  448. depending on `org-export-latex-low-levels'. The default is to
  449. convert them as description lists.
  450. HIDDEN is obsolete and does nothing.
  451. EXT-PLIST is a property list with
  452. external parameters overriding org-mode's default settings, but
  453. still inferior to file-local settings. When TO-BUFFER is
  454. non-nil, create a buffer with that name and export to that
  455. buffer. If TO-BUFFER is the symbol `string', don't leave any
  456. buffer behind but just return the resulting LaTeX as a string.
  457. When BODY-ONLY is set, don't produce the file header and footer,
  458. simply return the content of \begin{document}...\end{document},
  459. without even the \begin{document} and \end{document} commands.
  460. when PUB-DIR is set, use this as the publishing directory."
  461. (interactive "P")
  462. (run-hooks 'org-export-first-hook)
  463. ;; Make sure we have a file name when we need it.
  464. (when (and (not (or to-buffer body-only))
  465. (not buffer-file-name))
  466. (if (buffer-base-buffer)
  467. (org-set-local 'buffer-file-name
  468. (with-current-buffer (buffer-base-buffer)
  469. buffer-file-name))
  470. (error "Need a file name to be able to export")))
  471. (message "Exporting to LaTeX...")
  472. (org-unmodified
  473. (remove-text-properties (point-min) (point-max)
  474. '(:org-license-to-kill nil)))
  475. (org-update-radio-target-regexp)
  476. (org-export-latex-set-initial-vars ext-plist arg)
  477. (let* ((wcf (current-window-configuration))
  478. (opt-plist org-export-latex-options-plist)
  479. (region-p (org-region-active-p))
  480. (rbeg (and region-p (region-beginning)))
  481. (rend (and region-p (region-end)))
  482. (subtree-p
  483. (if (plist-get opt-plist :ignore-subtree-p)
  484. nil
  485. (when region-p
  486. (save-excursion
  487. (goto-char rbeg)
  488. (and (org-at-heading-p)
  489. (>= (org-end-of-subtree t t) rend))))))
  490. (opt-plist (setq org-export-opt-plist
  491. (if subtree-p
  492. (org-export-add-subtree-options opt-plist rbeg)
  493. opt-plist)))
  494. ;; Make sure the variable contains the updated values.
  495. (org-export-latex-options-plist opt-plist)
  496. (title (or (and subtree-p (org-export-get-title-from-subtree))
  497. (plist-get opt-plist :title)
  498. (and (not
  499. (plist-get opt-plist :skip-before-1st-heading))
  500. (org-export-grab-title-from-buffer))
  501. (file-name-sans-extension
  502. (file-name-nondirectory buffer-file-name))))
  503. (filename (concat (file-name-as-directory
  504. (or pub-dir
  505. (org-export-directory :LaTeX ext-plist)))
  506. (file-name-sans-extension
  507. (or (and subtree-p
  508. (org-entry-get rbeg "EXPORT_FILE_NAME" t))
  509. (file-name-nondirectory ;sans-extension
  510. buffer-file-name)))
  511. ".tex"))
  512. (filename (if (equal (file-truename filename)
  513. (file-truename buffer-file-name))
  514. (concat filename ".tex")
  515. filename))
  516. (buffer (if to-buffer
  517. (cond
  518. ((eq to-buffer 'string) (get-buffer-create
  519. "*Org LaTeX Export*"))
  520. (t (get-buffer-create to-buffer)))
  521. (find-file-noselect filename)))
  522. (odd org-odd-levels-only)
  523. (header (org-export-latex-make-header title opt-plist))
  524. (skip (cond (subtree-p nil)
  525. (region-p nil)
  526. (t (plist-get opt-plist :skip-before-1st-heading))))
  527. (text (plist-get opt-plist :text))
  528. (org-export-preprocess-hook
  529. (cons
  530. `(lambda () (org-set-local 'org-complex-heading-regexp
  531. ,org-export-latex-complex-heading-re))
  532. org-export-preprocess-hook))
  533. (first-lines (if skip "" (org-export-latex-first-lines
  534. opt-plist
  535. (if subtree-p
  536. (save-excursion
  537. (goto-char rbeg)
  538. (point-at-bol 2))
  539. rbeg)
  540. (if region-p rend))))
  541. (coding-system (and (boundp 'buffer-file-coding-system)
  542. buffer-file-coding-system))
  543. (coding-system-for-write (or org-export-latex-coding-system
  544. coding-system))
  545. (save-buffer-coding-system (or org-export-latex-coding-system
  546. coding-system))
  547. (region (buffer-substring
  548. (if region-p (region-beginning) (point-min))
  549. (if region-p (region-end) (point-max))))
  550. (string-for-export
  551. (org-export-preprocess-string
  552. region
  553. :emph-multiline t
  554. :for-LaTeX t
  555. :comments nil
  556. :tags (plist-get opt-plist :tags)
  557. :priority (plist-get opt-plist :priority)
  558. :footnotes (plist-get opt-plist :footnotes)
  559. :drawers (plist-get opt-plist :drawers)
  560. :timestamps (plist-get opt-plist :timestamps)
  561. :todo-keywords (plist-get opt-plist :todo-keywords)
  562. :add-text (if (eq to-buffer 'string) nil text)
  563. :skip-before-1st-heading skip
  564. :select-tags (plist-get opt-plist :select-tags)
  565. :exclude-tags (plist-get opt-plist :exclude-tags)
  566. :LaTeX-fragments nil)))
  567. (set-buffer buffer)
  568. (erase-buffer)
  569. (org-install-letbind)
  570. (and (fboundp 'set-buffer-file-coding-system)
  571. (set-buffer-file-coding-system coding-system-for-write))
  572. ;; insert the header and initial document commands
  573. (unless (or (eq to-buffer 'string) body-only)
  574. (insert header))
  575. ;; insert text found in #+TEXT
  576. (when (and text (not (eq to-buffer 'string)))
  577. (insert (org-export-latex-content
  578. text '(lists tables fixed-width keywords))
  579. "\n\n"))
  580. ;; insert lines before the first headline
  581. (unless skip
  582. (insert first-lines))
  583. ;; export the content of headlines
  584. (org-export-latex-global
  585. (with-temp-buffer
  586. (insert string-for-export)
  587. (goto-char (point-min))
  588. (when (re-search-forward "^\\(\\*+\\) " nil t)
  589. (let* ((asters (length (match-string 1)))
  590. (level (if odd (- asters 2) (- asters 1))))
  591. (setq org-export-latex-add-level
  592. (if odd (1- (/ (1+ asters) 2)) (1- asters)))
  593. (org-export-latex-parse-global level odd)))))
  594. ;; finalization
  595. (unless body-only (insert "\n\\end{document}"))
  596. ;; Relocate the table of contents
  597. (goto-char (point-min))
  598. (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  599. (goto-char (point-min))
  600. (while (re-search-forward "\\\\tableofcontents\\>[ \t]*\n?" nil t)
  601. (replace-match ""))
  602. (goto-char (point-min))
  603. (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  604. (replace-match "\\tableofcontents" t t)))
  605. ;; Cleanup forced line ends in itmes where they are not needed
  606. (goto-char (point-min))
  607. (while (re-search-forward
  608. "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)?\n\\\\begin"
  609. nil t)
  610. (delete-region (match-beginning 1) (match-end 1)))
  611. (run-hooks 'org-export-latex-final-hook)
  612. (or to-buffer (save-buffer))
  613. (goto-char (point-min))
  614. (or (org-export-push-to-kill-ring "LaTeX")
  615. (message "Exporting to LaTeX...done"))
  616. (prog1
  617. (if (eq to-buffer 'string)
  618. (prog1 (buffer-substring (point-min) (point-max))
  619. (kill-buffer (current-buffer)))
  620. (current-buffer))
  621. (set-window-configuration wcf))))
  622. ;;;###autoload
  623. (defun org-export-as-pdf (arg &optional hidden ext-plist
  624. to-buffer body-only pub-dir)
  625. "Export as LaTeX, then process through to PDF."
  626. (interactive "P")
  627. (message "Exporting to PDF...")
  628. (let* ((wconfig (current-window-configuration))
  629. (lbuf (org-export-as-latex arg hidden ext-plist
  630. to-buffer body-only pub-dir))
  631. (file (buffer-file-name lbuf))
  632. (base (file-name-sans-extension (buffer-file-name lbuf)))
  633. (pdffile (concat base ".pdf"))
  634. (cmds org-latex-to-pdf-process)
  635. (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
  636. (bibtex-p (with-current-buffer lbuf
  637. (save-excursion
  638. (goto-char (point-min))
  639. (re-search-forward "\\\\bibliography{" nil t))))
  640. cmd)
  641. (with-current-buffer outbuf (erase-buffer))
  642. (message "Processing LaTeX file...")
  643. (if (and cmds (symbolp cmds))
  644. (funcall cmds file)
  645. (while cmds
  646. (setq cmd (pop cmds))
  647. (while (string-match "%b" cmd)
  648. (setq cmd (replace-match
  649. (save-match-data
  650. (shell-quote-argument base))
  651. t t cmd)))
  652. (while (string-match "%s" cmd)
  653. (setq cmd (replace-match
  654. (save-match-data
  655. (shell-quote-argument file))
  656. t t cmd)))
  657. (shell-command cmd outbuf outbuf)))
  658. (message "Processing LaTeX file...done")
  659. (if (not (file-exists-p pdffile))
  660. (error "PDF file was not produced")
  661. (set-window-configuration wconfig)
  662. (when org-export-pdf-remove-logfiles
  663. (dolist (ext org-export-pdf-logfiles)
  664. (setq file (concat base "." ext))
  665. (and (file-exists-p file) (delete-file file))))
  666. (message "Exporting to PDF...done")
  667. pdffile)))
  668. ;;;###autoload
  669. (defun org-export-as-pdf-and-open (arg)
  670. "Export as LaTeX, then process through to PDF, and open."
  671. (interactive "P")
  672. (let ((pdffile (org-export-as-pdf arg)))
  673. (if pdffile
  674. (org-open-file pdffile)
  675. (error "PDF file was not produced"))))
  676. ;;; Parsing functions:
  677. (defun org-export-latex-parse-global (level odd)
  678. "Parse the current buffer recursively, starting at LEVEL.
  679. If ODD is non-nil, assume the buffer only contains odd sections.
  680. Return a list reflecting the document structure."
  681. (save-excursion
  682. (goto-char (point-min))
  683. (let* ((cnt 0) output
  684. (depth org-export-latex-sectioning-depth))
  685. (while (org-re-search-forward-unprotected
  686. (concat "^\\(\\(?:\\*\\)\\{"
  687. (number-to-string (+ (if odd 2 1) level))
  688. "\\}\\) \\(.*\\)$")
  689. ;; make sure that there is no upper heading
  690. (when (> level 0)
  691. (save-excursion
  692. (save-match-data
  693. (org-re-search-forward-unprotected
  694. (concat "^\\(\\(?:\\*\\)\\{"
  695. (number-to-string level)
  696. "\\}\\) \\(.*\\)$") nil t)))) t)
  697. (setq cnt (1+ cnt))
  698. (let* ((pos (match-beginning 0))
  699. (heading (match-string 2))
  700. (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
  701. (save-excursion
  702. (narrow-to-region
  703. (point)
  704. (save-match-data
  705. (if (org-re-search-forward-unprotected
  706. (concat "^\\(\\(?:\\*\\)\\{"
  707. (number-to-string (+ (if odd 2 1) level))
  708. "\\}\\) \\(.*\\)$") nil t)
  709. (match-beginning 0)
  710. (point-max))))
  711. (goto-char (point-min))
  712. (setq output
  713. (append output
  714. (list
  715. (list
  716. `(pos . ,pos)
  717. `(level . ,nlevel)
  718. `(occur . ,cnt)
  719. `(heading . ,heading)
  720. `(content . ,(org-export-latex-parse-content))
  721. `(subcontent . ,(org-export-latex-parse-subcontent
  722. level odd)))))))
  723. (widen)))
  724. (list output))))
  725. (defun org-export-latex-parse-content ()
  726. "Extract the content of a section."
  727. (let ((beg (point))
  728. (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
  729. (progn (beginning-of-line) (point))
  730. (point-max))))
  731. (buffer-substring beg end)))
  732. (defun org-export-latex-parse-subcontent (level odd)
  733. "Extract the subcontent of a section at LEVEL.
  734. If ODD Is non-nil, assume subcontent only contains odd sections."
  735. (if (not (org-re-search-forward-unprotected
  736. (concat "^\\(\\(?:\\*\\)\\{"
  737. (number-to-string (+ (if odd 4 2) level))
  738. "\\}\\) \\(.*\\)$")
  739. nil t))
  740. nil ; subcontent is nil
  741. (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
  742. ;;; Rendering functions:
  743. (defun org-export-latex-global (content)
  744. "Export CONTENT to LaTeX.
  745. CONTENT is an element of the list produced by
  746. `org-export-latex-parse-global'."
  747. (if (eq (car content) 'subcontent)
  748. (mapc 'org-export-latex-sub (cdr content))
  749. (org-export-latex-sub (car content))))
  750. (defun org-export-latex-sub (subcontent)
  751. "Export the list SUBCONTENT to LaTeX.
  752. SUBCONTENT is an alist containing information about the headline
  753. and its content."
  754. (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
  755. (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
  756. (defun org-export-latex-subcontent (subcontent num)
  757. "Export each cell of SUBCONTENT to LaTeX.
  758. If NUM, export sections as numerical sections."
  759. (let* ((heading (org-export-latex-fontify-headline
  760. (cdr (assoc 'heading subcontent))))
  761. (level (- (cdr (assoc 'level subcontent))
  762. org-export-latex-add-level))
  763. (occur (number-to-string (cdr (assoc 'occur subcontent))))
  764. (content (cdr (assoc 'content subcontent)))
  765. (subcontent (cadr (assoc 'subcontent subcontent)))
  766. (label (org-get-text-property-any 0 'target heading))
  767. (label-list (cons label (cdr (assoc label
  768. org-export-target-aliases)))))
  769. (cond
  770. ;; Normal conversion
  771. ((<= level org-export-latex-sectioning-depth)
  772. (let* ((sec (nth (1- level) org-export-latex-sectioning))
  773. start end)
  774. (if (consp (cdr sec))
  775. (setq start (nth (if num 0 2) sec)
  776. end (nth (if num 1 3) sec))
  777. (setq start (if num (car sec) (cdr sec))))
  778. (insert (format start heading) "\n")
  779. (when label
  780. (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
  781. label-list "\n") "\n"))
  782. (insert (org-export-latex-content content))
  783. (cond ((stringp subcontent) (insert subcontent))
  784. ((listp subcontent)
  785. (while (org-looking-back "\n\n") (backward-delete-char 1))
  786. (org-export-latex-sub subcontent)))
  787. (if end (insert end "\n"))))
  788. ;; At a level under the hl option: we can drop this subsection
  789. ((> level org-export-latex-sectioning-depth)
  790. (cond ((eq org-export-latex-low-levels 'description)
  791. (if (string-match "% ends low level$"
  792. (buffer-substring (point-at-bol 0) (point)))
  793. (delete-region (point-at-bol 0) (point))
  794. (insert "\\begin{description}\n"))
  795. (insert (format "\n\\item[%s]%s~\n"
  796. heading
  797. (if label (format "\\label{%s}" label) "")))
  798. (insert (org-export-latex-content content))
  799. (cond ((stringp subcontent) (insert subcontent))
  800. ((listp subcontent) (org-export-latex-sub subcontent)))
  801. (insert "\\end{description} % ends low level\n"))
  802. ((memq org-export-latex-low-levels '(itemize enumerate))
  803. (if (string-match "% ends low level$"
  804. (buffer-substring (point-at-bol 0) (point)))
  805. (delete-region (point-at-bol 0) (point))
  806. (insert (format "\\begin{%s}\n"
  807. (symbol-name org-export-latex-low-levels))))
  808. (insert (format "\n\\item %s\\\\\n%s%%"
  809. heading
  810. (if label (format "\\label{%s}" label) "")))
  811. (insert (org-export-latex-content content))
  812. (cond ((stringp subcontent) (insert subcontent))
  813. ((listp subcontent) (org-export-latex-sub subcontent)))
  814. (insert (format "\\end{%s} %% ends low level\n"
  815. (symbol-name org-export-latex-low-levels))))
  816. ((listp org-export-latex-low-levels)
  817. (if (string-match "% ends low level$"
  818. (buffer-substring (point-at-bol 0) (point)))
  819. (delete-region (point-at-bol 0) (point))
  820. (insert (car org-export-latex-low-levels) "\n"))
  821. (insert (format (nth 2 org-export-latex-low-levels)
  822. heading
  823. (if label (format "\\label{%s}" label) "")))
  824. (insert (org-export-latex-content content))
  825. (cond ((stringp subcontent) (insert subcontent))
  826. ((listp subcontent) (org-export-latex-sub subcontent)))
  827. (insert (nth 1 org-export-latex-low-levels)
  828. " %% ends low level\n"))
  829. ((stringp org-export-latex-low-levels)
  830. (insert (format org-export-latex-low-levels heading) "\n")
  831. (when label (insert (format "\\label{%s}\n" label)))
  832. (insert (org-export-latex-content content))
  833. (cond ((stringp subcontent) (insert subcontent))
  834. ((listp subcontent) (org-export-latex-sub subcontent)))))))))
  835. ;;; Exporting internals:
  836. (defun org-export-latex-set-initial-vars (ext-plist level)
  837. "Store org local variables required for LaTeX export.
  838. EXT-PLIST is an optional additional plist.
  839. LEVEL indicates the default depth for export."
  840. (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
  841. org-export-latex-done-keywords org-done-keywords
  842. org-export-latex-not-done-keywords org-not-done-keywords
  843. org-export-latex-complex-heading-re org-complex-heading-regexp
  844. org-export-latex-display-custom-times org-display-custom-times
  845. org-export-latex-all-targets-re
  846. (org-make-target-link-regexp (org-all-targets))
  847. org-export-latex-options-plist
  848. (org-combine-plists (org-default-export-plist) ext-plist
  849. (org-infile-export-plist))
  850. org-export-latex-class
  851. (or (and (org-region-active-p)
  852. (save-excursion
  853. (goto-char (region-beginning))
  854. (and (looking-at org-complex-heading-regexp)
  855. (org-entry-get nil "LaTeX_CLASS" 'selective))))
  856. (save-excursion
  857. (save-restriction
  858. (widen)
  859. (goto-char (point-min))
  860. (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t)
  861. (match-string 1))))
  862. (plist-get org-export-latex-options-plist :latex-class)
  863. org-export-latex-default-class)
  864. org-export-latex-class-options
  865. (or (and (org-region-active-p)
  866. (save-excursion
  867. (goto-char (region-beginning))
  868. (and (looking-at org-complex-heading-regexp)
  869. (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
  870. (save-excursion
  871. (save-restriction
  872. (widen)
  873. (goto-char (point-min))
  874. (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
  875. (match-string 1))))
  876. (plist-get org-export-latex-options-plist :latex-class-options))
  877. org-export-latex-class
  878. (or (car (assoc org-export-latex-class org-export-latex-classes))
  879. (error "No definition for class `%s' in `org-export-latex-classes'"
  880. org-export-latex-class))
  881. org-export-latex-header
  882. (cadr (assoc org-export-latex-class org-export-latex-classes))
  883. org-export-latex-sectioning
  884. (cddr (assoc org-export-latex-class org-export-latex-classes))
  885. org-export-latex-sectioning-depth
  886. (or level
  887. (let ((hl-levels
  888. (plist-get org-export-latex-options-plist :headline-levels))
  889. (sec-depth (length org-export-latex-sectioning)))
  890. (if (> hl-levels sec-depth) sec-depth hl-levels))))
  891. (when (and org-export-latex-class-options
  892. (string-match "\\S-" org-export-latex-class-options)
  893. (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?" org-export-latex-header))
  894. (setq org-export-latex-header
  895. (concat (substring org-export-latex-header 0 (match-end 1))
  896. org-export-latex-class-options
  897. (substring org-export-latex-header (match-end 0))))))
  898. (defun org-export-latex-make-header (title opt-plist)
  899. "Make the LaTeX header and return it as a string.
  900. TITLE is the current title from the buffer or region.
  901. OPT-PLIST is the options plist for current buffer."
  902. (let ((toc (plist-get opt-plist :table-of-contents))
  903. (author (plist-get opt-plist :author)))
  904. (concat
  905. (if (plist-get opt-plist :time-stamp-file)
  906. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  907. ;; insert LaTeX custom header
  908. (org-export-apply-macros-in-string org-export-latex-header)
  909. "\n"
  910. ;; insert information on LaTeX packages
  911. (when org-export-latex-packages-alist
  912. (mapconcat (lambda(p)
  913. (if (equal "" (car p))
  914. (format "\\usepackage{%s}" (cadr p))
  915. (format "\\usepackage[%s]{%s}"
  916. (car p) (cadr p))))
  917. org-export-latex-packages-alist "\n"))
  918. ;; insert additional commands in the header
  919. (org-export-apply-macros-in-string
  920. (plist-get opt-plist :latex-header-extra))
  921. (org-export-apply-macros-in-string org-export-latex-append-header)
  922. ;; insert the title
  923. (format
  924. "\n\n\\title{%s}\n"
  925. ;; convert the title
  926. (org-export-latex-content
  927. title '(lists tables fixed-width keywords)))
  928. ;; insert author info
  929. (if (plist-get opt-plist :author-info)
  930. (format "\\author{%s}\n"
  931. (org-export-latex-fontify-headline (or author user-full-name)))
  932. (format "%%\\author{%s}\n"
  933. (or author user-full-name)))
  934. ;; insert the date
  935. (format "\\date{%s}\n"
  936. (format-time-string
  937. (or (plist-get opt-plist :date)
  938. org-export-latex-date-format)))
  939. ;; beginning of the document
  940. "\n\\begin{document}\n\n"
  941. ;; insert the title command
  942. (when (string-match "\\S-" title)
  943. (if (string-match "%s" org-export-latex-title-command)
  944. (format org-export-latex-title-command title)
  945. org-export-latex-title-command))
  946. "\n\n"
  947. ;; table of contents
  948. (when (and org-export-with-toc
  949. (plist-get opt-plist :section-numbers))
  950. (cond ((numberp toc)
  951. (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
  952. (min toc (plist-get opt-plist :headline-levels))))
  953. (toc (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
  954. (plist-get opt-plist :headline-levels))))))))
  955. (defun org-export-latex-first-lines (opt-plist &optional beg end)
  956. "Export the first lines before first headline.
  957. If BEG is non-nil, it is the beginning of the region.
  958. If END is non-nil, it is the end of the region."
  959. (save-excursion
  960. (goto-char (or beg (point-min)))
  961. (let* ((pt (point))
  962. (end (if (re-search-forward "^\\*+ " end t)
  963. (goto-char (match-beginning 0))
  964. (goto-char (or end (point-max))))))
  965. (prog1
  966. (org-export-latex-content
  967. (org-export-preprocess-string
  968. (buffer-substring pt end)
  969. :for-LaTeX t
  970. :emph-multiline t
  971. :add-text nil
  972. :comments nil
  973. :skip-before-1st-heading nil
  974. :LaTeX-fragments nil
  975. :timestamps (plist-get opt-plist :timestamps)
  976. :footnotes (plist-get opt-plist :footnotes)))
  977. (org-unmodified
  978. (add-text-properties pt (max pt (1- end))
  979. '(:org-license-to-kill t)))))))
  980. (defvar org-export-latex-header-defs nil
  981. "The header definitions that might be used in the LaTeX body.")
  982. (defvar org-export-latex-header-defs-re nil
  983. "The header definitions that might be used in the LaTeX body.")
  984. (defun org-export-latex-content (content &optional exclude-list)
  985. "Convert CONTENT string to LaTeX.
  986. Don't perform conversions that are in EXCLUDE-LIST. Recognized
  987. conversion types are: quotation-marks, emphasis, sub-superscript,
  988. links, keywords, lists, tables, fixed-width"
  989. (with-temp-buffer
  990. (insert content)
  991. (unless (memq 'timestamps exclude-list)
  992. (org-export-latex-time-stamps))
  993. (unless (memq 'quotation-marks exclude-list)
  994. (org-export-latex-quotation-marks))
  995. (unless (memq 'emphasis exclude-list)
  996. (when (plist-get org-export-latex-options-plist :emphasize)
  997. (org-export-latex-fontify)))
  998. (unless (memq 'sub-superscript exclude-list)
  999. (org-export-latex-special-chars
  1000. (plist-get org-export-latex-options-plist :sub-superscript)))
  1001. (unless (memq 'links exclude-list)
  1002. (org-export-latex-links))
  1003. (unless (memq 'keywords exclude-list)
  1004. (org-export-latex-keywords))
  1005. (unless (memq 'lists exclude-list)
  1006. (org-export-latex-lists))
  1007. (unless (memq 'tables exclude-list)
  1008. (org-export-latex-tables
  1009. (plist-get org-export-latex-options-plist :tables)))
  1010. (unless (memq 'fixed-width exclude-list)
  1011. (org-export-latex-fixed-width
  1012. (plist-get org-export-latex-options-plist :fixed-width)))
  1013. ;; return string
  1014. (buffer-substring (point-min) (point-max))))
  1015. (defun org-export-latex-protect-string (s)
  1016. "Add the org-protected property to string S."
  1017. (add-text-properties 0 (length s) '(org-protected t) s) s)
  1018. (defun org-export-latex-protect-char-in-string (char-list string)
  1019. "Add org-protected text-property to char from CHAR-LIST in STRING."
  1020. (with-temp-buffer
  1021. (save-match-data
  1022. (insert string)
  1023. (goto-char (point-min))
  1024. (while (re-search-forward (regexp-opt char-list) nil t)
  1025. (add-text-properties (match-beginning 0)
  1026. (match-end 0) '(org-protected t)))
  1027. (buffer-string))))
  1028. (defun org-export-latex-keywords-maybe (&optional remove-list)
  1029. "Maybe remove keywords depending on rules in REMOVE-LIST."
  1030. (goto-char (point-min))
  1031. (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
  1032. (case-fold-search nil)
  1033. (todo-markup org-export-latex-todo-keyword-markup)
  1034. fmt)
  1035. ;; convert TODO keywords
  1036. (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
  1037. (if (plist-get remove-list :todo)
  1038. (replace-match "")
  1039. (setq fmt (cond
  1040. ((stringp todo-markup) todo-markup)
  1041. ((and (consp todo-markup) (stringp (car todo-markup)))
  1042. (if (member (match-string 1) org-export-latex-done-keywords)
  1043. (cdr todo-markup) (car todo-markup)))
  1044. (t (cdr (or (assoc (match-string 1) todo-markup)
  1045. (car todo-markup))))))
  1046. (replace-match (format fmt (match-string 1)) t t)))
  1047. ;; convert priority string
  1048. (when (re-search-forward "\\[\\\\#.\\]" nil t)
  1049. (if (plist-get remove-list :priority)
  1050. (replace-match "")
  1051. (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
  1052. ;; convert tags
  1053. (when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
  1054. (if (or (not org-export-with-tags)
  1055. (plist-get remove-list :tags))
  1056. (replace-match "")
  1057. (replace-match
  1058. (org-export-latex-protect-string
  1059. (format "\\textbf{%s}"
  1060. (save-match-data
  1061. (replace-regexp-in-string
  1062. "_" "\\\\_" (match-string 0)))))
  1063. t t)))))
  1064. (defun org-export-latex-fontify-headline (string)
  1065. "Fontify special words in STRING."
  1066. (with-temp-buffer
  1067. ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
  1068. ;; the beginning of the buffer - inserting "\n" is safe here though.
  1069. (insert "\n" string)
  1070. (goto-char (point-min))
  1071. (let ((re (concat "\\\\[a-zA-Z]+\\(?:"
  1072. "\\[.*\\]"
  1073. "\\)?"
  1074. (org-create-multibrace-regexp "{" "}" 3))))
  1075. (while (re-search-forward re nil t)
  1076. (unless (save-excursion (goto-char (match-beginning 0))
  1077. (equal (char-after (point-at-bol)) ?#))
  1078. (add-text-properties (match-beginning 0) (match-end 0)
  1079. '(org-protected t)))))
  1080. (when (plist-get org-export-latex-options-plist :emphasize)
  1081. (org-export-latex-fontify))
  1082. (org-export-latex-keywords-maybe)
  1083. (org-export-latex-special-chars
  1084. (plist-get org-export-latex-options-plist :sub-superscript))
  1085. (org-export-latex-links)
  1086. (org-trim (buffer-string))))
  1087. (defun org-export-latex-time-stamps ()
  1088. "Format time stamps."
  1089. (goto-char (point-min))
  1090. (let ((org-display-custom-times org-export-latex-display-custom-times))
  1091. (while (re-search-forward org-ts-regexp-both nil t)
  1092. (org-if-unprotected-at (1- (point))
  1093. (replace-match
  1094. (org-export-latex-protect-string
  1095. (format org-export-latex-timestamp-markup
  1096. (substring (org-translate-time (match-string 0)) 1 -1)))
  1097. t t)))))
  1098. (defun org-export-latex-quotation-marks ()
  1099. "Export quotation marks depending on language conventions."
  1100. (let* ((lang (plist-get org-export-latex-options-plist :language))
  1101. (quote-rpl (if (equal lang "fr")
  1102. '(("\\(\\s-\\)\"" "«~")
  1103. ("\\(\\S-\\)\"" "~»")
  1104. ("\\(\\s-\\)'" "`"))
  1105. '(("\\(\\s-\\|[[(]\\)\"" "``")
  1106. ("\\(\\S-\\)\"" "''")
  1107. ("\\(\\s-\\|(\\)'" "`")))))
  1108. (mapc (lambda(l) (goto-char (point-min))
  1109. (while (re-search-forward (car l) nil t)
  1110. (let ((rpl (concat (match-string 1)
  1111. (org-export-latex-protect-string
  1112. (copy-sequence (cadr l))))))
  1113. (org-if-unprotected-1
  1114. (replace-match rpl t t))))) quote-rpl)))
  1115. (defun org-export-latex-special-chars (sub-superscript)
  1116. "Export special characters to LaTeX.
  1117. If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
  1118. See the `org-export-latex.el' code for a complete conversion table."
  1119. (goto-char (point-min))
  1120. (mapc (lambda(c)
  1121. (goto-char (point-min))
  1122. (while (re-search-forward c nil t)
  1123. ;; Put the point where to check for org-protected
  1124. (unless (get-text-property (match-beginning 2) 'org-protected)
  1125. (cond ((member (match-string 2) '("\\$" "$"))
  1126. (if (equal (match-string 2) "\\$")
  1127. nil
  1128. (replace-match "\\$" t t)))
  1129. ((member (match-string 2) '("&" "%" "#"))
  1130. (if (equal (match-string 1) "\\")
  1131. (replace-match (match-string 2) t t)
  1132. (replace-match (concat (match-string 1) "\\"
  1133. (match-string 2)) t t)))
  1134. ((equal (match-string 2) "...")
  1135. (replace-match
  1136. (concat (match-string 1)
  1137. (org-export-latex-protect-string "\\ldots{}")) t t))
  1138. ((equal (match-string 2) "~")
  1139. (cond ((equal (match-string 1) "\\") nil)
  1140. ((eq 'org-link (get-text-property 0 'face (match-string 2)))
  1141. (replace-match (concat (match-string 1) "\\~") t t))
  1142. (t (replace-match
  1143. (org-export-latex-protect-string
  1144. (concat (match-string 1) "\\~{}")) t t))))
  1145. ((member (match-string 2) '("{" "}"))
  1146. (unless (save-match-data (org-inside-latex-math-p))
  1147. (if (equal (match-string 1) "\\")
  1148. (replace-match (match-string 2) t t)
  1149. (replace-match (concat (match-string 1) "\\"
  1150. (match-string 2)) t t)))))
  1151. (unless (save-match-data (org-inside-latex-math-p))
  1152. (cond ((equal (match-string 2) "\\")
  1153. (replace-match (or (save-match-data
  1154. (org-export-latex-treat-backslash-char
  1155. (match-string 1)
  1156. (or (match-string 3) "")))
  1157. "") t t))
  1158. ((member (match-string 2) '("_" "^"))
  1159. (replace-match (or (save-match-data
  1160. (org-export-latex-treat-sub-super-char
  1161. sub-superscript
  1162. (match-string 2)
  1163. (match-string 1)
  1164. (match-string 3))) "") t t)
  1165. (backward-char 1)))))))
  1166. '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
  1167. "\\(\\(\\\\?\\$\\)\\)"
  1168. "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
  1169. "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
  1170. "\\(.\\|^\\)\\(&\\)"
  1171. "\\(.\\|^\\)\\(#\\)"
  1172. "\\(.\\|^\\)\\(%\\)"
  1173. "\\(.\\|^\\)\\({\\)"
  1174. "\\(.\\|^\\)\\(}\\)"
  1175. "\\(.\\|^\\)\\(~\\)"
  1176. "\\(.\\|^\\)\\(\\.\\.\\.\\)"
  1177. ;; (?\< . "\\textless{}")
  1178. ;; (?\> . "\\textgreater{}")
  1179. )))
  1180. (defun org-inside-latex-math-p ()
  1181. (get-text-property (point) 'org-latex-math))
  1182. (defun org-export-latex-treat-sub-super-char
  1183. (subsup char string-before string-after)
  1184. "Convert the \"_\" and \"^\" characters to LaTeX.
  1185. SUBSUP corresponds to the ^: option in the #+OPTIONS line.
  1186. Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
  1187. (cond ((equal string-before "\\")
  1188. (concat string-before char string-after))
  1189. ((and (string-match "\\S-+" string-after))
  1190. ;; this is part of a math formula
  1191. (cond ((eq 'org-link (get-text-property 0 'face char))
  1192. (concat string-before "\\" char string-after))
  1193. ((save-match-data (org-inside-latex-math-p))
  1194. (if subsup
  1195. (cond ((eq 1 (length string-after))
  1196. (concat string-before char string-after))
  1197. ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
  1198. (format "%s%s{%s}" string-before char
  1199. (match-string 1 string-after))))))
  1200. ((and (> (length string-after) 1)
  1201. (or (eq subsup t)
  1202. (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
  1203. (string-match "[({]?\\([^)}]+\\)[)}]?" string-after))
  1204. (org-export-latex-protect-string
  1205. (format "%s$%s{%s}$" string-before char
  1206. (if (and (> (match-end 1) (1+ (match-beginning 1)))
  1207. (not (equal (substring string-after 0 2) "{\\")))
  1208. (concat "\\mathrm{" (match-string 1 string-after) "}")
  1209. (match-string 1 string-after)))))
  1210. ((eq subsup t) (concat string-before "$" char string-after "$"))
  1211. (t (org-export-latex-protect-string
  1212. (concat string-before "\\" char "{}" string-after)))))
  1213. (t (org-export-latex-protect-string
  1214. (concat string-before "\\" char "{}" string-after)))))
  1215. (defun org-export-latex-treat-backslash-char (string-before string-after)
  1216. "Convert the \"$\" special character to LaTeX.
  1217. The conversion is made depending of STRING-BEFORE and STRING-AFTER."
  1218. (cond ((member (list string-after) org-html-entities)
  1219. ;; backslash is part of a special entity (like "\alpha")
  1220. (concat string-before "$\\"
  1221. (or (cdar (member (list string-after) org-html-entities))
  1222. string-after) "$"))
  1223. ((and (not (string-match "^[ \n\t]" string-after))
  1224. (not (string-match "[ \t]\\'\\|^" string-before)))
  1225. ;; backslash is inside a word
  1226. (org-export-latex-protect-string
  1227. (concat string-before "\\textbackslash{}" string-after)))
  1228. ((not (or (equal string-after "")
  1229. (string-match "^[ \t\n]" string-after)))
  1230. ;; backslash might escape a character (like \#) or a user TeX
  1231. ;; macro (like \setcounter)
  1232. (org-export-latex-protect-string
  1233. (concat string-before "\\" string-after)))
  1234. ((and (string-match "^[ \t\n]" string-after)
  1235. (string-match "[ \t\n]\\'" string-before))
  1236. ;; backslash is alone, convert it to $\backslash$
  1237. (org-export-latex-protect-string
  1238. (concat string-before "\\textbackslash{}" string-after)))
  1239. (t (org-export-latex-protect-string
  1240. (concat string-before "\\textbackslash{}" string-after)))))
  1241. (defun org-export-latex-keywords ()
  1242. "Convert special keywords to LaTeX."
  1243. (goto-char (point-min))
  1244. (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
  1245. (replace-match (format org-export-latex-timestamp-keyword-markup
  1246. (match-string 0)) t t)
  1247. (save-excursion
  1248. (beginning-of-line 1)
  1249. (unless (looking-at ".*\\\\newline[ \t]*$")
  1250. (end-of-line 1)
  1251. (insert "\\newline")))))
  1252. (defun org-export-latex-fixed-width (opt)
  1253. "When OPT is non-nil convert fixed-width sections to LaTeX."
  1254. (goto-char (point-min))
  1255. (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
  1256. (if opt
  1257. (progn (goto-char (match-beginning 0))
  1258. (insert "\\begin{verbatim}\n")
  1259. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1260. (replace-match (concat (match-string 1)
  1261. (match-string 2)) t t)
  1262. (forward-line))
  1263. (insert "\\end{verbatim}\n\n"))
  1264. (progn (goto-char (match-beginning 0))
  1265. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1266. (replace-match (concat "%" (match-string 1)
  1267. (match-string 2)) t t)
  1268. (forward-line))))))
  1269. (defvar org-table-last-alignment) ; defined in org-table.el
  1270. (defvar org-table-last-column-widths) ; defined in org-table.el
  1271. (declare-function orgtbl-to-latex "org-table" (table params) t)
  1272. (defun org-export-latex-tables (insert)
  1273. "Convert tables to LaTeX and INSERT it."
  1274. (goto-char (point-min))
  1275. (while (re-search-forward "^\\([ \t]*\\)|" nil t)
  1276. (org-if-unprotected-at (1- (point))
  1277. (org-table-align)
  1278. (let* ((beg (org-table-begin))
  1279. (end (org-table-end))
  1280. (raw-table (buffer-substring beg end))
  1281. (org-table-last-alignment (copy-sequence org-table-last-alignment))
  1282. (org-table-last-column-widths (copy-sequence
  1283. org-table-last-column-widths))
  1284. fnum fields line lines olines gr colgropen line-fmt align
  1285. caption label attr floatp longtblp)
  1286. (if org-export-latex-tables-verbatim
  1287. (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
  1288. "\\end{verbatim}\n")))
  1289. (apply 'delete-region (list beg end))
  1290. (insert (org-export-latex-protect-string tbl)))
  1291. (progn
  1292. (setq caption (org-find-text-property-in-string
  1293. 'org-caption raw-table)
  1294. attr (org-find-text-property-in-string
  1295. 'org-attributes raw-table)
  1296. label (org-find-text-property-in-string
  1297. 'org-label raw-table)
  1298. longtblp (and attr (stringp attr)
  1299. (string-match "\\<longtable\\>" attr))
  1300. align (and attr (stringp attr)
  1301. (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
  1302. (match-string 1 attr))
  1303. floatp (or caption label))
  1304. (setq lines (org-split-string raw-table "\n"))
  1305. (apply 'delete-region (list beg end))
  1306. (when org-export-table-remove-special-lines
  1307. (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
  1308. (when org-table-clean-did-remove-column
  1309. (pop org-table-last-alignment)
  1310. (pop org-table-last-column-widths))
  1311. ;; make a formatting string to reflect alignment
  1312. (setq olines lines)
  1313. (while (and (not line-fmt) (setq line (pop olines)))
  1314. (unless (string-match "^[ \t]*|-" line)
  1315. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1316. (setq fnum (make-vector (length fields) 0))
  1317. (setq line-fmt
  1318. (mapconcat
  1319. (lambda (x)
  1320. (setq gr (pop org-table-colgroup-info))
  1321. (format "%s%%s%s"
  1322. (cond ((eq gr :start)
  1323. (prog1 (if colgropen "|" "|")
  1324. (setq colgropen t)))
  1325. ((eq gr :startend)
  1326. (prog1 (if colgropen "|" "|")
  1327. (setq colgropen nil)))
  1328. (t ""))
  1329. (if (memq gr '(:end :startend))
  1330. (progn (setq colgropen nil) "|")
  1331. "")))
  1332. fnum ""))))
  1333. ;; fix double || in line-fmt
  1334. (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
  1335. ;; maybe remove the first and last "|"
  1336. (when (and (not org-export-latex-tables-column-borders)
  1337. (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
  1338. (setq line-fmt (match-string 2 line-fmt)))
  1339. ;; format alignment
  1340. (unless align
  1341. (setq align (apply 'format
  1342. (cons line-fmt
  1343. (mapcar (lambda (x) (if x "r" "l"))
  1344. org-table-last-alignment)))))
  1345. ;; prepare the table to send to orgtbl-to-latex
  1346. (setq lines
  1347. (mapcar
  1348. (lambda(elem)
  1349. (or (and (string-match "[ \t]*|-+" elem) 'hline)
  1350. (org-split-string (org-trim elem) "|")))
  1351. lines))
  1352. (when insert
  1353. (insert (org-export-latex-protect-string
  1354. (concat
  1355. (if longtblp
  1356. (concat "\\begin{longtable}{" align "}\n")
  1357. (if floatp "\\begin{table}[htb]\n"))
  1358. (if (or floatp longtblp)
  1359. (format
  1360. "\\caption{%s%s}"
  1361. (if label (concat "\\\label{" label "}") "")
  1362. (or caption "")))
  1363. (if longtblp "\\\\\n" "\n")
  1364. (if (and org-export-latex-tables-centered (not longtblp))
  1365. "\\begin{center}\n")
  1366. (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
  1367. (orgtbl-to-latex
  1368. lines
  1369. `(:tstart nil :tend nil
  1370. :hlend ,(if longtblp
  1371. (format "\\\\
  1372. \\hline
  1373. \\endhead
  1374. \\hline\\multicolumn{%d}{r}{Continued on next page}\\
  1375. \\endfoot
  1376. \\endlastfoot" (length org-table-last-alignment))
  1377. nil)))
  1378. (if (not longtblp) (concat "\n\\end{tabular}"))
  1379. (if longtblp "\n" (if org-export-latex-tables-centered
  1380. "\n\\end{center}\n" "\n"))
  1381. (if longtblp
  1382. "\\end{longtable}"
  1383. (if floatp "\\end{table}"))))
  1384. "\n\n"))))))))
  1385. (defun org-export-latex-fontify ()
  1386. "Convert fontification to LaTeX."
  1387. (goto-char (point-min))
  1388. (while (re-search-forward org-emph-re nil t)
  1389. ;; The match goes one char after the *string*, except at the end of a line
  1390. (let ((emph (assoc (match-string 3)
  1391. org-export-latex-emphasis-alist))
  1392. (beg (match-beginning 0))
  1393. (end (match-end 0))
  1394. rpl s)
  1395. (unless emph
  1396. (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
  1397. (match-string 3)))
  1398. (unless (or (and (get-text-property (- (point) 2) 'org-protected)
  1399. (not (get-text-property
  1400. (- (point) 2) 'org-verbatim-emph)))
  1401. (save-excursion
  1402. (goto-char (match-beginning 1))
  1403. (save-match-data
  1404. (and (org-at-table-p)
  1405. (string-match
  1406. "[|\n]" (buffer-substring beg end))))))
  1407. (setq s (match-string 4))
  1408. (setq rpl (concat (match-string 1)
  1409. (org-export-latex-emph-format (cadr emph)
  1410. (match-string 4))
  1411. (match-string 5)))
  1412. (if (caddr emph)
  1413. (setq rpl (org-export-latex-protect-string rpl))
  1414. (save-match-data
  1415. (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
  1416. (progn
  1417. (add-text-properties (match-beginning 1) (match-end 1)
  1418. '(org-protected t) rpl)
  1419. (add-text-properties (match-beginning 3) (match-end 3)
  1420. '(org-protected t) rpl)))))
  1421. (replace-match rpl t t)))
  1422. (backward-char)))
  1423. (defvar org-export-latex-use-verb nil)
  1424. (defun org-export-latex-emph-format (format string)
  1425. "Format an emphasis string and handle the \\verb special case."
  1426. (when (equal format "\\verb")
  1427. (save-match-data
  1428. (if org-export-latex-use-verb
  1429. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1430. (catch 'exit
  1431. (loop for i from 0 to (1- (length ll)) do
  1432. (if (not (string-match (regexp-quote (substring ll i (1+ i)))
  1433. string))
  1434. (progn
  1435. (setq format (concat "\\verb" (substring ll i (1+ i))
  1436. "%s" (substring ll i (1+ i))))
  1437. (throw 'exit nil))))))
  1438. (let ((start 0)
  1439. (trans '(("\\" . "\\textbackslash{}")
  1440. ("~" . "\\textasciitilde{}")
  1441. ("^" . "\\textasciicircum{}")))
  1442. (rtn "") char)
  1443. (while (string-match "[\\{}$%&_#~^]" string)
  1444. (setq char (match-string 0 string))
  1445. (if (> (match-beginning 0) 0)
  1446. (setq rtn (concat rtn (substring string
  1447. 0 (match-beginning 0)))))
  1448. (setq string (substring string (1+ (match-beginning 0))))
  1449. (setq char (or (cdr (assoc char trans)) (concat "\\" char))
  1450. rtn (concat rtn char)))
  1451. (setq string (concat rtn string) format "\\texttt{%s}")))))
  1452. (format format string))
  1453. (defun org-export-latex-links ()
  1454. ;; Make sure to use the LaTeX hyperref and graphicx package
  1455. ;; or send some warnings.
  1456. "Convert links to LaTeX."
  1457. (goto-char (point-min))
  1458. (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
  1459. (org-if-unprotected-1
  1460. (goto-char (match-beginning 0))
  1461. (let* ((re-radio org-export-latex-all-targets-re)
  1462. (remove (list (match-beginning 0) (match-end 0)))
  1463. (raw-path (org-extract-attributes (match-string 3)))
  1464. (full-raw-path (concat (match-string 1) raw-path))
  1465. (desc (match-string 5))
  1466. (type (or (match-string 2)
  1467. (if (or (file-name-absolute-p raw-path)
  1468. (string-match "^\\.\\.?/" raw-path))
  1469. "file")))
  1470. (coderefp (equal type "coderef"))
  1471. (caption (org-find-text-property-in-string 'org-caption raw-path))
  1472. (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
  1473. (plist-get org-export-latex-options-plist :latex-image-options)))
  1474. (label (org-find-text-property-in-string 'org-label raw-path))
  1475. imgp radiop
  1476. ;; define the path of the link
  1477. (path (cond
  1478. ((member type '("coderef"))
  1479. raw-path)
  1480. ((member type '("http" "https" "ftp"))
  1481. (concat type ":" raw-path))
  1482. ((and re-radio (string-match re-radio raw-path))
  1483. (setq radiop t))
  1484. ((equal type "mailto")
  1485. (concat type ":" raw-path))
  1486. ((equal type "file")
  1487. (if (and (org-file-image-p
  1488. (expand-file-name
  1489. raw-path)
  1490. org-export-latex-inline-image-extensions)
  1491. (or (get-text-property 0 'org-no-description
  1492. raw-path)
  1493. (equal desc full-raw-path)))
  1494. (setq imgp t)
  1495. (progn (when (string-match "\\(.+\\)::.+" raw-path)
  1496. (setq raw-path (match-string 1 raw-path)))
  1497. (if (file-exists-p raw-path)
  1498. (concat type "://" (expand-file-name raw-path))
  1499. (concat type "://" (org-export-directory
  1500. :LaTeX org-export-latex-options-plist)
  1501. raw-path))))))))
  1502. ;; process with link inserting
  1503. (apply 'delete-region remove)
  1504. (cond ((and imgp
  1505. (plist-get org-export-latex-options-plist :inline-images))
  1506. ;; OK, we need to inline an image
  1507. (insert
  1508. (org-export-latex-format-image raw-path caption label attr)))
  1509. (coderefp
  1510. (insert (format
  1511. (org-export-get-coderef-format path desc)
  1512. (cdr (assoc path org-export-code-refs)))))
  1513. (radiop (insert (format "\\hyperref[%s]{%s}"
  1514. (org-solidify-link-text raw-path) desc)))
  1515. ((not type)
  1516. (insert (format "\\hyperref[%s]{%s}"
  1517. (org-remove-initial-hash
  1518. (org-solidify-link-text raw-path))
  1519. desc)))
  1520. (path
  1521. (when (org-at-table-p)
  1522. ;; There is a strange problem when we have a link in a table,
  1523. ;; ampersands then cause a problem. I think this must be
  1524. ;; a LaTeX issue, but we here implement a work-around anyway.
  1525. (setq path (org-export-latex-protect-amp path)
  1526. desc (org-export-latex-protect-amp desc)))
  1527. (insert (format "\\href{%s}{%s}" path desc)))
  1528. (t (insert "\\texttt{" desc "}")))))))
  1529. (defun org-export-latex-format-image (path caption label attr)
  1530. "Format the image element, depending on user settings."
  1531. (let (ind floatp wrapp placement figenv)
  1532. (setq floatp (or caption label))
  1533. (setq ind (org-get-text-property-any 0 'original-indentation path))
  1534. (when (and attr (stringp attr))
  1535. (if (string-match "[ \t]*\\<wrap\\>" attr)
  1536. (setq wrapp t floatp nil attr (replace-match "" t t attr)))
  1537. (if (string-match "[ \t]*\\<float\\>" attr)
  1538. (setq wrapp nil floatp t attr (replace-match "" t t attr))))
  1539. (setq placement
  1540. (cond
  1541. (wrapp "{l}{0.5\\textwidth}")
  1542. (floatp "[htb]")
  1543. (t "")))
  1544. (when (and attr (stringp attr)
  1545. (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
  1546. (setq placement (match-string 1 attr)
  1547. attr (replace-match "" t t attr)))
  1548. (setq attr (and attr (org-trim attr)))
  1549. (when (or (not attr) (= (length attr) 0))
  1550. (setq attr (cond (floatp "width=0.7\\textwidth")
  1551. (wrapp "width=0.48\\textwidth")
  1552. (t attr))))
  1553. (setq figenv
  1554. (cond
  1555. (wrapp "\\begin{wrapfigure}%placement
  1556. \\centering
  1557. \\includegraphics[%attr]{%path}
  1558. \\caption{%labelcmd%caption}
  1559. \\end{wrapfigure}")
  1560. (floatp "\\begin{figure}%placement
  1561. \\centering
  1562. \\includegraphics[%attr]{%path}
  1563. \\caption{%labelcmd%caption}
  1564. \\end{figure}")
  1565. (t "\\includegraphics[%attr]{%path}")))
  1566. (setq figenv (mapconcat 'identity (split-string figenv "\n")
  1567. (save-excursion (beginning-of-line 1)
  1568. (looking-at "[ \t]*")
  1569. (concat "\n" (match-string 0)))))
  1570. (if (and (not label) (not caption)
  1571. (string-match "^\\\\caption{.*\n" figenv))
  1572. (setq figenv (replace-match "" t t figenv)))
  1573. (org-add-props
  1574. (org-fill-template
  1575. figenv
  1576. (list (cons "path"
  1577. (if (file-name-absolute-p path)
  1578. (expand-file-name path)
  1579. path))
  1580. (cons "attr" attr)
  1581. (cons "labelcmd" (if label (format "\\label{%s}"
  1582. label)""))
  1583. (cons "caption" (or caption ""))
  1584. (cons "placement" (or placement ""))))
  1585. nil 'original-indentation ind)))
  1586. (defun org-export-latex-protect-amp (s)
  1587. (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
  1588. (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
  1589. t t s)))
  1590. s)
  1591. (defun org-remove-initial-hash (s)
  1592. (if (string-match "\\`#" s)
  1593. (substring s 1)
  1594. s))
  1595. (defvar org-latex-entities) ; defined below
  1596. (defvar org-latex-entities-regexp) ; defined below
  1597. (defvar org-latex-entities-exceptions) ; defined below
  1598. (defun org-export-latex-preprocess (parameters)
  1599. "Clean stuff in the LaTeX export."
  1600. ;; Preserve line breaks
  1601. (goto-char (point-min))
  1602. (while (re-search-forward "\\\\\\\\" nil t)
  1603. (add-text-properties (match-beginning 0) (match-end 0)
  1604. '(org-protected t)))
  1605. ;; Preserve latex environments
  1606. (goto-char (point-min))
  1607. (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
  1608. (let* ((start (progn (beginning-of-line) (point)))
  1609. (end (and (re-search-forward
  1610. (concat "^[ \t]*\\\\end{"
  1611. (regexp-quote (match-string 1))
  1612. "}") nil t)
  1613. (point-at-eol))))
  1614. (if end
  1615. (add-text-properties start end '(org-protected t))
  1616. (goto-char (point-at-eol)))))
  1617. ;; Preserve math snippets
  1618. (let* ((matchers (plist-get org-format-latex-options :matchers))
  1619. (re-list org-latex-regexps)
  1620. beg end re e m n block off)
  1621. ;; Check the different regular expressions
  1622. (while (setq e (pop re-list))
  1623. (setq m (car e) re (nth 1 e) n (nth 2 e)
  1624. block (if (nth 3 e) "\n\n" ""))
  1625. (setq off (if (member m '("$" "$1")) 1 0))
  1626. (when (and (member m matchers) (not (equal m "begin")))
  1627. (goto-char (point-min))
  1628. (while (re-search-forward re nil t)
  1629. (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
  1630. (add-text-properties beg end '(org-protected t org-latex-math t))))))
  1631. ;; Convert LaTeX to \LaTeX{}
  1632. (goto-char (point-min))
  1633. (let ((case-fold-search nil))
  1634. (while (re-search-forward "\\([^+_]\\)LaTeX" nil t)
  1635. (org-if-unprotected
  1636. (replace-match (org-export-latex-protect-string
  1637. (concat (match-string 1) "\\LaTeX{}")) t t))))
  1638. ;; Convert blockquotes
  1639. (goto-char (point-min))
  1640. (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
  1641. (org-replace-match-keep-properties "\\begin{quote}" t t))
  1642. (goto-char (point-min))
  1643. (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
  1644. (org-replace-match-keep-properties "\\end{quote}" t t))
  1645. ;; Convert verse
  1646. (goto-char (point-min))
  1647. (while (search-forward "ORG-VERSE-START" nil t)
  1648. (org-replace-match-keep-properties "\\begin{verse}" t t)
  1649. (beginning-of-line 2)
  1650. (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
  1651. (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
  1652. (goto-char (match-end 1))
  1653. (org-replace-match-keep-properties
  1654. (org-export-latex-protect-string
  1655. (concat "\\hspace*{1cm}" (match-string 2))) t t)
  1656. (beginning-of-line 1))
  1657. (if (looking-at "[ \t]*$")
  1658. (insert (org-export-latex-protect-string "\\vspace*{1em}"))
  1659. (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
  1660. (end-of-line 1)
  1661. (insert "\\\\")))
  1662. (beginning-of-line 2))
  1663. (and (looking-at "[ \t]*ORG-VERSE-END.*")
  1664. (org-replace-match-keep-properties "\\end{verse}" t t)))
  1665. ;; Convert center
  1666. (goto-char (point-min))
  1667. (while (search-forward "ORG-CENTER-START" nil t)
  1668. (org-replace-match-keep-properties "\\begin{center}" t t))
  1669. (goto-char (point-min))
  1670. (while (search-forward "ORG-CENTER-END" nil t)
  1671. (org-replace-match-keep-properties "\\end{center}" t t))
  1672. (run-hooks 'org-export-latex-after-blockquotes-hook)
  1673. ;; Convert horizontal rules
  1674. (goto-char (point-min))
  1675. (while (re-search-forward "^----+.$" nil t)
  1676. (org-if-unprotected
  1677. (replace-match (org-export-latex-protect-string "\\hrule") t t)))
  1678. ;; Protect LaTeX commands like \command[...]{...} or \command{...}
  1679. (let ((re (concat "\\\\[a-zA-Z]+\\(?:"
  1680. "\\[.*\\]"
  1681. "\\)?"
  1682. "\\(" (org-create-multibrace-regexp "{" "}" 3)
  1683. "\\)\\{1,3\\}")))
  1684. (while (re-search-forward re nil t)
  1685. (unless (save-excursion (goto-char (match-beginning 0))
  1686. (equal (char-after (point-at-bol)) ?#))
  1687. (add-text-properties (match-beginning 0) (match-end 0)
  1688. '(org-protected t)))))
  1689. ;; Protect LaTeX entities
  1690. (goto-char (point-min))
  1691. (let (a)
  1692. (while (re-search-forward org-latex-entities-regexp nil t)
  1693. (if (setq a (assoc (match-string 0) org-latex-entities-exceptions))
  1694. (replace-match (org-add-props (nth 1 a) nil 'org-protected t)
  1695. t t)
  1696. (add-text-properties (match-beginning 0) (match-end 0)
  1697. '(org-protected t)))))
  1698. ;; Replace radio links
  1699. (goto-char (point-min))
  1700. (while (re-search-forward
  1701. (concat "<<<?" org-export-latex-all-targets-re
  1702. ">>>?\\((INVISIBLE)\\)?") nil t)
  1703. (org-if-unprotected-at (+ (match-beginning 0) 2)
  1704. (replace-match
  1705. (org-export-latex-protect-string
  1706. (format "\\label{%s}%s" (save-match-data (org-solidify-link-text
  1707. (match-string 1)))
  1708. (if (match-string 2) "" (match-string 1)))) t t)))
  1709. ;; Delete @<...> constructs
  1710. ;; Thanks to Daniel Clemente for this regexp
  1711. (goto-char (point-min))
  1712. (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
  1713. (org-if-unprotected
  1714. (replace-match "")))
  1715. ;; When converting to LaTeX, replace footnotes
  1716. ;; FIXME: don't protect footnotes from conversion
  1717. (when (plist-get org-export-latex-options-plist :footnotes)
  1718. (goto-char (point-min))
  1719. (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
  1720. (org-if-unprotected
  1721. (when (and (save-match-data
  1722. (save-excursion (beginning-of-line)
  1723. (looking-at "[^:|#]")))
  1724. (not (org-in-verbatim-emphasis)))
  1725. (let ((foot-beg (match-beginning 0))
  1726. (foot-end (match-end 0))
  1727. (foot-prefix (match-string 0))
  1728. footnote footnote-rpl)
  1729. (save-excursion
  1730. (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
  1731. nil t))
  1732. (replace-match (org-export-latex-protect-string
  1733. (concat "$^{" (match-string 1) "}$")))
  1734. (replace-match "")
  1735. (let ((end (save-excursion
  1736. (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
  1737. (match-beginning 0) (point-max)))))
  1738. (setq footnote (concat (org-trim (buffer-substring (point) end))
  1739. " ")) ; prevent last } being part of a link
  1740. (delete-region (point) end))
  1741. (goto-char foot-beg)
  1742. (delete-region foot-beg foot-end)
  1743. (unless (null footnote)
  1744. (setq footnote-rpl (format "\\footnote{%s}" footnote))
  1745. (add-text-properties 0 10 '(org-protected t) footnote-rpl)
  1746. (add-text-properties (1- (length footnote-rpl))
  1747. (length footnote-rpl)
  1748. '(org-protected t) footnote-rpl)
  1749. (insert footnote-rpl)))
  1750. )))))
  1751. ;; Remove footnote section tag for LaTeX
  1752. (goto-char (point-min))
  1753. (while (re-search-forward
  1754. (concat "^" footnote-section-tag-regexp) nil t)
  1755. (org-if-unprotected
  1756. (replace-match "")))))
  1757. ;;; List handling:
  1758. (defun org-export-latex-lists ()
  1759. "Convert plain text lists in current buffer into LaTeX lists."
  1760. (goto-char (point-min))
  1761. (while (re-search-forward org-list-beginning-re nil t)
  1762. (org-if-unprotected
  1763. (beginning-of-line)
  1764. (insert (org-list-to-latex (org-list-parse-list t)
  1765. org-export-latex-list-parameters))
  1766. "\n")))
  1767. (defconst org-latex-entities
  1768. '("\\!"
  1769. "\\'"
  1770. "\\+"
  1771. "\\,"
  1772. "\\-"
  1773. "\\:"
  1774. "\\;"
  1775. "\\<"
  1776. "\\="
  1777. "\\>"
  1778. "\\Huge"
  1779. "\\LARGE"
  1780. "\\Large"
  1781. "\\Styles"
  1782. "\\\\"
  1783. "\\`"
  1784. "\\addcontentsline"
  1785. "\\address"
  1786. "\\addtocontents"
  1787. "\\addtocounter"
  1788. "\\addtolength"
  1789. "\\addvspace"
  1790. "\\alph"
  1791. "\\appendix"
  1792. "\\arabic"
  1793. "\\author"
  1794. "\\begin{array}"
  1795. "\\begin{center}"
  1796. "\\begin{description}"
  1797. "\\begin{enumerate}"
  1798. "\\begin{eqnarray}"
  1799. "\\begin{equation}"
  1800. "\\begin{figure}"
  1801. "\\begin{flushleft}"
  1802. "\\begin{flushright}"
  1803. "\\begin{itemize}"
  1804. "\\begin{list}"
  1805. "\\begin{minipage}"
  1806. "\\begin{picture}"
  1807. "\\begin{quotation}"
  1808. "\\begin{quote}"
  1809. "\\begin{tabbing}"
  1810. "\\begin{table}"
  1811. "\\begin{tabular}"
  1812. "\\begin{thebibliography}"
  1813. "\\begin{theorem}"
  1814. "\\begin{titlepage}"
  1815. "\\begin{verbatim}"
  1816. "\\begin{verse}"
  1817. "\\bf"
  1818. "\\bf"
  1819. "\\bibitem"
  1820. "\\bigskip"
  1821. "\\cdots"
  1822. "\\centering"
  1823. "\\circle"
  1824. "\\cite"
  1825. "\\cleardoublepage"
  1826. "\\clearpage"
  1827. "\\cline"
  1828. "\\closing"
  1829. "\\dashbox"
  1830. "\\date"
  1831. "\\ddots"
  1832. "\\dotfill"
  1833. "\\em"
  1834. "\\fbox"
  1835. "\\flushbottom"
  1836. "\\fnsymbol"
  1837. "\\footnote"
  1838. "\\footnotemark"
  1839. "\\footnotesize"
  1840. "\\footnotetext"
  1841. "\\frac"
  1842. "\\frame"
  1843. "\\framebox"
  1844. "\\hfill"
  1845. "\\hline"
  1846. "\\hrulespace"
  1847. "\\hspace"
  1848. "\\huge"
  1849. "\\hyphenation"
  1850. "\\include"
  1851. "\\includeonly"
  1852. "\\indent"
  1853. "\\input"
  1854. "\\it"
  1855. "\\kill"
  1856. "\\label"
  1857. "\\large"
  1858. "\\ldots"
  1859. "\\line"
  1860. "\\linebreak"
  1861. "\\linethickness"
  1862. "\\listoffigures"
  1863. "\\listoftables"
  1864. "\\location"
  1865. "\\makebox"
  1866. "\\maketitle"
  1867. "\\mark"
  1868. "\\mbox"
  1869. "\\medskip"
  1870. "\\multicolumn"
  1871. "\\multiput"
  1872. ("\\nbsp" "~")
  1873. "\\newcommand"
  1874. "\\newcounter"
  1875. "\\newenvironment"
  1876. "\\newfont"
  1877. "\\newlength"
  1878. "\\newline"
  1879. "\\newpage"
  1880. "\\newsavebox"
  1881. "\\newtheorem"
  1882. "\\nocite"
  1883. "\\nofiles"
  1884. "\\noindent"
  1885. "\\nolinebreak"
  1886. "\\nopagebreak"
  1887. "\\normalsize"
  1888. "\\onecolumn"
  1889. "\\opening"
  1890. "\\oval"
  1891. "\\overbrace"
  1892. "\\overline"
  1893. "\\pagebreak"
  1894. "\\pagenumbering"
  1895. "\\pageref"
  1896. "\\pagestyle"
  1897. "\\par"
  1898. "\\parbox"
  1899. "\\put"
  1900. "\\raggedbottom"
  1901. "\\raggedleft"
  1902. "\\raggedright"
  1903. "\\raisebox"
  1904. "\\ref"
  1905. "\\rm"
  1906. "\\roman"
  1907. "\\rule"
  1908. "\\savebox"
  1909. "\\sc"
  1910. "\\scriptsize"
  1911. "\\setcounter"
  1912. "\\setlength"
  1913. "\\settowidth"
  1914. "\\sf"
  1915. "\\shortstack"
  1916. "\\signature"
  1917. "\\sl"
  1918. "\\small"
  1919. "\\smallskip"
  1920. "\\sqrt"
  1921. "\\tableofcontents"
  1922. "\\telephone"
  1923. "\\thanks"
  1924. "\\thispagestyle"
  1925. "\\tiny"
  1926. "\\title"
  1927. "\\tt"
  1928. "\\twocolumn"
  1929. "\\typein"
  1930. "\\typeout"
  1931. "\\underbrace"
  1932. "\\underline"
  1933. "\\usebox"
  1934. "\\usecounter"
  1935. "\\value"
  1936. "\\vdots"
  1937. "\\vector"
  1938. "\\verb"
  1939. "\\vfill"
  1940. "\\vline"
  1941. "\\vspace")
  1942. "A list of LaTeX commands to be protected when performing conversion.")
  1943. (defvar org-latex-entities-exceptions nil)
  1944. (defconst org-latex-entities-regexp
  1945. (let (names rest)
  1946. (dolist (x org-latex-entities)
  1947. (when (consp x)
  1948. (add-to-list 'org-latex-entities-exceptions x)
  1949. (setq x (car x)))
  1950. (if (string-match "[a-zA-Z]$" x)
  1951. (push x names)
  1952. (push x rest)))
  1953. (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
  1954. "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
  1955. (provide 'org-export-latex)
  1956. (provide 'org-latex)
  1957. ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
  1958. ;;; org-latex.el ends here