org-latex.el 78 KB

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