org-export-latex.el 56 KB

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