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