org-export-latex.el 58 KB

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