org-latex.el 79 KB

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