org-latex.el 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  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.25trans
  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. ;;; Variables:
  46. (defvar org-export-latex-class nil)
  47. (defvar org-export-latex-header nil)
  48. (defvar org-export-latex-append-header nil)
  49. (defvar org-export-latex-options-plist nil)
  50. (defvar org-export-latex-todo-keywords-1 nil)
  51. (defvar org-export-latex-display-custom-times nil)
  52. (defvar org-export-latex-all-targets-re nil)
  53. (defvar org-export-latex-add-level 0)
  54. (defvar org-export-latex-sectioning "")
  55. (defvar org-export-latex-sectioning-depth 0)
  56. (defvar org-export-latex-special-keyword-regexp
  57. (concat "\\<\\(" org-scheduled-string "\\|"
  58. org-deadline-string "\\|"
  59. org-closed-string"\\)")
  60. "Regexp matching special time planning keywords plus the time after it.")
  61. (defvar latexp) ; dynamically scoped from org.el
  62. (defvar re-quote) ; dynamically scoped from org.el
  63. (defvar commentsp) ; dynamically scoped from org.el
  64. ;;; User variables:
  65. (defgroup org-export-latex nil
  66. "Options for exporting Org-mode files to LaTeX."
  67. :tag "Org Export LaTeX"
  68. :group 'org-export)
  69. (defcustom org-export-latex-default-class "article"
  70. "The default LaTeX class."
  71. :group 'org-export-latex
  72. :type '(string :tag "LaTeX class"))
  73. (defcustom org-export-latex-classes
  74. '(("article"
  75. "\\documentclass[11pt]{article}
  76. \\usepackage[utf8]{inputenc}
  77. \\usepackage[T1]{fontenc}
  78. \\usepackage{graphicx}
  79. \\usepackage{longtable}
  80. \\usepackage{hyperref}"
  81. ("\\section{%s}" . "\\section*{%s}")
  82. ("\\subsection{%s}" . "\\subsection*{%s}")
  83. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  84. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  85. ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
  86. ("report"
  87. "\\documentclass[11pt]{report}
  88. \\usepackage[utf8]{inputenc}
  89. \\usepackage[T1]{fontenc}
  90. \\usepackage{graphicx}
  91. \\usepackage{longtable}
  92. \\usepackage{hyperref}"
  93. ("\\part{%s}" . "\\part*{%s}")
  94. ("\\chapter{%s}" . "\\chapter*{%s}")
  95. ("\\section{%s}" . "\\section*{%s}")
  96. ("\\subsection{%s}" . "\\subsection*{%s}")
  97. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
  98. ("book"
  99. "\\documentclass[11pt]{book}
  100. \\usepackage[utf8]{inputenc}
  101. \\usepackage[T1]{fontenc}
  102. \\usepackage{graphicx}
  103. \\usepackage{longtable}
  104. \\usepackage{hyperref}"
  105. ("\\part{%s}" . "\\part*{%s}")
  106. ("\\chapter{%s}" . "\\chapter*{%s}")
  107. ("\\section{%s}" . "\\section*{%s}")
  108. ("\\subsection{%s}" . "\\subsection*{%s}")
  109. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
  110. "Alist of LaTeX classes and associated header and structure.
  111. If #+LaTeX_CLASS is set in the buffer, use its value and the
  112. associated information. Here is the structure of each cell:
  113. \(class-name
  114. header-string
  115. (numbered-section . unnumbered-section\)
  116. ...\)
  117. A %s formatter is mandatory in each section string and will be
  118. replaced by the title of the section.
  119. Instead of a cons cell (numbered . unnumbered), you can also provide a list
  120. of 2-4 elements,
  121. (numbered-open numbered-close)
  122. or
  123. (numbered-open numbered-close unnumbered-open unnumbered-close)
  124. providing opening and closing strings for an environment that should
  125. represent the document section. The opening clause should have a %s
  126. to represent the section title."
  127. :group 'org-export-latex
  128. :type '(repeat
  129. (list (string :tag "LaTeX class")
  130. (string :tag "LaTeX header")
  131. (repeat :tag "Levels" :inline t
  132. (choice
  133. (cons :tag "Heading"
  134. (string :tag "numbered")
  135. (string :tag "unnumbered)"))
  136. (list :tag "Environment"
  137. (string :tag "Opening (numbered) ")
  138. (string :tag "Closing (numbered) ")
  139. (string :tag "Opening (unnumbered)")
  140. (string :tag "Closing (unnumbered)")))))))
  141. (defcustom org-export-latex-emphasis-alist
  142. '(("*" "\\textbf{%s}" nil)
  143. ("/" "\\emph{%s}" nil)
  144. ("_" "\\underline{%s}" nil)
  145. ("+" "\\texttt{%s}" nil)
  146. ("=" "\\verb" t)
  147. ("~" "\\verb" t))
  148. "Alist of LaTeX expressions to convert emphasis fontifiers.
  149. Each element of the list is a list of three elements.
  150. The first element is the character used as a marker for fontification.
  151. The second element is a formatting string to wrap fontified text with.
  152. If it is \"\\verb\", Org will automatically select a deimiter
  153. character that is not in the string.
  154. The third element decides whether to protect converted text from other
  155. conversions."
  156. :group 'org-export-latex
  157. :type 'alist)
  158. (defcustom org-export-latex-title-command "\\maketitle"
  159. "The command used to insert the title just after \\begin{document}.
  160. If this string contains the formatting specification \"%s\" then
  161. it will be used as a formatting string, passing the title as an
  162. argument."
  163. :group 'org-export-latex
  164. :type 'string)
  165. (defcustom org-export-latex-import-inbuffer-stuff nil
  166. "Non-nil means define TeX macros for Org's inbuffer definitions.
  167. For example \orgTITLE for #+TITLE."
  168. :group 'org-export-latex
  169. :type 'boolean)
  170. (defcustom org-export-latex-date-format
  171. "%d %B %Y"
  172. "Format string for \\date{...}."
  173. :group 'org-export-latex
  174. :type 'string)
  175. (defcustom org-export-latex-timestamp-markup "\\textit{%s}"
  176. "A printf format string to be applied to time stamps."
  177. :group 'org-export-latex
  178. :type 'string)
  179. (defcustom org-export-latex-tables-verbatim nil
  180. "When non-nil, tables are exported verbatim."
  181. :group 'org-export-latex
  182. :type 'boolean)
  183. (defcustom org-export-latex-tables-column-borders nil
  184. "When non-nil, grouping columns can cause outer vertical lines in tables.
  185. When nil, grouping causes only separation lines between groups."
  186. :group 'org-export-latex
  187. :type 'boolean)
  188. (defcustom org-export-latex-packages-alist nil
  189. "Alist of packages to be inserted in the header.
  190. Each cell is of the forma \( \"option\" . \"package\" \)."
  191. :group 'org-export-latex
  192. :type 'alist)
  193. (defcustom org-export-latex-low-levels 'itemize
  194. "How to convert sections below the current level of sectioning.
  195. This is specified by the `org-export-headline-levels' option or the
  196. value of \"H:\" in Org's #+OPTION line.
  197. This can be either nil (skip the sections), `description', `itemize',
  198. or `enumerate' (convert the sections as the corresponding list type), or
  199. a string to be used instead of \\section{%s}. In this latter case,
  200. the %s stands here for the inserted headline and is mandatory."
  201. :group 'org-export-latex
  202. :type '(choice (const :tag "Ignore" nil)
  203. (symbol :tag "Convert as descriptive list" description)
  204. (symbol :tag "Convert as itemized list" itemize)
  205. (symbol :tag "Convert as enumerated list" enumerate)
  206. (string :tag "Use a section string" :value "\\subparagraph{%s}")))
  207. (defcustom org-export-latex-list-parameters
  208. '(:cbon "\\texttt{[X]}" :cboff "\\texttt{[ ]}")
  209. "Parameters for the LaTeX list exporter.
  210. These parameters will be passed on to `org-list-to-latex', which in turn
  211. will pass them (combined with the LaTeX default list parameters) to
  212. `org-list-to-generic'."
  213. :group 'org-export-latex
  214. :type 'plist)
  215. (defcustom org-export-latex-remove-from-headlines
  216. '(:todo nil :priority nil :tags nil)
  217. "A plist of keywords to remove from headlines. OBSOLETE.
  218. Non-nil means remove this keyword type from the headline.
  219. Don't remove the keys, just change their values.
  220. Obsolete, this variable is no longer used. Use the separate
  221. variables `org-export-with-todo-keywords', `org-export-with-priority',
  222. and `org-export-with-tags' instead."
  223. :type 'plist
  224. :group 'org-export-latex)
  225. (defcustom org-export-latex-image-default-option "width=10em"
  226. "Default option for images."
  227. :group 'org-export-latex
  228. :type 'string)
  229. (defcustom org-export-latex-inline-image-extensions
  230. '("pdf" "jpeg" "jpg" "png")
  231. "Extensions of image files that can be inlined into LaTeX.
  232. Note that this depends on the way the LaTeX file is processed.
  233. The default setting (pdf and jpg) assumes that pdflatex is doing the
  234. processing. If you are using latex and dvips or something similar,
  235. only postscript files can be included."
  236. :group 'org-export-html
  237. :type '(repeat (string :tag "Extension")))
  238. (defcustom org-export-latex-coding-system nil
  239. "Coding system for the exported LaTex file."
  240. :group 'org-export-latex
  241. :type 'coding-system)
  242. (defgroup org-export-pdf nil
  243. "Options for exporting Org-mode files to PDF, via LaTeX."
  244. :tag "Org Export LaTeX"
  245. :group 'org-export-latex
  246. :group 'org-export)
  247. (defcustom org-export-pdf-remove-logfiles t
  248. "Non-nil means, remove the logfiles produced by PDF production.
  249. These are the .aux, .log, .out, and .toc files."
  250. :group 'org-export-latex
  251. :type 'boolean)
  252. ;;; Autoload functions:
  253. ;;;###autoload
  254. (defun org-export-as-latex-batch ()
  255. "Call `org-export-as-latex', may be used in batch processing.
  256. For example:
  257. emacs --batch
  258. --load=$HOME/lib/emacs/org.el
  259. --eval \"(setq org-export-headline-levels 2)\"
  260. --visit=MyFile --funcall org-export-as-latex-batch"
  261. (org-export-as-latex org-export-headline-levels 'hidden))
  262. ;;;###autoload
  263. (defun org-export-as-latex-to-buffer (arg)
  264. "Call `org-export-as-latex` with output to a temporary buffer.
  265. No file is created. The prefix ARG is passed through to `org-export-as-latex'."
  266. (interactive "P")
  267. (org-export-as-latex arg nil nil "*Org LaTeX Export*")
  268. (switch-to-buffer-other-window "*Org LaTeX Export*"))
  269. ;;;###autoload
  270. (defun org-replace-region-by-latex (beg end)
  271. "Replace the region from BEG to END with its LaTeX export.
  272. It assumes the region has `org-mode' syntax, and then convert it to
  273. LaTeX. This can be used in any buffer. For example, you could
  274. write an itemized list in `org-mode' syntax in an LaTeX buffer and
  275. then use this command to convert it."
  276. (interactive "r")
  277. (let (reg latex buf)
  278. (save-window-excursion
  279. (if (org-mode-p)
  280. (setq latex (org-export-region-as-latex
  281. beg end t 'string))
  282. (setq reg (buffer-substring beg end)
  283. buf (get-buffer-create "*Org tmp*"))
  284. (save-excursion
  285. (set-buffer buf)
  286. (erase-buffer)
  287. (insert reg)
  288. (org-mode)
  289. (setq latex (org-export-region-as-latex
  290. (point-min) (point-max) t 'string)))
  291. (kill-buffer buf)))
  292. (delete-region beg end)
  293. (insert latex)))
  294. ;;;###autoload
  295. (defun org-export-region-as-latex (beg end &optional body-only buffer)
  296. "Convert region from BEG to END in `org-mode' buffer to LaTeX.
  297. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  298. contents, and only produce the region of converted text, useful for
  299. cut-and-paste operations.
  300. If BUFFER is a buffer or a string, use/create that buffer as a target
  301. of the converted LaTeX. If BUFFER is the symbol `string', return the
  302. produced LaTeX as a string and leave not buffer behind. For example,
  303. a Lisp program could call this function in the following way:
  304. (setq latex (org-export-region-as-latex beg end t 'string))
  305. When called interactively, the output buffer is selected, and shown
  306. in a window. A non-interactive call will only retunr the buffer."
  307. (interactive "r\nP")
  308. (when (interactive-p)
  309. (setq buffer "*Org LaTeX Export*"))
  310. (let ((transient-mark-mode t) (zmacs-regions t)
  311. rtn)
  312. (goto-char end)
  313. (set-mark (point)) ;; to activate the region
  314. (goto-char beg)
  315. (setq rtn (org-export-as-latex
  316. nil nil nil
  317. buffer body-only))
  318. (if (fboundp 'deactivate-mark) (deactivate-mark))
  319. (if (and (interactive-p) (bufferp rtn))
  320. (switch-to-buffer-other-window rtn)
  321. rtn)))
  322. ;;;###autoload
  323. (defun org-export-as-latex (arg &optional hidden ext-plist
  324. to-buffer body-only pub-dir)
  325. "Export current buffer to a LaTeX file.
  326. If there is an active region, export only the region. The prefix
  327. ARG specifies how many levels of the outline should become
  328. headlines. The default is 3. Lower levels will be exported
  329. depending on `org-export-latex-low-levels'. The default is to
  330. convert them as description lists. When HIDDEN is non-nil, don't
  331. display the LaTeX buffer. EXT-PLIST is a property list with
  332. external parameters overriding org-mode's default settings, but
  333. still inferior to file-local settings. When TO-BUFFER is
  334. non-nil, create a buffer with that name and export to that
  335. buffer. If TO-BUFFER is the symbol `string', don't leave any
  336. buffer behind but just return the resulting LaTeX as a string.
  337. When BODY-ONLY is set, don't produce the file header and footer,
  338. simply return the content of \begin{document}...\end{document},
  339. without even the \begin{document} and \end{document} commands.
  340. when PUB-DIR is set, use this as the publishing directory."
  341. (interactive "P")
  342. ;; Make sure we have a file name when we need it.
  343. (when (and (not (or to-buffer body-only))
  344. (not buffer-file-name))
  345. (if (buffer-base-buffer)
  346. (org-set-local 'buffer-file-name
  347. (with-current-buffer (buffer-base-buffer)
  348. buffer-file-name))
  349. (error "Need a file name to be able to export")))
  350. (message "Exporting to LaTeX...")
  351. (org-unmodified
  352. (remove-text-properties (point-min) (point-max)
  353. '(:org-license-to-kill nil)))
  354. (org-update-radio-target-regexp)
  355. (org-export-latex-set-initial-vars ext-plist arg)
  356. (let* ((wcf (current-window-configuration))
  357. (opt-plist org-export-latex-options-plist)
  358. (region-p (org-region-active-p))
  359. (rbeg (and region-p (region-beginning)))
  360. (rend (and region-p (region-end)))
  361. (subtree-p
  362. (when region-p
  363. (save-excursion
  364. (goto-char rbeg)
  365. (and (org-at-heading-p)
  366. (>= (org-end-of-subtree t t) rend)))))
  367. (opt-plist (setq org-export-opt-plist
  368. (if subtree-p
  369. (org-export-add-subtree-options opt-plist rbeg)
  370. opt-plist)))
  371. ;; Make sure the variable contains the updated values.
  372. (org-export-latex-options-plist opt-plist)
  373. (title (or (and subtree-p (org-export-get-title-from-subtree))
  374. (plist-get opt-plist :title)
  375. (and (not
  376. (plist-get opt-plist :skip-before-1st-heading))
  377. (org-export-grab-title-from-buffer))
  378. (file-name-sans-extension
  379. (file-name-nondirectory buffer-file-name))))
  380. (filename (concat (file-name-as-directory
  381. (or pub-dir
  382. (org-export-directory :LaTeX ext-plist)))
  383. (file-name-sans-extension
  384. (or (and subtree-p
  385. (org-entry-get rbeg "EXPORT_FILE_NAME" t))
  386. (file-name-nondirectory ;sans-extension
  387. buffer-file-name)))
  388. ".tex"))
  389. (filename (if (equal (file-truename filename)
  390. (file-truename buffer-file-name))
  391. (concat filename ".tex")
  392. filename))
  393. (buffer (if to-buffer
  394. (cond
  395. ((eq to-buffer 'string) (get-buffer-create
  396. "*Org LaTeX Export*"))
  397. (t (get-buffer-create to-buffer)))
  398. (find-file-noselect filename)))
  399. (odd org-odd-levels-only)
  400. (header (org-export-latex-make-header title opt-plist))
  401. (skip (cond (subtree-p nil)
  402. (region-p nil)
  403. (t (plist-get opt-plist :skip-before-1st-heading))))
  404. (text (plist-get opt-plist :text))
  405. (first-lines (if skip "" (org-export-latex-first-lines
  406. opt-plist rbeg)))
  407. (coding-system (and (boundp 'buffer-file-coding-system)
  408. buffer-file-coding-system))
  409. (coding-system-for-write (or org-export-latex-coding-system
  410. coding-system))
  411. (save-buffer-coding-system (or org-export-latex-coding-system
  412. coding-system))
  413. (region (buffer-substring
  414. (if region-p (region-beginning) (point-min))
  415. (if region-p (region-end) (point-max))))
  416. (string-for-export
  417. (org-export-preprocess-string
  418. region
  419. :emph-multiline t
  420. :for-LaTeX t
  421. :comments nil
  422. :tags (plist-get opt-plist :tags)
  423. :priority (plist-get opt-plist :priority)
  424. :footnotes (plist-get opt-plist :footnotes)
  425. :timestamps (plist-get opt-plist :timestamps)
  426. :todo-keywords (plist-get opt-plist :todo-keywords)
  427. :add-text (if (eq to-buffer 'string) nil text)
  428. :skip-before-1st-heading skip
  429. :select-tags (plist-get opt-plist :select-tags)
  430. :exclude-tags (plist-get opt-plist :exclude-tags)
  431. :LaTeX-fragments nil)))
  432. (set-buffer buffer)
  433. (erase-buffer)
  434. (and (fboundp 'set-buffer-file-coding-system)
  435. (set-buffer-file-coding-system coding-system-for-write))
  436. ;; insert the header and initial document commands
  437. (unless (or (eq to-buffer 'string) body-only)
  438. (insert header))
  439. ;; insert text found in #+TEXT
  440. (when (and text (not (eq to-buffer 'string)))
  441. (insert (org-export-latex-content
  442. text '(lists tables fixed-width keywords))
  443. "\n\n"))
  444. ;; insert lines before the first headline
  445. (unless (or skip (eq to-buffer 'string))
  446. (insert first-lines))
  447. ;; export the content of headlines
  448. (org-export-latex-global
  449. (with-temp-buffer
  450. (insert string-for-export)
  451. (goto-char (point-min))
  452. (when (re-search-forward "^\\(\\*+\\) " nil t)
  453. (let* ((asters (length (match-string 1)))
  454. (level (if odd (- asters 2) (- asters 1))))
  455. (setq org-export-latex-add-level
  456. (if odd (1- (/ (1+ asters) 2)) (1- asters)))
  457. (org-export-latex-parse-global level odd)))))
  458. ;; finalization
  459. (unless body-only (insert "\n\\end{document}"))
  460. (or to-buffer (save-buffer))
  461. (goto-char (point-min))
  462. (message "Exporting to LaTeX...done")
  463. (prog1
  464. (if (eq to-buffer 'string)
  465. (prog1 (buffer-substring (point-min) (point-max))
  466. (kill-buffer (current-buffer)))
  467. (current-buffer))
  468. (set-window-configuration wcf))))
  469. ;;;###autoload
  470. (defun org-export-as-pdf (arg &optional hidden ext-plist
  471. to-buffer body-only pub-dir)
  472. "Export as LaTeX, then process through to PDF."
  473. (interactive "P")
  474. (message "Exporting to PDF...")
  475. (let* ((wconfig (current-window-configuration))
  476. (lbuf (org-export-as-latex arg hidden ext-plist
  477. to-buffer body-only pub-dir))
  478. (file (buffer-file-name lbuf))
  479. (base (file-name-sans-extension (buffer-file-name lbuf)))
  480. (pdffile (concat base ".pdf")))
  481. (and (file-exists-p pdffile) (delete-file pdffile))
  482. (message "Processing LaTeX file...")
  483. (shell-command (format "pdflatex -interaction nonstopmode %s"
  484. (shell-quote-argument file)))
  485. (shell-command (format "pdflatex -interaction nonstopmode %s"
  486. (shell-quote-argument file)))
  487. (message "Processing LaTeX file...done")
  488. (if (not (file-exists-p pdffile))
  489. (error "PDF file was not produced")
  490. (set-window-configuration wconfig)
  491. (when org-export-pdf-remove-logfiles
  492. (dolist (ext '("aux" "log" "out" "toc"))
  493. (setq file (concat base "." ext))
  494. (and (file-exists-p file) (delete-file file))))
  495. (message "Exporting to PDF...done")
  496. pdffile)))
  497. ;;;###autoload
  498. (defun org-export-as-pdf-and-open (arg)
  499. "Export as LaTeX, then process through to PDF, and open."
  500. (interactive "P")
  501. (let ((pdffile (org-export-as-pdf arg)))
  502. (if pdffile
  503. (org-open-file pdffile)
  504. (error "PDF file was not produced"))))
  505. ;;; Parsing functions:
  506. (defun org-export-latex-parse-global (level odd)
  507. "Parse the current buffer recursively, starting at LEVEL.
  508. If ODD is non-nil, assume the buffer only contains odd sections.
  509. Return a list reflecting the document structure."
  510. (save-excursion
  511. (goto-char (point-min))
  512. (let* ((cnt 0) output
  513. (depth org-export-latex-sectioning-depth))
  514. (while (re-search-forward
  515. (concat "^\\(\\(?:\\*\\)\\{"
  516. (number-to-string (+ (if odd 2 1) level))
  517. "\\}\\) \\(.*\\)$")
  518. ;; make sure that there is no upper heading
  519. (when (> level 0)
  520. (save-excursion
  521. (save-match-data
  522. (re-search-forward
  523. (concat "^\\(\\(?:\\*\\)\\{"
  524. (number-to-string level)
  525. "\\}\\) \\(.*\\)$") nil t)))) t)
  526. (setq cnt (1+ cnt))
  527. (let* ((pos (match-beginning 0))
  528. (heading (match-string 2))
  529. (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
  530. (save-excursion
  531. (narrow-to-region
  532. (point)
  533. (save-match-data
  534. (if (re-search-forward
  535. (concat "^\\(\\(?:\\*\\)\\{"
  536. (number-to-string (+ (if odd 2 1) level))
  537. "\\}\\) \\(.*\\)$") nil t)
  538. (match-beginning 0)
  539. (point-max))))
  540. (goto-char (point-min))
  541. (setq output
  542. (append output
  543. (list
  544. (list
  545. `(pos . ,pos)
  546. `(level . ,nlevel)
  547. `(occur . ,cnt)
  548. `(heading . ,heading)
  549. `(content . ,(org-export-latex-parse-content))
  550. `(subcontent . ,(org-export-latex-parse-subcontent
  551. level odd)))))))
  552. (widen)))
  553. (list output))))
  554. (defun org-export-latex-parse-content ()
  555. "Extract the content of a section."
  556. (let ((beg (point))
  557. (end (if (re-search-forward "^\\(\\*\\)+ .*$" nil t)
  558. (progn (beginning-of-line) (point))
  559. (point-max))))
  560. (buffer-substring beg end)))
  561. (defun org-export-latex-parse-subcontent (level odd)
  562. "Extract the subcontent of a section at LEVEL.
  563. If ODD Is non-nil, assume subcontent only contains odd sections."
  564. (if (not (re-search-forward
  565. (concat "^\\(\\(?:\\*\\)\\{"
  566. (number-to-string (+ (if odd 4 2) level))
  567. "\\}\\) \\(.*\\)$")
  568. nil t))
  569. nil ; subcontent is nil
  570. (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
  571. ;;; Rendering functions:
  572. (defun org-export-latex-global (content)
  573. "Export CONTENT to LaTeX.
  574. CONTENT is an element of the list produced by
  575. `org-export-latex-parse-global'."
  576. (if (eq (car content) 'subcontent)
  577. (mapc 'org-export-latex-sub (cdr content))
  578. (org-export-latex-sub (car content))))
  579. (defun org-export-latex-sub (subcontent)
  580. "Export the list SUBCONTENT to LaTeX.
  581. SUBCONTENT is an alist containing information about the headline
  582. and its content."
  583. (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
  584. (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
  585. (defun org-export-latex-subcontent (subcontent num)
  586. "Export each cell of SUBCONTENT to LaTeX.
  587. If NUM, export sections as numerical sections."
  588. (let* ((heading (org-export-latex-fontify-headline
  589. (cdr (assoc 'heading subcontent))))
  590. (level (- (cdr (assoc 'level subcontent))
  591. org-export-latex-add-level))
  592. (occur (number-to-string (cdr (assoc 'occur subcontent))))
  593. (content (cdr (assoc 'content subcontent)))
  594. (subcontent (cadr (assoc 'subcontent subcontent)))
  595. (label (org-get-text-property-any 0 'target heading))
  596. (label-list (cons label (cdr (assoc label
  597. org-export-target-aliases)))))
  598. (cond
  599. ;; Normal conversion
  600. ((<= level org-export-latex-sectioning-depth)
  601. (let* ((sec (nth (1- level) org-export-latex-sectioning))
  602. start end)
  603. (if (consp (cdr sec))
  604. (setq start (nth (if num 0 2) sec)
  605. end (nth (if num 1 3) sec))
  606. (setq start (if num (car sec) (cdr sec))))
  607. (insert (format start heading) "\n")
  608. (when label
  609. (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
  610. label-list "\n") "\n"))
  611. (insert (org-export-latex-content content))
  612. (cond ((stringp subcontent) (insert subcontent))
  613. ((listp subcontent) (org-export-latex-sub subcontent)))
  614. (if end (insert end "\n"))))
  615. ;; At a level under the hl option: we can drop this subsection
  616. ((> level org-export-latex-sectioning-depth)
  617. (cond ((eq org-export-latex-low-levels 'description)
  618. (if (string-match "% ends low level$"
  619. (buffer-substring (point-at-bol 0) (point)))
  620. (delete-region (point-at-bol 0) (point))
  621. (insert "\\begin{description}\n"))
  622. (insert (format "\n\\item[%s]%s~\n\n"
  623. heading
  624. (if label (format "\\label{%s}" label) "")))
  625. (insert (org-export-latex-content content))
  626. (cond ((stringp subcontent) (insert subcontent))
  627. ((listp subcontent) (org-export-latex-sub subcontent)))
  628. (insert "\\end{description} % ends low level\n"))
  629. ((memq org-export-latex-low-levels '(itemize enumerate))
  630. (if (string-match "% ends low level$"
  631. (buffer-substring (point-at-bol 0) (point)))
  632. (delete-region (point-at-bol 0) (point))
  633. (insert (format "\\begin{%s}\n"
  634. (symbol-name org-export-latex-low-levels))))
  635. (insert (format "\n\\item %s\\\\\n%s\n"
  636. heading
  637. (if label (format "\\label{%s}" label) "")))
  638. (insert (org-export-latex-content content))
  639. (cond ((stringp subcontent) (insert subcontent))
  640. ((listp subcontent) (org-export-latex-sub subcontent)))
  641. (insert (format "\\end{%s} %% ends low level\n"
  642. (symbol-name org-export-latex-low-levels))))
  643. ((stringp org-export-latex-low-levels)
  644. (insert (format org-export-latex-low-levels heading) "\n")
  645. (when label (insert (format "\\label{%s}\n" label)))
  646. (insert (org-export-latex-content content))
  647. (cond ((stringp subcontent) (insert subcontent))
  648. ((listp subcontent) (org-export-latex-sub subcontent)))))))))
  649. ;;; Exporting internals:
  650. (defun org-export-latex-set-initial-vars (ext-plist level)
  651. "Store org local variables required for LaTeX export.
  652. EXT-PLIST is an optional additional plist.
  653. LEVEL indicates the default depth for export."
  654. (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
  655. org-export-latex-display-custom-times org-display-custom-times
  656. org-export-latex-all-targets-re
  657. (org-make-target-link-regexp (org-all-targets))
  658. org-export-latex-options-plist
  659. (org-combine-plists (org-default-export-plist) ext-plist
  660. (org-infile-export-plist))
  661. org-export-latex-class
  662. (or (and (org-region-active-p)
  663. (save-excursion
  664. (goto-char (region-beginning))
  665. (and (looking-at org-complex-heading-regexp)
  666. (org-entry-get nil "LaTeX_CLASS" 'selective))))
  667. (save-excursion
  668. (save-restriction
  669. (widen)
  670. (goto-char (point-min))
  671. (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t)
  672. (match-string 1))))
  673. org-export-latex-default-class)
  674. org-export-latex-class
  675. (or (car (assoc org-export-latex-class org-export-latex-classes))
  676. (error "No definition for class `%s' in `org-export-latex-classes'"
  677. org-export-latex-class))
  678. org-export-latex-header
  679. (cadr (assoc org-export-latex-class org-export-latex-classes))
  680. org-export-latex-sectioning
  681. (cddr (assoc org-export-latex-class org-export-latex-classes))
  682. org-export-latex-sectioning-depth
  683. (or level
  684. (let ((hl-levels
  685. (plist-get org-export-latex-options-plist :headline-levels))
  686. (sec-depth (length org-export-latex-sectioning)))
  687. (if (> hl-levels sec-depth) sec-depth hl-levels)))))
  688. (defun org-export-latex-make-header (title opt-plist)
  689. "Make the LaTeX header and return it as a string.
  690. TITLE is the current title from the buffer or region.
  691. OPT-PLIST is the options plist for current buffer."
  692. (let ((toc (plist-get opt-plist :table-of-contents))
  693. (author (plist-get opt-plist :author)))
  694. (concat
  695. (if (plist-get opt-plist :time-stamp-file)
  696. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  697. ;; insert LaTeX custom header
  698. (org-export-apply-macros-in-string org-export-latex-header)
  699. "\n"
  700. ;; insert information on LaTeX packages
  701. (when org-export-latex-packages-alist
  702. (mapconcat (lambda(p)
  703. (if (equal "" (car p))
  704. (format "\\usepackage{%s}" (cadr p))
  705. (format "\\usepackage[%s]{%s}"
  706. (car p) (cadr p))))
  707. org-export-latex-packages-alist "\n"))
  708. ;; insert additional commands in the header
  709. (org-export-apply-macros-in-string
  710. (plist-get opt-plist :latex-header-extra))
  711. (org-export-apply-macros-in-string org-export-latex-append-header)
  712. ;; insert the title
  713. (format
  714. "\n\n\\title{%s}\n"
  715. ;; convert the title
  716. (org-export-latex-content
  717. title '(lists tables fixed-width keywords)))
  718. ;; insert author info
  719. (if (plist-get opt-plist :author-info)
  720. (format "\\author{%s}\n"
  721. (or author user-full-name))
  722. (format "%%\\author{%s}\n"
  723. (or author user-full-name)))
  724. ;; insert the date
  725. (format "\\date{%s}\n"
  726. (format-time-string
  727. (or (plist-get opt-plist :date)
  728. org-export-latex-date-format)))
  729. ;; beginning of the document
  730. "\n\\begin{document}\n\n"
  731. ;; insert the title command
  732. (if (string-match "%s" org-export-latex-title-command)
  733. (format org-export-latex-title-command title)
  734. org-export-latex-title-command)
  735. "\n\n"
  736. ;; table of contents
  737. (when (and org-export-with-toc
  738. (plist-get opt-plist :section-numbers))
  739. (cond ((numberp toc)
  740. (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
  741. (min toc (plist-get opt-plist :headline-levels))))
  742. (toc (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
  743. (plist-get opt-plist :headline-levels))))))))
  744. (defun org-export-latex-first-lines (opt-plist &optional beg)
  745. "Export the first lines before first headline.
  746. If BEG is non-nil, the is the beginning of he region."
  747. (save-excursion
  748. (goto-char (or beg (point-min)))
  749. (if (org-at-heading-p) (beginning-of-line 2))
  750. (let* ((pt (point))
  751. (end (if (re-search-forward "^\\*+ " nil t)
  752. (goto-char (match-beginning 0))
  753. (goto-char (point-max)))))
  754. (prog1
  755. (org-export-latex-content
  756. (org-export-preprocess-string
  757. (buffer-substring pt end)
  758. :for-LaTeX t
  759. :emph-multiline t
  760. :add-text nil
  761. :comments nil
  762. :skip-before-1st-heading nil
  763. :LaTeX-fragments nil
  764. :timestamps (plist-get opt-plist :timestamps)
  765. :footnotes (plist-get opt-plist :footnotes)))
  766. (org-unmodified
  767. (add-text-properties pt (max pt (1- end))
  768. '(:org-license-to-kill t)))))))
  769. (defvar org-export-latex-header-defs nil
  770. "The header definitions that might be used in the LaTeX body.")
  771. (defvar org-export-latex-header-defs-re nil
  772. "The header definitions that might be used in the LaTeX body.")
  773. (defun org-export-latex-content (content &optional exclude-list)
  774. "Convert CONTENT string to LaTeX.
  775. Don't perform conversions that are in EXCLUDE-LIST. Recognized
  776. conversion types are: quotation-marks, emphasis, sub-superscript,
  777. links, keywords, lists, tables, fixed-width"
  778. (with-temp-buffer
  779. (insert content)
  780. (unless (memq 'timestamps exclude-list)
  781. (org-export-latex-time-stamps))
  782. (unless (memq 'quotation-marks exclude-list)
  783. (org-export-latex-quotation-marks))
  784. (unless (memq 'emphasis exclude-list)
  785. (when (plist-get org-export-latex-options-plist :emphasize)
  786. (org-export-latex-fontify)))
  787. (unless (memq 'sub-superscript exclude-list)
  788. (org-export-latex-special-chars
  789. (plist-get org-export-latex-options-plist :sub-superscript)))
  790. (unless (memq 'links exclude-list)
  791. (org-export-latex-links))
  792. (unless (memq 'keywords exclude-list)
  793. (org-export-latex-keywords))
  794. (unless (memq 'lists exclude-list)
  795. (org-export-latex-lists))
  796. (unless (memq 'tables exclude-list)
  797. (org-export-latex-tables
  798. (plist-get org-export-latex-options-plist :tables)))
  799. (unless (memq 'fixed-width exclude-list)
  800. (org-export-latex-fixed-width
  801. (plist-get org-export-latex-options-plist :fixed-width)))
  802. ;; return string
  803. (buffer-substring (point-min) (point-max))))
  804. (defun org-export-latex-protect-string (s)
  805. "Add the org-protected property to string S."
  806. (add-text-properties 0 (length s) '(org-protected t) s) s)
  807. (defun org-export-latex-protect-char-in-string (char-list string)
  808. "Add org-protected text-property to char from CHAR-LIST in STRING."
  809. (with-temp-buffer
  810. (save-match-data
  811. (insert string)
  812. (goto-char (point-min))
  813. (while (re-search-forward (regexp-opt char-list) nil t)
  814. (add-text-properties (match-beginning 0)
  815. (match-end 0) '(org-protected t)))
  816. (buffer-string))))
  817. (defun org-export-latex-keywords-maybe (&optional remove-list)
  818. "Maybe remove keywords depending on rules in REMOVE-LIST."
  819. (goto-char (point-min))
  820. (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
  821. (case-fold-search nil))
  822. ;; convert TODO keywords
  823. (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
  824. (if (plist-get remove-list :todo)
  825. (replace-match "")
  826. (replace-match (format "\\textbf{%s}" (match-string 1)) t t)))
  827. ;; convert priority string
  828. (when (re-search-forward "\\[\\\\#.\\]" nil t)
  829. (if (plist-get remove-list :priority)
  830. (replace-match "")
  831. (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
  832. ;; convert tags
  833. (when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
  834. (if (or (not org-export-with-tags)
  835. (plist-get remove-list :tags))
  836. (replace-match "")
  837. (replace-match
  838. (org-export-latex-protect-string
  839. (format "\\textbf{%s}"
  840. (save-match-data
  841. (replace-regexp-in-string
  842. "_" "\\\\_" (match-string 0)))))
  843. t t)))))
  844. (defun org-export-latex-fontify-headline (string)
  845. "Fontify special words in STRING."
  846. (with-temp-buffer
  847. ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
  848. ;; the beginning of the buffer - inserting "\n" is safe here though.
  849. (insert "\n" string)
  850. (goto-char (point-min))
  851. (when (plist-get org-export-latex-options-plist :emphasize)
  852. (org-export-latex-fontify))
  853. (org-export-latex-keywords-maybe)
  854. (org-export-latex-special-chars
  855. (plist-get org-export-latex-options-plist :sub-superscript))
  856. (org-export-latex-links)
  857. (org-trim (buffer-string))))
  858. (defun org-export-latex-time-stamps ()
  859. "Format time stamps."
  860. (goto-char (point-min))
  861. (let ((org-display-custom-times org-export-latex-display-custom-times))
  862. (while (re-search-forward org-ts-regexp-both nil t)
  863. (org-if-unprotected-at (1- (point))
  864. (replace-match
  865. (org-export-latex-protect-string
  866. (format org-export-latex-timestamp-markup
  867. (substring (org-translate-time (match-string 0)) 1 -1)))
  868. t t)))))
  869. (defun org-export-latex-quotation-marks ()
  870. "Export quotation marks depending on language conventions."
  871. (let* ((lang (plist-get org-export-latex-options-plist :language))
  872. (quote-rpl (if (equal lang "fr")
  873. '(("\\(\\s-\\)\"" "«~")
  874. ("\\(\\S-\\)\"" "~»")
  875. ("\\(\\s-\\)'" "`"))
  876. '(("\\(\\s-\\)\"" "``")
  877. ("\\(\\S-\\)\"" "''")
  878. ("\\(\\s-\\)'" "`")))))
  879. (mapc (lambda(l) (goto-char (point-min))
  880. (while (re-search-forward (car l) nil t)
  881. (let ((rpl (concat (match-string 1) (cadr l))))
  882. (org-export-latex-protect-string rpl)
  883. (org-if-unprotected-1
  884. (replace-match rpl t t))))) quote-rpl)))
  885. (defun org-export-latex-special-chars (sub-superscript)
  886. "Export special characters to LaTeX.
  887. If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
  888. See the `org-export-latex.el' code for a complete conversion table."
  889. (goto-char (point-min))
  890. (mapc (lambda(c)
  891. (goto-char (point-min))
  892. (while (re-search-forward c nil t)
  893. ;; Put the point where to check for org-protected
  894. (unless (get-text-property (match-beginning 2) 'org-protected)
  895. (cond ((member (match-string 2) '("\\$" "$"))
  896. (if (equal (match-string 2) "\\$")
  897. nil
  898. (replace-match "\\$" t t)))
  899. ((member (match-string 2) '("&" "%" "#"))
  900. (if (equal (match-string 1) "\\")
  901. (replace-match (match-string 2) t t)
  902. (replace-match (concat (match-string 1) "\\"
  903. (match-string 2)) t t)))
  904. ((equal (match-string 2) "...")
  905. (replace-match
  906. (concat (match-string 1)
  907. (org-export-latex-protect-string "\\ldots{}")) t t))
  908. ((equal (match-string 2) "~")
  909. (cond ((equal (match-string 1) "\\") nil)
  910. ((eq 'org-link (get-text-property 0 'face (match-string 2)))
  911. (replace-match (concat (match-string 1) "\\~") t t))
  912. (t (replace-match
  913. (org-export-latex-protect-string
  914. (concat (match-string 1) "\\~{}")) t t))))
  915. ((member (match-string 2) '("{" "}"))
  916. (unless (save-match-data (org-inside-latex-math-p))
  917. (if (equal (match-string 1) "\\")
  918. (replace-match (match-string 2) t t)
  919. (replace-match (concat (match-string 1) "\\"
  920. (match-string 2)) t t)))))
  921. (unless (save-match-data (org-inside-latex-math-p))
  922. (cond ((equal (match-string 2) "\\")
  923. (replace-match (or (save-match-data
  924. (org-export-latex-treat-backslash-char
  925. (match-string 1)
  926. (or (match-string 3) "")))
  927. "") t t))
  928. ((member (match-string 2) '("_" "^"))
  929. (replace-match (or (save-match-data
  930. (org-export-latex-treat-sub-super-char
  931. sub-superscript
  932. (match-string 2)
  933. (match-string 1)
  934. (match-string 3))) "") t t)))))))
  935. '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
  936. "\\(\\(\\\\?\\$\\)\\)"
  937. "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
  938. "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
  939. "\\(.\\|^\\)\\(&\\)"
  940. "\\(.\\|^\\)\\(#\\)"
  941. "\\(.\\|^\\)\\(%\\)"
  942. "\\(.\\|^\\)\\({\\)"
  943. "\\(.\\|^\\)\\(}\\)"
  944. "\\(.\\|^\\)\\(~\\)"
  945. "\\(.\\|^\\)\\(\\.\\.\\.\\)"
  946. ;; (?\< . "\\textless{}")
  947. ;; (?\> . "\\textgreater{}")
  948. )))
  949. (defun org-inside-latex-math-p ()
  950. (get-text-property (point) 'org-latex-math))
  951. (defun org-export-latex-treat-sub-super-char
  952. (subsup char string-before string-after)
  953. "Convert the \"_\" and \"^\" characters to LaTeX.
  954. SUBSUP corresponds to the ^: option in the #+OPTIONS line.
  955. Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
  956. (cond ((equal string-before "\\")
  957. (concat string-before char string-after))
  958. ;; this is part of a math formula
  959. ((and (string-match "\\S-+" string-before)
  960. (string-match "\\S-+" string-after))
  961. (cond ((eq 'org-link (get-text-property 0 'face char))
  962. (concat string-before "\\" char string-after))
  963. ((save-match-data (org-inside-latex-math-p))
  964. (if subsup
  965. (cond ((eq 1 (length string-after))
  966. (concat string-before char string-after))
  967. ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
  968. (format "%s%s{%s}" string-before char
  969. (match-string 1 string-after))))))
  970. ((and (> (length string-after) 1)
  971. (or (eq subsup t)
  972. (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
  973. (string-match "[({]?\\([^)}]+\\)[)}]?" string-after))
  974. (org-export-latex-protect-string
  975. (format "%s$%s{%s}$" string-before char
  976. (if (and (> (match-end 1) (1+ (match-beginning 1)))
  977. (not (equal (substring string-after 0 2) "{\\")))
  978. (concat "\\mathrm{" (match-string 1 string-after) "}")
  979. (match-string 1 string-after)))))
  980. ((eq subsup t) (concat string-before "$" char string-after "$"))
  981. (t (org-export-latex-protect-string
  982. (concat string-before "\\" char "{}" string-after)))))
  983. (t (org-export-latex-protect-string
  984. (concat string-before "\\" char "{}" string-after)))))
  985. (defun org-export-latex-treat-backslash-char (string-before string-after)
  986. "Convert the \"$\" special character to LaTeX.
  987. The conversion is made depending of STRING-BEFORE and STRING-AFTER."
  988. (cond ((member (list string-after) org-html-entities)
  989. ;; backslash is part of a special entity (like "\alpha")
  990. (concat string-before "$\\"
  991. (or (cdar (member (list string-after) org-html-entities))
  992. string-after) "$"))
  993. ((and (not (string-match "^[ \n\t]" string-after))
  994. (not (string-match "[ \t]\\'\\|^" string-before)))
  995. ;; backslash is inside a word
  996. (org-export-latex-protect-string
  997. (concat string-before "\\textbackslash{}" string-after)))
  998. ((not (or (equal string-after "")
  999. (string-match "^[ \t\n]" string-after)))
  1000. ;; backslash might escape a character (like \#) or a user TeX
  1001. ;; macro (like \setcounter)
  1002. (org-export-latex-protect-string
  1003. (concat string-before "\\" string-after)))
  1004. ((and (string-match "^[ \t\n]" string-after)
  1005. (string-match "[ \t\n]\\'" string-before))
  1006. ;; backslash is alone, convert it to $\backslash$
  1007. (org-export-latex-protect-string
  1008. (concat string-before "\\textbackslash{}" string-after)))
  1009. (t (org-export-latex-protect-string
  1010. (concat string-before "\\textbackslash{}" string-after)))))
  1011. (defun org-export-latex-keywords ()
  1012. "Convert special keywords to LaTeX."
  1013. (goto-char (point-min))
  1014. (let ((re (concat org-export-latex-special-keyword-regexp
  1015. ".*" ; including the time stamp....
  1016. )))
  1017. (while (re-search-forward re nil t)
  1018. (replace-match (format "\\texttt{%s}" (match-string 0)) t t))))
  1019. (defun org-export-latex-fixed-width (opt)
  1020. "When OPT is non-nil convert fixed-width sections to LaTeX."
  1021. (goto-char (point-min))
  1022. (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
  1023. (if opt
  1024. (progn (goto-char (match-beginning 0))
  1025. (insert "\\begin{verbatim}\n")
  1026. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1027. (replace-match (concat (match-string 1)
  1028. (match-string 2)) t t)
  1029. (forward-line))
  1030. (insert "\\end{verbatim}\n\n"))
  1031. (progn (goto-char (match-beginning 0))
  1032. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1033. (replace-match (concat "%" (match-string 1)
  1034. (match-string 2)) t t)
  1035. (forward-line))))))
  1036. (defvar org-table-last-alignment) ; defined in org-table.el
  1037. (declare-function orgtbl-to-latex "org-table" (table params) t)
  1038. (defun org-export-latex-tables (insert)
  1039. "Convert tables to LaTeX and INSERT it."
  1040. (goto-char (point-min))
  1041. (while (re-search-forward "^\\([ \t]*\\)|" nil t)
  1042. ;; FIXME really need to save-excursion?
  1043. (save-excursion (org-table-align))
  1044. (let* ((beg (org-table-begin))
  1045. (end (org-table-end))
  1046. (raw-table (buffer-substring beg end))
  1047. fnum fields line lines olines gr colgropen line-fmt align
  1048. caption label attr floatp longtblp)
  1049. (if org-export-latex-tables-verbatim
  1050. (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
  1051. "\\end{verbatim}\n")))
  1052. (apply 'delete-region (list beg end))
  1053. (insert (org-export-latex-protect-string tbl)))
  1054. (progn
  1055. (setq caption (org-find-text-property-in-string
  1056. 'org-caption raw-table)
  1057. attr (org-find-text-property-in-string
  1058. 'org-attributes raw-table)
  1059. label (org-find-text-property-in-string
  1060. 'org-label raw-table)
  1061. longtblp (and attr (stringp attr)
  1062. (string-match "\\<longtable\\>" attr))
  1063. align (and attr (stringp attr)
  1064. (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
  1065. (match-string 1 attr))
  1066. floatp (or caption label))
  1067. (setq lines (org-split-string raw-table "\n"))
  1068. (apply 'delete-region (list beg end))
  1069. (when org-export-table-remove-special-lines
  1070. (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
  1071. ;; make a formatting string to reflect aligment
  1072. (setq olines lines)
  1073. (while (and (not line-fmt) (setq line (pop olines)))
  1074. (unless (string-match "^[ \t]*|-" line)
  1075. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1076. (setq fnum (make-vector (length fields) 0))
  1077. (setq line-fmt
  1078. (mapconcat
  1079. (lambda (x)
  1080. (setq gr (pop org-table-colgroup-info))
  1081. (format "%s%%s%s"
  1082. (cond ((eq gr :start)
  1083. (prog1 (if colgropen "|" "|")
  1084. (setq colgropen t)))
  1085. ((eq gr :startend)
  1086. (prog1 (if colgropen "|" "|")
  1087. (setq colgropen nil)))
  1088. (t ""))
  1089. (if (memq gr '(:end :startend))
  1090. (progn (setq colgropen nil) "|")
  1091. "")))
  1092. fnum ""))))
  1093. ;; fix double || in line-fmt
  1094. (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
  1095. ;; maybe remove the first and last "|"
  1096. (when (and (not org-export-latex-tables-column-borders)
  1097. (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
  1098. (setq line-fmt (match-string 2 line-fmt)))
  1099. ;; format alignment
  1100. (unless align
  1101. (setq align (apply 'format
  1102. (cons line-fmt
  1103. (mapcar (lambda (x) (if x "r" "l"))
  1104. org-table-last-alignment)))))
  1105. ;; prepare the table to send to orgtbl-to-latex
  1106. (setq lines
  1107. (mapcar
  1108. (lambda(elem)
  1109. (or (and (string-match "[ \t]*|-+" elem) 'hline)
  1110. (org-split-string (org-trim elem) "|")))
  1111. lines))
  1112. (when insert
  1113. (insert (org-export-latex-protect-string
  1114. (concat
  1115. (if longtblp
  1116. (concat "\\begin{longtable}{" align "}\n")
  1117. (if floatp "\\begin{table}[htb]\n"))
  1118. (if (or floatp longtblp)
  1119. (format
  1120. "\\caption{%s%s}"
  1121. (if label (concat "\\\label{" label "}") "")
  1122. (or caption "")))
  1123. (if longtblp "\\\\\n" "\n")
  1124. (if (not longtblp) "\\begin{center}\n")
  1125. (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
  1126. (orgtbl-to-latex
  1127. lines
  1128. `(:tstart nil :tend nil
  1129. :hlend ,(if longtblp
  1130. (format "\\\\
  1131. \\hline
  1132. \\endhead
  1133. \\hline\\multicolumn{%d}{r}{Continued on next page}\\
  1134. \\endfoot
  1135. \\endlastfoot" (length org-table-last-alignment))
  1136. nil)))
  1137. (if (not longtblp) (concat "\n\\end{tabular}"))
  1138. (if longtblp "\n" "\n\\end{center}\n")
  1139. (if longtblp
  1140. "\\end{longtable}"
  1141. (if floatp "\\end{table}"))))
  1142. "\n\n")))))))
  1143. (defun org-export-latex-fontify ()
  1144. "Convert fontification to LaTeX."
  1145. (goto-char (point-min))
  1146. (while (re-search-forward org-emph-re nil t)
  1147. ;; The match goes one char after the *string*
  1148. (let ((emph (assoc (match-string 3)
  1149. org-export-latex-emphasis-alist))
  1150. (beg (match-beginning 0))
  1151. (end (match-end 0))
  1152. rpl)
  1153. (unless emph
  1154. (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
  1155. (match-string 3)))
  1156. (unless (or (get-text-property (1- (point)) 'org-protected)
  1157. (save-excursion
  1158. (goto-char (match-beginning 1))
  1159. (save-match-data
  1160. (and (org-at-table-p)
  1161. (string-match
  1162. "[|\n]" (buffer-substring beg end))))))
  1163. (setq rpl (concat (match-string 1)
  1164. (org-export-latex-emph-format (cadr emph)
  1165. (match-string 4))
  1166. (match-string 5)))
  1167. (if (caddr emph)
  1168. (setq rpl (org-export-latex-protect-string rpl)))
  1169. (replace-match rpl t t)))
  1170. (backward-char)))
  1171. (defun org-export-latex-emph-format (format string)
  1172. "Format an emphasis string and handle the \\verb special case."
  1173. (when (equal format "\\verb")
  1174. (save-match-data
  1175. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1176. (catch 'exit
  1177. (loop for i from 0 to (1- (length ll)) do
  1178. (if (not (string-match (regexp-quote (substring ll i (1+ i)))
  1179. string))
  1180. (progn
  1181. (setq format (concat "\\verb" (substring ll i (1+ i))
  1182. "%s" (substring ll i (1+ i))))
  1183. (throw 'exit nil))))))))
  1184. (setq string (org-export-latex-protect-string
  1185. (format format string))))
  1186. (defun org-export-latex-links ()
  1187. ;; Make sure to use the LaTeX hyperref and graphicx package
  1188. ;; or send some warnings.
  1189. "Convert links to LaTeX."
  1190. (goto-char (point-min))
  1191. (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
  1192. (org-if-unprotected
  1193. (goto-char (match-beginning 0))
  1194. (let* ((re-radio org-export-latex-all-targets-re)
  1195. (remove (list (match-beginning 0) (match-end 0)))
  1196. (raw-path (org-extract-attributes (match-string 3)))
  1197. (full-raw-path (concat (match-string 1) raw-path))
  1198. (desc (match-string 5))
  1199. (type (or (match-string 2)
  1200. (if (or (file-name-absolute-p raw-path)
  1201. (string-match "^\\.\\.?/" raw-path))
  1202. "file")))
  1203. (coderefp (equal type "coderef"))
  1204. (caption (org-find-text-property-in-string 'org-caption raw-path))
  1205. (attr (org-find-text-property-in-string 'org-attributes raw-path))
  1206. (label (org-find-text-property-in-string 'org-label raw-path))
  1207. (floatp (or label caption))
  1208. imgp radiop
  1209. ;; define the path of the link
  1210. (path (cond
  1211. ((member type '("coderef"))
  1212. raw-path)
  1213. ((member type '("http" "https" "ftp"))
  1214. (concat type ":" raw-path))
  1215. ((and re-radio (string-match re-radio raw-path))
  1216. (setq radiop t))
  1217. ((equal type "mailto")
  1218. (concat type ":" raw-path))
  1219. ((equal type "file")
  1220. (if (and (org-file-image-p
  1221. (expand-file-name
  1222. raw-path)
  1223. org-export-latex-inline-image-extensions)
  1224. (equal desc full-raw-path))
  1225. (setq imgp t)
  1226. (progn (when (string-match "\\(.+\\)::.+" raw-path)
  1227. (setq raw-path (match-string 1 raw-path)))
  1228. (if (file-exists-p raw-path)
  1229. (concat type "://" (expand-file-name raw-path))
  1230. (concat type "://" (org-export-directory
  1231. :LaTeX org-export-latex-options-plist)
  1232. raw-path))))))))
  1233. ;; process with link inserting
  1234. (apply 'delete-region remove)
  1235. (cond ((and imgp (plist-get org-export-latex-options-plist :inline-images))
  1236. (insert
  1237. (concat
  1238. (if floatp "\\begin{figure}[htb]\n")
  1239. (format "\\centerline{\\includegraphics[%s]{%s}}\n"
  1240. (or attr org-export-latex-image-default-option)
  1241. (if (file-name-absolute-p raw-path)
  1242. (expand-file-name raw-path)
  1243. raw-path))
  1244. (if floatp
  1245. (format "\\caption{%s%s}\n"
  1246. (if label (concat "\\label{" label "}") "")
  1247. (or caption "")))
  1248. (if floatp "\\end{figure}\n"))))
  1249. (coderefp
  1250. (insert (format
  1251. (org-export-get-coderef-format path desc)
  1252. (cdr (assoc path org-export-code-refs)))))
  1253. (radiop (insert (format "\\hyperref[%s]{%s}"
  1254. (org-solidify-link-text raw-path) desc)))
  1255. ((not type)
  1256. (insert (format "\\hyperref[%s]{%s}"
  1257. (org-solidify-link-text raw-path) desc)))
  1258. (path (insert (format "\\href{%s}{%s}" path desc)))
  1259. (t (insert "\\texttt{" desc "}")))))))
  1260. (defvar org-latex-entities) ; defined below
  1261. (defvar org-latex-entities-regexp) ; defined below
  1262. (defun org-export-latex-preprocess (parameters)
  1263. "Clean stuff in the LaTeX export."
  1264. ;; Preserve line breaks
  1265. (goto-char (point-min))
  1266. (while (re-search-forward "\\\\\\\\" nil t)
  1267. (add-text-properties (match-beginning 0) (match-end 0)
  1268. '(org-protected t)))
  1269. ;; Preserve latex environments
  1270. (goto-char (point-min))
  1271. (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\)}" nil t)
  1272. (let* ((start (progn (beginning-of-line) (point)))
  1273. (end (or (and (re-search-forward
  1274. (concat "^[ \t]*\\\\end{" (match-string 1) "}") nil t)
  1275. (point-at-eol))
  1276. (point-max))))
  1277. (add-text-properties start end '(org-protected t))))
  1278. ;; Preserve math snippets
  1279. (let* ((matchers (plist-get org-format-latex-options :matchers))
  1280. (re-list org-latex-regexps)
  1281. beg end re e m n block off)
  1282. ;; Check the different regular expressions
  1283. (while (setq e (pop re-list))
  1284. (setq m (car e) re (nth 1 e) n (nth 2 e)
  1285. block (if (nth 3 e) "\n\n" ""))
  1286. (setq off (if (member m '("$" "$1")) 1 0))
  1287. (when (and (member m matchers) (not (equal m "begin")))
  1288. (goto-char (point-min))
  1289. (while (re-search-forward re nil t)
  1290. (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
  1291. (add-text-properties beg end '(org-protected t org-latex-math t))))))
  1292. ;; Convert LaTeX to \LaTeX{}
  1293. (goto-char (point-min))
  1294. (let ((case-fold-search nil))
  1295. (while (re-search-forward "\\([^+_]\\)LaTeX" nil t)
  1296. (org-if-unprotected
  1297. (replace-match (org-export-latex-protect-string
  1298. (concat (match-string 1) "\\LaTeX{}")) t t))))
  1299. ;; Convert blockquotes
  1300. (goto-char (point-min))
  1301. (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
  1302. (replace-match "\\begin{quote}" t t))
  1303. (goto-char (point-min))
  1304. (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
  1305. (replace-match "\\end{quote}" t t))
  1306. ;; Convert verse
  1307. (goto-char (point-min))
  1308. (while (search-forward "ORG-VERSE-START" nil t)
  1309. (replace-match "\\begin{verse}" t t)
  1310. (beginning-of-line 2)
  1311. (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
  1312. (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
  1313. (goto-char (match-end 1))
  1314. (replace-match
  1315. (org-export-latex-protect-string
  1316. (concat "\\hspace*{1cm}" (match-string 2))) t t)
  1317. (beginning-of-line 1))
  1318. (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
  1319. (end-of-line 1)
  1320. (insert "\\\\"))
  1321. (beginning-of-line 2))
  1322. (and (looking-at "[ \t]*ORG-VERSE-END.*")
  1323. (replace-match "\\end{verse}" t t)))
  1324. ;; Convert center
  1325. (goto-char (point-min))
  1326. (while (search-forward "ORG-CENTER-START" nil t)
  1327. (replace-match "\\begin{center}" t t))
  1328. (goto-char (point-min))
  1329. (while (search-forward "ORG-CENTER-END" nil t)
  1330. (replace-match "\\end{center}" t t))
  1331. ;; Convert horizontal rules
  1332. (goto-char (point-min))
  1333. (while (re-search-forward "^----+.$" nil t)
  1334. (org-if-unprotected
  1335. (replace-match (org-export-latex-protect-string "\\hrule") t t)))
  1336. ;; Protect LaTeX commands like \command[...]{...} or \command{...}
  1337. (goto-char (point-min))
  1338. (while (re-search-forward "\\\\[a-zA-Z]+\\(?:\\[.*\\]\\)?{.*}" nil t)
  1339. (add-text-properties (match-beginning 0) (match-end 0)
  1340. '(org-protected t)))
  1341. ;; Protect LaTeX entities
  1342. (goto-char (point-min))
  1343. (while (re-search-forward org-latex-entities-regexp nil t)
  1344. (add-text-properties (match-beginning 0) (match-end 0)
  1345. '(org-protected t)))
  1346. ;; Replace radio links
  1347. (goto-char (point-min))
  1348. (while (re-search-forward
  1349. (concat "<<<?" org-export-latex-all-targets-re
  1350. ">>>?\\((INVISIBLE)\\)?") nil t)
  1351. (org-if-unprotected
  1352. (replace-match
  1353. (org-export-latex-protect-string
  1354. (format "\\label{%s}%s" (save-match-data (org-solidify-link-text
  1355. (match-string 1)))
  1356. (if (match-string 2) "" (match-string 1)))) t t)))
  1357. ;; Delete @<...> constructs
  1358. ;; Thanks to Daniel Clemente for this regexp
  1359. (goto-char (point-min))
  1360. (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
  1361. (org-if-unprotected
  1362. (replace-match "")))
  1363. ;; When converting to LaTeX, replace footnotes
  1364. ;; FIXME: don't protect footnotes from conversion
  1365. (when (plist-get org-export-latex-options-plist :footnotes)
  1366. (goto-char (point-min))
  1367. (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
  1368. (org-if-unprotected
  1369. (when (save-match-data
  1370. (save-excursion (beginning-of-line)
  1371. (looking-at "[^:|#]")))
  1372. (let ((foot-beg (match-beginning 0))
  1373. (foot-end (match-end 0))
  1374. (foot-prefix (match-string 0))
  1375. footnote footnote-rpl)
  1376. (save-excursion
  1377. (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
  1378. nil t))
  1379. (replace-match "$^{\\1}$")
  1380. (replace-match "")
  1381. (let ((end (save-excursion
  1382. (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
  1383. (match-beginning 0) (point-max)))))
  1384. (setq footnote (concat (org-trim (buffer-substring (point) end))
  1385. " ")) ; prevent last } being part of a link
  1386. (delete-region (point) end))
  1387. (goto-char foot-beg)
  1388. (delete-region foot-beg foot-end)
  1389. (unless (null footnote)
  1390. (setq footnote-rpl (format "\\footnote{%s}" footnote))
  1391. (add-text-properties 0 10 '(org-protected t) footnote-rpl)
  1392. (add-text-properties (1- (length footnote-rpl))
  1393. (length footnote-rpl)
  1394. '(org-protected t) footnote-rpl)
  1395. (insert footnote-rpl)))
  1396. )))))
  1397. ;; Remove footnote section tag for LaTeX
  1398. (goto-char (point-min))
  1399. (while (re-search-forward
  1400. (concat "^" footnote-section-tag-regexp) nil t)
  1401. (org-if-unprotected
  1402. (replace-match "")))))
  1403. ;;; List handling:
  1404. (defun org-export-latex-lists ()
  1405. "Convert plain text lists in current buffer into LaTeX lists."
  1406. (goto-char (point-min))
  1407. (while (re-search-forward org-list-beginning-re nil t)
  1408. (org-if-unprotected
  1409. (beginning-of-line)
  1410. (insert (org-list-to-latex (org-list-parse-list t)
  1411. org-export-latex-list-parameters))
  1412. "\n")))
  1413. (defconst org-latex-entities
  1414. '("\\!"
  1415. "\\'"
  1416. "\\+"
  1417. "\\,"
  1418. "\\-"
  1419. "\\:"
  1420. "\\;"
  1421. "\\<"
  1422. "\\="
  1423. "\\>"
  1424. "\\Huge"
  1425. "\\LARGE"
  1426. "\\Large"
  1427. "\\Styles"
  1428. "\\\\"
  1429. "\\`"
  1430. "\\addcontentsline"
  1431. "\\address"
  1432. "\\addtocontents"
  1433. "\\addtocounter"
  1434. "\\addtolength"
  1435. "\\addvspace"
  1436. "\\alph"
  1437. "\\appendix"
  1438. "\\arabic"
  1439. "\\author"
  1440. "\\begin{array}"
  1441. "\\begin{center}"
  1442. "\\begin{description}"
  1443. "\\begin{enumerate}"
  1444. "\\begin{eqnarray}"
  1445. "\\begin{equation}"
  1446. "\\begin{figure}"
  1447. "\\begin{flushleft}"
  1448. "\\begin{flushright}"
  1449. "\\begin{itemize}"
  1450. "\\begin{list}"
  1451. "\\begin{minipage}"
  1452. "\\begin{picture}"
  1453. "\\begin{quotation}"
  1454. "\\begin{quote}"
  1455. "\\begin{tabbing}"
  1456. "\\begin{table}"
  1457. "\\begin{tabular}"
  1458. "\\begin{thebibliography}"
  1459. "\\begin{theorem}"
  1460. "\\begin{titlepage}"
  1461. "\\begin{verbatim}"
  1462. "\\begin{verse}"
  1463. "\\bf"
  1464. "\\bf"
  1465. "\\bibitem"
  1466. "\\bigskip"
  1467. "\\cdots"
  1468. "\\centering"
  1469. "\\circle"
  1470. "\\cite"
  1471. "\\cleardoublepage"
  1472. "\\clearpage"
  1473. "\\cline"
  1474. "\\closing"
  1475. "\\dashbox"
  1476. "\\date"
  1477. "\\ddots"
  1478. "\\dotfill"
  1479. "\\em"
  1480. "\\fbox"
  1481. "\\flushbottom"
  1482. "\\fnsymbol"
  1483. "\\footnote"
  1484. "\\footnotemark"
  1485. "\\footnotesize"
  1486. "\\footnotetext"
  1487. "\\frac"
  1488. "\\frame"
  1489. "\\framebox"
  1490. "\\hfill"
  1491. "\\hline"
  1492. "\\hrulespace"
  1493. "\\hspace"
  1494. "\\huge"
  1495. "\\hyphenation"
  1496. "\\include"
  1497. "\\includeonly"
  1498. "\\indent"
  1499. "\\input"
  1500. "\\it"
  1501. "\\kill"
  1502. "\\label"
  1503. "\\large"
  1504. "\\ldots"
  1505. "\\line"
  1506. "\\linebreak"
  1507. "\\linethickness"
  1508. "\\listoffigures"
  1509. "\\listoftables"
  1510. "\\location"
  1511. "\\makebox"
  1512. "\\maketitle"
  1513. "\\mark"
  1514. "\\mbox"
  1515. "\\medskip"
  1516. "\\multicolumn"
  1517. "\\multiput"
  1518. "\\newcommand"
  1519. "\\newcounter"
  1520. "\\newenvironment"
  1521. "\\newfont"
  1522. "\\newlength"
  1523. "\\newline"
  1524. "\\newpage"
  1525. "\\newsavebox"
  1526. "\\newtheorem"
  1527. "\\nocite"
  1528. "\\nofiles"
  1529. "\\noindent"
  1530. "\\nolinebreak"
  1531. "\\nopagebreak"
  1532. "\\normalsize"
  1533. "\\onecolumn"
  1534. "\\opening"
  1535. "\\oval"
  1536. "\\overbrace"
  1537. "\\overline"
  1538. "\\pagebreak"
  1539. "\\pagenumbering"
  1540. "\\pageref"
  1541. "\\pagestyle"
  1542. "\\par"
  1543. "\\parbox"
  1544. "\\put"
  1545. "\\raggedbottom"
  1546. "\\raggedleft"
  1547. "\\raggedright"
  1548. "\\raisebox"
  1549. "\\ref"
  1550. "\\rm"
  1551. "\\roman"
  1552. "\\rule"
  1553. "\\savebox"
  1554. "\\sc"
  1555. "\\scriptsize"
  1556. "\\setcounter"
  1557. "\\setlength"
  1558. "\\settowidth"
  1559. "\\sf"
  1560. "\\shortstack"
  1561. "\\signature"
  1562. "\\sl"
  1563. "\\small"
  1564. "\\smallskip"
  1565. "\\sqrt"
  1566. "\\tableofcontents"
  1567. "\\telephone"
  1568. "\\thanks"
  1569. "\\thispagestyle"
  1570. "\\tiny"
  1571. "\\title"
  1572. "\\tt"
  1573. "\\twocolumn"
  1574. "\\typein"
  1575. "\\typeout"
  1576. "\\underbrace"
  1577. "\\underline"
  1578. "\\usebox"
  1579. "\\usecounter"
  1580. "\\value"
  1581. "\\vdots"
  1582. "\\vector"
  1583. "\\verb"
  1584. "\\vfill"
  1585. "\\vline"
  1586. "\\vspace")
  1587. "A list of LaTeX commands to be protected when performing conversion.")
  1588. (defconst org-latex-entities-regexp
  1589. (let (names rest)
  1590. (dolist (x org-latex-entities)
  1591. (if (string-match "[a-z][A-Z]$" x)
  1592. (push x names)
  1593. (push x rest)))
  1594. (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
  1595. "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
  1596. (provide 'org-export-latex)
  1597. (provide 'org-latex)
  1598. ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
  1599. ;;; org-latex.el ends here