org-export-latex.el 55 KB

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