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