org-latex.el 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  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-initial-vars-hook nil
  367. "Hook run before LaTeX export.
  368. The exact moment is after the initial variables like org-export-latex-class
  369. have been determined from the environment.")
  370. (defvar org-export-latex-after-blockquotes-hook nil
  371. "Hook run during LaTeX export, after blockquote, verse, center are done.")
  372. (defvar org-export-latex-final-hook nil
  373. "Hook run in the finalized LaTeX buffer.")
  374. ;;; Autoload functions:
  375. ;;;###autoload
  376. (defun org-export-as-latex-batch ()
  377. "Call `org-export-as-latex', may be used in batch processing.
  378. For example:
  379. emacs --batch
  380. --load=$HOME/lib/emacs/org.el
  381. --eval \"(setq org-export-headline-levels 2)\"
  382. --visit=MyFile --funcall org-export-as-latex-batch"
  383. (org-export-as-latex org-export-headline-levels 'hidden))
  384. ;;;###autoload
  385. (defun org-export-as-latex-to-buffer (arg)
  386. "Call `org-export-as-latex` with output to a temporary buffer.
  387. No file is created. The prefix ARG is passed through to `org-export-as-latex'."
  388. (interactive "P")
  389. (org-export-as-latex arg nil nil "*Org LaTeX Export*")
  390. (when org-export-show-temporary-export-buffer
  391. (switch-to-buffer-other-window "*Org LaTeX Export*")))
  392. ;;;###autoload
  393. (defun org-replace-region-by-latex (beg end)
  394. "Replace the region from BEG to END with its LaTeX export.
  395. It assumes the region has `org-mode' syntax, and then convert it to
  396. LaTeX. This can be used in any buffer. For example, you could
  397. write an itemized list in `org-mode' syntax in an LaTeX buffer and
  398. then use this command to convert it."
  399. (interactive "r")
  400. (let (reg latex buf)
  401. (save-window-excursion
  402. (if (org-mode-p)
  403. (setq latex (org-export-region-as-latex
  404. beg end t 'string))
  405. (setq reg (buffer-substring beg end)
  406. buf (get-buffer-create "*Org tmp*"))
  407. (with-current-buffer buf
  408. (erase-buffer)
  409. (insert reg)
  410. (org-mode)
  411. (setq latex (org-export-region-as-latex
  412. (point-min) (point-max) t 'string)))
  413. (kill-buffer buf)))
  414. (delete-region beg end)
  415. (insert latex)))
  416. ;;;###autoload
  417. (defun org-export-region-as-latex (beg end &optional body-only buffer)
  418. "Convert region from BEG to END in `org-mode' buffer to LaTeX.
  419. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  420. contents, and only produce the region of converted text, useful for
  421. cut-and-paste operations.
  422. If BUFFER is a buffer or a string, use/create that buffer as a target
  423. of the converted LaTeX. If BUFFER is the symbol `string', return the
  424. produced LaTeX as a string and leave no buffer behind. For example,
  425. a Lisp program could call this function in the following way:
  426. (setq latex (org-export-region-as-latex beg end t 'string))
  427. When called interactively, the output buffer is selected, and shown
  428. in a window. A non-interactive call will only return the buffer."
  429. (interactive "r\nP")
  430. (when (interactive-p)
  431. (setq buffer "*Org LaTeX Export*"))
  432. (let ((transient-mark-mode t) (zmacs-regions t)
  433. ext-plist rtn)
  434. (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
  435. (goto-char end)
  436. (set-mark (point)) ;; to activate the region
  437. (goto-char beg)
  438. (setq rtn (org-export-as-latex
  439. nil nil ext-plist
  440. buffer body-only))
  441. (if (fboundp 'deactivate-mark) (deactivate-mark))
  442. (if (and (interactive-p) (bufferp rtn))
  443. (switch-to-buffer-other-window rtn)
  444. rtn)))
  445. ;;;###autoload
  446. (defun org-export-as-latex (arg &optional hidden ext-plist
  447. to-buffer body-only pub-dir)
  448. "Export current buffer to a LaTeX file.
  449. If there is an active region, export only the region. The prefix
  450. ARG specifies how many levels of the outline should become
  451. headlines. The default is 3. Lower levels will be exported
  452. depending on `org-export-latex-low-levels'. The default is to
  453. convert them as description lists.
  454. HIDDEN is obsolete and does nothing.
  455. EXT-PLIST is a property list with
  456. external parameters overriding org-mode's default settings, but
  457. still inferior to file-local settings. When TO-BUFFER is
  458. non-nil, create a buffer with that name and export to that
  459. buffer. If TO-BUFFER is the symbol `string', don't leave any
  460. buffer behind but just return the resulting LaTeX as a string.
  461. When BODY-ONLY is set, don't produce the file header and footer,
  462. simply return the content of \begin{document}...\end{document},
  463. without even the \begin{document} and \end{document} commands.
  464. when PUB-DIR is set, use this as the publishing directory."
  465. (interactive "P")
  466. (run-hooks 'org-export-first-hook)
  467. ;; Make sure we have a file name when we need it.
  468. (when (and (not (or to-buffer body-only))
  469. (not buffer-file-name))
  470. (if (buffer-base-buffer)
  471. (org-set-local 'buffer-file-name
  472. (with-current-buffer (buffer-base-buffer)
  473. buffer-file-name))
  474. (error "Need a file name to be able to export")))
  475. (message "Exporting to LaTeX...")
  476. (org-unmodified
  477. (remove-text-properties (point-min) (point-max)
  478. '(:org-license-to-kill nil)))
  479. (org-update-radio-target-regexp)
  480. (org-export-latex-set-initial-vars ext-plist arg)
  481. (run-hooks 'org-export-latex-after-initial-vars-hook)
  482. (let* ((wcf (current-window-configuration))
  483. (opt-plist org-export-latex-options-plist)
  484. (region-p (org-region-active-p))
  485. (rbeg (and region-p (region-beginning)))
  486. (rend (and region-p (region-end)))
  487. (subtree-p
  488. (if (plist-get opt-plist :ignore-subtree-p)
  489. nil
  490. (when region-p
  491. (save-excursion
  492. (goto-char rbeg)
  493. (and (org-at-heading-p)
  494. (>= (org-end-of-subtree t t) rend))))))
  495. (opt-plist (setq org-export-opt-plist
  496. (if subtree-p
  497. (org-export-add-subtree-options opt-plist rbeg)
  498. opt-plist)))
  499. ;; Make sure the variable contains the updated values.
  500. (org-export-latex-options-plist opt-plist)
  501. (title (or (and subtree-p (org-export-get-title-from-subtree))
  502. (plist-get opt-plist :title)
  503. (and (not
  504. (plist-get opt-plist :skip-before-1st-heading))
  505. (org-export-grab-title-from-buffer))
  506. (file-name-sans-extension
  507. (file-name-nondirectory buffer-file-name))))
  508. (filename (concat (file-name-as-directory
  509. (or pub-dir
  510. (org-export-directory :LaTeX ext-plist)))
  511. (file-name-sans-extension
  512. (or (and subtree-p
  513. (org-entry-get rbeg "EXPORT_FILE_NAME" t))
  514. (file-name-nondirectory ;sans-extension
  515. buffer-file-name)))
  516. ".tex"))
  517. (filename (if (equal (file-truename filename)
  518. (file-truename buffer-file-name))
  519. (concat filename ".tex")
  520. filename))
  521. (buffer (if to-buffer
  522. (cond
  523. ((eq to-buffer 'string) (get-buffer-create
  524. "*Org LaTeX Export*"))
  525. (t (get-buffer-create to-buffer)))
  526. (find-file-noselect filename)))
  527. (odd org-odd-levels-only)
  528. (header (org-export-latex-make-header title opt-plist))
  529. (skip (cond (subtree-p nil)
  530. (region-p nil)
  531. (t (plist-get opt-plist :skip-before-1st-heading))))
  532. (text (plist-get opt-plist :text))
  533. (org-export-preprocess-hook
  534. (cons
  535. `(lambda () (org-set-local 'org-complex-heading-regexp
  536. ,org-export-latex-complex-heading-re))
  537. org-export-preprocess-hook))
  538. (first-lines (if skip "" (org-export-latex-first-lines
  539. opt-plist
  540. (if subtree-p
  541. (save-excursion
  542. (goto-char rbeg)
  543. (point-at-bol 2))
  544. rbeg)
  545. (if region-p rend))))
  546. (coding-system (and (boundp 'buffer-file-coding-system)
  547. buffer-file-coding-system))
  548. (coding-system-for-write (or org-export-latex-coding-system
  549. coding-system))
  550. (save-buffer-coding-system (or org-export-latex-coding-system
  551. coding-system))
  552. (region (buffer-substring
  553. (if region-p (region-beginning) (point-min))
  554. (if region-p (region-end) (point-max))))
  555. (string-for-export
  556. (org-export-preprocess-string
  557. region
  558. :emph-multiline t
  559. :for-LaTeX t
  560. :comments nil
  561. :tags (plist-get opt-plist :tags)
  562. :priority (plist-get opt-plist :priority)
  563. :footnotes (plist-get opt-plist :footnotes)
  564. :drawers (plist-get opt-plist :drawers)
  565. :timestamps (plist-get opt-plist :timestamps)
  566. :todo-keywords (plist-get opt-plist :todo-keywords)
  567. :add-text (if (eq to-buffer 'string) nil text)
  568. :skip-before-1st-heading skip
  569. :select-tags (plist-get opt-plist :select-tags)
  570. :exclude-tags (plist-get opt-plist :exclude-tags)
  571. :LaTeX-fragments nil)))
  572. (set-buffer buffer)
  573. (erase-buffer)
  574. (org-install-letbind)
  575. (and (fboundp 'set-buffer-file-coding-system)
  576. (set-buffer-file-coding-system coding-system-for-write))
  577. ;; insert the header and initial document commands
  578. (unless (or (eq to-buffer 'string) body-only)
  579. (insert header))
  580. ;; insert text found in #+TEXT
  581. (when (and text (not (eq to-buffer 'string)))
  582. (insert (org-export-latex-content
  583. text '(lists tables fixed-width keywords))
  584. "\n\n"))
  585. ;; insert lines before the first headline
  586. (unless skip
  587. (insert first-lines))
  588. ;; export the content of headlines
  589. (org-export-latex-global
  590. (with-temp-buffer
  591. (insert string-for-export)
  592. (goto-char (point-min))
  593. (when (re-search-forward "^\\(\\*+\\) " nil t)
  594. (let* ((asters (length (match-string 1)))
  595. (level (if odd (- asters 2) (- asters 1))))
  596. (setq org-export-latex-add-level
  597. (if odd (1- (/ (1+ asters) 2)) (1- asters)))
  598. (org-export-latex-parse-global level odd)))))
  599. ;; finalization
  600. (unless body-only (insert "\n\\end{document}"))
  601. ;; Relocate the table of contents
  602. (goto-char (point-min))
  603. (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  604. (goto-char (point-min))
  605. (while (re-search-forward "\\\\tableofcontents\\>[ \t]*\n?" nil t)
  606. (replace-match ""))
  607. (goto-char (point-min))
  608. (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  609. (replace-match "\\tableofcontents" t t)))
  610. ;; Cleanup forced line ends in itmes where they are not needed
  611. (goto-char (point-min))
  612. (while (re-search-forward
  613. "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)?\n\\\\begin"
  614. nil t)
  615. (delete-region (match-beginning 1) (match-end 1)))
  616. (run-hooks 'org-export-latex-final-hook)
  617. (or to-buffer (save-buffer))
  618. (goto-char (point-min))
  619. (or (org-export-push-to-kill-ring "LaTeX")
  620. (message "Exporting to LaTeX...done"))
  621. (prog1
  622. (if (eq to-buffer 'string)
  623. (prog1 (buffer-substring (point-min) (point-max))
  624. (kill-buffer (current-buffer)))
  625. (current-buffer))
  626. (set-window-configuration wcf))))
  627. ;;;###autoload
  628. (defun org-export-as-pdf (arg &optional hidden ext-plist
  629. to-buffer body-only pub-dir)
  630. "Export as LaTeX, then process through to PDF."
  631. (interactive "P")
  632. (message "Exporting to PDF...")
  633. (let* ((wconfig (current-window-configuration))
  634. (lbuf (org-export-as-latex arg hidden ext-plist
  635. to-buffer body-only pub-dir))
  636. (file (buffer-file-name lbuf))
  637. (base (file-name-sans-extension (buffer-file-name lbuf)))
  638. (pdffile (concat base ".pdf"))
  639. (cmds org-latex-to-pdf-process)
  640. (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
  641. (bibtex-p (with-current-buffer lbuf
  642. (save-excursion
  643. (goto-char (point-min))
  644. (re-search-forward "\\\\bibliography{" nil t))))
  645. cmd)
  646. (with-current-buffer outbuf (erase-buffer))
  647. (message "Processing LaTeX file...")
  648. (if (and cmds (symbolp cmds))
  649. (funcall cmds file)
  650. (while cmds
  651. (setq cmd (pop cmds))
  652. (while (string-match "%b" cmd)
  653. (setq cmd (replace-match
  654. (save-match-data
  655. (shell-quote-argument base))
  656. t t cmd)))
  657. (while (string-match "%s" cmd)
  658. (setq cmd (replace-match
  659. (save-match-data
  660. (shell-quote-argument file))
  661. t t cmd)))
  662. (shell-command cmd outbuf outbuf)))
  663. (message "Processing LaTeX file...done")
  664. (if (not (file-exists-p pdffile))
  665. (error "PDF file was not produced")
  666. (set-window-configuration wconfig)
  667. (when org-export-pdf-remove-logfiles
  668. (dolist (ext org-export-pdf-logfiles)
  669. (setq file (concat base "." ext))
  670. (and (file-exists-p file) (delete-file file))))
  671. (message "Exporting to PDF...done")
  672. pdffile)))
  673. ;;;###autoload
  674. (defun org-export-as-pdf-and-open (arg)
  675. "Export as LaTeX, then process through to PDF, and open."
  676. (interactive "P")
  677. (let ((pdffile (org-export-as-pdf arg)))
  678. (if pdffile
  679. (org-open-file pdffile)
  680. (error "PDF file was not produced"))))
  681. ;;; Parsing functions:
  682. (defun org-export-latex-parse-global (level odd)
  683. "Parse the current buffer recursively, starting at LEVEL.
  684. If ODD is non-nil, assume the buffer only contains odd sections.
  685. Return a list reflecting the document structure."
  686. (save-excursion
  687. (goto-char (point-min))
  688. (let* ((cnt 0) output
  689. (depth org-export-latex-sectioning-depth))
  690. (while (org-re-search-forward-unprotected
  691. (concat "^\\(\\(?:\\*\\)\\{"
  692. (number-to-string (+ (if odd 2 1) level))
  693. "\\}\\) \\(.*\\)$")
  694. ;; make sure that there is no upper heading
  695. (when (> level 0)
  696. (save-excursion
  697. (save-match-data
  698. (org-re-search-forward-unprotected
  699. (concat "^\\(\\(?:\\*\\)\\{"
  700. (number-to-string level)
  701. "\\}\\) \\(.*\\)$") nil t)))) t)
  702. (setq cnt (1+ cnt))
  703. (let* ((pos (match-beginning 0))
  704. (heading (match-string 2))
  705. (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
  706. (save-excursion
  707. (narrow-to-region
  708. (point)
  709. (save-match-data
  710. (if (org-re-search-forward-unprotected
  711. (concat "^\\(\\(?:\\*\\)\\{"
  712. (number-to-string (+ (if odd 2 1) level))
  713. "\\}\\) \\(.*\\)$") nil t)
  714. (match-beginning 0)
  715. (point-max))))
  716. (goto-char (point-min))
  717. (setq output
  718. (append output
  719. (list
  720. (list
  721. `(pos . ,pos)
  722. `(level . ,nlevel)
  723. `(occur . ,cnt)
  724. `(heading . ,heading)
  725. `(content . ,(org-export-latex-parse-content))
  726. `(subcontent . ,(org-export-latex-parse-subcontent
  727. level odd)))))))
  728. (widen)))
  729. (list output))))
  730. (defun org-export-latex-parse-content ()
  731. "Extract the content of a section."
  732. (let ((beg (point))
  733. (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
  734. (progn (beginning-of-line) (point))
  735. (point-max))))
  736. (buffer-substring beg end)))
  737. (defun org-export-latex-parse-subcontent (level odd)
  738. "Extract the subcontent of a section at LEVEL.
  739. If ODD Is non-nil, assume subcontent only contains odd sections."
  740. (if (not (org-re-search-forward-unprotected
  741. (concat "^\\(\\(?:\\*\\)\\{"
  742. (number-to-string (+ (if odd 4 2) level))
  743. "\\}\\) \\(.*\\)$")
  744. nil t))
  745. nil ; subcontent is nil
  746. (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
  747. ;;; Rendering functions:
  748. (defun org-export-latex-global (content)
  749. "Export CONTENT to LaTeX.
  750. CONTENT is an element of the list produced by
  751. `org-export-latex-parse-global'."
  752. (if (eq (car content) 'subcontent)
  753. (mapc 'org-export-latex-sub (cdr content))
  754. (org-export-latex-sub (car content))))
  755. (defun org-export-latex-sub (subcontent)
  756. "Export the list SUBCONTENT to LaTeX.
  757. SUBCONTENT is an alist containing information about the headline
  758. and its content."
  759. (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
  760. (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
  761. (defun org-export-latex-subcontent (subcontent num)
  762. "Export each cell of SUBCONTENT to LaTeX.
  763. If NUM, export sections as numerical sections."
  764. (let* ((heading (org-export-latex-fontify-headline
  765. (cdr (assoc 'heading subcontent))))
  766. (level (- (cdr (assoc 'level subcontent))
  767. org-export-latex-add-level))
  768. (occur (number-to-string (cdr (assoc 'occur subcontent))))
  769. (content (cdr (assoc 'content subcontent)))
  770. (subcontent (cadr (assoc 'subcontent subcontent)))
  771. (label (org-get-text-property-any 0 'target heading))
  772. (label-list (cons label (cdr (assoc label
  773. org-export-target-aliases)))))
  774. (cond
  775. ;; Normal conversion
  776. ((<= level org-export-latex-sectioning-depth)
  777. (let* ((sec (nth (1- level) org-export-latex-sectioning))
  778. start end)
  779. (if (consp (cdr sec))
  780. (setq start (nth (if num 0 2) sec)
  781. end (nth (if num 1 3) sec))
  782. (setq start (if num (car sec) (cdr sec))))
  783. (insert (format start heading) "\n")
  784. (when label
  785. (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
  786. label-list "\n") "\n"))
  787. (insert (org-export-latex-content content))
  788. (cond ((stringp subcontent) (insert subcontent))
  789. ((listp subcontent)
  790. (while (org-looking-back "\n\n") (backward-delete-char 1))
  791. (org-export-latex-sub subcontent)))
  792. (if end (insert end "\n"))))
  793. ;; At a level under the hl option: we can drop this subsection
  794. ((> level org-export-latex-sectioning-depth)
  795. (cond ((eq org-export-latex-low-levels 'description)
  796. (if (string-match "% ends low level$"
  797. (buffer-substring (point-at-bol 0) (point)))
  798. (delete-region (point-at-bol 0) (point))
  799. (insert "\\begin{description}\n"))
  800. (insert (format "\n\\item[%s]%s~\n"
  801. heading
  802. (if label (format "\\label{%s}" label) "")))
  803. (insert (org-export-latex-content content))
  804. (cond ((stringp subcontent) (insert subcontent))
  805. ((listp subcontent) (org-export-latex-sub subcontent)))
  806. (insert "\\end{description} % ends low level\n"))
  807. ((memq org-export-latex-low-levels '(itemize enumerate))
  808. (if (string-match "% ends low level$"
  809. (buffer-substring (point-at-bol 0) (point)))
  810. (delete-region (point-at-bol 0) (point))
  811. (insert (format "\\begin{%s}\n"
  812. (symbol-name org-export-latex-low-levels))))
  813. (insert (format "\n\\item %s\\\\\n%s%%"
  814. heading
  815. (if label (format "\\label{%s}" label) "")))
  816. (insert (org-export-latex-content content))
  817. (cond ((stringp subcontent) (insert subcontent))
  818. ((listp subcontent) (org-export-latex-sub subcontent)))
  819. (insert (format "\\end{%s} %% ends low level\n"
  820. (symbol-name org-export-latex-low-levels))))
  821. ((listp org-export-latex-low-levels)
  822. (if (string-match "% ends low level$"
  823. (buffer-substring (point-at-bol 0) (point)))
  824. (delete-region (point-at-bol 0) (point))
  825. (insert (car org-export-latex-low-levels) "\n"))
  826. (insert (format (nth 2 org-export-latex-low-levels)
  827. heading
  828. (if label (format "\\label{%s}" label) "")))
  829. (insert (org-export-latex-content content))
  830. (cond ((stringp subcontent) (insert subcontent))
  831. ((listp subcontent) (org-export-latex-sub subcontent)))
  832. (insert (nth 1 org-export-latex-low-levels)
  833. " %% ends low level\n"))
  834. ((stringp org-export-latex-low-levels)
  835. (insert (format org-export-latex-low-levels heading) "\n")
  836. (when label (insert (format "\\label{%s}\n" label)))
  837. (insert (org-export-latex-content content))
  838. (cond ((stringp subcontent) (insert subcontent))
  839. ((listp subcontent) (org-export-latex-sub subcontent)))))))))
  840. ;;; Exporting internals:
  841. (defun org-export-latex-set-initial-vars (ext-plist level)
  842. "Store org local variables required for LaTeX export.
  843. EXT-PLIST is an optional additional plist.
  844. LEVEL indicates the default depth for export."
  845. (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
  846. org-export-latex-done-keywords org-done-keywords
  847. org-export-latex-not-done-keywords org-not-done-keywords
  848. org-export-latex-complex-heading-re org-complex-heading-regexp
  849. org-export-latex-display-custom-times org-display-custom-times
  850. org-export-latex-all-targets-re
  851. (org-make-target-link-regexp (org-all-targets))
  852. org-export-latex-options-plist
  853. (org-combine-plists (org-default-export-plist) ext-plist
  854. (org-infile-export-plist))
  855. org-export-latex-class
  856. (or (and (org-region-active-p)
  857. (save-excursion
  858. (goto-char (region-beginning))
  859. (and (looking-at org-complex-heading-regexp)
  860. (org-entry-get nil "LaTeX_CLASS" 'selective))))
  861. (save-excursion
  862. (save-restriction
  863. (widen)
  864. (goto-char (point-min))
  865. (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t)
  866. (match-string 1))))
  867. (plist-get org-export-latex-options-plist :latex-class)
  868. org-export-latex-default-class)
  869. org-export-latex-class-options
  870. (or (and (org-region-active-p)
  871. (save-excursion
  872. (goto-char (region-beginning))
  873. (and (looking-at org-complex-heading-regexp)
  874. (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
  875. (save-excursion
  876. (save-restriction
  877. (widen)
  878. (goto-char (point-min))
  879. (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
  880. (match-string 1))))
  881. (plist-get org-export-latex-options-plist :latex-class-options))
  882. org-export-latex-class
  883. (or (car (assoc org-export-latex-class org-export-latex-classes))
  884. (error "No definition for class `%s' in `org-export-latex-classes'"
  885. org-export-latex-class))
  886. org-export-latex-header
  887. (cadr (assoc org-export-latex-class org-export-latex-classes))
  888. org-export-latex-sectioning
  889. (cddr (assoc org-export-latex-class org-export-latex-classes))
  890. org-export-latex-sectioning-depth
  891. (or level
  892. (let ((hl-levels
  893. (plist-get org-export-latex-options-plist :headline-levels))
  894. (sec-depth (length org-export-latex-sectioning)))
  895. (if (> hl-levels sec-depth) sec-depth hl-levels))))
  896. (when (and org-export-latex-class-options
  897. (string-match "\\S-" org-export-latex-class-options)
  898. (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?"
  899. org-export-latex-header))
  900. (setq org-export-latex-header
  901. (concat (substring org-export-latex-header 0 (match-end 1))
  902. org-export-latex-class-options
  903. (substring org-export-latex-header (match-end 0))))))
  904. (defvar org-export-latex-format-toc-function
  905. 'org-export-latex-format-toc-default
  906. "The function formatting returning the string to createthe table of contents.
  907. The function mus take one parameter, the depth of the table of contents.")
  908. (defun org-export-latex-make-header (title opt-plist)
  909. "Make the LaTeX header and return it as a string.
  910. TITLE is the current title from the buffer or region.
  911. OPT-PLIST is the options plist for current buffer."
  912. (let ((toc (plist-get opt-plist :table-of-contents))
  913. (author (plist-get opt-plist :author)))
  914. (concat
  915. (if (plist-get opt-plist :time-stamp-file)
  916. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  917. ;; insert LaTeX custom header
  918. (org-export-apply-macros-in-string org-export-latex-header)
  919. "\n"
  920. ;; insert information on LaTeX packages
  921. (when org-export-latex-packages-alist
  922. (mapconcat (lambda(p)
  923. (if (equal "" (car p))
  924. (format "\\usepackage{%s}" (cadr p))
  925. (format "\\usepackage[%s]{%s}"
  926. (car p) (cadr p))))
  927. org-export-latex-packages-alist "\n"))
  928. ;; insert additional commands in the header
  929. (org-export-apply-macros-in-string
  930. (plist-get opt-plist :latex-header-extra))
  931. (org-export-apply-macros-in-string org-export-latex-append-header)
  932. ;; insert the title
  933. (format
  934. "\n\n\\title{%s}\n"
  935. ;; convert the title
  936. (org-export-latex-content
  937. title '(lists tables fixed-width keywords)))
  938. ;; insert author info
  939. (if (plist-get opt-plist :author-info)
  940. (format "\\author{%s}\n"
  941. (org-export-latex-fontify-headline (or author user-full-name)))
  942. (format "%%\\author{%s}\n"
  943. (or author user-full-name)))
  944. ;; insert the date
  945. (format "\\date{%s}\n"
  946. (format-time-string
  947. (or (plist-get opt-plist :date)
  948. org-export-latex-date-format)))
  949. ;; beginning of the document
  950. "\n\\begin{document}\n\n"
  951. ;; insert the title command
  952. (when (string-match "\\S-" title)
  953. (if (string-match "%s" org-export-latex-title-command)
  954. (format org-export-latex-title-command title)
  955. org-export-latex-title-command))
  956. "\n\n"
  957. ;; table of contents
  958. (when (and org-export-with-toc
  959. (plist-get opt-plist :section-numbers))
  960. (funcall org-export-latex-format-toc-function
  961. (cond ((numberp toc)
  962. (min toc (plist-get opt-plist :headline-levels)))
  963. (toc (plist-get opt-plist :headline-levels))))))))
  964. (defun org-export-latex-format-toc-default (depth)
  965. (when depth
  966. (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
  967. depth)))
  968. (defun org-export-latex-first-lines (opt-plist &optional beg end)
  969. "Export the first lines before first headline.
  970. If BEG is non-nil, it is the beginning of the region.
  971. If END is non-nil, it is the end of the region."
  972. (save-excursion
  973. (goto-char (or beg (point-min)))
  974. (let* ((pt (point))
  975. (end (if (re-search-forward "^\\*+ " end t)
  976. (goto-char (match-beginning 0))
  977. (goto-char (or end (point-max))))))
  978. (prog1
  979. (org-export-latex-content
  980. (org-export-preprocess-string
  981. (buffer-substring pt end)
  982. :for-LaTeX t
  983. :emph-multiline t
  984. :add-text nil
  985. :comments nil
  986. :skip-before-1st-heading nil
  987. :LaTeX-fragments nil
  988. :timestamps (plist-get opt-plist :timestamps)
  989. :footnotes (plist-get opt-plist :footnotes)))
  990. (org-unmodified
  991. (add-text-properties pt (max pt (1- end))
  992. '(:org-license-to-kill t)))))))
  993. (defvar org-export-latex-header-defs nil
  994. "The header definitions that might be used in the LaTeX body.")
  995. (defvar org-export-latex-header-defs-re nil
  996. "The header definitions that might be used in the LaTeX body.")
  997. (defun org-export-latex-content (content &optional exclude-list)
  998. "Convert CONTENT string to LaTeX.
  999. Don't perform conversions that are in EXCLUDE-LIST. Recognized
  1000. conversion types are: quotation-marks, emphasis, sub-superscript,
  1001. links, keywords, lists, tables, fixed-width"
  1002. (with-temp-buffer
  1003. (insert content)
  1004. (unless (memq 'timestamps exclude-list)
  1005. (org-export-latex-time-stamps))
  1006. (unless (memq 'quotation-marks exclude-list)
  1007. (org-export-latex-quotation-marks))
  1008. (unless (memq 'emphasis exclude-list)
  1009. (when (plist-get org-export-latex-options-plist :emphasize)
  1010. (org-export-latex-fontify)))
  1011. (unless (memq 'sub-superscript exclude-list)
  1012. (org-export-latex-special-chars
  1013. (plist-get org-export-latex-options-plist :sub-superscript)))
  1014. (unless (memq 'links exclude-list)
  1015. (org-export-latex-links))
  1016. (unless (memq 'keywords exclude-list)
  1017. (org-export-latex-keywords))
  1018. (unless (memq 'lists exclude-list)
  1019. (org-export-latex-lists))
  1020. (unless (memq 'tables exclude-list)
  1021. (org-export-latex-tables
  1022. (plist-get org-export-latex-options-plist :tables)))
  1023. (unless (memq 'fixed-width exclude-list)
  1024. (org-export-latex-fixed-width
  1025. (plist-get org-export-latex-options-plist :fixed-width)))
  1026. ;; return string
  1027. (buffer-substring (point-min) (point-max))))
  1028. (defun org-export-latex-protect-string (s)
  1029. "Add the org-protected property to string S."
  1030. (add-text-properties 0 (length s) '(org-protected t) s) s)
  1031. (defun org-export-latex-protect-char-in-string (char-list string)
  1032. "Add org-protected text-property to char from CHAR-LIST in STRING."
  1033. (with-temp-buffer
  1034. (save-match-data
  1035. (insert string)
  1036. (goto-char (point-min))
  1037. (while (re-search-forward (regexp-opt char-list) nil t)
  1038. (add-text-properties (match-beginning 0)
  1039. (match-end 0) '(org-protected t)))
  1040. (buffer-string))))
  1041. (defun org-export-latex-keywords-maybe (&optional remove-list)
  1042. "Maybe remove keywords depending on rules in REMOVE-LIST."
  1043. (goto-char (point-min))
  1044. (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
  1045. (case-fold-search nil)
  1046. (todo-markup org-export-latex-todo-keyword-markup)
  1047. fmt)
  1048. ;; convert TODO keywords
  1049. (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
  1050. (if (plist-get remove-list :todo)
  1051. (replace-match "")
  1052. (setq fmt (cond
  1053. ((stringp todo-markup) todo-markup)
  1054. ((and (consp todo-markup) (stringp (car todo-markup)))
  1055. (if (member (match-string 1) org-export-latex-done-keywords)
  1056. (cdr todo-markup) (car todo-markup)))
  1057. (t (cdr (or (assoc (match-string 1) todo-markup)
  1058. (car todo-markup))))))
  1059. (replace-match (format fmt (match-string 1)) t t)))
  1060. ;; convert priority string
  1061. (when (re-search-forward "\\[\\\\#.\\]" nil t)
  1062. (if (plist-get remove-list :priority)
  1063. (replace-match "")
  1064. (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
  1065. ;; convert tags
  1066. (when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
  1067. (if (or (not org-export-with-tags)
  1068. (plist-get remove-list :tags))
  1069. (replace-match "")
  1070. (replace-match
  1071. (org-export-latex-protect-string
  1072. (format "\\textbf{%s}"
  1073. (save-match-data
  1074. (replace-regexp-in-string
  1075. "_" "\\\\_" (match-string 0)))))
  1076. t t)))))
  1077. (defun org-export-latex-fontify-headline (string)
  1078. "Fontify special words in STRING."
  1079. (with-temp-buffer
  1080. ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
  1081. ;; the beginning of the buffer - inserting "\n" is safe here though.
  1082. (insert "\n" string)
  1083. (goto-char (point-min))
  1084. (let ((re (concat "\\\\[a-zA-Z]+\\(?:"
  1085. "\\[.*\\]"
  1086. "\\)?"
  1087. (org-create-multibrace-regexp "{" "}" 3))))
  1088. (while (re-search-forward re nil t)
  1089. (unless (save-excursion (goto-char (match-beginning 0))
  1090. (equal (char-after (point-at-bol)) ?#))
  1091. (add-text-properties (match-beginning 0) (match-end 0)
  1092. '(org-protected t)))))
  1093. (when (plist-get org-export-latex-options-plist :emphasize)
  1094. (org-export-latex-fontify))
  1095. (org-export-latex-keywords-maybe)
  1096. (org-export-latex-special-chars
  1097. (plist-get org-export-latex-options-plist :sub-superscript))
  1098. (org-export-latex-links)
  1099. (org-trim (buffer-string))))
  1100. (defun org-export-latex-time-stamps ()
  1101. "Format time stamps."
  1102. (goto-char (point-min))
  1103. (let ((org-display-custom-times org-export-latex-display-custom-times))
  1104. (while (re-search-forward org-ts-regexp-both nil t)
  1105. (org-if-unprotected-at (1- (point))
  1106. (replace-match
  1107. (org-export-latex-protect-string
  1108. (format org-export-latex-timestamp-markup
  1109. (substring (org-translate-time (match-string 0)) 1 -1)))
  1110. t t)))))
  1111. (defun org-export-latex-quotation-marks ()
  1112. "Export quotation marks depending on language conventions."
  1113. (let* ((lang (plist-get org-export-latex-options-plist :language))
  1114. (quote-rpl (if (equal lang "fr")
  1115. '(("\\(\\s-\\)\"" "«~")
  1116. ("\\(\\S-\\)\"" "~»")
  1117. ("\\(\\s-\\)'" "`"))
  1118. '(("\\(\\s-\\|[[(]\\)\"" "``")
  1119. ("\\(\\S-\\)\"" "''")
  1120. ("\\(\\s-\\|(\\)'" "`")))))
  1121. (mapc (lambda(l) (goto-char (point-min))
  1122. (while (re-search-forward (car l) nil t)
  1123. (let ((rpl (concat (match-string 1)
  1124. (org-export-latex-protect-string
  1125. (copy-sequence (cadr l))))))
  1126. (org-if-unprotected-1
  1127. (replace-match rpl t t))))) quote-rpl)))
  1128. (defun org-export-latex-special-chars (sub-superscript)
  1129. "Export special characters to LaTeX.
  1130. If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
  1131. See the `org-export-latex.el' code for a complete conversion table."
  1132. (goto-char (point-min))
  1133. (mapc (lambda(c)
  1134. (goto-char (point-min))
  1135. (while (re-search-forward c nil t)
  1136. ;; Put the point where to check for org-protected
  1137. (unless (get-text-property (match-beginning 2) 'org-protected)
  1138. (cond ((member (match-string 2) '("\\$" "$"))
  1139. (if (equal (match-string 2) "\\$")
  1140. nil
  1141. (replace-match "\\$" t t)))
  1142. ((member (match-string 2) '("&" "%" "#"))
  1143. (if (equal (match-string 1) "\\")
  1144. (replace-match (match-string 2) t t)
  1145. (replace-match (concat (match-string 1) "\\"
  1146. (match-string 2)) t t)))
  1147. ((equal (match-string 2) "...")
  1148. (replace-match
  1149. (concat (match-string 1)
  1150. (org-export-latex-protect-string "\\ldots{}")) t t))
  1151. ((equal (match-string 2) "~")
  1152. (cond ((equal (match-string 1) "\\") nil)
  1153. ((eq 'org-link (get-text-property 0 'face (match-string 2)))
  1154. (replace-match (concat (match-string 1) "\\~") t t))
  1155. (t (replace-match
  1156. (org-export-latex-protect-string
  1157. (concat (match-string 1) "\\~{}")) t t))))
  1158. ((member (match-string 2) '("{" "}"))
  1159. (unless (save-match-data (org-inside-latex-math-p))
  1160. (if (equal (match-string 1) "\\")
  1161. (replace-match (match-string 2) t t)
  1162. (replace-match (concat (match-string 1) "\\"
  1163. (match-string 2)) t t)))))
  1164. (unless (save-match-data (org-inside-latex-math-p))
  1165. (cond ((equal (match-string 2) "\\")
  1166. (replace-match (or (save-match-data
  1167. (org-export-latex-treat-backslash-char
  1168. (match-string 1)
  1169. (or (match-string 3) "")))
  1170. "") t t))
  1171. ((member (match-string 2) '("_" "^"))
  1172. (replace-match (or (save-match-data
  1173. (org-export-latex-treat-sub-super-char
  1174. sub-superscript
  1175. (match-string 2)
  1176. (match-string 1)
  1177. (match-string 3))) "") t t)
  1178. (backward-char 1)))))))
  1179. '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
  1180. "\\(\\(\\\\?\\$\\)\\)"
  1181. "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
  1182. "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
  1183. "\\(.\\|^\\)\\(&\\)"
  1184. "\\(.\\|^\\)\\(#\\)"
  1185. "\\(.\\|^\\)\\(%\\)"
  1186. "\\(.\\|^\\)\\({\\)"
  1187. "\\(.\\|^\\)\\(}\\)"
  1188. "\\(.\\|^\\)\\(~\\)"
  1189. "\\(.\\|^\\)\\(\\.\\.\\.\\)"
  1190. ;; (?\< . "\\textless{}")
  1191. ;; (?\> . "\\textgreater{}")
  1192. )))
  1193. (defun org-inside-latex-math-p ()
  1194. (get-text-property (point) 'org-latex-math))
  1195. (defun org-export-latex-treat-sub-super-char
  1196. (subsup char string-before string-after)
  1197. "Convert the \"_\" and \"^\" characters to LaTeX.
  1198. SUBSUP corresponds to the ^: option in the #+OPTIONS line.
  1199. Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
  1200. (cond ((equal string-before "\\")
  1201. (concat string-before char string-after))
  1202. ((and (string-match "\\S-+" string-after))
  1203. ;; this is part of a math formula
  1204. (cond ((eq 'org-link (get-text-property 0 'face char))
  1205. (concat string-before "\\" char string-after))
  1206. ((save-match-data (org-inside-latex-math-p))
  1207. (if subsup
  1208. (cond ((eq 1 (length string-after))
  1209. (concat string-before char string-after))
  1210. ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
  1211. (format "%s%s{%s}" string-before char
  1212. (match-string 1 string-after))))))
  1213. ((and (> (length string-after) 1)
  1214. (or (eq subsup t)
  1215. (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
  1216. (string-match "[({]?\\([^)}]+\\)[)}]?" string-after))
  1217. (org-export-latex-protect-string
  1218. (format "%s$%s{%s}$" string-before char
  1219. (if (and (> (match-end 1) (1+ (match-beginning 1)))
  1220. (not (equal (substring string-after 0 2) "{\\")))
  1221. (concat "\\mathrm{" (match-string 1 string-after) "}")
  1222. (match-string 1 string-after)))))
  1223. ((eq subsup t) (concat string-before "$" char string-after "$"))
  1224. (t (org-export-latex-protect-string
  1225. (concat string-before "\\" char "{}" string-after)))))
  1226. (t (org-export-latex-protect-string
  1227. (concat string-before "\\" char "{}" string-after)))))
  1228. (defun org-export-latex-treat-backslash-char (string-before string-after)
  1229. "Convert the \"$\" special character to LaTeX.
  1230. The conversion is made depending of STRING-BEFORE and STRING-AFTER."
  1231. (cond ((member (list string-after) org-html-entities)
  1232. ;; backslash is part of a special entity (like "\alpha")
  1233. (concat string-before "$\\"
  1234. (or (cdar (member (list string-after) org-html-entities))
  1235. string-after) "$"))
  1236. ((and (not (string-match "^[ \n\t]" string-after))
  1237. (not (string-match "[ \t]\\'\\|^" string-before)))
  1238. ;; backslash is inside a word
  1239. (org-export-latex-protect-string
  1240. (concat string-before "\\textbackslash{}" string-after)))
  1241. ((not (or (equal string-after "")
  1242. (string-match "^[ \t\n]" string-after)))
  1243. ;; backslash might escape a character (like \#) or a user TeX
  1244. ;; macro (like \setcounter)
  1245. (org-export-latex-protect-string
  1246. (concat string-before "\\" string-after)))
  1247. ((and (string-match "^[ \t\n]" string-after)
  1248. (string-match "[ \t\n]\\'" string-before))
  1249. ;; backslash is alone, convert it to $\backslash$
  1250. (org-export-latex-protect-string
  1251. (concat string-before "\\textbackslash{}" string-after)))
  1252. (t (org-export-latex-protect-string
  1253. (concat string-before "\\textbackslash{}" string-after)))))
  1254. (defun org-export-latex-keywords ()
  1255. "Convert special keywords to LaTeX."
  1256. (goto-char (point-min))
  1257. (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
  1258. (replace-match (format org-export-latex-timestamp-keyword-markup
  1259. (match-string 0)) t t)
  1260. (save-excursion
  1261. (beginning-of-line 1)
  1262. (unless (looking-at ".*\\\\newline[ \t]*$")
  1263. (end-of-line 1)
  1264. (insert "\\newline")))))
  1265. (defun org-export-latex-fixed-width (opt)
  1266. "When OPT is non-nil convert fixed-width sections to LaTeX."
  1267. (goto-char (point-min))
  1268. (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
  1269. (if opt
  1270. (progn (goto-char (match-beginning 0))
  1271. (insert "\\begin{verbatim}\n")
  1272. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1273. (replace-match (concat (match-string 1)
  1274. (match-string 2)) t t)
  1275. (forward-line))
  1276. (insert "\\end{verbatim}\n\n"))
  1277. (progn (goto-char (match-beginning 0))
  1278. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1279. (replace-match (concat "%" (match-string 1)
  1280. (match-string 2)) t t)
  1281. (forward-line))))))
  1282. (defvar org-table-last-alignment) ; defined in org-table.el
  1283. (defvar org-table-last-column-widths) ; defined in org-table.el
  1284. (declare-function orgtbl-to-latex "org-table" (table params) t)
  1285. (defun org-export-latex-tables (insert)
  1286. "Convert tables to LaTeX and INSERT it."
  1287. (goto-char (point-min))
  1288. (while (re-search-forward "^\\([ \t]*\\)|" nil t)
  1289. (org-if-unprotected-at (1- (point))
  1290. (org-table-align)
  1291. (let* ((beg (org-table-begin))
  1292. (end (org-table-end))
  1293. (raw-table (buffer-substring beg end))
  1294. (org-table-last-alignment (copy-sequence org-table-last-alignment))
  1295. (org-table-last-column-widths (copy-sequence
  1296. org-table-last-column-widths))
  1297. fnum fields line lines olines gr colgropen line-fmt align
  1298. caption label attr floatp longtblp)
  1299. (if org-export-latex-tables-verbatim
  1300. (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
  1301. "\\end{verbatim}\n")))
  1302. (apply 'delete-region (list beg end))
  1303. (insert (org-export-latex-protect-string tbl)))
  1304. (progn
  1305. (setq caption (org-find-text-property-in-string
  1306. 'org-caption raw-table)
  1307. attr (org-find-text-property-in-string
  1308. 'org-attributes raw-table)
  1309. label (org-find-text-property-in-string
  1310. 'org-label raw-table)
  1311. longtblp (and attr (stringp attr)
  1312. (string-match "\\<longtable\\>" attr))
  1313. align (and attr (stringp attr)
  1314. (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
  1315. (match-string 1 attr))
  1316. floatp (or caption label))
  1317. (setq lines (org-split-string raw-table "\n"))
  1318. (apply 'delete-region (list beg end))
  1319. (when org-export-table-remove-special-lines
  1320. (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
  1321. (when org-table-clean-did-remove-column
  1322. (pop org-table-last-alignment)
  1323. (pop org-table-last-column-widths))
  1324. ;; make a formatting string to reflect alignment
  1325. (setq olines lines)
  1326. (while (and (not line-fmt) (setq line (pop olines)))
  1327. (unless (string-match "^[ \t]*|-" line)
  1328. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1329. (setq fnum (make-vector (length fields) 0))
  1330. (setq line-fmt
  1331. (mapconcat
  1332. (lambda (x)
  1333. (setq gr (pop org-table-colgroup-info))
  1334. (format "%s%%s%s"
  1335. (cond ((eq gr :start)
  1336. (prog1 (if colgropen "|" "|")
  1337. (setq colgropen t)))
  1338. ((eq gr :startend)
  1339. (prog1 (if colgropen "|" "|")
  1340. (setq colgropen nil)))
  1341. (t ""))
  1342. (if (memq gr '(:end :startend))
  1343. (progn (setq colgropen nil) "|")
  1344. "")))
  1345. fnum ""))))
  1346. ;; fix double || in line-fmt
  1347. (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
  1348. ;; maybe remove the first and last "|"
  1349. (when (and (not org-export-latex-tables-column-borders)
  1350. (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
  1351. (setq line-fmt (match-string 2 line-fmt)))
  1352. ;; format alignment
  1353. (unless align
  1354. (setq align (apply 'format
  1355. (cons line-fmt
  1356. (mapcar (lambda (x) (if x "r" "l"))
  1357. org-table-last-alignment)))))
  1358. ;; prepare the table to send to orgtbl-to-latex
  1359. (setq lines
  1360. (mapcar
  1361. (lambda(elem)
  1362. (or (and (string-match "[ \t]*|-+" elem) 'hline)
  1363. (org-split-string (org-trim elem) "|")))
  1364. lines))
  1365. (when insert
  1366. (insert (org-export-latex-protect-string
  1367. (concat
  1368. (if longtblp
  1369. (concat "\\begin{longtable}{" align "}\n")
  1370. (if floatp "\\begin{table}[htb]\n"))
  1371. (if (or floatp longtblp)
  1372. (format
  1373. "\\caption{%s%s}"
  1374. (if label (concat "\\\label{" label "}") "")
  1375. (or caption "")))
  1376. (if longtblp "\\\\\n" "\n")
  1377. (if (and org-export-latex-tables-centered (not longtblp))
  1378. "\\begin{center}\n")
  1379. (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
  1380. (orgtbl-to-latex
  1381. lines
  1382. `(:tstart nil :tend nil
  1383. :hlend ,(if longtblp
  1384. (format "\\\\
  1385. \\hline
  1386. \\endhead
  1387. \\hline\\multicolumn{%d}{r}{Continued on next page}\\
  1388. \\endfoot
  1389. \\endlastfoot" (length org-table-last-alignment))
  1390. nil)))
  1391. (if (not longtblp) (concat "\n\\end{tabular}"))
  1392. (if longtblp "\n" (if org-export-latex-tables-centered
  1393. "\n\\end{center}\n" "\n"))
  1394. (if longtblp
  1395. "\\end{longtable}"
  1396. (if floatp "\\end{table}"))))
  1397. "\n\n"))))))))
  1398. (defun org-export-latex-fontify ()
  1399. "Convert fontification to LaTeX."
  1400. (goto-char (point-min))
  1401. (while (re-search-forward org-emph-re nil t)
  1402. ;; The match goes one char after the *string*, except at the end of a line
  1403. (let ((emph (assoc (match-string 3)
  1404. org-export-latex-emphasis-alist))
  1405. (beg (match-beginning 0))
  1406. (end (match-end 0))
  1407. rpl s)
  1408. (unless emph
  1409. (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
  1410. (match-string 3)))
  1411. (unless (or (and (get-text-property (- (point) 2) 'org-protected)
  1412. (not (get-text-property
  1413. (- (point) 2) 'org-verbatim-emph)))
  1414. (save-excursion
  1415. (goto-char (match-beginning 1))
  1416. (save-match-data
  1417. (and (org-at-table-p)
  1418. (string-match
  1419. "[|\n]" (buffer-substring beg end))))))
  1420. (setq s (match-string 4))
  1421. (setq rpl (concat (match-string 1)
  1422. (org-export-latex-emph-format (cadr emph)
  1423. (match-string 4))
  1424. (match-string 5)))
  1425. (if (caddr emph)
  1426. (setq rpl (org-export-latex-protect-string rpl))
  1427. (save-match-data
  1428. (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
  1429. (progn
  1430. (add-text-properties (match-beginning 1) (match-end 1)
  1431. '(org-protected t) rpl)
  1432. (add-text-properties (match-beginning 3) (match-end 3)
  1433. '(org-protected t) rpl)))))
  1434. (replace-match rpl t t)))
  1435. (backward-char)))
  1436. (defvar org-export-latex-use-verb nil)
  1437. (defun org-export-latex-emph-format (format string)
  1438. "Format an emphasis string and handle the \\verb special case."
  1439. (when (equal format "\\verb")
  1440. (save-match-data
  1441. (if org-export-latex-use-verb
  1442. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1443. (catch 'exit
  1444. (loop for i from 0 to (1- (length ll)) do
  1445. (if (not (string-match (regexp-quote (substring ll i (1+ i)))
  1446. string))
  1447. (progn
  1448. (setq format (concat "\\verb" (substring ll i (1+ i))
  1449. "%s" (substring ll i (1+ i))))
  1450. (throw 'exit nil))))))
  1451. (let ((start 0)
  1452. (trans '(("\\" . "\\textbackslash{}")
  1453. ("~" . "\\textasciitilde{}")
  1454. ("^" . "\\textasciicircum{}")))
  1455. (rtn "") char)
  1456. (while (string-match "[\\{}$%&_#~^]" string)
  1457. (setq char (match-string 0 string))
  1458. (if (> (match-beginning 0) 0)
  1459. (setq rtn (concat rtn (substring string
  1460. 0 (match-beginning 0)))))
  1461. (setq string (substring string (1+ (match-beginning 0))))
  1462. (setq char (or (cdr (assoc char trans)) (concat "\\" char))
  1463. rtn (concat rtn char)))
  1464. (setq string (concat rtn string) format "\\texttt{%s}")))))
  1465. (format format string))
  1466. (defun org-export-latex-links ()
  1467. ;; Make sure to use the LaTeX hyperref and graphicx package
  1468. ;; or send some warnings.
  1469. "Convert links to LaTeX."
  1470. (goto-char (point-min))
  1471. (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
  1472. (org-if-unprotected-1
  1473. (goto-char (match-beginning 0))
  1474. (let* ((re-radio org-export-latex-all-targets-re)
  1475. (remove (list (match-beginning 0) (match-end 0)))
  1476. (raw-path (org-extract-attributes (match-string 3)))
  1477. (full-raw-path (concat (match-string 1) raw-path))
  1478. (desc (match-string 5))
  1479. (type (or (match-string 2)
  1480. (if (or (file-name-absolute-p raw-path)
  1481. (string-match "^\\.\\.?/" raw-path))
  1482. "file")))
  1483. (coderefp (equal type "coderef"))
  1484. (caption (org-find-text-property-in-string 'org-caption raw-path))
  1485. (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
  1486. (plist-get org-export-latex-options-plist :latex-image-options)))
  1487. (label (org-find-text-property-in-string 'org-label raw-path))
  1488. imgp radiop
  1489. ;; define the path of the link
  1490. (path (cond
  1491. ((member type '("coderef"))
  1492. raw-path)
  1493. ((member type '("http" "https" "ftp"))
  1494. (concat type ":" raw-path))
  1495. ((and re-radio (string-match re-radio raw-path))
  1496. (setq radiop t))
  1497. ((equal type "mailto")
  1498. (concat type ":" raw-path))
  1499. ((equal type "file")
  1500. (if (and (org-file-image-p
  1501. (expand-file-name
  1502. raw-path)
  1503. org-export-latex-inline-image-extensions)
  1504. (or (get-text-property 0 'org-no-description
  1505. raw-path)
  1506. (equal desc full-raw-path)))
  1507. (setq imgp t)
  1508. (progn (when (string-match "\\(.+\\)::.+" raw-path)
  1509. (setq raw-path (match-string 1 raw-path)))
  1510. (if (file-exists-p raw-path)
  1511. (concat type "://" (expand-file-name raw-path))
  1512. (concat type "://" (org-export-directory
  1513. :LaTeX org-export-latex-options-plist)
  1514. raw-path))))))))
  1515. ;; process with link inserting
  1516. (apply 'delete-region remove)
  1517. (cond ((and imgp
  1518. (plist-get org-export-latex-options-plist :inline-images))
  1519. ;; OK, we need to inline an image
  1520. (insert
  1521. (org-export-latex-format-image raw-path caption label attr)))
  1522. (coderefp
  1523. (insert (format
  1524. (org-export-get-coderef-format path desc)
  1525. (cdr (assoc path org-export-code-refs)))))
  1526. (radiop (insert (format "\\hyperref[%s]{%s}"
  1527. (org-solidify-link-text raw-path) desc)))
  1528. ((not type)
  1529. (insert (format "\\hyperref[%s]{%s}"
  1530. (org-remove-initial-hash
  1531. (org-solidify-link-text raw-path))
  1532. desc)))
  1533. (path
  1534. (when (org-at-table-p)
  1535. ;; There is a strange problem when we have a link in a table,
  1536. ;; ampersands then cause a problem. I think this must be
  1537. ;; a LaTeX issue, but we here implement a work-around anyway.
  1538. (setq path (org-export-latex-protect-amp path)
  1539. desc (org-export-latex-protect-amp desc)))
  1540. (insert (format "\\href{%s}{%s}" path desc)))
  1541. (t (insert "\\texttt{" desc "}")))))))
  1542. (defun org-export-latex-format-image (path caption label attr)
  1543. "Format the image element, depending on user settings."
  1544. (let (ind floatp wrapp placement figenv)
  1545. (setq floatp (or caption label))
  1546. (setq ind (org-get-text-property-any 0 'original-indentation path))
  1547. (when (and attr (stringp attr))
  1548. (if (string-match "[ \t]*\\<wrap\\>" attr)
  1549. (setq wrapp t floatp nil attr (replace-match "" t t attr)))
  1550. (if (string-match "[ \t]*\\<float\\>" attr)
  1551. (setq wrapp nil floatp t attr (replace-match "" t t attr))))
  1552. (setq placement
  1553. (cond
  1554. (wrapp "{l}{0.5\\textwidth}")
  1555. (floatp "[htb]")
  1556. (t "")))
  1557. (when (and attr (stringp attr)
  1558. (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
  1559. (setq placement (match-string 1 attr)
  1560. attr (replace-match "" t t attr)))
  1561. (setq attr (and attr (org-trim attr)))
  1562. (when (or (not attr) (= (length attr) 0))
  1563. (setq attr (cond (floatp "width=0.7\\textwidth")
  1564. (wrapp "width=0.48\\textwidth")
  1565. (t attr))))
  1566. (setq figenv
  1567. (cond
  1568. (wrapp "\\begin{wrapfigure}%placement
  1569. \\centering
  1570. \\includegraphics[%attr]{%path}
  1571. \\caption{%labelcmd%caption}
  1572. \\end{wrapfigure}")
  1573. (floatp "\\begin{figure}%placement
  1574. \\centering
  1575. \\includegraphics[%attr]{%path}
  1576. \\caption{%labelcmd%caption}
  1577. \\end{figure}")
  1578. (t "\\includegraphics[%attr]{%path}")))
  1579. (setq figenv (mapconcat 'identity (split-string figenv "\n")
  1580. (save-excursion (beginning-of-line 1)
  1581. (looking-at "[ \t]*")
  1582. (concat "\n" (match-string 0)))))
  1583. (if (and (not label) (not caption)
  1584. (string-match "^\\\\caption{.*\n" figenv))
  1585. (setq figenv (replace-match "" t t figenv)))
  1586. (org-add-props
  1587. (org-fill-template
  1588. figenv
  1589. (list (cons "path"
  1590. (if (file-name-absolute-p path)
  1591. (expand-file-name path)
  1592. path))
  1593. (cons "attr" attr)
  1594. (cons "labelcmd" (if label (format "\\label{%s}"
  1595. label)""))
  1596. (cons "caption" (or caption ""))
  1597. (cons "placement" (or placement ""))))
  1598. nil 'original-indentation ind)))
  1599. (defun org-export-latex-protect-amp (s)
  1600. (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
  1601. (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
  1602. t t s)))
  1603. s)
  1604. (defun org-remove-initial-hash (s)
  1605. (if (string-match "\\`#" s)
  1606. (substring s 1)
  1607. s))
  1608. (defvar org-latex-entities) ; defined below
  1609. (defvar org-latex-entities-regexp) ; defined below
  1610. (defvar org-latex-entities-exceptions) ; defined below
  1611. (defun org-export-latex-preprocess (parameters)
  1612. "Clean stuff in the LaTeX export."
  1613. ;; Preserve line breaks
  1614. (goto-char (point-min))
  1615. (while (re-search-forward "\\\\\\\\" nil t)
  1616. (add-text-properties (match-beginning 0) (match-end 0)
  1617. '(org-protected t)))
  1618. ;; Preserve latex environments
  1619. (goto-char (point-min))
  1620. (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
  1621. (let* ((start (progn (beginning-of-line) (point)))
  1622. (end (and (re-search-forward
  1623. (concat "^[ \t]*\\\\end{"
  1624. (regexp-quote (match-string 1))
  1625. "}") nil t)
  1626. (point-at-eol))))
  1627. (if end
  1628. (add-text-properties start end '(org-protected t))
  1629. (goto-char (point-at-eol)))))
  1630. ;; Preserve math snippets
  1631. (let* ((matchers (plist-get org-format-latex-options :matchers))
  1632. (re-list org-latex-regexps)
  1633. beg end re e m n block off)
  1634. ;; Check the different regular expressions
  1635. (while (setq e (pop re-list))
  1636. (setq m (car e) re (nth 1 e) n (nth 2 e)
  1637. block (if (nth 3 e) "\n\n" ""))
  1638. (setq off (if (member m '("$" "$1")) 1 0))
  1639. (when (and (member m matchers) (not (equal m "begin")))
  1640. (goto-char (point-min))
  1641. (while (re-search-forward re nil t)
  1642. (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
  1643. (add-text-properties beg end '(org-protected t org-latex-math t))))))
  1644. ;; Convert LaTeX to \LaTeX{}
  1645. (goto-char (point-min))
  1646. (let ((case-fold-search nil))
  1647. (while (re-search-forward "\\([^+_]\\)LaTeX" nil t)
  1648. (org-if-unprotected
  1649. (replace-match (org-export-latex-protect-string
  1650. (concat (match-string 1) "\\LaTeX{}")) t t))))
  1651. ;; Convert blockquotes
  1652. (goto-char (point-min))
  1653. (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
  1654. (org-replace-match-keep-properties "\\begin{quote}" t t))
  1655. (goto-char (point-min))
  1656. (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
  1657. (org-replace-match-keep-properties "\\end{quote}" t t))
  1658. ;; Convert verse
  1659. (goto-char (point-min))
  1660. (while (search-forward "ORG-VERSE-START" nil t)
  1661. (org-replace-match-keep-properties "\\begin{verse}" t t)
  1662. (beginning-of-line 2)
  1663. (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
  1664. (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
  1665. (goto-char (match-end 1))
  1666. (org-replace-match-keep-properties
  1667. (org-export-latex-protect-string
  1668. (concat "\\hspace*{1cm}" (match-string 2))) t t)
  1669. (beginning-of-line 1))
  1670. (if (looking-at "[ \t]*$")
  1671. (insert (org-export-latex-protect-string "\\vspace*{1em}"))
  1672. (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
  1673. (end-of-line 1)
  1674. (insert "\\\\")))
  1675. (beginning-of-line 2))
  1676. (and (looking-at "[ \t]*ORG-VERSE-END.*")
  1677. (org-replace-match-keep-properties "\\end{verse}" t t)))
  1678. ;; Convert center
  1679. (goto-char (point-min))
  1680. (while (search-forward "ORG-CENTER-START" nil t)
  1681. (org-replace-match-keep-properties "\\begin{center}" t t))
  1682. (goto-char (point-min))
  1683. (while (search-forward "ORG-CENTER-END" nil t)
  1684. (org-replace-match-keep-properties "\\end{center}" t t))
  1685. (run-hooks 'org-export-latex-after-blockquotes-hook)
  1686. ;; Convert horizontal rules
  1687. (goto-char (point-min))
  1688. (while (re-search-forward "^----+.$" nil t)
  1689. (org-if-unprotected
  1690. (replace-match (org-export-latex-protect-string "\\hrule") t t)))
  1691. ;; Protect LaTeX commands like \command[...]{...} or \command{...}
  1692. (let ((re (concat "\\\\[a-zA-Z]+\\(?:"
  1693. "\\[.*\\]"
  1694. "\\)?"
  1695. "\\(" (org-create-multibrace-regexp "{" "}" 3)
  1696. "\\)\\{1,3\\}")))
  1697. (while (re-search-forward re nil t)
  1698. (unless (save-excursion (goto-char (match-beginning 0))
  1699. (equal (char-after (point-at-bol)) ?#))
  1700. (add-text-properties (match-beginning 0) (match-end 0)
  1701. '(org-protected t)))))
  1702. ;; Protect LaTeX entities
  1703. (goto-char (point-min))
  1704. (let (a)
  1705. (while (re-search-forward org-latex-entities-regexp nil t)
  1706. (if (setq a (assoc (match-string 0) org-latex-entities-exceptions))
  1707. (replace-match (org-add-props (nth 1 a) nil 'org-protected t)
  1708. t t)
  1709. (add-text-properties (match-beginning 0) (match-end 0)
  1710. '(org-protected t)))))
  1711. ;; Replace radio links
  1712. (goto-char (point-min))
  1713. (while (re-search-forward
  1714. (concat "<<<?" org-export-latex-all-targets-re
  1715. ">>>?\\((INVISIBLE)\\)?") nil t)
  1716. (org-if-unprotected-at (+ (match-beginning 0) 2)
  1717. (replace-match
  1718. (org-export-latex-protect-string
  1719. (format "\\label{%s}%s" (save-match-data (org-solidify-link-text
  1720. (match-string 1)))
  1721. (if (match-string 2) "" (match-string 1)))) t t)))
  1722. ;; Delete @<...> constructs
  1723. ;; Thanks to Daniel Clemente for this regexp
  1724. (goto-char (point-min))
  1725. (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
  1726. (org-if-unprotected
  1727. (replace-match "")))
  1728. ;; When converting to LaTeX, replace footnotes
  1729. ;; FIXME: don't protect footnotes from conversion
  1730. (when (plist-get org-export-latex-options-plist :footnotes)
  1731. (goto-char (point-min))
  1732. (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
  1733. (org-if-unprotected
  1734. (when (and (save-match-data
  1735. (save-excursion (beginning-of-line)
  1736. (looking-at "[^:|#]")))
  1737. (not (org-in-verbatim-emphasis)))
  1738. (let ((foot-beg (match-beginning 0))
  1739. (foot-end (match-end 0))
  1740. (foot-prefix (match-string 0))
  1741. footnote footnote-rpl)
  1742. (save-excursion
  1743. (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
  1744. nil t))
  1745. (replace-match (org-export-latex-protect-string
  1746. (concat "$^{" (match-string 1) "}$")))
  1747. (replace-match "")
  1748. (let ((end (save-excursion
  1749. (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
  1750. (match-beginning 0) (point-max)))))
  1751. (setq footnote (concat (org-trim (buffer-substring (point) end))
  1752. " ")) ; prevent last } being part of a link
  1753. (delete-region (point) end))
  1754. (goto-char foot-beg)
  1755. (delete-region foot-beg foot-end)
  1756. (unless (null footnote)
  1757. (setq footnote-rpl (format "\\footnote{%s}" footnote))
  1758. (add-text-properties 0 10 '(org-protected t) footnote-rpl)
  1759. (add-text-properties (1- (length footnote-rpl))
  1760. (length footnote-rpl)
  1761. '(org-protected t) footnote-rpl)
  1762. (insert footnote-rpl)))
  1763. )))))
  1764. ;; Remove footnote section tag for LaTeX
  1765. (goto-char (point-min))
  1766. (while (re-search-forward
  1767. (concat "^" footnote-section-tag-regexp) nil t)
  1768. (org-if-unprotected
  1769. (replace-match "")))))
  1770. ;;; List handling:
  1771. (defun org-export-latex-lists ()
  1772. "Convert plain text lists in current buffer into LaTeX lists."
  1773. (goto-char (point-min))
  1774. (while (re-search-forward org-list-beginning-re nil t)
  1775. (org-if-unprotected
  1776. (beginning-of-line)
  1777. (insert (org-list-to-latex (org-list-parse-list t)
  1778. org-export-latex-list-parameters))
  1779. "\n")))
  1780. (defconst org-latex-entities
  1781. '("\\!"
  1782. "\\'"
  1783. "\\+"
  1784. "\\,"
  1785. "\\-"
  1786. "\\:"
  1787. "\\;"
  1788. "\\<"
  1789. "\\="
  1790. "\\>"
  1791. "\\Huge"
  1792. "\\LARGE"
  1793. "\\Large"
  1794. "\\Styles"
  1795. "\\\\"
  1796. "\\`"
  1797. "\\addcontentsline"
  1798. "\\address"
  1799. "\\addtocontents"
  1800. "\\addtocounter"
  1801. "\\addtolength"
  1802. "\\addvspace"
  1803. "\\alph"
  1804. "\\appendix"
  1805. "\\arabic"
  1806. "\\author"
  1807. "\\begin{array}"
  1808. "\\begin{center}"
  1809. "\\begin{description}"
  1810. "\\begin{enumerate}"
  1811. "\\begin{eqnarray}"
  1812. "\\begin{equation}"
  1813. "\\begin{figure}"
  1814. "\\begin{flushleft}"
  1815. "\\begin{flushright}"
  1816. "\\begin{itemize}"
  1817. "\\begin{list}"
  1818. "\\begin{minipage}"
  1819. "\\begin{picture}"
  1820. "\\begin{quotation}"
  1821. "\\begin{quote}"
  1822. "\\begin{tabbing}"
  1823. "\\begin{table}"
  1824. "\\begin{tabular}"
  1825. "\\begin{thebibliography}"
  1826. "\\begin{theorem}"
  1827. "\\begin{titlepage}"
  1828. "\\begin{verbatim}"
  1829. "\\begin{verse}"
  1830. "\\bf"
  1831. "\\bf"
  1832. "\\bibitem"
  1833. "\\bigskip"
  1834. "\\cdots"
  1835. "\\centering"
  1836. "\\circle"
  1837. "\\cite"
  1838. "\\cleardoublepage"
  1839. "\\clearpage"
  1840. "\\cline"
  1841. "\\closing"
  1842. "\\dashbox"
  1843. "\\date"
  1844. "\\ddots"
  1845. "\\dotfill"
  1846. "\\em"
  1847. "\\fbox"
  1848. "\\flushbottom"
  1849. "\\fnsymbol"
  1850. "\\footnote"
  1851. "\\footnotemark"
  1852. "\\footnotesize"
  1853. "\\footnotetext"
  1854. "\\frac"
  1855. "\\frame"
  1856. "\\framebox"
  1857. "\\hfill"
  1858. "\\hline"
  1859. "\\hrulespace"
  1860. "\\hspace"
  1861. "\\huge"
  1862. "\\hyphenation"
  1863. "\\include"
  1864. "\\includeonly"
  1865. "\\indent"
  1866. "\\input"
  1867. "\\it"
  1868. "\\kill"
  1869. "\\label"
  1870. "\\large"
  1871. "\\ldots"
  1872. "\\line"
  1873. "\\linebreak"
  1874. "\\linethickness"
  1875. "\\listoffigures"
  1876. "\\listoftables"
  1877. "\\location"
  1878. "\\makebox"
  1879. "\\maketitle"
  1880. "\\mark"
  1881. "\\mbox"
  1882. "\\medskip"
  1883. "\\multicolumn"
  1884. "\\multiput"
  1885. ("\\nbsp" "~")
  1886. "\\newcommand"
  1887. "\\newcounter"
  1888. "\\newenvironment"
  1889. "\\newfont"
  1890. "\\newlength"
  1891. "\\newline"
  1892. "\\newpage"
  1893. "\\newsavebox"
  1894. "\\newtheorem"
  1895. "\\nocite"
  1896. "\\nofiles"
  1897. "\\noindent"
  1898. "\\nolinebreak"
  1899. "\\nopagebreak"
  1900. "\\normalsize"
  1901. "\\onecolumn"
  1902. "\\opening"
  1903. "\\oval"
  1904. "\\overbrace"
  1905. "\\overline"
  1906. "\\pagebreak"
  1907. "\\pagenumbering"
  1908. "\\pageref"
  1909. "\\pagestyle"
  1910. "\\par"
  1911. "\\parbox"
  1912. "\\put"
  1913. "\\raggedbottom"
  1914. "\\raggedleft"
  1915. "\\raggedright"
  1916. "\\raisebox"
  1917. "\\ref"
  1918. "\\rm"
  1919. "\\roman"
  1920. "\\rule"
  1921. "\\savebox"
  1922. "\\sc"
  1923. "\\scriptsize"
  1924. "\\setcounter"
  1925. "\\setlength"
  1926. "\\settowidth"
  1927. "\\sf"
  1928. "\\shortstack"
  1929. "\\signature"
  1930. "\\sl"
  1931. "\\small"
  1932. "\\smallskip"
  1933. "\\sqrt"
  1934. "\\tableofcontents"
  1935. "\\telephone"
  1936. "\\thanks"
  1937. "\\thispagestyle"
  1938. "\\tiny"
  1939. "\\title"
  1940. "\\tt"
  1941. "\\twocolumn"
  1942. "\\typein"
  1943. "\\typeout"
  1944. "\\underbrace"
  1945. "\\underline"
  1946. "\\usebox"
  1947. "\\usecounter"
  1948. "\\value"
  1949. "\\vdots"
  1950. "\\vector"
  1951. "\\verb"
  1952. "\\vfill"
  1953. "\\vline"
  1954. "\\vspace")
  1955. "A list of LaTeX commands to be protected when performing conversion.")
  1956. (defvar org-latex-entities-exceptions nil)
  1957. (defconst org-latex-entities-regexp
  1958. (let (names rest)
  1959. (dolist (x org-latex-entities)
  1960. (when (consp x)
  1961. (add-to-list 'org-latex-entities-exceptions x)
  1962. (setq x (car x)))
  1963. (if (string-match "[a-zA-Z]$" x)
  1964. (push x names)
  1965. (push x rest)))
  1966. (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
  1967. "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
  1968. (provide 'org-export-latex)
  1969. (provide 'org-latex)
  1970. ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
  1971. ;;; org-latex.el ends here