Release 6.36a
[org-mode/org-tableheadings.git] / lisp / org-latex.el
blob5e51a6a4a2f8964e8267dee9612b0c11e273d57b
1 ;;; org-latex.el --- LaTeX exporter for org-mode
2 ;;
3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 ;;
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: org-latex.el
7 ;; Version: 6.36
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)
52 (require 'org-macs)
53 (require 'org-beamer)
55 ;;; Variables:
56 (defvar org-export-latex-class nil)
57 (defvar org-export-latex-class-options nil)
58 (defvar org-export-latex-header nil)
59 (defvar org-export-latex-append-header nil)
60 (defvar org-export-latex-options-plist nil)
61 (defvar org-export-latex-todo-keywords-1 nil)
62 (defvar org-export-latex-complex-heading-re nil)
63 (defvar org-export-latex-not-done-keywords nil)
64 (defvar org-export-latex-done-keywords nil)
65 (defvar org-export-latex-display-custom-times nil)
66 (defvar org-export-latex-all-targets-re nil)
67 (defvar org-export-latex-add-level 0)
68 (defvar org-export-latex-sectioning "")
69 (defvar org-export-latex-sectioning-depth 0)
70 (defvar org-export-latex-special-keyword-regexp
71 (concat "\\<\\(" org-scheduled-string "\\|"
72 org-deadline-string "\\|"
73 org-closed-string"\\)")
74 "Regexp matching special time planning keywords plus the time after it.")
76 (defvar latexp) ; dynamically scoped from org.el
77 (defvar re-quote) ; dynamically scoped from org.el
78 (defvar commentsp) ; dynamically scoped from org.el
80 ;;; User variables:
82 (defgroup org-export-latex nil
83 "Options for exporting Org-mode files to LaTeX."
84 :tag "Org Export LaTeX"
85 :group 'org-export)
87 (defcustom org-export-latex-default-class "article"
88 "The default LaTeX class."
89 :group 'org-export-latex
90 :type '(string :tag "LaTeX class"))
92 (defcustom org-export-latex-classes
93 '(("article"
94 "\\documentclass[11pt]{article}"
95 ("\\section{%s}" . "\\section*{%s}")
96 ("\\subsection{%s}" . "\\subsection*{%s}")
97 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
98 ("\\paragraph{%s}" . "\\paragraph*{%s}")
99 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
100 ("report"
101 "\\documentclass[11pt]{report}"
102 ("\\part{%s}" . "\\part*{%s}")
103 ("\\chapter{%s}" . "\\chapter*{%s}")
104 ("\\section{%s}" . "\\section*{%s}")
105 ("\\subsection{%s}" . "\\subsection*{%s}")
106 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
107 ("book"
108 "\\documentclass[11pt]{book}"
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 ("beamer"
115 "\\documentclass{beamer}"
116 org-beamer-sectioning
118 "Alist of LaTeX classes and associated header and structure.
119 If #+LaTeX_CLASS is set in the buffer, use its value and the
120 associated information. Here is the structure of each cell:
122 \(class-name
123 header-string
124 (numbered-section . unnumbered-section\)
125 ...\)
127 The header string
128 -----------------
130 The HEADER-STRING is the header that will be inserted into the LaTeX file.
131 It should contain the \\documentclass macro, and anything else that is needed
132 for this setup. To this header, the following commands will be added:
134 - Calls to \\usepackage for all packages mentioned in the variables
135 `org-export-latex-default-packages-alist' and
136 `org-export-latex-packages-alist'. Thus, your header definitions should
137 avoid to also request these packages.
139 - Lines specified via \"#+LaTeX_HEADER:\"
141 If you need more control about the sequence in which the header is built
142 up, or if you want to exclude one of these building blocks for a particular
143 class, you can use the following macro-like placeholders.
145 [DEFAULT-PACKAGES] \\usepackage statements for default packages
146 [NO-DEFAULT-PACKAGES] do not include any of the default packages
147 [PACKAGES] \\usepackage statements for packages
148 [NO-PACKAGES] do not include the packages
149 [EXTRA] the stuff from #+LaTeX_HEADER
150 [NO-EXTRA] do not include #+LaTeX_HEADER stuff
152 So a header like
154 \\documentclass{article}
155 [NO-DEFAULT-PACKAGES]
156 [EXTRA]
157 \\providecommand{\\alert}[1]{\\textbf{#1}}
158 [PACKAGES]
160 will omit the default packages, and will include the #+LaTeX_HEADER lines,
161 then have a call to \\providecommand, and then place \\usepackage commands
162 based on the content of `org-export-latex-packages-alist'.
164 If your header or `org-export-latex-default-packages-alist' inserts
165 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be replaced with
166 a coding system derived from `buffer-file-coding-system'. See also the
167 variable `org-export-latex-inputenc-alist' for a way to influence this
168 mechanism.
170 The sectioning structure
171 ------------------------
173 The sectioning structure of the class is given by the elements following
174 the header string. For each sectioning level, a number of strings is
175 specified. A %s formatter is mandatory in each section string and will
176 be replaced by the title of the section.
178 Instead of a cons cell (numbered . unnumbered), you can also provide a list
179 of 2 or 4 elements,
181 (numbered-open numbered-close)
185 (numbered-open numbered-close unnumbered-open unnumbered-close)
187 providing opening and closing strings for a LaTeX environment that should
188 represent the document section. The opening clause should have a %s
189 to represent the section title.
191 Instead of a list of sectioning commands, you can also specify a
192 function name. That function will be called with two parameters,
193 the (reduced) level of the headline, and the headline text. The function
194 must return a cons cell with the (possibly modified) headline text, and the
195 sectioning list in the cdr."
196 :group 'org-export-latex
197 :type '(repeat
198 (list (string :tag "LaTeX class")
199 (string :tag "LaTeX header")
200 (repeat :tag "Levels" :inline t
201 (choice
202 (cons :tag "Heading"
203 (string :tag " numbered")
204 (string :tag "unnumbered"))
205 (list :tag "Environment"
206 (string :tag "Opening (numbered)")
207 (string :tag "Closing (numbered)")
208 (string :tag "Opening (unnumbered)")
209 (string :tag "Closing (unnumbered)"))
210 (function :tag "Hook computing sectioning"))))))
212 (defcustom org-export-latex-inputenc-alist nil
213 "Alist of inputenc coding system names, and what should really be used.
214 For example, adding an entry
216 (\"utf8\" . \"utf8x\")
218 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
219 are written as utf8 files."
220 :group 'org-export-latex
221 :type '(repeat
222 (cons
223 (string :tag "Derived from buffer")
224 (string :tag "Use this instead"))))
227 (defcustom org-export-latex-emphasis-alist
228 '(("*" "\\textbf{%s}" nil)
229 ("/" "\\emph{%s}" nil)
230 ("_" "\\underline{%s}" nil)
231 ("+" "\\st{%s}" nil)
232 ("=" "\\verb" t)
233 ("~" "\\verb" t))
234 "Alist of LaTeX expressions to convert emphasis fontifiers.
235 Each element of the list is a list of three elements.
236 The first element is the character used as a marker for fontification.
237 The second element is a formatting string to wrap fontified text with.
238 If it is \"\\verb\", Org will automatically select a delimiter
239 character that is not in the string.
240 The third element decides whether to protect converted text from other
241 conversions."
242 :group 'org-export-latex
243 :type 'alist)
245 (defcustom org-export-latex-title-command "\\maketitle"
246 "The command used to insert the title just after \\begin{document}.
247 If this string contains the formatting specification \"%s\" then
248 it will be used as a formatting string, passing the title as an
249 argument."
250 :group 'org-export-latex
251 :type 'string)
253 (defcustom org-export-latex-import-inbuffer-stuff nil
254 "Non-nil means define TeX macros for Org's inbuffer definitions.
255 For example \orgTITLE for #+TITLE."
256 :group 'org-export-latex
257 :type 'boolean)
259 (defcustom org-export-latex-date-format
260 "%d %B %Y"
261 "Format string for \\date{...}."
262 :group 'org-export-latex
263 :type 'string)
265 (defcustom org-export-latex-todo-keyword-markup "\\textbf{%s}"
266 "Markup for TODO keywords, as a printf format.
267 This can be a single format for all keywords, a cons cell with separate
268 formats for not-done and done states, or an association list with setup
269 for individual keywords. If a keyword shows up for which there is no
270 markup defined, the first one in the association list will be used."
271 :group 'org-export-latex
272 :type '(choice
273 (string :tag "Default")
274 (cons :tag "Distinguish undone and done"
275 (string :tag "Not-DONE states")
276 (string :tag "DONE states"))
277 (repeat :tag "Per keyword markup"
278 (cons
279 (string :tag "Keyword")
280 (string :tag "Markup")))))
282 (defcustom org-export-latex-timestamp-markup "\\textit{%s}"
283 "A printf format string to be applied to time stamps."
284 :group 'org-export-latex
285 :type 'string)
287 (defcustom org-export-latex-timestamp-keyword-markup "\\texttt{%s}"
288 "A printf format string to be applied to time stamps."
289 :group 'org-export-latex
290 :type 'string)
292 (defcustom org-export-latex-hyperref-format "\\href{%s}{%s}"
293 "A printf format string to be applied to hyperref links.
294 The format must contain two %s instances. The first will be filled with
295 the link, the second with the link description."
296 :group 'org-export-latex
297 :type 'string)
299 (defcustom org-export-latex-tables-verbatim nil
300 "When non-nil, tables are exported verbatim."
301 :group 'org-export-latex
302 :type 'boolean)
304 (defcustom org-export-latex-tables-centered t
305 "When non-nil, tables are exported in a center environment."
306 :group 'org-export-latex
307 :type 'boolean)
309 (defcustom org-export-latex-tables-column-borders nil
310 "When non-nil, grouping columns can cause outer vertical lines in tables.
311 When nil, grouping causes only separation lines between groups."
312 :group 'org-export-latex
313 :type 'boolean)
315 (defcustom org-export-latex-low-levels 'itemize
316 "How to convert sections below the current level of sectioning.
317 This is specified by the `org-export-headline-levels' option or the
318 value of \"H:\" in Org's #+OPTION line.
320 This can be either nil (skip the sections), `description', `itemize',
321 or `enumerate' (convert the sections as the corresponding list type), or
322 a string to be used instead of \\section{%s}. In this latter case,
323 the %s stands here for the inserted headline and is mandatory.
325 It may also be a list of three string to define a user-defined environment
326 that should be used. The first string should be the like
327 \"\\begin{itemize}\", the second should be like \"\\item %s %s\" with up
328 to two occurrences of %s for the title and a label, respectively. The third
329 string should be like \"\\end{itemize\"."
330 :group 'org-export-latex
331 :type '(choice (const :tag "Ignore" nil)
332 (const :tag "Convert as descriptive list" description)
333 (const :tag "Convert as itemized list" itemize)
334 (const :tag "Convert as enumerated list" enumerate)
335 (list :tag "User-defined environment"
336 :value ("\\begin{itemize}" "\\end{itemize}" "\\item %s")
337 (string :tag "Start")
338 (string :tag "End")
339 (string :tag "item"))
340 (string :tag "Use a section string" :value "\\subparagraph{%s}")))
342 (defcustom org-export-latex-list-parameters
343 '(:cbon "$\\boxtimes$" :cboff "$\\Box$")
344 "Parameters for the LaTeX list exporter.
345 These parameters will be passed on to `org-list-to-latex', which in turn
346 will pass them (combined with the LaTeX default list parameters) to
347 `org-list-to-generic'."
348 :group 'org-export-latex
349 :type 'plist)
351 (defcustom org-export-latex-verbatim-wrap
352 '("\\begin{verbatim}\n" . "\\end{verbatim}\n")
353 "Environment to be wrapped around a fixed-width section in LaTeX export.
354 This is a cons with two strings, to be added before and after the
355 fixed-with text.
357 Defaults to \\begin{verbatim} and \\end{verbatim}."
358 :group 'org-export-translation
359 :group 'org-export-latex
360 :type '(cons (string :tag "Open")
361 (string :tag "Close")))
363 (defcustom org-export-latex-listings nil
364 "Non-nil means export source code using the listings package.
365 This package will fontify source code, possibly even with color.
366 If you want to use this, you also need to make LaTeX use the
367 listings package, and if you want to have color, the color
368 package. Just add these to `org-export-latex-packages-alist',
369 for example using customize, or with something like
371 (require 'org-latex)
372 (add-to-list 'org-export-latex-packages-alist '(\"\" \"listings\"))
373 (add-to-list 'org-export-latex-packages-alist '(\"\" \"color\"))"
374 :group 'org-export-latex
375 :type 'boolean)
377 (defcustom org-export-latex-listings-langs
378 '((emacs-lisp "Lisp") (lisp "Lisp")
379 (c "C") (cc "C++")
380 (fortran "fortran")
381 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
382 (html "HTML") (xml "XML")
383 (tex "TeX") (latex "TeX")
384 (shell-script "bash")
385 (gnuplot "Gnuplot")
386 (ocaml "Caml") (caml "Caml")
387 (sql "SQL"))
388 "Alist mapping languages to their listing language counterpart.
389 The key is a symbol, the major mode symbol without the \"-mode\".
390 The value is the string that should be inserted as the language parameter
391 for the listings package. If the mode name and the listings name are
392 the same, the language does not need an entry in this list - but it does not
393 hurt if it is present."
394 :group 'org-export-latex
395 :type '(repeat
396 (list
397 (symbol :tag "Major mode ")
398 (string :tag "Listings language"))))
400 (defcustom org-export-latex-remove-from-headlines
401 '(:todo nil :priority nil :tags nil)
402 "A plist of keywords to remove from headlines. OBSOLETE.
403 Non-nil means remove this keyword type from the headline.
405 Don't remove the keys, just change their values.
407 Obsolete, this variable is no longer used. Use the separate
408 variables `org-export-with-todo-keywords', `org-export-with-priority',
409 and `org-export-with-tags' instead."
410 :type 'plist
411 :group 'org-export-latex)
413 (defcustom org-export-latex-image-default-option "width=10em"
414 "Default option for images."
415 :group 'org-export-latex
416 :type 'string)
418 (defcustom org-export-latex-inline-image-extensions
419 '("pdf" "jpeg" "jpg" "png" "ps" "eps")
420 "Extensions of image files that can be inlined into LaTeX.
421 Note that the image extension *actually* allowed depend on the way the
422 LaTeX file is processed. When used with pdflatex, pdf, jpg and png images
423 are OK. When processing through dvi to Postscript, only ps and eps are
424 allowed. The default we use here encompasses both."
425 :group 'org-export-latex
426 :type '(repeat (string :tag "Extension")))
428 (defcustom org-export-latex-coding-system nil
429 "Coding system for the exported LaTex file."
430 :group 'org-export-latex
431 :type 'coding-system)
433 (defgroup org-export-pdf nil
434 "Options for exporting Org-mode files to PDF, via LaTeX."
435 :tag "Org Export PDF"
436 :group 'org-export-latex
437 :group 'org-export)
439 (defcustom org-latex-to-pdf-process
440 '("pdflatex -interaction nonstopmode %s"
441 "pdflatex -interaction nonstopmode %s")
442 "Commands to process a LaTeX file to a PDF file.
443 This is a list of strings, each of them will be given to the shell
444 as a command. %s in the command will be replaced by the full file name, %b
445 by the file base name (i.e. without extension).
446 The reason why this is a list is that it usually takes several runs of
447 pdflatex, maybe mixed with a call to bibtex. Org does not have a clever
448 mechanism to detect which of these commands have to be run to get to a stable
449 result, and it also does not do any error checking.
451 Alternatively, this may be a Lisp function that does the processing, so you
452 could use this to apply the machinery of AUCTeX or the Emacs LaTeX mode.
453 This function should accept the file name as its single argument."
454 :group 'org-export-pdf
455 :type '(choice (repeat :tag "Shell command sequence"
456 (string :tag "Shell command"))
457 (function)))
459 (defcustom org-export-pdf-logfiles
460 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
461 "The list of file extensions to consider as LaTeX logfiles."
462 :group 'org-export-pdf
463 :type '(repeat (string :tag "Extension")))
465 (defcustom org-export-pdf-remove-logfiles t
466 "Non-nil means remove the logfiles produced by PDF production.
467 These are the .aux, .log, .out, and .toc files."
468 :group 'org-export-pdf
469 :type 'boolean)
471 ;;; Hooks
473 (defvar org-export-latex-after-initial-vars-hook nil
474 "Hook run before LaTeX export.
475 The exact moment is after the initial variables like org-export-latex-class
476 have been determined from the environment.")
478 (defvar org-export-latex-after-blockquotes-hook nil
479 "Hook run during LaTeX export, after blockquote, verse, center are done.")
481 (defvar org-export-latex-final-hook nil
482 "Hook run in the finalized LaTeX buffer.")
484 (defvar org-export-latex-after-save-hook nil
485 "Hook run in the finalized LaTeX buffer, after it has been saved.")
487 ;;; Autoload functions:
489 ;;;###autoload
490 (defun org-export-as-latex-batch ()
491 "Call `org-export-as-latex', may be used in batch processing.
492 For example:
494 emacs --batch
495 --load=$HOME/lib/emacs/org.el
496 --eval \"(setq org-export-headline-levels 2)\"
497 --visit=MyFile --funcall org-export-as-latex-batch"
498 (org-export-as-latex org-export-headline-levels 'hidden))
500 ;;;###autoload
501 (defun org-export-as-latex-to-buffer (arg)
502 "Call `org-export-as-latex` with output to a temporary buffer.
503 No file is created. The prefix ARG is passed through to `org-export-as-latex'."
504 (interactive "P")
505 (org-export-as-latex arg nil nil "*Org LaTeX Export*")
506 (when org-export-show-temporary-export-buffer
507 (switch-to-buffer-other-window "*Org LaTeX Export*")))
509 ;;;###autoload
510 (defun org-replace-region-by-latex (beg end)
511 "Replace the region from BEG to END with its LaTeX export.
512 It assumes the region has `org-mode' syntax, and then convert it to
513 LaTeX. This can be used in any buffer. For example, you could
514 write an itemized list in `org-mode' syntax in an LaTeX buffer and
515 then use this command to convert it."
516 (interactive "r")
517 (let (reg latex buf)
518 (save-window-excursion
519 (if (org-mode-p)
520 (setq latex (org-export-region-as-latex
521 beg end t 'string))
522 (setq reg (buffer-substring beg end)
523 buf (get-buffer-create "*Org tmp*"))
524 (with-current-buffer buf
525 (erase-buffer)
526 (insert reg)
527 (org-mode)
528 (setq latex (org-export-region-as-latex
529 (point-min) (point-max) t 'string)))
530 (kill-buffer buf)))
531 (delete-region beg end)
532 (insert latex)))
534 ;;;###autoload
535 (defun org-export-region-as-latex (beg end &optional body-only buffer)
536 "Convert region from BEG to END in `org-mode' buffer to LaTeX.
537 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
538 contents, and only produce the region of converted text, useful for
539 cut-and-paste operations.
540 If BUFFER is a buffer or a string, use/create that buffer as a target
541 of the converted LaTeX. If BUFFER is the symbol `string', return the
542 produced LaTeX as a string and leave no buffer behind. For example,
543 a Lisp program could call this function in the following way:
545 (setq latex (org-export-region-as-latex beg end t 'string))
547 When called interactively, the output buffer is selected, and shown
548 in a window. A non-interactive call will only return the buffer."
549 (interactive "r\nP")
550 (when (interactive-p)
551 (setq buffer "*Org LaTeX Export*"))
552 (let ((transient-mark-mode t) (zmacs-regions t)
553 ext-plist rtn)
554 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
555 (goto-char end)
556 (set-mark (point)) ;; to activate the region
557 (goto-char beg)
558 (setq rtn (org-export-as-latex
559 nil nil ext-plist
560 buffer body-only))
561 (if (fboundp 'deactivate-mark) (deactivate-mark))
562 (if (and (interactive-p) (bufferp rtn))
563 (switch-to-buffer-other-window rtn)
564 rtn)))
566 ;;;###autoload
567 (defun org-export-as-latex (arg &optional hidden ext-plist
568 to-buffer body-only pub-dir)
569 "Export current buffer to a LaTeX file.
570 If there is an active region, export only the region. The prefix
571 ARG specifies how many levels of the outline should become
572 headlines. The default is 3. Lower levels will be exported
573 depending on `org-export-latex-low-levels'. The default is to
574 convert them as description lists.
575 HIDDEN is obsolete and does nothing.
576 EXT-PLIST is a property list with
577 external parameters overriding org-mode's default settings, but
578 still inferior to file-local settings. When TO-BUFFER is
579 non-nil, create a buffer with that name and export to that
580 buffer. If TO-BUFFER is the symbol `string', don't leave any
581 buffer behind but just return the resulting LaTeX as a string.
582 When BODY-ONLY is set, don't produce the file header and footer,
583 simply return the content of \begin{document}...\end{document},
584 without even the \begin{document} and \end{document} commands.
585 when PUB-DIR is set, use this as the publishing directory."
586 (interactive "P")
587 (when (and (not body-only) arg (listp arg)) (setq body-only t))
588 (run-hooks 'org-export-first-hook)
590 ;; Make sure we have a file name when we need it.
591 (when (and (not (or to-buffer body-only))
592 (not buffer-file-name))
593 (if (buffer-base-buffer)
594 (org-set-local 'buffer-file-name
595 (with-current-buffer (buffer-base-buffer)
596 buffer-file-name))
597 (error "Need a file name to be able to export")))
599 (message "Exporting to LaTeX...")
600 (org-unmodified
601 (let ((inhibit-read-only t))
602 (remove-text-properties (point-min) (point-max)
603 '(:org-license-to-kill nil))))
604 (org-update-radio-target-regexp)
605 (org-export-latex-set-initial-vars ext-plist arg)
606 (setq org-export-opt-plist org-export-latex-options-plist)
607 (org-install-letbind)
608 (run-hooks 'org-export-latex-after-initial-vars-hook)
609 (let* ((wcf (current-window-configuration))
610 (opt-plist org-export-latex-options-plist)
611 (region-p (org-region-active-p))
612 (rbeg (and region-p (region-beginning)))
613 (rend (and region-p (region-end)))
614 (subtree-p
615 (if (plist-get opt-plist :ignore-subtree-p)
617 (when region-p
618 (save-excursion
619 (goto-char rbeg)
620 (and (org-at-heading-p)
621 (>= (org-end-of-subtree t t) rend))))))
622 (opt-plist (setq org-export-opt-plist
623 (if subtree-p
624 (org-export-add-subtree-options opt-plist rbeg)
625 opt-plist)))
626 ;; Make sure the variable contains the updated values.
627 (org-export-latex-options-plist (setq org-export-opt-plist opt-plist))
628 ;; The following two are dynamically scoped into other
629 ;; routines below.
630 (org-current-export-dir
631 (or pub-dir (org-export-directory :html opt-plist)))
632 (org-current-export-file buffer-file-name)
633 (title (or (and subtree-p (org-export-get-title-from-subtree))
634 (plist-get opt-plist :title)
635 (and (not
636 (plist-get opt-plist :skip-before-1st-heading))
637 (org-export-grab-title-from-buffer))
638 (and buffer-file-name
639 (file-name-sans-extension
640 (file-name-nondirectory buffer-file-name)))
641 "No Title"))
642 (filename
643 (and (not to-buffer)
644 (concat
645 (file-name-as-directory
646 (or pub-dir
647 (org-export-directory :LaTeX ext-plist)))
648 (file-name-sans-extension
649 (or (and subtree-p
650 (org-entry-get rbeg "EXPORT_FILE_NAME" t))
651 (file-name-nondirectory ;sans-extension
652 (or buffer-file-name
653 (error "Don't know which export file to use.")))))
654 ".tex")))
655 (filename
656 (and filename
657 (if (equal (file-truename filename)
658 (file-truename (or buffer-file-name "dummy.org")))
659 (concat filename ".tex")
660 filename)))
661 (buffer (if to-buffer
662 (cond
663 ((eq to-buffer 'string) (get-buffer-create
664 "*Org LaTeX Export*"))
665 (t (get-buffer-create to-buffer)))
666 (find-file-noselect filename)))
667 (odd org-odd-levels-only)
668 (header (org-export-latex-make-header title opt-plist))
669 (skip (cond (subtree-p nil)
670 (region-p nil)
671 (t (plist-get opt-plist :skip-before-1st-heading))))
672 (text (plist-get opt-plist :text))
673 (org-export-preprocess-hook
674 (cons
675 `(lambda () (org-set-local 'org-complex-heading-regexp
676 ,org-export-latex-complex-heading-re))
677 org-export-preprocess-hook))
678 (first-lines (if skip "" (org-export-latex-first-lines
679 opt-plist
680 (if subtree-p
681 (save-excursion
682 (goto-char rbeg)
683 (point-at-bol 2))
684 rbeg)
685 (if region-p rend))))
686 (coding-system (and (boundp 'buffer-file-coding-system)
687 buffer-file-coding-system))
688 (coding-system-for-write (or org-export-latex-coding-system
689 coding-system))
690 (save-buffer-coding-system (or org-export-latex-coding-system
691 coding-system))
692 (region (buffer-substring
693 (if region-p (region-beginning) (point-min))
694 (if region-p (region-end) (point-max))))
695 (text
696 (and text (string-match "\\S-" text)
697 (org-export-preprocess-string
698 text
699 :emph-multiline t
700 :for-LaTeX t
701 :comments nil
702 :tags (plist-get opt-plist :tags)
703 :priority (plist-get opt-plist :priority)
704 :footnotes (plist-get opt-plist :footnotes)
705 :drawers (plist-get opt-plist :drawers)
706 :timestamps (plist-get opt-plist :timestamps)
707 :todo-keywords (plist-get opt-plist :todo-keywords)
708 :add-text nil
709 :skip-before-1st-heading skip
710 :select-tags nil
711 :exclude-tags nil
712 :LaTeX-fragments nil)))
713 (string-for-export
714 (org-export-preprocess-string
715 region
716 :emph-multiline t
717 :for-LaTeX t
718 :comments nil
719 :tags (plist-get opt-plist :tags)
720 :priority (plist-get opt-plist :priority)
721 :footnotes (plist-get opt-plist :footnotes)
722 :drawers (plist-get opt-plist :drawers)
723 :timestamps (plist-get opt-plist :timestamps)
724 :todo-keywords (plist-get opt-plist :todo-keywords)
725 :add-text (if (eq to-buffer 'string) nil text)
726 :skip-before-1st-heading skip
727 :select-tags (plist-get opt-plist :select-tags)
728 :exclude-tags (plist-get opt-plist :exclude-tags)
729 :LaTeX-fragments nil)))
731 (set-buffer buffer)
732 (erase-buffer)
733 (org-install-letbind)
735 (and (fboundp 'set-buffer-file-coding-system)
736 (set-buffer-file-coding-system coding-system-for-write))
738 ;; insert the header and initial document commands
739 (unless (or (eq to-buffer 'string) body-only)
740 (insert header))
742 ;; insert text found in #+TEXT
743 (when (and text (not (eq to-buffer 'string)))
744 (insert (org-export-latex-content
745 text '(lists tables fixed-width keywords))
746 "\n\n"))
748 ;; insert lines before the first headline
749 (unless skip
750 (insert first-lines))
752 ;; export the content of headlines
753 (org-export-latex-global
754 (with-temp-buffer
755 (insert string-for-export)
756 (goto-char (point-min))
757 (when (re-search-forward "^\\(\\*+\\) " nil t)
758 (let* ((asters (length (match-string 1)))
759 (level (if odd (- asters 2) (- asters 1))))
760 (setq org-export-latex-add-level
761 (if odd (1- (/ (1+ asters) 2)) (1- asters)))
762 (org-export-latex-parse-global level odd)))))
764 ;; finalization
765 (unless body-only (insert "\n\\end{document}"))
767 ;; Attach description terms to the \item macro
768 (goto-char (point-min))
769 (while (re-search-forward "^[ \t]*\\\\item\\([ \t]+\\)\\[" nil t)
770 (delete-region (match-beginning 1) (match-end 1)))
772 ;; Relocate the table of contents
773 (goto-char (point-min))
774 (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
775 (goto-char (point-min))
776 (while (re-search-forward "\\\\tableofcontents\\>[ \t]*\n?" nil t)
777 (replace-match ""))
778 (goto-char (point-min))
779 (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
780 (replace-match "\\tableofcontents" t t)))
782 ;; Cleanup forced line ends in items where they are not needed
783 (goto-char (point-min))
784 (while (re-search-forward
785 "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*\n\\\\begin"
786 nil t)
787 (delete-region (match-beginning 1) (match-end 1)))
788 (goto-char (point-min))
789 (while (re-search-forward
790 "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*"
791 nil t)
792 (if (looking-at "[\n \t]+")
793 (replace-match "\n")))
795 (run-hooks 'org-export-latex-final-hook)
796 (if to-buffer
797 (unless (eq major-mode 'latex-mode) (latex-mode))
798 (save-buffer))
799 (org-export-latex-fix-inputenc)
800 (run-hooks 'org-export-latex-after-save-hook)
801 (goto-char (point-min))
802 (or (org-export-push-to-kill-ring "LaTeX")
803 (message "Exporting to LaTeX...done"))
804 (prog1
805 (if (eq to-buffer 'string)
806 (prog1 (buffer-substring (point-min) (point-max))
807 (kill-buffer (current-buffer)))
808 (current-buffer))
809 (set-window-configuration wcf))))
811 ;;;###autoload
812 (defun org-export-as-pdf (arg &optional hidden ext-plist
813 to-buffer body-only pub-dir)
814 "Export as LaTeX, then process through to PDF."
815 (interactive "P")
816 (message "Exporting to PDF...")
817 (let* ((wconfig (current-window-configuration))
818 (lbuf (org-export-as-latex arg hidden ext-plist
819 to-buffer body-only pub-dir))
820 (file (buffer-file-name lbuf))
821 (base (file-name-sans-extension (buffer-file-name lbuf)))
822 (pdffile (concat base ".pdf"))
823 (cmds org-latex-to-pdf-process)
824 (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
825 (bibtex-p (with-current-buffer lbuf
826 (save-excursion
827 (goto-char (point-min))
828 (re-search-forward "\\\\bibliography{" nil t))))
829 cmd)
830 (with-current-buffer outbuf (erase-buffer))
831 (message "Processing LaTeX file...")
832 (if (and cmds (symbolp cmds))
833 (funcall cmds file)
834 (while cmds
835 (setq cmd (pop cmds))
836 (while (string-match "%b" cmd)
837 (setq cmd (replace-match
838 (save-match-data
839 (shell-quote-argument base))
840 t t cmd)))
841 (while (string-match "%s" cmd)
842 (setq cmd (replace-match
843 (save-match-data
844 (shell-quote-argument file))
845 t t cmd)))
846 (shell-command cmd outbuf outbuf)))
847 (message "Processing LaTeX file...done")
848 (if (not (file-exists-p pdffile))
849 (error "PDF file was not produced")
850 (set-window-configuration wconfig)
851 (when org-export-pdf-remove-logfiles
852 (dolist (ext org-export-pdf-logfiles)
853 (setq file (concat base "." ext))
854 (and (file-exists-p file) (delete-file file))))
855 (message "Exporting to PDF...done")
856 pdffile)))
858 ;;;###autoload
859 (defun org-export-as-pdf-and-open (arg)
860 "Export as LaTeX, then process through to PDF, and open."
861 (interactive "P")
862 (let ((pdffile (org-export-as-pdf arg)))
863 (if pdffile
864 (progn
865 (org-open-file pdffile)
866 (when org-export-kill-product-buffer-when-displayed
867 (kill-buffer (find-buffer-visiting
868 (concat (file-name-sans-extension (buffer-file-name))
869 ".tex")))))
870 (error "PDF file was not produced"))))
872 ;;; Parsing functions:
874 (defun org-export-latex-parse-global (level odd)
875 "Parse the current buffer recursively, starting at LEVEL.
876 If ODD is non-nil, assume the buffer only contains odd sections.
877 Return a list reflecting the document structure."
878 (save-excursion
879 (goto-char (point-min))
880 (let* ((cnt 0) output
881 (depth org-export-latex-sectioning-depth))
882 (while (org-re-search-forward-unprotected
883 (concat "^\\(\\(?:\\*\\)\\{"
884 (number-to-string (+ (if odd 2 1) level))
885 "\\}\\) \\(.*\\)$")
886 ;; make sure that there is no upper heading
887 (when (> level 0)
888 (save-excursion
889 (save-match-data
890 (org-re-search-forward-unprotected
891 (concat "^\\(\\(?:\\*\\)\\{"
892 (number-to-string level)
893 "\\}\\) \\(.*\\)$") nil t)))) t)
894 (setq cnt (1+ cnt))
895 (let* ((pos (match-beginning 0))
896 (heading (match-string 2))
897 (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
898 (save-excursion
899 (narrow-to-region
900 (point)
901 (save-match-data
902 (if (org-re-search-forward-unprotected
903 (concat "^\\(\\(?:\\*\\)\\{"
904 (number-to-string (+ (if odd 2 1) level))
905 "\\}\\) \\(.*\\)$") nil t)
906 (match-beginning 0)
907 (point-max))))
908 (goto-char (point-min))
909 (setq output
910 (append output
911 (list
912 (list
913 `(pos . ,pos)
914 `(level . ,nlevel)
915 `(occur . ,cnt)
916 `(heading . ,heading)
917 `(content . ,(org-export-latex-parse-content))
918 `(subcontent . ,(org-export-latex-parse-subcontent
919 level odd)))))))
920 (widen)))
921 (list output))))
923 (defun org-export-latex-parse-content ()
924 "Extract the content of a section."
925 (let ((beg (point))
926 (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
927 (progn (beginning-of-line) (point))
928 (point-max))))
929 (buffer-substring beg end)))
931 (defun org-export-latex-parse-subcontent (level odd)
932 "Extract the subcontent of a section at LEVEL.
933 If ODD Is non-nil, assume subcontent only contains odd sections."
934 (if (not (org-re-search-forward-unprotected
935 (concat "^\\(\\(?:\\*\\)\\{"
936 (number-to-string (+ (if odd 4 2) level))
937 "\\}\\) \\(.*\\)$")
938 nil t))
939 nil ; subcontent is nil
940 (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
942 ;;; Rendering functions:
943 (defun org-export-latex-global (content)
944 "Export CONTENT to LaTeX.
945 CONTENT is an element of the list produced by
946 `org-export-latex-parse-global'."
947 (if (eq (car content) 'subcontent)
948 (mapc 'org-export-latex-sub (cdr content))
949 (org-export-latex-sub (car content))))
951 (defun org-export-latex-sub (subcontent)
952 "Export the list SUBCONTENT to LaTeX.
953 SUBCONTENT is an alist containing information about the headline
954 and its content."
955 (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
956 (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
958 (defun org-export-latex-subcontent (subcontent num)
959 "Export each cell of SUBCONTENT to LaTeX.
960 If NUM, export sections as numerical sections."
961 (let* ((heading (cdr (assoc 'heading subcontent)))
962 (level (- (cdr (assoc 'level subcontent))
963 org-export-latex-add-level))
964 (occur (number-to-string (cdr (assoc 'occur subcontent))))
965 (content (cdr (assoc 'content subcontent)))
966 (subcontent (cadr (assoc 'subcontent subcontent)))
967 (label (org-get-text-property-any 0 'target heading))
968 (label-list (cons label (cdr (assoc label
969 org-export-target-aliases))))
970 (sectioning org-export-latex-sectioning)
971 (depth org-export-latex-sectioning-depth)
972 main-heading sub-heading)
973 (when (symbolp (car sectioning))
974 (setq sectioning (funcall (car sectioning) level heading))
975 (when sectioning
976 (setq heading (car sectioning)
977 sectioning (cdr sectioning)
978 ;; target property migh have changed...
979 label (org-get-text-property-any 0 'target heading)
980 label-list (cons label (cdr (assoc label
981 org-export-target-aliases)))))
982 (if sectioning (setq sectioning (make-list 10 sectioning)))
983 (setq depth (if sectioning 10000 0)))
984 (if (string-match "[ \t]*\\\\\\\\[ \t]*" heading)
985 (setq main-heading (substring heading 0 (match-beginning 0))
986 sub-heading (substring heading (match-end 0))))
987 (setq heading (org-export-latex-fontify-headline heading)
988 sub-heading (and sub-heading
989 (org-export-latex-fontify-headline sub-heading))
990 main-heading (and main-heading
991 (org-export-latex-fontify-headline main-heading)))
992 (cond
993 ;; Normal conversion
994 ((<= level depth)
995 (let* ((sec (nth (1- level) sectioning))
996 start end)
997 (if (consp (cdr sec))
998 (setq start (nth (if num 0 2) sec)
999 end (nth (if num 1 3) sec))
1000 (setq start (if num (car sec) (cdr sec))))
1001 (insert (format start (if main-heading main-heading heading)
1002 (or sub-heading "")))
1003 (insert "\n")
1004 (when label
1005 (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
1006 label-list "\n") "\n"))
1007 (insert (org-export-latex-content content))
1008 (cond ((stringp subcontent) (insert subcontent))
1009 ((listp subcontent)
1010 (while (org-looking-back "\n\n") (backward-delete-char 1))
1011 (org-export-latex-sub subcontent)))
1012 (when (and end (string-match "[^ \t]" end))
1013 (let ((hook (org-get-text-property-any 0 'org-insert-hook end)))
1014 (and (functionp hook) (funcall hook)))
1015 (insert end "\n"))))
1016 ;; At a level under the hl option: we can drop this subsection
1017 ((> level depth)
1018 (cond ((eq org-export-latex-low-levels 'description)
1019 (if (string-match "% ends low level$"
1020 (buffer-substring (point-at-bol 0) (point)))
1021 (delete-region (point-at-bol 0) (point))
1022 (insert "\\begin{description}\n"))
1023 (insert (format "\n\\item[%s]%s~\n"
1024 heading
1025 (if label (format "\\label{%s}" label) "")))
1026 (insert (org-export-latex-content content))
1027 (cond ((stringp subcontent) (insert subcontent))
1028 ((listp subcontent) (org-export-latex-sub subcontent)))
1029 (insert "\\end{description} % ends low level\n"))
1030 ((memq org-export-latex-low-levels '(itemize enumerate))
1031 (if (string-match "% ends low level$"
1032 (buffer-substring (point-at-bol 0) (point)))
1033 (delete-region (point-at-bol 0) (point))
1034 (insert (format "\\begin{%s}\n"
1035 (symbol-name org-export-latex-low-levels))))
1036 (insert (format "\n\\item %s\\\\\n%s%%"
1037 heading
1038 (if label (format "\\label{%s}" label) "")))
1039 (insert (org-export-latex-content content))
1040 (cond ((stringp subcontent) (insert subcontent))
1041 ((listp subcontent) (org-export-latex-sub subcontent)))
1042 (insert (format "\\end{%s} %% ends low level\n"
1043 (symbol-name org-export-latex-low-levels))))
1045 ((listp org-export-latex-low-levels)
1046 (if (string-match "% ends low level$"
1047 (buffer-substring (point-at-bol 0) (point)))
1048 (delete-region (point-at-bol 0) (point))
1049 (insert (car org-export-latex-low-levels) "\n"))
1050 (insert (format (nth 2 org-export-latex-low-levels)
1051 heading
1052 (if label (format "\\label{%s}" label) "")))
1053 (insert (org-export-latex-content content))
1054 (cond ((stringp subcontent) (insert subcontent))
1055 ((listp subcontent) (org-export-latex-sub subcontent)))
1056 (insert (nth 1 org-export-latex-low-levels)
1057 " %% ends low level\n"))
1059 ((stringp org-export-latex-low-levels)
1060 (insert (format org-export-latex-low-levels heading) "\n")
1061 (when label (insert (format "\\label{%s}\n" label)))
1062 (insert (org-export-latex-content content))
1063 (cond ((stringp subcontent) (insert subcontent))
1064 ((listp subcontent) (org-export-latex-sub subcontent)))))))))
1066 ;;; Exporting internals:
1067 (defun org-export-latex-set-initial-vars (ext-plist level)
1068 "Store org local variables required for LaTeX export.
1069 EXT-PLIST is an optional additional plist.
1070 LEVEL indicates the default depth for export."
1071 (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
1072 org-export-latex-done-keywords org-done-keywords
1073 org-export-latex-not-done-keywords org-not-done-keywords
1074 org-export-latex-complex-heading-re org-complex-heading-regexp
1075 org-export-latex-display-custom-times org-display-custom-times
1076 org-export-latex-all-targets-re
1077 (org-make-target-link-regexp (org-all-targets))
1078 org-export-latex-options-plist
1079 (org-combine-plists (org-default-export-plist) ext-plist
1080 (org-infile-export-plist))
1081 org-export-latex-class
1082 (or (and (org-region-active-p)
1083 (save-excursion
1084 (goto-char (region-beginning))
1085 (and (looking-at org-complex-heading-regexp)
1086 (org-entry-get nil "LaTeX_CLASS" 'selective))))
1087 (save-excursion
1088 (save-restriction
1089 (widen)
1090 (goto-char (point-min))
1091 (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\(-[a-zA-Z]+\\)" nil t)
1092 (match-string 1))))
1093 (plist-get org-export-latex-options-plist :latex-class)
1094 org-export-latex-default-class)
1095 org-export-latex-class-options
1096 (or (and (org-region-active-p)
1097 (save-excursion
1098 (goto-char (region-beginning))
1099 (and (looking-at org-complex-heading-regexp)
1100 (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
1101 (save-excursion
1102 (save-restriction
1103 (widen)
1104 (goto-char (point-min))
1105 (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
1106 (match-string 1))))
1107 (plist-get org-export-latex-options-plist :latex-class-options))
1108 org-export-latex-class
1109 (or (car (assoc org-export-latex-class org-export-latex-classes))
1110 (error "No definition for class `%s' in `org-export-latex-classes'"
1111 org-export-latex-class))
1112 org-export-latex-header
1113 (cadr (assoc org-export-latex-class org-export-latex-classes))
1114 org-export-latex-sectioning
1115 (cddr (assoc org-export-latex-class org-export-latex-classes))
1116 org-export-latex-sectioning-depth
1117 (or level
1118 (let ((hl-levels
1119 (plist-get org-export-latex-options-plist :headline-levels))
1120 (sec-depth (length org-export-latex-sectioning)))
1121 (if (> hl-levels sec-depth) sec-depth hl-levels))))
1122 (when (and org-export-latex-class-options
1123 (string-match "\\S-" org-export-latex-class-options)
1124 (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?"
1125 org-export-latex-header))
1126 (setq org-export-latex-header
1127 (concat (substring org-export-latex-header 0 (match-end 1))
1128 org-export-latex-class-options
1129 (substring org-export-latex-header (match-end 0))))))
1131 (defvar org-export-latex-format-toc-function
1132 'org-export-latex-format-toc-default
1133 "The function formatting returning the string to createthe table of contents.
1134 The function mus take one parameter, the depth of the table of contents.")
1136 (defun org-export-latex-make-header (title opt-plist)
1137 "Make the LaTeX header and return it as a string.
1138 TITLE is the current title from the buffer or region.
1139 OPT-PLIST is the options plist for current buffer."
1140 (let ((toc (plist-get opt-plist :table-of-contents))
1141 (author (org-export-apply-macros-in-string
1142 (plist-get opt-plist :author))))
1143 (concat
1144 (if (plist-get opt-plist :time-stamp-file)
1145 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1146 ;; insert LaTeX custom header and packages from the list
1147 (org-splice-latex-header
1148 (org-export-apply-macros-in-string org-export-latex-header)
1149 org-export-latex-default-packages-alist
1150 org-export-latex-packages-alist nil
1151 (org-export-apply-macros-in-string
1152 (plist-get opt-plist :latex-header-extra)))
1153 ;; append another special variable
1154 (org-export-apply-macros-in-string org-export-latex-append-header)
1155 ;; define align if not yet defined
1156 "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
1157 ;; insert the title
1158 (format
1159 "\n\n\\title{%s}\n"
1160 ;; convert the title
1161 (org-export-latex-content
1162 title '(lists tables fixed-width keywords)))
1163 ;; insert author info
1164 (if (plist-get opt-plist :author-info)
1165 (format "\\author{%s}\n"
1166 (org-export-latex-fontify-headline (or author user-full-name)))
1167 (format "%%\\author{%s}\n"
1168 (org-export-latex-fontify-headline (or author user-full-name))))
1169 ;; insert the date
1170 (format "\\date{%s}\n"
1171 (format-time-string
1172 (or (plist-get opt-plist :date)
1173 org-export-latex-date-format)))
1174 ;; beginning of the document
1175 "\n\\begin{document}\n\n"
1176 ;; insert the title command
1177 (when (string-match "\\S-" title)
1178 (if (string-match "%s" org-export-latex-title-command)
1179 (format org-export-latex-title-command title)
1180 org-export-latex-title-command))
1181 "\n\n"
1182 ;; table of contents
1183 (when (and org-export-with-toc
1184 (plist-get opt-plist :section-numbers))
1185 (funcall org-export-latex-format-toc-function
1186 (cond ((numberp toc)
1187 (min toc (plist-get opt-plist :headline-levels)))
1188 (toc (plist-get opt-plist :headline-levels))))))))
1190 (defun org-export-latex-format-toc-default (depth)
1191 (when depth
1192 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
1193 depth)))
1195 (defun org-export-latex-first-lines (opt-plist &optional beg end)
1196 "Export the first lines before first headline.
1197 If BEG is non-nil, it is the beginning of the region.
1198 If END is non-nil, it is the end of the region."
1199 (save-excursion
1200 (goto-char (or beg (point-min)))
1201 (let* ((pt (point))
1202 (end (if (re-search-forward "^\\*+ " end t)
1203 (goto-char (match-beginning 0))
1204 (goto-char (or end (point-max))))))
1205 (prog1
1206 (org-export-latex-content
1207 (org-export-preprocess-string
1208 (buffer-substring pt end)
1209 :for-LaTeX t
1210 :emph-multiline t
1211 :add-text nil
1212 :comments nil
1213 :skip-before-1st-heading nil
1214 :LaTeX-fragments nil
1215 :timestamps (plist-get opt-plist :timestamps)
1216 :footnotes (plist-get opt-plist :footnotes)))
1217 (org-unmodified
1218 (let ((inhibit-read-only t))
1219 (add-text-properties pt (max pt (1- end))
1220 '(:org-license-to-kill t))))))))
1222 (defvar org-export-latex-header-defs nil
1223 "The header definitions that might be used in the LaTeX body.")
1224 (defvar org-export-latex-header-defs-re nil
1225 "The header definitions that might be used in the LaTeX body.")
1227 (defun org-export-latex-content (content &optional exclude-list)
1228 "Convert CONTENT string to LaTeX.
1229 Don't perform conversions that are in EXCLUDE-LIST. Recognized
1230 conversion types are: quotation-marks, emphasis, sub-superscript,
1231 links, keywords, lists, tables, fixed-width"
1232 (with-temp-buffer
1233 (insert content)
1234 (unless (memq 'timestamps exclude-list)
1235 (org-export-latex-time-stamps))
1236 (unless (memq 'quotation-marks exclude-list)
1237 (org-export-latex-quotation-marks))
1238 (unless (memq 'emphasis exclude-list)
1239 (when (plist-get org-export-latex-options-plist :emphasize)
1240 (org-export-latex-fontify)))
1241 (unless (memq 'sub-superscript exclude-list)
1242 (org-export-latex-special-chars
1243 (plist-get org-export-latex-options-plist :sub-superscript)))
1244 (unless (memq 'links exclude-list)
1245 (org-export-latex-links))
1246 (unless (memq 'keywords exclude-list)
1247 (org-export-latex-keywords))
1248 (unless (memq 'lists exclude-list)
1249 (org-export-latex-lists))
1250 (unless (memq 'tables exclude-list)
1251 (org-export-latex-tables
1252 (plist-get org-export-latex-options-plist :tables)))
1253 (unless (memq 'fixed-width exclude-list)
1254 (org-export-latex-fixed-width
1255 (plist-get org-export-latex-options-plist :fixed-width)))
1256 ;; return string
1257 (buffer-substring (point-min) (point-max))))
1259 (defun org-export-latex-protect-string (s)
1260 "Add the org-protected property to string S."
1261 (add-text-properties 0 (length s) '(org-protected t) s) s)
1263 (defun org-export-latex-protect-char-in-string (char-list string)
1264 "Add org-protected text-property to char from CHAR-LIST in STRING."
1265 (with-temp-buffer
1266 (save-match-data
1267 (insert string)
1268 (goto-char (point-min))
1269 (while (re-search-forward (regexp-opt char-list) nil t)
1270 (add-text-properties (match-beginning 0)
1271 (match-end 0) '(org-protected t)))
1272 (buffer-string))))
1274 (defun org-export-latex-keywords-maybe (&optional remove-list)
1275 "Maybe remove keywords depending on rules in REMOVE-LIST."
1276 (goto-char (point-min))
1277 (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
1278 (case-fold-search nil)
1279 (todo-markup org-export-latex-todo-keyword-markup)
1280 fmt)
1281 ;; convert TODO keywords
1282 (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
1283 (if (plist-get remove-list :todo)
1284 (replace-match "")
1285 (setq fmt (cond
1286 ((stringp todo-markup) todo-markup)
1287 ((and (consp todo-markup) (stringp (car todo-markup)))
1288 (if (member (match-string 1) org-export-latex-done-keywords)
1289 (cdr todo-markup) (car todo-markup)))
1290 (t (cdr (or (assoc (match-string 1) todo-markup)
1291 (car todo-markup))))))
1292 (replace-match (format fmt (match-string 1)) t t)))
1293 ;; convert priority string
1294 (when (re-search-forward "\\[\\\\#.\\]" nil t)
1295 (if (plist-get remove-list :priority)
1296 (replace-match "")
1297 (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
1298 ;; convert tags
1299 (when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
1300 (if (or (not org-export-with-tags)
1301 (plist-get remove-list :tags))
1302 (replace-match "")
1303 (replace-match
1304 (org-export-latex-protect-string
1305 (format "\\textbf{%s}"
1306 (save-match-data
1307 (replace-regexp-in-string
1308 "_" "\\\\_" (match-string 0)))))
1309 t t)))))
1311 (defun org-export-latex-fontify-headline (string)
1312 "Fontify special words in STRING."
1313 (with-temp-buffer
1314 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
1315 ;; the beginning of the buffer - inserting "\n" is safe here though.
1316 (insert "\n" string)
1317 (goto-char (point-min))
1318 (let ((re (concat "\\\\\\([a-zA-Z]+\\)"
1319 "\\(?:<[^<>\n]*>\\)*"
1320 "\\(?:\\[[^][\n]*?\\]\\)*"
1321 "\\(?:<[^<>\n]*>\\)*"
1322 "\\("
1323 (org-create-multibrace-regexp "{" "}" 3)
1324 "\\)\\{1,3\\}")))
1325 (while (re-search-forward re nil t)
1326 (unless (or
1327 ;; check for comment line
1328 (save-excursion (goto-char (match-beginning 0))
1329 (equal (char-after (point-at-bol)) ?#))
1330 ;; Check if this is a defined entity, so that is may need conversion
1331 (org-entity-get (match-string 1)))
1332 (add-text-properties (match-beginning 0) (match-end 0)
1333 '(org-protected t)))))
1334 (when (plist-get org-export-latex-options-plist :emphasize)
1335 (org-export-latex-fontify))
1336 (org-export-latex-keywords-maybe)
1337 (org-export-latex-special-chars
1338 (plist-get org-export-latex-options-plist :sub-superscript))
1339 (org-export-latex-links)
1340 (org-trim (buffer-string))))
1342 (defun org-export-latex-time-stamps ()
1343 "Format time stamps."
1344 (goto-char (point-min))
1345 (let ((org-display-custom-times org-export-latex-display-custom-times))
1346 (while (re-search-forward org-ts-regexp-both nil t)
1347 (org-if-unprotected-at (1- (point))
1348 (replace-match
1349 (org-export-latex-protect-string
1350 (format org-export-latex-timestamp-markup
1351 (substring (org-translate-time (match-string 0)) 1 -1)))
1352 t t)))))
1354 (defun org-export-latex-quotation-marks ()
1355 "Export quotation marks depending on language conventions."
1356 (let* ((lang (plist-get org-export-latex-options-plist :language))
1357 (quote-rpl (if (equal lang "fr")
1358 '(("\\(\\s-\\)\"" "«~")
1359 ("\\(\\S-\\)\"" "~»")
1360 ("\\(\\s-\\)'" "`"))
1361 '(("\\(\\s-\\|[[(]\\)\"" "``")
1362 ("\\(\\S-\\)\"" "''")
1363 ("\\(\\s-\\|(\\)'" "`")))))
1364 (mapc (lambda(l) (goto-char (point-min))
1365 (while (re-search-forward (car l) nil t)
1366 (let ((rpl (concat (match-string 1)
1367 (org-export-latex-protect-string
1368 (copy-sequence (cadr l))))))
1369 (org-if-unprotected-1
1370 (replace-match rpl t t))))) quote-rpl)))
1372 (defun org-export-latex-special-chars (sub-superscript)
1373 "Export special characters to LaTeX.
1374 If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
1375 See the `org-export-latex.el' code for a complete conversion table."
1376 (goto-char (point-min))
1377 (mapc (lambda(c)
1378 (goto-char (point-min))
1379 (while (re-search-forward c nil t)
1380 ;; Put the point where to check for org-protected
1381 (unless (get-text-property (match-beginning 2) 'org-protected)
1382 (cond ((member (match-string 2) '("\\$" "$"))
1383 (if (equal (match-string 2) "\\$")
1385 (replace-match "\\$" t t)))
1386 ((member (match-string 2) '("&" "%" "#"))
1387 (if (equal (match-string 1) "\\")
1388 (replace-match (match-string 2) t t)
1389 (replace-match (concat (match-string 1) "\\"
1390 (match-string 2)) t t)
1391 (backward-char 1)))
1392 ((equal (match-string 2) "...")
1393 (replace-match
1394 (concat (match-string 1)
1395 (org-export-latex-protect-string "\\ldots{}")) t t))
1396 ((equal (match-string 2) "~")
1397 (cond ((equal (match-string 1) "\\") nil)
1398 ((eq 'org-link (get-text-property 0 'face (match-string 2)))
1399 (replace-match (concat (match-string 1) "\\~") t t))
1400 (t (replace-match
1401 (org-export-latex-protect-string
1402 (concat (match-string 1) "\\~{}")) t t))))
1403 ((member (match-string 2) '("{" "}"))
1404 (unless (save-match-data (org-inside-latex-math-p))
1405 (if (equal (match-string 1) "\\")
1406 (replace-match (match-string 2) t t)
1407 (replace-match (concat (match-string 1) "\\"
1408 (match-string 2)) t t)))))
1409 (unless (save-match-data (org-inside-latex-math-p))
1410 (cond ((equal (match-string 2) "\\")
1411 (replace-match (or (save-match-data
1412 (org-export-latex-treat-backslash-char
1413 (match-string 1)
1414 (or (match-string 3) "")))
1415 "") t t)
1416 (when (and (get-text-property (1- (point)) 'org-entity)
1417 (looking-at "{}"))
1418 ;; OK, this was an entity replacement, and the user
1419 ;; had terminated the entity with {}. Make sure
1420 ;; {} is protected as well, and remove the extra {}
1421 ;; inserted by the conversion.
1422 (put-text-property (point) (+ 2 (point)) 'org-protected t)
1423 (if (save-excursion (goto-char (max (- (point) 2) (point-min)))
1424 (looking-at "{}"))
1425 (replace-match ""))
1426 (forward-char 2))
1427 (backward-char 1))
1428 ((member (match-string 2) '("_" "^"))
1429 (replace-match (or (save-match-data
1430 (org-export-latex-treat-sub-super-char
1431 sub-superscript
1432 (match-string 2)
1433 (match-string 1)
1434 (match-string 3))) "") t t)
1435 (backward-char 1)))))))
1436 '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
1437 "\\(\\(\\\\?\\$\\)\\)"
1438 "\\([a-zA-Z0-9()]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-zA-Z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-zA-Z0-9]+}\\|([a-zA-Z0-9]+)\\)"
1439 "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|\\([&#%{}\"]\\|[a-zA-Z][a-zA-Z0-9]*\\)\\)"
1440 "\\(.\\|^\\)\\(&\\)"
1441 "\\(.\\|^\\)\\(#\\)"
1442 "\\(.\\|^\\)\\(%\\)"
1443 "\\(.\\|^\\)\\({\\)"
1444 "\\(.\\|^\\)\\(}\\)"
1445 "\\(.\\|^\\)\\(~\\)"
1446 "\\(.\\|^\\)\\(\\.\\.\\.\\)"
1447 ;; (?\< . "\\textless{}")
1448 ;; (?\> . "\\textgreater{}")
1451 (defun org-inside-latex-math-p ()
1452 (get-text-property (point) 'org-latex-math))
1454 (defun org-export-latex-treat-sub-super-char
1455 (subsup char string-before string-after)
1456 "Convert the \"_\" and \"^\" characters to LaTeX.
1457 SUBSUP corresponds to the ^: option in the #+OPTIONS line.
1458 Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
1459 (cond ((equal string-before "\\")
1460 (concat string-before char string-after))
1461 ((and (string-match "\\S-+" string-after))
1462 ;; this is part of a math formula
1463 (cond ((eq 'org-link (get-text-property 0 'face char))
1464 (concat string-before "\\" char string-after))
1465 ((save-match-data (org-inside-latex-math-p))
1466 (if subsup
1467 (cond ((eq 1 (length string-after))
1468 (concat string-before char string-after))
1469 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
1470 (format "%s%s{%s}" string-before char
1471 (match-string 1 string-after))))))
1472 ((and (> (length string-after) 1)
1473 (or (eq subsup t)
1474 (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
1475 (or (string-match "[{]?\\([^}]+\\)[}]?" string-after)
1476 (string-match "[(]?\\([^)]+\\)[)]?" string-after)))
1478 (org-export-latex-protect-string
1479 (format "%s$%s{%s}$" string-before char
1480 (if (and (> (match-end 1) (1+ (match-beginning 1)))
1481 (not (equal (substring string-after 0 2) "{\\")))
1482 (concat "\\mathrm{" (match-string 1 string-after) "}")
1483 (match-string 1 string-after)))))
1484 ((eq subsup t) (concat string-before "$" char string-after "$"))
1485 (t (org-export-latex-protect-string
1486 (concat string-before "\\" char "{}" string-after)))))
1487 (t (org-export-latex-protect-string
1488 (concat string-before "\\" char "{}" string-after)))))
1490 (defun org-export-latex-treat-backslash-char (string-before string-after)
1491 "Convert the \"$\" special character to LaTeX.
1492 The conversion is made depending of STRING-BEFORE and STRING-AFTER."
1493 (let ((ass (org-entity-get string-after)))
1494 (cond
1495 (ass (org-add-props
1496 (if (nth 2 ass)
1497 (concat string-before
1498 (org-export-latex-protect-string
1499 (concat "$" (nth 1 ass) "$")))
1500 (concat string-before (org-export-latex-protect-string
1501 (nth 1 ass))))
1502 nil 'org-entity t))
1503 ((and (not (string-match "^[ \n\t]" string-after))
1504 (not (string-match "[ \t]\\'\\|^" string-before)))
1505 ;; backslash is inside a word
1506 (concat string-before
1507 (org-export-latex-protect-string
1508 (concat "\\textbackslash{}" string-after))))
1509 ((not (or (equal string-after "")
1510 (string-match "^[ \t\n]" string-after)))
1511 ;; backslash might escape a character (like \#) or a user TeX
1512 ;; macro (like \setcounter)
1513 (concat string-before
1514 (org-export-latex-protect-string (concat "\\" string-after))))
1515 ((and (string-match "^[ \t\n]" string-after)
1516 (string-match "[ \t\n]\\'" string-before))
1517 ;; backslash is alone, convert it to $\backslash$
1518 (org-export-latex-protect-string
1519 (concat string-before "\\textbackslash{}" string-after)))
1520 (t (org-export-latex-protect-string
1521 (concat string-before "\\textbackslash{}" string-after))))))
1523 (defun org-export-latex-keywords ()
1524 "Convert special keywords to LaTeX."
1525 (goto-char (point-min))
1526 (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
1527 (replace-match (format org-export-latex-timestamp-keyword-markup
1528 (match-string 0)) t t)
1529 (save-excursion
1530 (beginning-of-line 1)
1531 (unless (looking-at ".*\n[ \t]*\n")
1532 (end-of-line 1)
1533 (insert "\n")))))
1535 (defun org-export-latex-fixed-width (opt)
1536 "When OPT is non-nil convert fixed-width sections to LaTeX."
1537 (goto-char (point-min))
1538 (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
1539 (if opt
1540 (progn (goto-char (match-beginning 0))
1541 (insert "\\begin{verbatim}\n")
1542 (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
1543 (replace-match (concat (match-string 1)
1544 (match-string 2)) t t)
1545 (forward-line))
1546 (insert "\\end{verbatim}\n\n"))
1547 (progn (goto-char (match-beginning 0))
1548 (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
1549 (replace-match (concat "%" (match-string 1)
1550 (match-string 2)) t t)
1551 (forward-line))))))
1554 (defvar org-table-last-alignment) ; defined in org-table.el
1555 (defvar org-table-last-column-widths) ; defined in org-table.el
1556 (declare-function orgtbl-to-latex "org-table" (table params) t)
1557 (defun org-export-latex-tables (insert)
1558 "Convert tables to LaTeX and INSERT it."
1559 ;; First, get the table.el tables
1560 (goto-char (point-min))
1561 (while (re-search-forward "^[ \t]*\\(\\+-[-+]*\\+\\)[ \t]*\n[ \t]*|" nil t)
1562 (org-if-unprotected
1563 (require 'table)
1564 (org-export-latex-convert-table.el-table)))
1566 ;; And now the Org-mode tables
1567 (goto-char (point-min))
1568 (while (re-search-forward "^\\([ \t]*\\)|" nil t)
1569 (org-if-unprotected-at (1- (point))
1570 (org-table-align)
1571 (let* ((beg (org-table-begin))
1572 (end (org-table-end))
1573 (raw-table (buffer-substring beg end))
1574 (org-table-last-alignment (copy-sequence org-table-last-alignment))
1575 (org-table-last-column-widths (copy-sequence
1576 org-table-last-column-widths))
1577 fnum fields line lines olines gr colgropen line-fmt align
1578 caption label attr floatp longtblp)
1579 (if org-export-latex-tables-verbatim
1580 (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
1581 "\\end{verbatim}\n")))
1582 (apply 'delete-region (list beg end))
1583 (insert (org-export-latex-protect-string tbl)))
1584 (progn
1585 (setq caption (org-find-text-property-in-string
1586 'org-caption raw-table)
1587 attr (org-find-text-property-in-string
1588 'org-attributes raw-table)
1589 label (org-find-text-property-in-string
1590 'org-label raw-table)
1591 longtblp (and attr (stringp attr)
1592 (string-match "\\<longtable\\>" attr))
1593 align (and attr (stringp attr)
1594 (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
1595 (match-string 1 attr))
1596 floatp (or caption label))
1597 (setq caption (and caption (org-export-latex-fontify-headline caption)))
1598 (setq lines (org-split-string raw-table "\n"))
1599 (apply 'delete-region (list beg end))
1600 (when org-export-table-remove-special-lines
1601 (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
1602 (when org-table-clean-did-remove-column
1603 (pop org-table-last-alignment)
1604 (pop org-table-last-column-widths))
1605 ;; make a formatting string to reflect alignment
1606 (setq olines lines)
1607 (while (and (not line-fmt) (setq line (pop olines)))
1608 (unless (string-match "^[ \t]*|-" line)
1609 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1610 (setq fnum (make-vector (length fields) 0))
1611 (setq line-fmt
1612 (mapconcat
1613 (lambda (x)
1614 (setq gr (pop org-table-colgroup-info))
1615 (format "%s%%s%s"
1616 (cond ((eq gr :start)
1617 (prog1 (if colgropen "|" "|")
1618 (setq colgropen t)))
1619 ((eq gr :startend)
1620 (prog1 (if colgropen "|" "|")
1621 (setq colgropen nil)))
1622 (t ""))
1623 (if (memq gr '(:end :startend))
1624 (progn (setq colgropen nil) "|")
1625 "")))
1626 fnum ""))))
1627 ;; fix double || in line-fmt
1628 (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
1629 ;; maybe remove the first and last "|"
1630 (when (and (not org-export-latex-tables-column-borders)
1631 (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
1632 (setq line-fmt (match-string 2 line-fmt)))
1633 ;; format alignment
1634 (unless align
1635 (setq align (apply 'format
1636 (cons line-fmt
1637 (mapcar (lambda (x) (if x "r" "l"))
1638 org-table-last-alignment)))))
1639 ;; prepare the table to send to orgtbl-to-latex
1640 (setq lines
1641 (mapcar
1642 (lambda(elem)
1643 (or (and (string-match "[ \t]*|-+" elem) 'hline)
1644 (org-split-string (org-trim elem) "|")))
1645 lines))
1646 (when insert
1647 (insert (org-export-latex-protect-string
1648 (concat
1649 (if longtblp
1650 (concat "\\begin{longtable}{" align "}\n")
1651 (if floatp "\\begin{table}[htb]\n"))
1652 (if floatp
1653 (format
1654 "\\caption{%s%s}"
1655 (if label (concat "\\\label{" label "}") "")
1656 (or caption "")))
1657 (if (and longtblp caption) "\\\\\n" "\n")
1658 (if (and org-export-latex-tables-centered (not longtblp))
1659 "\\begin{center}\n")
1660 (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
1661 (orgtbl-to-latex
1662 lines
1663 `(:tstart nil :tend nil
1664 :hlend ,(if longtblp
1665 (format "\\\\
1666 \\hline
1667 \\endhead
1668 \\hline\\multicolumn{%d}{r}{Continued on next page}\\
1669 \\endfoot
1670 \\endlastfoot" (length org-table-last-alignment))
1671 nil)))
1672 (if (not longtblp) (concat "\n\\end{tabular}"))
1673 (if longtblp "\n" (if org-export-latex-tables-centered
1674 "\n\\end{center}\n" "\n"))
1675 (if longtblp
1676 "\\end{longtable}"
1677 (if floatp "\\end{table}"))))
1678 "\n\n"))))))))
1680 (defun org-export-latex-convert-table.el-table ()
1681 "Replace table.el table at point with LaTeX code."
1682 (let (tbl caption label line floatp attr align rmlines)
1683 (setq line (buffer-substring (point-at-bol) (point-at-eol))
1684 label (org-get-text-property-any 0 'org-label line)
1685 caption (org-get-text-property-any 0 'org-caption line)
1686 attr (org-get-text-property-any 0 'org-attributes line)
1687 align (and attr (stringp attr)
1688 (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
1689 (match-string 1 attr))
1690 rmlines (and attr (stringp attr)
1691 (string-match "\\<rmlines\\>" attr))
1692 floatp (or label caption))
1693 (and (get-buffer "*org-export-table*")
1694 (kill-buffer (get-buffer "*org-export-table*")))
1695 (table-generate-source 'latex "*org-export-table*" "caption")
1696 (setq tbl (with-current-buffer "*org-export-table*"
1697 (buffer-string)))
1698 (while (string-match "^%.*\n" tbl)
1699 (setq tbl (replace-match "" t t tbl)))
1700 ;; fix the hlines
1701 (when rmlines
1702 (let ((n 0) lines)
1703 (setq lines (mapcar (lambda (x)
1704 (if (string-match "^\\\\hline$" x)
1705 (progn
1706 (setq n (1+ n))
1707 (if (= n 2) x nil))
1709 (org-split-string tbl "\n")))
1710 (setq tbl (mapconcat 'identity (delq nil lines) "\n"))))
1711 (when (and align (string-match "\\\\begin{tabular}{.*}" tbl))
1712 (setq tbl (replace-match (concat "\\begin{tabular}{" align "}")
1713 t t tbl)))
1714 (and (get-buffer "*org-export-table*")
1715 (kill-buffer (get-buffer "*org-export-table*")))
1716 (beginning-of-line 0)
1717 (while (looking-at "[ \t]*\\(|\\|\\+-\\)")
1718 (delete-region (point) (1+ (point-at-eol))))
1719 (when org-export-latex-tables-centered
1720 (setq tbl (concat "\\begin{center}\n" tbl "\\end{center}")))
1721 (when floatp
1722 (setq tbl (concat "\\begin{table}\n"
1723 (format "\\caption{%s%s}\n"
1724 (if label (format "\\label{%s}" label) "")
1725 (or caption ""))
1727 "\n\\end{table}\n")))
1728 (insert (org-export-latex-protect-string tbl))))
1730 (defun org-export-latex-fontify ()
1731 "Convert fontification to LaTeX."
1732 (goto-char (point-min))
1733 (while (re-search-forward org-emph-re nil t)
1734 ;; The match goes one char after the *string*, except at the end of a line
1735 (let ((emph (assoc (match-string 3)
1736 org-export-latex-emphasis-alist))
1737 (beg (match-beginning 0))
1738 (end (match-end 0))
1739 rpl s)
1740 (unless emph
1741 (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
1742 (match-string 3)))
1743 (unless (or (and (get-text-property (- (point) 2) 'org-protected)
1744 (not (get-text-property
1745 (- (point) 2) 'org-verbatim-emph)))
1746 (save-excursion
1747 (goto-char (match-beginning 1))
1748 (save-match-data
1749 (and (org-at-table-p)
1750 (string-match
1751 "[|\n]" (buffer-substring beg end)))))
1752 (and (equal (match-string 3) "+")
1753 (save-match-data
1754 (string-match "\\`-+\\'" (match-string 4)))))
1755 (setq s (match-string 4))
1756 (setq rpl (concat (match-string 1)
1757 (org-export-latex-emph-format (cadr emph)
1758 (match-string 4))
1759 (match-string 5)))
1760 (if (caddr emph)
1761 (setq rpl (org-export-latex-protect-string rpl))
1762 (save-match-data
1763 (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
1764 (progn
1765 (add-text-properties (match-beginning 1) (match-end 1)
1766 '(org-protected t) rpl)
1767 (add-text-properties (match-beginning 3) (match-end 3)
1768 '(org-protected t) rpl)))))
1769 (replace-match rpl t t)))
1770 (backward-char)))
1772 (defvar org-export-latex-use-verb nil)
1773 (defun org-export-latex-emph-format (format string)
1774 "Format an emphasis string and handle the \\verb special case."
1775 (when (equal format "\\verb")
1776 (save-match-data
1777 (if org-export-latex-use-verb
1778 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1779 (catch 'exit
1780 (loop for i from 0 to (1- (length ll)) do
1781 (if (not (string-match (regexp-quote (substring ll i (1+ i)))
1782 string))
1783 (progn
1784 (setq format (concat "\\verb" (substring ll i (1+ i))
1785 "%s" (substring ll i (1+ i))))
1786 (throw 'exit nil))))))
1787 (let ((start 0)
1788 (trans '(("\\" . "\\textbackslash{}")
1789 ("~" . "\\textasciitilde{}")
1790 ("^" . "\\textasciicircum{}")))
1791 (rtn "") char)
1792 (while (string-match "[\\{}$%&_#~^]" string)
1793 (setq char (match-string 0 string))
1794 (if (> (match-beginning 0) 0)
1795 (setq rtn (concat rtn (substring string
1796 0 (match-beginning 0)))))
1797 (setq string (substring string (1+ (match-beginning 0))))
1798 (setq char (or (cdr (assoc char trans)) (concat "\\" char))
1799 rtn (concat rtn char)))
1800 (setq string (concat rtn string) format "\\texttt{%s}")))))
1801 (format format string))
1803 (defun org-export-latex-links ()
1804 ;; Make sure to use the LaTeX hyperref and graphicx package
1805 ;; or send some warnings.
1806 "Convert links to LaTeX."
1807 (goto-char (point-min))
1808 (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
1809 (org-if-unprotected-1
1810 (goto-char (match-beginning 0))
1811 (let* ((re-radio org-export-latex-all-targets-re)
1812 (remove (list (match-beginning 0) (match-end 0)))
1813 (raw-path (org-extract-attributes (match-string 3)))
1814 (full-raw-path (concat (match-string 1) raw-path))
1815 (desc (match-string 5))
1816 (type (or (match-string 2)
1817 (if (or (file-name-absolute-p raw-path)
1818 (string-match "^\\.\\.?/" raw-path))
1819 "file")))
1820 (coderefp (equal type "coderef"))
1821 (caption (org-find-text-property-in-string 'org-caption raw-path))
1822 (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
1823 (plist-get org-export-latex-options-plist :latex-image-options)))
1824 (label (org-find-text-property-in-string 'org-label raw-path))
1825 imgp radiop
1826 ;; define the path of the link
1827 (path (cond
1828 ((member type '("coderef"))
1829 raw-path)
1830 ((member type '("http" "https" "ftp"))
1831 (concat type ":" raw-path))
1832 ((and re-radio (string-match re-radio raw-path))
1833 (setq radiop t))
1834 ((equal type "mailto")
1835 (concat type ":" raw-path))
1836 ((equal type "file")
1837 (if (and (org-file-image-p
1838 (expand-file-name
1839 raw-path)
1840 org-export-latex-inline-image-extensions)
1841 (or (get-text-property 0 'org-no-description
1842 raw-path)
1843 (equal desc full-raw-path)))
1844 (setq imgp t)
1845 (progn (when (string-match "\\(.+\\)::.+" raw-path)
1846 (setq raw-path (match-string 1 raw-path)))
1847 (if (file-exists-p raw-path)
1848 (concat type "://" (expand-file-name raw-path))
1849 (concat type "://" (org-export-directory
1850 :LaTeX org-export-latex-options-plist)
1851 raw-path))))))))
1852 ;; process with link inserting
1853 (apply 'delete-region remove)
1854 (setq caption (and caption (org-export-latex-fontify-headline caption)))
1855 (cond ((and imgp
1856 (plist-get org-export-latex-options-plist :inline-images))
1857 ;; OK, we need to inline an image
1858 (insert
1859 (org-export-latex-format-image raw-path caption label attr)))
1860 (coderefp
1861 (insert (format
1862 (org-export-get-coderef-format path desc)
1863 (cdr (assoc path org-export-code-refs)))))
1864 (radiop (insert (format "\\hyperref[%s]{%s}"
1865 (org-solidify-link-text raw-path) desc)))
1866 ((not type)
1867 (insert (format "\\hyperref[%s]{%s}"
1868 (org-remove-initial-hash
1869 (org-solidify-link-text raw-path))
1870 desc)))
1871 (path
1872 (when (org-at-table-p)
1873 ;; There is a strange problem when we have a link in a table,
1874 ;; ampersands then cause a problem. I think this must be
1875 ;; a LaTeX issue, but we here implement a work-around anyway.
1876 (setq path (org-export-latex-protect-amp path)
1877 desc (org-export-latex-protect-amp desc)))
1878 (insert (format org-export-latex-hyperref-format path desc)))
1879 (t (insert "\\texttt{" desc "}")))))))
1882 (defun org-export-latex-format-image (path caption label attr)
1883 "Format the image element, depending on user settings."
1884 (let (ind floatp wrapp placement figenv)
1885 (setq floatp (or caption label))
1886 (setq ind (org-get-text-property-any 0 'original-indentation path))
1887 (when (and attr (stringp attr))
1888 (if (string-match "[ \t]*\\<wrap\\>" attr)
1889 (setq wrapp t floatp nil attr (replace-match "" t t attr)))
1890 (if (string-match "[ \t]*\\<float\\>" attr)
1891 (setq wrapp nil floatp t attr (replace-match "" t t attr))))
1893 (setq placement
1894 (cond
1895 (wrapp "{l}{0.5\\textwidth}")
1896 (floatp "[htb]")
1897 (t "")))
1899 (when (and attr (stringp attr)
1900 (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
1901 (setq placement (match-string 1 attr)
1902 attr (replace-match "" t t attr)))
1903 (setq attr (and attr (org-trim attr)))
1904 (when (or (not attr) (= (length attr) 0))
1905 (setq attr (cond (floatp "width=0.7\\textwidth")
1906 (wrapp "width=0.48\\textwidth")
1907 (t attr))))
1908 (setq figenv
1909 (cond
1910 (wrapp "\\begin{wrapfigure}%placement
1911 \\centering
1912 \\includegraphics[%attr]{%path}
1913 \\caption{%labelcmd%caption}
1914 \\end{wrapfigure}")
1915 (floatp "\\begin{figure}%placement
1916 \\centering
1917 \\includegraphics[%attr]{%path}
1918 \\caption{%labelcmd%caption}
1919 \\end{figure}")
1920 (t "\\includegraphics[%attr]{%path}")))
1923 (setq figenv (mapconcat 'identity (split-string figenv "\n")
1924 (save-excursion (beginning-of-line 1)
1925 (looking-at "[ \t]*")
1926 (concat "\n" (match-string 0)))))
1928 (if (and (not label) (not caption)
1929 (string-match "^\\\\caption{.*\n" figenv))
1930 (setq figenv (replace-match "" t t figenv)))
1931 (org-add-props
1932 (org-fill-template
1933 figenv
1934 (list (cons "path"
1935 (if (file-name-absolute-p path)
1936 (expand-file-name path)
1937 path))
1938 (cons "attr" attr)
1939 (cons "labelcmd" (if label (format "\\label{%s}"
1940 label)""))
1941 (cons "caption" (or caption ""))
1942 (cons "placement" (or placement ""))))
1943 nil 'original-indentation ind)))
1945 (defun org-export-latex-protect-amp (s)
1946 (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
1947 (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
1948 t t s)))
1951 (defun org-remove-initial-hash (s)
1952 (if (string-match "\\`#" s)
1953 (substring s 1)
1955 (defvar org-latex-entities) ; defined below
1956 (defvar org-latex-entities-regexp) ; defined below
1957 (defvar org-latex-entities-exceptions) ; defined below
1959 (defun org-export-latex-preprocess (parameters)
1960 "Clean stuff in the LaTeX export."
1961 ;; Preserve line breaks
1962 (goto-char (point-min))
1963 (while (re-search-forward "\\\\\\\\" nil t)
1964 (add-text-properties (match-beginning 0) (match-end 0)
1965 '(org-protected t)))
1967 ;; Preserve latex environments
1968 (goto-char (point-min))
1969 (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
1970 (let* ((start (progn (beginning-of-line) (point)))
1971 (end (and (re-search-forward
1972 (concat "^[ \t]*\\\\end{"
1973 (regexp-quote (match-string 1))
1974 "}") nil t)
1975 (point-at-eol))))
1976 (if end
1977 (add-text-properties start end '(org-protected t))
1978 (goto-char (point-at-eol)))))
1980 ;; Preserve math snippets
1982 (let* ((matchers (plist-get org-format-latex-options :matchers))
1983 (re-list org-latex-regexps)
1984 beg end re e m n block off)
1985 ;; Check the different regular expressions
1986 (while (setq e (pop re-list))
1987 (setq m (car e) re (nth 1 e) n (nth 2 e)
1988 block (if (nth 3 e) "\n\n" ""))
1989 (setq off (if (member m '("$" "$1")) 1 0))
1990 (when (and (member m matchers) (not (equal m "begin")))
1991 (goto-char (point-min))
1992 (while (re-search-forward re nil t)
1993 (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
1994 (add-text-properties beg end '(org-protected t org-latex-math t))))))
1996 ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
1997 (goto-char (point-min))
1998 (let ((case-fold-search nil))
1999 (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
2000 (unless (eq (char-before (match-beginning 1)) ?\\)
2001 (org-if-unprotected-1
2002 (replace-match (org-export-latex-protect-string
2003 (concat "\\" (match-string 1)
2004 "{}")) t t)))))
2006 ;; Convert blockquotes
2007 (goto-char (point-min))
2008 (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
2009 (org-replace-match-keep-properties "\\begin{quote}" t t))
2010 (goto-char (point-min))
2011 (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
2012 (org-replace-match-keep-properties "\\end{quote}" t t))
2014 ;; Convert verse
2015 (goto-char (point-min))
2016 (while (search-forward "ORG-VERSE-START" nil t)
2017 (org-replace-match-keep-properties "\\begin{verse}" t t)
2018 (beginning-of-line 2)
2019 (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
2020 (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
2021 (goto-char (match-end 1))
2022 (org-replace-match-keep-properties
2023 (org-export-latex-protect-string
2024 (concat "\\hspace*{1cm}" (match-string 2))) t t)
2025 (beginning-of-line 1))
2026 (if (looking-at "[ \t]*$")
2027 (insert (org-export-latex-protect-string "\\vspace*{1em}"))
2028 (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
2029 (end-of-line 1)
2030 (insert "\\\\")))
2031 (beginning-of-line 2))
2032 (and (looking-at "[ \t]*ORG-VERSE-END.*")
2033 (org-replace-match-keep-properties "\\end{verse}" t t)))
2035 ;; Convert center
2036 (goto-char (point-min))
2037 (while (search-forward "ORG-CENTER-START" nil t)
2038 (org-replace-match-keep-properties "\\begin{center}" t t))
2039 (goto-char (point-min))
2040 (while (search-forward "ORG-CENTER-END" nil t)
2041 (org-replace-match-keep-properties "\\end{center}" t t))
2043 (run-hooks 'org-export-latex-after-blockquotes-hook)
2045 ;; Convert horizontal rules
2046 (goto-char (point-min))
2047 (while (re-search-forward "^----+.$" nil t)
2048 (org-if-unprotected
2049 (replace-match (org-export-latex-protect-string "\\hrule") t t)))
2051 ;; Protect LaTeX commands like \command[...]{...} or \command{...}
2052 (goto-char (point-min))
2053 (let ((re (concat
2054 "\\\\\\([a-zA-Z]+\\)"
2055 "\\(?:<[^<>\n]*>\\)*"
2056 "\\(?:\\[[^][\n]*?\\]\\)*"
2057 "\\(?:<[^<>\n]*>\\)*"
2058 "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}")))
2059 (while (re-search-forward re nil t)
2060 (unless (or
2061 ;; check for comment line
2062 (save-excursion (goto-char (match-beginning 0))
2063 (equal (char-after (point-at-bol)) ?#))
2064 ;; Check if this is a defined entity, so that is may need conversion
2065 (org-entity-get (match-string 1))
2067 (add-text-properties (match-beginning 0) (match-end 0)
2068 '(org-protected t)))))
2070 ;; Protect LaTeX entities
2071 (goto-char (point-min))
2072 (let (a)
2073 (while (re-search-forward org-latex-entities-regexp nil t)
2074 (if (setq a (assoc (match-string 0) org-latex-entities-exceptions))
2075 (replace-match (org-add-props (nth 1 a) nil 'org-protected t)
2076 t t)
2077 (add-text-properties (match-beginning 0) (match-end 0)
2078 '(org-protected t)))))
2080 ;; Replace radio links
2081 (goto-char (point-min))
2082 (while (re-search-forward
2083 (concat "<<<?" org-export-latex-all-targets-re
2084 ">>>?\\((INVISIBLE)\\)?") nil t)
2085 (org-if-unprotected-at (+ (match-beginning 0) 2)
2086 (replace-match
2087 (concat
2088 (org-export-latex-protect-string
2089 (format "\\label{%s}" (save-match-data (org-solidify-link-text
2090 (match-string 1)))))
2091 (if (match-string 2) "" (match-string 1)))
2092 t t)))
2094 ;; Delete @<...> constructs
2095 ;; Thanks to Daniel Clemente for this regexp
2096 (goto-char (point-min))
2097 (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
2098 (org-if-unprotected
2099 (replace-match "")))
2101 ;; When converting to LaTeX, replace footnotes
2102 ;; FIXME: don't protect footnotes from conversion
2103 (when (plist-get org-export-latex-options-plist :footnotes)
2104 (goto-char (point-min))
2105 (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
2106 (org-if-unprotected
2107 (when (and (save-match-data
2108 (save-excursion (beginning-of-line)
2109 (looking-at "[^:|#]")))
2110 (not (org-in-verbatim-emphasis)))
2111 (let ((foot-beg (match-beginning 0))
2112 (foot-end (match-end 0))
2113 (foot-prefix (match-string 0))
2114 footnote footnote-rpl)
2115 (save-excursion
2116 (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
2117 nil t))
2118 (replace-match (org-export-latex-protect-string
2119 (concat "$^{" (match-string 1) "}$")))
2120 (replace-match "")
2121 (let ((end (save-excursion
2122 (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
2123 (match-beginning 0) (point-max)))))
2124 (setq footnote (concat (org-trim (buffer-substring (point) end))
2125 " ")) ; prevent last } being part of a link
2126 (delete-region (point) end))
2127 (goto-char foot-beg)
2128 (delete-region foot-beg foot-end)
2129 (unless (null footnote)
2130 (setq footnote-rpl (format "\\footnote{%s}" footnote))
2131 (add-text-properties 0 10 '(org-protected t) footnote-rpl)
2132 (add-text-properties (1- (length footnote-rpl))
2133 (length footnote-rpl)
2134 '(org-protected t) footnote-rpl)
2135 (if (org-on-heading-p)
2136 (setq footnote-rpl
2137 (concat (org-export-latex-protect-string "\\protect")
2138 footnote-rpl)))
2139 (insert footnote-rpl)))
2140 )))))
2142 ;; Remove footnote section tag for LaTeX
2143 (goto-char (point-min))
2144 (while (re-search-forward
2145 (concat "^" footnote-section-tag-regexp) nil t)
2146 (org-if-unprotected
2147 (replace-match "")))))
2149 (defun org-export-latex-fix-inputenc ()
2150 "Set the codingsystem in inputenc to what the buffer is."
2151 (let* ((cs buffer-file-coding-system)
2152 (opt (or (ignore-errors (latexenc-coding-system-to-inputenc cs))
2153 "utf8")))
2154 (when opt
2155 ;; Translate if that is requested
2156 (setq opt (or (cdr (assoc opt org-export-latex-inputenc-alist)) opt))
2157 ;; find the \usepackage statement and replace the option
2158 (goto-char (point-min))
2159 (while (re-search-forward "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
2160 nil t)
2161 (goto-char (match-beginning 1))
2162 (delete-region (match-beginning 1) (match-end 1))
2163 (insert opt))
2164 (and buffer-file-name
2165 (save-buffer)))))
2167 ;;; List handling:
2169 (defun org-export-latex-lists ()
2170 "Convert plain text lists in current buffer into LaTeX lists."
2171 (let (res)
2172 (goto-char (point-min))
2173 (while (re-search-forward org-list-beginning-re nil t)
2174 (org-if-unprotected
2175 (beginning-of-line)
2176 (setq res (org-list-to-latex (org-list-parse-list t)
2177 org-export-latex-list-parameters))
2178 (while (string-match "^\\(\\\\item[ \t]+\\)\\[@start:\\([0-9]+\\)\\]"
2179 res)
2180 (setq res (replace-match
2181 (concat (format "\\setcounter{enumi}{%d}"
2182 (1- (string-to-number
2183 (match-string 2 res))))
2184 "\n"
2185 (match-string 1 res))
2186 t t res)))
2187 (insert res "\n")))))
2189 (defconst org-latex-entities
2190 '("\\!"
2191 "\\'"
2192 "\\+"
2193 "\\,"
2194 "\\-"
2195 "\\:"
2196 "\\;"
2197 "\\<"
2198 "\\="
2199 "\\>"
2200 "\\Huge"
2201 "\\LARGE"
2202 "\\Large"
2203 "\\Styles"
2204 "\\\\"
2205 "\\`"
2206 "\\addcontentsline"
2207 "\\address"
2208 "\\addtocontents"
2209 "\\addtocounter"
2210 "\\addtolength"
2211 "\\addvspace"
2212 "\\alph"
2213 "\\appendix"
2214 "\\arabic"
2215 "\\author"
2216 "\\begin{array}"
2217 "\\begin{center}"
2218 "\\begin{description}"
2219 "\\begin{enumerate}"
2220 "\\begin{eqnarray}"
2221 "\\begin{equation}"
2222 "\\begin{figure}"
2223 "\\begin{flushleft}"
2224 "\\begin{flushright}"
2225 "\\begin{itemize}"
2226 "\\begin{list}"
2227 "\\begin{minipage}"
2228 "\\begin{picture}"
2229 "\\begin{quotation}"
2230 "\\begin{quote}"
2231 "\\begin{tabbing}"
2232 "\\begin{table}"
2233 "\\begin{tabular}"
2234 "\\begin{thebibliography}"
2235 "\\begin{theorem}"
2236 "\\begin{titlepage}"
2237 "\\begin{verbatim}"
2238 "\\begin{verse}"
2239 "\\bf"
2240 "\\bf"
2241 "\\bibitem"
2242 "\\bigskip"
2243 "\\cdots"
2244 "\\centering"
2245 "\\circle"
2246 "\\cite"
2247 "\\cleardoublepage"
2248 "\\clearpage"
2249 "\\cline"
2250 "\\closing"
2251 "\\dashbox"
2252 "\\date"
2253 "\\ddots"
2254 "\\dotfill"
2255 "\\em"
2256 "\\fbox"
2257 "\\flushbottom"
2258 "\\fnsymbol"
2259 "\\footnote"
2260 "\\footnotemark"
2261 "\\footnotesize"
2262 "\\footnotetext"
2263 "\\frac"
2264 "\\frame"
2265 "\\framebox"
2266 "\\hfill"
2267 "\\hline"
2268 "\\hrulespace"
2269 "\\hspace"
2270 "\\huge"
2271 "\\hyphenation"
2272 "\\include"
2273 "\\includeonly"
2274 "\\indent"
2275 "\\input"
2276 "\\it"
2277 "\\kill"
2278 "\\label"
2279 "\\large"
2280 "\\ldots"
2281 "\\line"
2282 "\\linebreak"
2283 "\\linethickness"
2284 "\\listoffigures"
2285 "\\listoftables"
2286 "\\location"
2287 "\\makebox"
2288 "\\maketitle"
2289 "\\mark"
2290 "\\mbox"
2291 "\\medskip"
2292 "\\multicolumn"
2293 "\\multiput"
2294 ("\\nbsp" "~")
2295 "\\newcommand"
2296 "\\newcounter"
2297 "\\newenvironment"
2298 "\\newfont"
2299 "\\newlength"
2300 "\\newline"
2301 "\\newpage"
2302 "\\newsavebox"
2303 "\\newtheorem"
2304 "\\nocite"
2305 "\\nofiles"
2306 "\\noindent"
2307 "\\nolinebreak"
2308 "\\nopagebreak"
2309 "\\normalsize"
2310 "\\onecolumn"
2311 "\\opening"
2312 "\\oval"
2313 "\\overbrace"
2314 "\\overline"
2315 "\\pagebreak"
2316 "\\pagenumbering"
2317 "\\pageref"
2318 "\\pagestyle"
2319 "\\par"
2320 "\\parbox"
2321 "\\put"
2322 "\\raggedbottom"
2323 "\\raggedleft"
2324 "\\raggedright"
2325 "\\raisebox"
2326 "\\ref"
2327 "\\rm"
2328 "\\roman"
2329 "\\rule"
2330 "\\savebox"
2331 "\\sc"
2332 "\\scriptsize"
2333 "\\setcounter"
2334 "\\setlength"
2335 "\\settowidth"
2336 "\\sf"
2337 "\\shortstack"
2338 "\\signature"
2339 "\\sl"
2340 "\\small"
2341 "\\smallskip"
2342 "\\sqrt"
2343 "\\tableofcontents"
2344 "\\telephone"
2345 "\\thanks"
2346 "\\thispagestyle"
2347 "\\tiny"
2348 "\\title"
2349 "\\tt"
2350 "\\twocolumn"
2351 "\\typein"
2352 "\\typeout"
2353 "\\underbrace"
2354 "\\underline"
2355 "\\usebox"
2356 "\\usecounter"
2357 "\\value"
2358 "\\vdots"
2359 "\\vector"
2360 "\\verb"
2361 "\\vfill"
2362 "\\vline"
2363 "\\vspace")
2364 "A list of LaTeX commands to be protected when performing conversion.")
2366 (defvar org-latex-entities-exceptions nil)
2368 (defconst org-latex-entities-regexp
2369 (let (names rest)
2370 (dolist (x org-latex-entities)
2371 (when (consp x)
2372 (add-to-list 'org-latex-entities-exceptions x)
2373 (setq x (car x)))
2374 (if (string-match "[a-zA-Z]$" x)
2375 (push x names)
2376 (push x rest)))
2377 (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
2378 "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
2380 (provide 'org-export-latex)
2381 (provide 'org-latex)
2383 ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
2385 ;;; org-latex.el ends here