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