org-export-latex.el 56 KB

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