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