org-latex.el 58 KB

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