org-latex.el 59 KB

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