org-element: Fix previous patch
[org-mode.git] / lisp / org-latex.el
blob933fa56b8ddc80636a02501151e0f0cafd830b9f
1 ;;; org-latex.el --- LaTeX exporter for org-mode
2 ;;
3 ;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
4 ;;
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: org-latex.el
7 ;; Author: Bastien Guerry <bzg AT gnu DOT org>
8 ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
9 ;; Keywords: org, wp, tex
10 ;; Description: Converts an org-mode buffer into LaTeX
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Commentary:
29 ;; This library implements a LaTeX exporter for org-mode.
31 ;; It is part of Org and will be autoloaded
33 ;; The interactive functions are similar to those of the HTML exporter:
35 ;; M-x `org-export-as-latex'
36 ;; M-x `org-export-as-pdf'
37 ;; M-x `org-export-as-pdf-and-open'
38 ;; M-x `org-export-as-latex-batch'
39 ;; M-x `org-export-as-latex-to-buffer'
40 ;; M-x `org-export-region-as-latex'
41 ;; M-x `org-replace-region-by-latex'
43 ;;; Code:
45 (eval-when-compile
46 (require 'cl))
48 (require 'footnote)
49 (require 'org)
50 (require 'org-exp)
51 (require 'org-macs)
52 (require 'org-beamer)
54 ;;; Variables:
55 (defvar org-export-latex-class nil)
56 (defvar org-export-latex-class-options nil)
57 (defvar org-export-latex-header nil)
58 (defvar org-export-latex-append-header nil)
59 (defvar org-export-latex-options-plist nil)
60 (defvar org-export-latex-todo-keywords-1 nil)
61 (defvar org-export-latex-complex-heading-re nil)
62 (defvar org-export-latex-not-done-keywords nil)
63 (defvar org-export-latex-done-keywords nil)
64 (defvar org-export-latex-display-custom-times nil)
65 (defvar org-export-latex-all-targets-re nil)
66 (defvar org-export-latex-add-level 0)
67 (defvar org-export-latex-footmark-seen nil
68 "List of footnotes markers seen so far by exporter.")
69 (defvar org-export-latex-sectioning "")
70 (defvar org-export-latex-sectioning-depth 0)
71 (defvar org-export-latex-special-keyword-regexp
72 (concat "\\<\\(" org-scheduled-string "\\|"
73 org-deadline-string "\\|"
74 org-closed-string"\\)")
75 "Regexp matching special time planning keywords plus the time after it.")
76 (defvar org-re-quote) ; dynamically scoped from org.el
77 (defvar org-commentsp) ; dynamically scoped from org.el
79 ;;; User variables:
81 (defgroup org-export-latex nil
82 "Options for exporting Org-mode files to LaTeX."
83 :tag "Org Export LaTeX"
84 :group 'org-export)
86 (defcustom org-export-latex-default-class "article"
87 "The default LaTeX class."
88 :group 'org-export-latex
89 :type '(string :tag "LaTeX class"))
91 (defcustom org-export-latex-classes
92 '(("article"
93 "\\documentclass[11pt]{article}"
94 ("\\section{%s}" . "\\section*{%s}")
95 ("\\subsection{%s}" . "\\subsection*{%s}")
96 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
97 ("\\paragraph{%s}" . "\\paragraph*{%s}")
98 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
99 ("report"
100 "\\documentclass[11pt]{report}"
101 ("\\part{%s}" . "\\part*{%s}")
102 ("\\chapter{%s}" . "\\chapter*{%s}")
103 ("\\section{%s}" . "\\section*{%s}")
104 ("\\subsection{%s}" . "\\subsection*{%s}")
105 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
106 ("book"
107 "\\documentclass[11pt]{book}"
108 ("\\part{%s}" . "\\part*{%s}")
109 ("\\chapter{%s}" . "\\chapter*{%s}")
110 ("\\section{%s}" . "\\section*{%s}")
111 ("\\subsection{%s}" . "\\subsection*{%s}")
112 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
113 ("beamer"
114 "\\documentclass{beamer}"
115 org-beamer-sectioning
117 "Alist of LaTeX classes and associated header and structure.
118 If #+LaTeX_CLASS is set in the buffer, use its value and the
119 associated information. Here is the structure of each cell:
121 \(class-name
122 header-string
123 (numbered-section . unnumbered-section\)
124 ...\)
126 The header string
127 -----------------
129 The HEADER-STRING is the header that will be inserted into the LaTeX file.
130 It should contain the \\documentclass macro, and anything else that is needed
131 for this setup. To this header, the following commands will be added:
133 - Calls to \\usepackage for all packages mentioned in the variables
134 `org-export-latex-default-packages-alist' and
135 `org-export-latex-packages-alist'. Thus, your header definitions should
136 avoid to also request these packages.
138 - Lines specified via \"#+LaTeX_HEADER:\"
140 If you need more control about the sequence in which the header is built
141 up, or if you want to exclude one of these building blocks for a particular
142 class, you can use the following macro-like placeholders.
144 [DEFAULT-PACKAGES] \\usepackage statements for default packages
145 [NO-DEFAULT-PACKAGES] do not include any of the default packages
146 [PACKAGES] \\usepackage statements for packages
147 [NO-PACKAGES] do not include the packages
148 [EXTRA] the stuff from #+LaTeX_HEADER
149 [NO-EXTRA] do not include #+LaTeX_HEADER stuff
150 [BEAMER-HEADER-EXTRA] the beamer extra headers
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 :version "24.1"
222 :type '(repeat
223 (cons
224 (string :tag "Derived from buffer")
225 (string :tag "Use this instead"))))
228 (defcustom org-export-latex-emphasis-alist
229 '(("*" "\\textbf{%s}" nil)
230 ("/" "\\emph{%s}" nil)
231 ("_" "\\underline{%s}" nil)
232 ("+" "\\st{%s}" nil)
233 ("=" "\\protectedtexttt" t)
234 ("~" "\\verb" t))
235 "Alist of LaTeX expressions to convert emphasis fontifiers.
236 Each element of the list is a list of three elements.
237 The first element is the character used as a marker for fontification.
238 The second element is a format string to wrap fontified text with.
239 If it is \"\\verb\", Org will automatically select a delimiter
240 character that is not in the string. \"\\protectedtexttt\" will use \\texttt
241 to typeset and try to protect special characters.
242 The third element decides whether to protect converted text from other
243 conversions."
244 :group 'org-export-latex
245 :type 'alist)
247 (defcustom org-export-latex-title-command "\\maketitle"
248 "The command used to insert the title just after \\begin{document}.
249 If this string contains the formatting specification \"%s\" then
250 it will be used as a format string, passing the title as an
251 argument."
252 :group 'org-export-latex
253 :type 'string)
255 (defcustom org-export-latex-import-inbuffer-stuff nil
256 "Non-nil means define TeX macros for Org's inbuffer definitions.
257 For example \orgTITLE for #+TITLE."
258 :group 'org-export-latex
259 :type 'boolean)
261 (defcustom org-export-latex-date-format
262 "\\today"
263 "Format string for \\date{...}."
264 :group 'org-export-latex
265 :type 'string)
267 (defcustom org-export-latex-todo-keyword-markup "\\textbf{%s}"
268 "Markup for TODO keywords, as a printf format.
269 This can be a single format for all keywords, a cons cell with separate
270 formats for not-done and done states, or an association list with setup
271 for individual keywords. If a keyword shows up for which there is no
272 markup defined, the first one in the association list will be used."
273 :group 'org-export-latex
274 :type '(choice
275 (string :tag "Default")
276 (cons :tag "Distinguish undone and done"
277 (string :tag "Not-DONE states")
278 (string :tag "DONE states"))
279 (repeat :tag "Per keyword markup"
280 (cons
281 (string :tag "Keyword")
282 (string :tag "Markup")))))
284 (defcustom org-export-latex-tag-markup "\\textbf{%s}"
285 "Markup for tags, as a printf format."
286 :group 'org-export-latex
287 :version "24.1"
288 :type 'string)
290 (defcustom org-export-latex-timestamp-markup "\\textit{%s}"
291 "A printf format string to be applied to time stamps."
292 :group 'org-export-latex
293 :type 'string)
295 (defcustom org-export-latex-timestamp-inactive-markup "\\textit{%s}"
296 "A printf format string to be applied to inactive time stamps."
297 :group 'org-export-latex
298 :version "24.1"
299 :type 'string)
301 (defcustom org-export-latex-timestamp-keyword-markup "\\texttt{%s}"
302 "A printf format string to be applied to time stamps."
303 :group 'org-export-latex
304 :type 'string)
306 (defcustom org-export-latex-href-format "\\href{%s}{%s}"
307 "A printf format string to be applied to href links.
308 The format must contain either two %s instances or just one.
309 If it contains two %s instances, the first will be filled with
310 the link, the second with the link description. If it contains
311 only one, the %s will be filled with the link."
312 :group 'org-export-latex
313 :version "24.1"
314 :type 'string)
316 (defcustom org-export-latex-hyperref-format "\\hyperref[%s]{%s}"
317 "A printf format string to be applied to hyperref links.
318 The format must contain one or two %s instances. The first one
319 will be filled with the link, the second with its description."
320 :group 'org-export-latex
321 :version "24.1"
322 :type 'string)
324 (defcustom org-export-latex-hyperref-options-format
325 "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={Emacs Org-mode version %s}}\n"
326 "A format string for hyperref options.
327 When non-nil, it must contain three %s format specifications
328 which will respectively be replaced by the document's keywords,
329 its description and the Org's version number, as a string. Set
330 this option to the empty string if you don't want to include
331 hyperref options altogether."
332 :type 'string
333 :version "24.3"
334 :group 'org-export-latex)
336 (defcustom org-export-latex-footnote-separator "\\textsuperscript{,}\\,"
337 "Text used to separate footnotes."
338 :group 'org-export-latex
339 :version "24.1"
340 :type 'string)
342 (defcustom org-export-latex-quotes
343 '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
344 ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
345 "Alist for quotes to use when converting english double-quotes.
347 The CAR of each item in this alist is the language code.
348 The CDR of each item in this alist is a list of three CONS:
349 - the first CONS defines the opening quote;
350 - the second CONS defines the closing quote;
351 - the last CONS defines single quotes.
353 For each item in a CONS, the first string is a regexp
354 for allowed characters before/after the quote, the second
355 string defines the replacement string for this quote."
356 :group 'org-export-latex
357 :version "24.1"
358 :type '(list
359 (cons :tag "Opening quote"
360 (string :tag "Regexp for char before")
361 (string :tag "Replacement quote "))
362 (cons :tag "Closing quote"
363 (string :tag "Regexp for char after ")
364 (string :tag "Replacement quote "))
365 (cons :tag "Single quote"
366 (string :tag "Regexp for char before")
367 (string :tag "Replacement quote "))))
369 (defcustom org-export-latex-tables-verbatim nil
370 "When non-nil, tables are exported verbatim."
371 :group 'org-export-latex
372 :type 'boolean)
374 (defcustom org-export-latex-tables-centered t
375 "When non-nil, tables are exported in a center environment."
376 :group 'org-export-latex
377 :type 'boolean)
379 (defcustom org-export-latex-table-caption-above t
380 "When non-nil, the caption is set above the table. When nil,
381 the caption is set below the table."
382 :group 'org-export-latex
383 :version "24.1"
384 :type 'boolean)
386 (defcustom org-export-latex-tables-column-borders nil
387 "When non-nil, grouping columns can cause outer vertical lines in tables.
388 When nil, grouping causes only separation lines between groups."
389 :group 'org-export-latex
390 :type 'boolean)
392 (defcustom org-export-latex-tables-tstart nil
393 "LaTeX command for top rule for tables."
394 :group 'org-export-latex
395 :version "24.1"
396 :type '(choice
397 (const :tag "Nothing" nil)
398 (string :tag "String")
399 (const :tag "Booktabs default: \\toprule" "\\toprule")))
401 (defcustom org-export-latex-tables-hline "\\hline"
402 "LaTeX command to use for a rule somewhere in the middle of a table."
403 :group 'org-export-latex
404 :version "24.1"
405 :type '(choice
406 (string :tag "String")
407 (const :tag "Standard: \\hline" "\\hline")
408 (const :tag "Booktabs default: \\midrule" "\\midrule")))
410 (defcustom org-export-latex-tables-tend nil
411 "LaTeX command for bottom rule for tables."
412 :group 'org-export-latex
413 :version "24.1"
414 :type '(choice
415 (const :tag "Nothing" nil)
416 (string :tag "String")
417 (const :tag "Booktabs default: \\bottomrule" "\\bottomrule")))
419 (defcustom org-export-latex-low-levels 'itemize
420 "How to convert sections below the current level of sectioning.
421 This is specified by the `org-export-headline-levels' option or the
422 value of \"H:\" in Org's #+OPTION line.
424 This can be either nil (skip the sections), `description', `itemize',
425 or `enumerate' (convert the sections as the corresponding list type), or
426 a string to be used instead of \\section{%s}. In this latter case,
427 the %s stands here for the inserted headline and is mandatory.
429 It may also be a list of three string to define a user-defined environment
430 that should be used. The first string should be the like
431 \"\\begin{itemize}\", the second should be like \"\\item %s %s\" with up
432 to two occurrences of %s for the title and a label, respectively. The third
433 string should be like \"\\end{itemize\"."
434 :group 'org-export-latex
435 :type '(choice (const :tag "Ignore" nil)
436 (const :tag "Convert as descriptive list" description)
437 (const :tag "Convert as itemized list" itemize)
438 (const :tag "Convert as enumerated list" enumerate)
439 (list :tag "User-defined environment"
440 :value ("\\begin{itemize}" "\\end{itemize}" "\\item %s")
441 (string :tag "Start")
442 (string :tag "End")
443 (string :tag "item"))
444 (string :tag "Use a section string" :value "\\subparagraph{%s}")))
446 (defcustom org-export-latex-list-parameters
447 '(:cbon "$\\boxtimes$" :cboff "$\\Box$" :cbtrans "$\\boxminus$")
448 "Parameters for the LaTeX list exporter.
449 These parameters will be passed on to `org-list-to-latex', which in turn
450 will pass them (combined with the LaTeX default list parameters) to
451 `org-list-to-generic'."
452 :group 'org-export-latex
453 :type 'plist)
455 (defcustom org-export-latex-verbatim-wrap
456 '("\\begin{verbatim}\n" . "\\end{verbatim}")
457 "Environment to be wrapped around a fixed-width section in LaTeX export.
458 This is a cons with two strings, to be added before and after the
459 fixed-with text.
461 Defaults to \\begin{verbatim} and \\end{verbatim}."
462 :group 'org-export-translation
463 :group 'org-export-latex
464 :type '(cons (string :tag "Open")
465 (string :tag "Close")))
467 (defcustom org-export-latex-listings nil
468 "Non-nil means export source code using the listings package.
469 This package will fontify source code, possibly even with color.
470 If you want to use this, you also need to make LaTeX use the
471 listings package, and if you want to have color, the color
472 package. Just add these to `org-export-latex-packages-alist',
473 for example using customize, or with something like
475 (require 'org-latex)
476 (add-to-list 'org-export-latex-packages-alist '(\"\" \"listings\"))
477 (add-to-list 'org-export-latex-packages-alist '(\"\" \"color\"))
479 Alternatively,
481 (setq org-export-latex-listings 'minted)
483 causes source code to be exported using the minted package as
484 opposed to listings. If you want to use minted, you need to add
485 the minted package to `org-export-latex-packages-alist', for
486 example using customize, or with
488 (require 'org-latex)
489 (add-to-list 'org-export-latex-packages-alist '(\"\" \"minted\"))
491 In addition, it is necessary to install
492 pygments (http://pygments.org), and to configure the variable
493 `org-latex-to-pdf-process' so that the -shell-escape option is
494 passed to pdflatex.
496 :group 'org-export-latex
497 :type 'boolean)
499 (defcustom org-export-latex-listings-langs
500 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
501 (c "C") (cc "C++")
502 (fortran "fortran")
503 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
504 (html "HTML") (xml "XML")
505 (tex "TeX") (latex "TeX")
506 (shell-script "bash")
507 (gnuplot "Gnuplot")
508 (ocaml "Caml") (caml "Caml")
509 (sql "SQL") (sqlite "sql"))
510 "Alist mapping languages to their listing language counterpart.
511 The key is a symbol, the major mode symbol without the \"-mode\".
512 The value is the string that should be inserted as the language parameter
513 for the listings package. If the mode name and the listings name are
514 the same, the language does not need an entry in this list - but it does not
515 hurt if it is present."
516 :group 'org-export-latex
517 :type '(repeat
518 (list
519 (symbol :tag "Major mode ")
520 (string :tag "Listings language"))))
522 (defcustom org-export-latex-listings-w-names t
523 "Non-nil means export names of named code blocks.
524 Code blocks exported with the listings package (controlled by the
525 `org-export-latex-listings' variable) can be named in the style
526 of noweb."
527 :group 'org-export-latex
528 :version "24.1"
529 :type 'boolean)
531 (defcustom org-export-latex-minted-langs
532 '((emacs-lisp "common-lisp")
533 (cc "c++")
534 (cperl "perl")
535 (shell-script "bash")
536 (caml "ocaml"))
537 "Alist mapping languages to their minted language counterpart.
538 The key is a symbol, the major mode symbol without the \"-mode\".
539 The value is the string that should be inserted as the language parameter
540 for the minted package. If the mode name and the listings name are
541 the same, the language does not need an entry in this list - but it does not
542 hurt if it is present.
544 Note that minted uses all lower case for language identifiers,
545 and that the full list of language identifiers can be obtained
546 with:
547 pygmentize -L lexers
549 :group 'org-export-latex
550 :version "24.1"
551 :type '(repeat
552 (list
553 (symbol :tag "Major mode ")
554 (string :tag "Listings language"))))
556 (defcustom org-export-latex-listings-options nil
557 "Association list of options for the latex listings package.
559 These options are supplied as a comma-separated list to the
560 \\lstset command. Each element of the association list should be
561 a list containing two strings: the name of the option, and the
562 value. For example,
564 (setq org-export-latex-listings-options
565 '((\"basicstyle\" \"\\small\")
566 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
568 will typeset the code in a small size font with underlined, bold
569 black keywords.
571 Note that the same options will be applied to blocks of all
572 languages."
573 :group 'org-export-latex
574 :version "24.1"
575 :type '(repeat
576 (list
577 (string :tag "Listings option name ")
578 (string :tag "Listings option value"))))
580 (defcustom org-export-latex-minted-options nil
581 "Association list of options for the latex minted package.
583 These options are supplied within square brackets in
584 \\begin{minted} environments. Each element of the alist should be
585 a list containing two strings: the name of the option, and the
586 value. For example,
588 (setq org-export-latex-minted-options
589 '((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
591 will result in src blocks being exported with
593 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
595 as the start of the minted environment. Note that the same
596 options will be applied to blocks of all languages."
597 :group 'org-export-latex
598 :version "24.1"
599 :type '(repeat
600 (list
601 (string :tag "Minted option name ")
602 (string :tag "Minted option value"))))
604 (defvar org-export-latex-custom-lang-environments nil
605 "Association list mapping languages to language-specific latex
606 environments used during export of src blocks by the listings
607 and minted latex packages. For example,
609 (setq org-export-latex-custom-lang-environments
610 '((python \"pythoncode\")))
612 would have the effect that if org encounters begin_src python
613 during latex export it will output
615 \\begin{pythoncode}
616 <src block body>
617 \\end{pythoncode}")
619 (defcustom org-export-latex-remove-from-headlines
620 '(:todo nil :priority nil :tags nil)
621 "A plist of keywords to remove from headlines. OBSOLETE.
622 Non-nil means remove this keyword type from the headline.
624 Don't remove the keys, just change their values.
626 Obsolete, this variable is no longer used. Use the separate
627 variables `org-export-with-todo-keywords', `org-export-with-priority',
628 and `org-export-with-tags' instead."
629 :type 'plist
630 :group 'org-export-latex)
632 (defcustom org-export-latex-image-default-option "width=.9\\linewidth"
633 "Default option for images."
634 :group 'org-export-latex
635 :type 'string)
637 (defcustom org-latex-default-figure-position "htb"
638 "Default position for latex figures."
639 :group 'org-export-latex
640 :version "24.1"
641 :type 'string)
643 (defcustom org-export-latex-tabular-environment "tabular"
644 "Default environment used to build tables."
645 :group 'org-export-latex
646 :version "24.1"
647 :type 'string)
649 (defcustom org-export-latex-link-with-unknown-path-format "\\texttt{%s}"
650 "Format string for links with unknown path type."
651 :group 'org-export-latex
652 :version "24.3"
653 :type 'string)
655 (defcustom org-export-latex-inline-image-extensions
656 '("pdf" "jpeg" "jpg" "png" "ps" "eps")
657 "Extensions of image files that can be inlined into LaTeX.
658 Note that the image extension *actually* allowed depend on the way the
659 LaTeX file is processed. When used with pdflatex, pdf, jpg and png images
660 are OK. When processing through dvi to Postscript, only ps and eps are
661 allowed. The default we use here encompasses both."
662 :group 'org-export-latex
663 :type '(repeat (string :tag "Extension")))
665 (defcustom org-export-latex-coding-system nil
666 "Coding system for the exported LaTeX file."
667 :group 'org-export-latex
668 :type 'coding-system)
670 (defgroup org-export-pdf nil
671 "Options for exporting Org-mode files to PDF, via LaTeX."
672 :tag "Org Export PDF"
673 :group 'org-export-latex
674 :group 'org-export)
676 (defcustom org-latex-to-pdf-process
677 '("pdflatex -interaction nonstopmode -output-directory %o %f"
678 "pdflatex -interaction nonstopmode -output-directory %o %f"
679 "pdflatex -interaction nonstopmode -output-directory %o %f")
680 "Commands to process a LaTeX file to a PDF file and process latex
681 fragments to pdf files.By default,this is a list of strings,and each of
682 strings will be given to the shell as a command. %f in the command will
683 be replaced by the full file name, %b by the file base name (i.e. without
684 extension) and %o by the base directory of the file.
686 If you set `org-create-formula-image-program'
687 `org-export-with-LaTeX-fragments' to 'imagemagick, you can add a
688 sublist which contains your own command(s) for LaTeX fragments
689 previewing, like this:
691 '(\"xelatex -interaction nonstopmode -output-directory %o %f\"
692 \"xelatex -interaction nonstopmode -output-directory %o %f\"
693 ;; use below command(s) to convert latex fragments
694 (\"xelatex %f\"))
696 With no such sublist, the default command used to convert LaTeX
697 fragments will be the first string in the list.
699 The reason why this is a list is that it usually takes several runs of
700 `pdflatex', maybe mixed with a call to `bibtex'. Org does not have a clever
701 mechanism to detect which of these commands have to be run to get to a stable
702 result, and it also does not do any error checking.
704 By default, Org uses 3 runs of `pdflatex' to do the processing. If you
705 have texi2dvi on your system and if that does not cause the infamous
706 egrep/locale bug:
708 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
710 then `texi2dvi' is the superior choice. Org does offer it as one
711 of the customize options.
713 Alternatively, this may be a Lisp function that does the processing, so you
714 could use this to apply the machinery of AUCTeX or the Emacs LaTeX mode.
715 This function should accept the file name as its single argument."
716 :group 'org-export-pdf
717 :type '(choice
718 (repeat :tag "Shell command sequence"
719 (string :tag "Shell command"))
720 (const :tag "2 runs of pdflatex"
721 ("pdflatex -interaction nonstopmode -output-directory %o %f"
722 "pdflatex -interaction nonstopmode -output-directory %o %f"))
723 (const :tag "3 runs of pdflatex"
724 ("pdflatex -interaction nonstopmode -output-directory %o %f"
725 "pdflatex -interaction nonstopmode -output-directory %o %f"
726 "pdflatex -interaction nonstopmode -output-directory %o %f"))
727 (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
728 ("pdflatex -interaction nonstopmode -output-directory %o %f"
729 "bibtex %b"
730 "pdflatex -interaction nonstopmode -output-directory %o %f"
731 "pdflatex -interaction nonstopmode -output-directory %o %f"))
732 (const :tag "2 runs of xelatex"
733 ("xelatex -interaction nonstopmode -output-directory %o %f"
734 "xelatex -interaction nonstopmode -output-directory %o %f"))
735 (const :tag "3 runs of xelatex"
736 ("xelatex -interaction nonstopmode -output-directory %o %f"
737 "xelatex -interaction nonstopmode -output-directory %o %f"
738 "xelatex -interaction nonstopmode -output-directory %o %f"))
739 (const :tag "xelatex,bibtex,xelatex,xelatex"
740 ("xelatex -interaction nonstopmode -output-directory %o %f"
741 "bibtex %b"
742 "xelatex -interaction nonstopmode -output-directory %o %f"
743 "xelatex -interaction nonstopmode -output-directory %o %f"))
744 (const :tag "texi2dvi"
745 ("texi2dvi -p -b -c -V %f"))
746 (const :tag "rubber"
747 ("rubber -d --into %o %f"))
748 (function)))
750 (defcustom org-export-pdf-logfiles
751 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
752 "The list of file extensions to consider as LaTeX logfiles."
753 :group 'org-export-pdf
754 :version "24.1"
755 :type '(repeat (string :tag "Extension")))
757 (defcustom org-export-pdf-remove-logfiles t
758 "Non-nil means remove the logfiles produced by PDF production.
759 These are the .aux, .log, .out, and .toc files."
760 :group 'org-export-pdf
761 :type 'boolean)
763 ;;; Hooks
765 (defvar org-export-latex-after-initial-vars-hook nil
766 "Hook run before LaTeX export.
767 The exact moment is after the initial variables like org-export-latex-class
768 have been determined from the environment.")
770 (defvar org-export-latex-after-blockquotes-hook nil
771 "Hook run during LaTeX export, after blockquote, verse, center are done.")
773 (defvar org-export-latex-final-hook nil
774 "Hook run in the finalized LaTeX buffer.")
776 (defvar org-export-latex-after-save-hook nil
777 "Hook run in the finalized LaTeX buffer, after it has been saved.")
779 ;;; Autoload functions:
781 ;;;###autoload
782 (defun org-export-as-latex-batch ()
783 "Call `org-export-as-latex', may be used in batch processing.
784 For example:
786 emacs --batch
787 --load=$HOME/lib/emacs/org.el
788 --eval \"(setq org-export-headline-levels 2)\"
789 --visit=MyFile --funcall org-export-as-latex-batch"
790 (org-export-as-latex org-export-headline-levels 'hidden))
792 ;;;###autoload
793 (defun org-export-as-latex-to-buffer (arg)
794 "Call `org-export-as-latex` with output to a temporary buffer.
795 No file is created. The prefix ARG is passed through to `org-export-as-latex'."
796 (interactive "P")
797 (org-export-as-latex arg nil nil "*Org LaTeX Export*")
798 (when org-export-show-temporary-export-buffer
799 (switch-to-buffer-other-window "*Org LaTeX Export*")))
801 ;;;###autoload
802 (defun org-replace-region-by-latex (beg end)
803 "Replace the region from BEG to END with its LaTeX export.
804 It assumes the region has `org-mode' syntax, and then convert it to
805 LaTeX. This can be used in any buffer. For example, you could
806 write an itemized list in `org-mode' syntax in an LaTeX buffer and
807 then use this command to convert it."
808 (interactive "r")
809 (let (reg latex buf)
810 (save-window-excursion
811 (if (derived-mode-p 'org-mode)
812 (setq latex (org-export-region-as-latex
813 beg end t 'string))
814 (setq reg (buffer-substring beg end)
815 buf (get-buffer-create "*Org tmp*"))
816 (with-current-buffer buf
817 (erase-buffer)
818 (insert reg)
819 (org-mode)
820 (setq latex (org-export-region-as-latex
821 (point-min) (point-max) t 'string)))
822 (kill-buffer buf)))
823 (delete-region beg end)
824 (insert latex)))
826 ;;;###autoload
827 (defun org-export-region-as-latex (beg end &optional body-only buffer)
828 "Convert region from BEG to END in `org-mode' buffer to LaTeX.
829 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
830 contents, and only produce the region of converted text, useful for
831 cut-and-paste operations.
832 If BUFFER is a buffer or a string, use/create that buffer as a target
833 of the converted LaTeX. If BUFFER is the symbol `string', return the
834 produced LaTeX as a string and leave no buffer behind. For example,
835 a Lisp program could call this function in the following way:
837 (setq latex (org-export-region-as-latex beg end t 'string))
839 When called interactively, the output buffer is selected, and shown
840 in a window. A non-interactive call will only return the buffer."
841 (interactive "r\nP")
842 (when (org-called-interactively-p 'any)
843 (setq buffer "*Org LaTeX Export*"))
844 (let ((transient-mark-mode t) (zmacs-regions t)
845 ext-plist rtn)
846 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
847 (goto-char end)
848 (set-mark (point)) ;; to activate the region
849 (goto-char beg)
850 (setq rtn (org-export-as-latex
851 nil nil ext-plist
852 buffer body-only))
853 (if (fboundp 'deactivate-mark) (deactivate-mark))
854 (if (and (org-called-interactively-p 'any) (bufferp rtn))
855 (switch-to-buffer-other-window rtn)
856 rtn)))
858 ;;;###autoload
859 (defun org-export-as-latex (arg &optional hidden ext-plist
860 to-buffer body-only pub-dir)
861 "Export current buffer to a LaTeX file.
862 If there is an active region, export only the region. The prefix
863 ARG specifies how many levels of the outline should become
864 headlines. The default is 3. Lower levels will be exported
865 depending on `org-export-latex-low-levels'. The default is to
866 convert them as description lists.
867 HIDDEN is obsolete and does nothing.
868 EXT-PLIST is a property list with
869 external parameters overriding org-mode's default settings, but
870 still inferior to file-local settings. When TO-BUFFER is
871 non-nil, create a buffer with that name and export to that
872 buffer. If TO-BUFFER is the symbol `string', don't leave any
873 buffer behind but just return the resulting LaTeX as a string.
874 When BODY-ONLY is set, don't produce the file header and footer,
875 simply return the content of \\begin{document}...\\end{document},
876 without even the \\begin{document} and \\end{document} commands.
877 when PUB-DIR is set, use this as the publishing directory."
878 (interactive "P")
879 (when (and (not body-only) arg (listp arg)) (setq body-only t))
880 (run-hooks 'org-export-first-hook)
882 ;; Make sure we have a file name when we need it.
883 (when (and (not (or to-buffer body-only))
884 (not buffer-file-name))
885 (if (buffer-base-buffer)
886 (org-set-local 'buffer-file-name
887 (with-current-buffer (buffer-base-buffer)
888 buffer-file-name))
889 (error "Need a file name to be able to export")))
891 (message "Exporting to LaTeX...")
892 (org-unmodified
893 (let ((inhibit-read-only t))
894 (remove-text-properties (point-min) (point-max)
895 '(:org-license-to-kill nil))))
896 (org-update-radio-target-regexp)
897 (org-export-latex-set-initial-vars ext-plist arg)
898 (setq org-export-opt-plist org-export-latex-options-plist
899 org-export-footnotes-data (org-footnote-all-labels 'with-defs)
900 org-export-footnotes-seen nil
901 org-export-latex-footmark-seen nil)
902 (org-install-letbind)
903 (run-hooks 'org-export-latex-after-initial-vars-hook)
904 (let* ((wcf (current-window-configuration))
905 (opt-plist
906 (org-export-process-option-filters org-export-latex-options-plist))
907 (region-p (org-region-active-p))
908 (rbeg (and region-p (region-beginning)))
909 (rend (and region-p (region-end)))
910 (subtree-p
911 (if (plist-get opt-plist :ignore-subtree-p)
913 (when region-p
914 (save-excursion
915 (goto-char rbeg)
916 (and (org-at-heading-p)
917 (>= (org-end-of-subtree t t) rend))))))
918 (opt-plist (setq org-export-opt-plist
919 (if subtree-p
920 (org-export-add-subtree-options opt-plist rbeg)
921 opt-plist)))
922 ;; Make sure the variable contains the updated values.
923 (org-export-latex-options-plist (setq org-export-opt-plist opt-plist))
924 ;; The following two are dynamically scoped into other
925 ;; routines below.
926 (org-current-export-dir
927 (or pub-dir (org-export-directory :html opt-plist)))
928 (org-current-export-file buffer-file-name)
929 (title (or (and subtree-p (org-export-get-title-from-subtree))
930 (plist-get opt-plist :title)
931 (and (not
932 (plist-get opt-plist :skip-before-1st-heading))
933 (org-export-grab-title-from-buffer))
934 (and buffer-file-name
935 (file-name-sans-extension
936 (file-name-nondirectory buffer-file-name)))
937 "No Title"))
938 (filename
939 (and (not to-buffer)
940 (concat
941 (file-name-as-directory
942 (or pub-dir
943 (org-export-directory :LaTeX org-export-latex-options-plist)))
944 (file-name-sans-extension
945 (or (and subtree-p
946 (org-entry-get rbeg "EXPORT_FILE_NAME" t))
947 (file-name-nondirectory ;sans-extension
948 (or buffer-file-name
949 (error "Don't know which export file to use")))))
950 ".tex")))
951 (filename
952 (and filename
953 (if (equal (file-truename filename)
954 (file-truename (or buffer-file-name "dummy.org")))
955 (concat filename ".tex")
956 filename)))
957 (auto-insert nil); Avoid any auto-insert stuff for the new file
958 (TeX-master (boundp 'TeX-master))
959 (buffer (if to-buffer
960 (cond
961 ((eq to-buffer 'string) (get-buffer-create
962 "*Org LaTeX Export*"))
963 (t (get-buffer-create to-buffer)))
964 (find-file-noselect filename)))
965 (odd org-odd-levels-only)
966 (header (org-export-latex-make-header title opt-plist))
967 (skip (cond (subtree-p nil)
968 (region-p nil)
969 (t (plist-get opt-plist :skip-before-1st-heading))))
970 (text (plist-get opt-plist :text))
971 (org-export-preprocess-hook
972 (cons
973 `(lambda () (org-set-local 'org-complex-heading-regexp
974 ,org-export-latex-complex-heading-re))
975 org-export-preprocess-hook))
976 (first-lines (if skip "" (org-export-latex-first-lines
977 opt-plist
978 (if subtree-p
979 (save-excursion
980 (goto-char rbeg)
981 (point-at-bol 2))
982 rbeg)
983 (if region-p rend))))
984 (coding-system (and (boundp 'buffer-file-coding-system)
985 buffer-file-coding-system))
986 (coding-system-for-write (or org-export-latex-coding-system
987 coding-system))
988 (save-buffer-coding-system (or org-export-latex-coding-system
989 coding-system))
990 (region (buffer-substring
991 (if region-p (region-beginning) (point-min))
992 (if region-p (region-end) (point-max))))
993 (text
994 (and text (string-match "\\S-" text)
995 (org-export-preprocess-string
996 text
997 :emph-multiline t
998 :for-backend 'latex
999 :comments nil
1000 :tags (plist-get opt-plist :tags)
1001 :priority (plist-get opt-plist :priority)
1002 :footnotes (plist-get opt-plist :footnotes)
1003 :drawers (plist-get opt-plist :drawers)
1004 :timestamps (plist-get opt-plist :timestamps)
1005 :todo-keywords (plist-get opt-plist :todo-keywords)
1006 :tasks (plist-get opt-plist :tasks)
1007 :add-text nil
1008 :skip-before-1st-heading skip
1009 :select-tags nil
1010 :exclude-tags nil
1011 :LaTeX-fragments nil)))
1012 (string-for-export
1013 (org-export-preprocess-string
1014 region
1015 :emph-multiline t
1016 :for-backend 'latex
1017 :comments nil
1018 :tags (plist-get opt-plist :tags)
1019 :priority (plist-get opt-plist :priority)
1020 :footnotes (plist-get opt-plist :footnotes)
1021 :drawers (plist-get opt-plist :drawers)
1022 :timestamps (plist-get opt-plist :timestamps)
1023 :todo-keywords (plist-get opt-plist :todo-keywords)
1024 :tasks (plist-get opt-plist :tasks)
1025 :add-text (if (eq to-buffer 'string) nil text)
1026 :skip-before-1st-heading skip
1027 :select-tags (plist-get opt-plist :select-tags)
1028 :exclude-tags (plist-get opt-plist :exclude-tags)
1029 :LaTeX-fragments nil)))
1031 (set-buffer buffer)
1032 (erase-buffer)
1033 (org-install-letbind)
1035 (and (fboundp 'set-buffer-file-coding-system)
1036 (set-buffer-file-coding-system coding-system-for-write))
1038 ;; insert the header and initial document commands
1039 (unless (or (eq to-buffer 'string) body-only)
1040 (insert header))
1042 ;; insert text found in #+TEXT
1043 (when (and text (not (eq to-buffer 'string)))
1044 (insert (org-export-latex-content
1045 text '(lists tables fixed-width keywords))
1046 "\n\n"))
1048 ;; insert lines before the first headline
1049 (unless (or skip (string-match "^\\*" first-lines))
1050 (insert first-lines))
1052 ;; export the content of headlines
1053 (org-export-latex-global
1054 (with-temp-buffer
1055 (insert string-for-export)
1056 (goto-char (point-min))
1057 (when (re-search-forward "^\\(\\*+\\) " nil t)
1058 (let* ((asters (length (match-string 1)))
1059 (level (if odd (- asters 2) (- asters 1))))
1060 (setq org-export-latex-add-level
1061 (if odd (1- (/ (1+ asters) 2)) (1- asters)))
1062 (org-export-latex-parse-global level odd)))))
1064 ;; finalization
1065 (unless body-only (insert "\n\\end{document}"))
1067 ;; Attach description terms to the \item macro
1068 (goto-char (point-min))
1069 (while (re-search-forward "^[ \t]*\\\\item\\([ \t]+\\)\\[" nil t)
1070 (delete-region (match-beginning 1) (match-end 1)))
1072 ;; Relocate the table of contents
1073 (goto-char (point-min))
1074 (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
1075 (goto-char (point-min))
1076 (while (re-search-forward "\\\\tableofcontents\\>[ \t]*\n?" nil t)
1077 (replace-match ""))
1078 (goto-char (point-min))
1079 (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
1080 (replace-match "\\tableofcontents" t t)))
1082 ;; Cleanup forced line ends in items where they are not needed
1083 (goto-char (point-min))
1084 (while (re-search-forward
1085 "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*\n\\\\begin"
1086 nil t)
1087 (delete-region (match-beginning 1) (match-end 1)))
1088 (goto-char (point-min))
1089 (while (re-search-forward
1090 "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*"
1091 nil t)
1092 (if (looking-at "[\n \t]+")
1093 (replace-match "\n")))
1095 ;; Ensure we have a final newline
1096 (goto-char (point-max))
1097 (or (eq (char-before) ?\n)
1098 (insert ?\n))
1100 (run-hooks 'org-export-latex-final-hook)
1101 (if to-buffer
1102 (unless (eq major-mode 'latex-mode) (latex-mode))
1103 (save-buffer))
1104 (org-export-latex-fix-inputenc)
1105 (run-hooks 'org-export-latex-after-save-hook)
1106 (goto-char (point-min))
1107 (or (org-export-push-to-kill-ring "LaTeX")
1108 (message "Exporting to LaTeX...done"))
1109 (prog1
1110 (if (eq to-buffer 'string)
1111 (prog1 (buffer-substring (point-min) (point-max))
1112 (kill-buffer (current-buffer)))
1113 (current-buffer))
1114 (set-window-configuration wcf))))
1116 ;;;###autoload
1117 (defun org-export-as-pdf (arg &optional hidden ext-plist
1118 to-buffer body-only pub-dir)
1119 "Export as LaTeX, then process through to PDF."
1120 (interactive "P")
1121 (message "Exporting to PDF...")
1122 (let* ((wconfig (current-window-configuration))
1123 (lbuf (org-export-as-latex arg hidden ext-plist
1124 to-buffer body-only pub-dir))
1125 (file (buffer-file-name lbuf))
1126 (base (file-name-sans-extension (buffer-file-name lbuf)))
1127 (pdffile (concat base ".pdf"))
1128 (cmds (if (eq org-export-latex-listings 'minted)
1129 ;; automatically add -shell-escape when needed
1130 (mapcar (lambda (cmd)
1131 (replace-regexp-in-string
1132 "pdflatex " "pdflatex -shell-escape " cmd))
1133 org-latex-to-pdf-process)
1134 org-latex-to-pdf-process))
1135 (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
1136 (bibtex-p (with-current-buffer lbuf
1137 (save-excursion
1138 (goto-char (point-min))
1139 (re-search-forward "\\\\bibliography{" nil t))))
1140 cmd output-dir errors)
1141 (with-current-buffer outbuf (erase-buffer))
1142 (message (concat "Processing LaTeX file " file "..."))
1143 (setq output-dir (file-name-directory file))
1144 (with-current-buffer lbuf
1145 (save-excursion
1146 (if (and cmds (symbolp cmds))
1147 (funcall cmds (shell-quote-argument file))
1148 (while cmds
1149 (setq cmd (pop cmds))
1150 (cond
1151 ((not (listp cmd))
1152 (while (string-match "%b" cmd)
1153 (setq cmd (replace-match
1154 (save-match-data
1155 (shell-quote-argument base))
1156 t t cmd)))
1157 (while (string-match "%f" cmd)
1158 (setq cmd (replace-match
1159 (save-match-data
1160 (shell-quote-argument file))
1161 t t cmd)))
1162 (while (string-match "%o" cmd)
1163 (setq cmd (replace-match
1164 (save-match-data
1165 (shell-quote-argument output-dir))
1166 t t cmd)))
1167 (shell-command cmd outbuf)))))))
1168 (message (concat "Processing LaTeX file " file "...done"))
1169 (setq errors (org-export-latex-get-error outbuf))
1170 (if (not (file-exists-p pdffile))
1171 (error (concat "PDF file " pdffile " was not produced"
1172 (if errors (concat ":" errors "") "")))
1173 (set-window-configuration wconfig)
1174 (when org-export-pdf-remove-logfiles
1175 (dolist (ext org-export-pdf-logfiles)
1176 (setq file (concat base "." ext))
1177 (and (file-exists-p file) (delete-file file))))
1178 (message (concat
1179 "Exporting to PDF...done"
1180 (if errors
1181 (concat ", with some errors:" errors)
1182 "")))
1183 pdffile)))
1185 (defun org-export-latex-get-error (buf)
1186 "Collect the kinds of errors that remain in pdflatex processing."
1187 (with-current-buffer buf
1188 (save-excursion
1189 (goto-char (point-max))
1190 (when (re-search-backward "^[ \t]*This is pdf.*?TeX.*?Version" nil t)
1191 ;; OK, we are at the location of the final run
1192 (let ((pos (point)) (errors "") (case-fold-search t))
1193 (if (re-search-forward "Reference.*?undefined" nil t)
1194 (setq errors (concat errors " [undefined reference]")))
1195 (goto-char pos)
1196 (if (re-search-forward "Citation.*?undefined" nil t)
1197 (setq errors (concat errors " [undefined citation]")))
1198 (goto-char pos)
1199 (if (re-search-forward "Undefined control sequence" nil t)
1200 (setq errors (concat errors " [undefined control sequence]")))
1201 (and (org-string-nw-p errors) errors))))))
1203 ;;;###autoload
1204 (defun org-export-as-pdf-and-open (arg)
1205 "Export as LaTeX, then process through to PDF, and open."
1206 (interactive "P")
1207 (let ((pdffile (org-export-as-pdf arg)))
1208 (if pdffile
1209 (progn
1210 (org-open-file pdffile)
1211 (when org-export-kill-product-buffer-when-displayed
1212 (kill-buffer (find-buffer-visiting
1213 (concat (file-name-sans-extension (buffer-file-name))
1214 ".tex")))))
1215 (error "PDF file was not produced"))))
1217 ;;; Parsing functions:
1219 (defun org-export-latex-parse-global (level odd)
1220 "Parse the current buffer recursively, starting at LEVEL.
1221 If ODD is non-nil, assume the buffer only contains odd sections.
1222 Return a list reflecting the document structure."
1223 (save-excursion
1224 (goto-char (point-min))
1225 (let* ((cnt 0) output
1226 (depth org-export-latex-sectioning-depth))
1227 (while (org-re-search-forward-unprotected
1228 (concat "^\\(\\(?:\\*\\)\\{"
1229 (number-to-string (+ (if odd 2 1) level))
1230 "\\}\\) \\(.*\\)$")
1231 ;; make sure that there is no upper heading
1232 (when (> level 0)
1233 (save-excursion
1234 (save-match-data
1235 (org-re-search-forward-unprotected
1236 (concat "^\\(\\(?:\\*\\)\\{"
1237 (number-to-string level)
1238 "\\}\\) \\(.*\\)$") nil t)))) t)
1239 (setq cnt (1+ cnt))
1240 (let* ((pos (match-beginning 0))
1241 (heading (match-string 2))
1242 (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
1243 (save-excursion
1244 (narrow-to-region
1245 (point)
1246 (save-match-data
1247 (if (org-re-search-forward-unprotected
1248 (concat "^\\(\\(?:\\*\\)\\{"
1249 (number-to-string (+ (if odd 2 1) level))
1250 "\\}\\) \\(.*\\)$") nil t)
1251 (match-beginning 0)
1252 (point-max))))
1253 (goto-char (point-min))
1254 (setq output
1255 (append output
1256 (list
1257 (list
1258 `(pos . ,pos)
1259 `(level . ,nlevel)
1260 `(occur . ,cnt)
1261 `(heading . ,heading)
1262 `(content . ,(org-export-latex-parse-content))
1263 `(subcontent . ,(org-export-latex-parse-subcontent
1264 level odd)))))))
1265 (widen)))
1266 (list output))))
1268 (defun org-export-latex-parse-content ()
1269 "Extract the content of a section."
1270 (let ((beg (point))
1271 (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
1272 (progn (beginning-of-line) (point))
1273 (point-max))))
1274 (buffer-substring beg end)))
1276 (defun org-export-latex-parse-subcontent (level odd)
1277 "Extract the subcontent of a section at LEVEL.
1278 If ODD Is non-nil, assume subcontent only contains odd sections."
1279 (if (not (org-re-search-forward-unprotected
1280 (concat "^\\(\\(?:\\*\\)\\{"
1281 (number-to-string (+ (if odd 4 2) level))
1282 "\\}\\) \\(.*\\)$")
1283 nil t))
1284 nil ; subcontent is nil
1285 (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
1287 ;;; Rendering functions:
1288 (defun org-export-latex-global (content)
1289 "Export CONTENT to LaTeX.
1290 CONTENT is an element of the list produced by
1291 `org-export-latex-parse-global'."
1292 (if (eq (car content) 'subcontent)
1293 (mapc 'org-export-latex-sub (cdr content))
1294 (org-export-latex-sub (car content))))
1296 (defun org-export-latex-sub (subcontent)
1297 "Export the list SUBCONTENT to LaTeX.
1298 SUBCONTENT is an alist containing information about the headline
1299 and its content."
1300 (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
1301 (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
1303 (defun org-export-latex-subcontent (subcontent num)
1304 "Export each cell of SUBCONTENT to LaTeX.
1305 If NUM is non-nil export numbered sections, otherwise use unnumbered
1306 sections. If NUM is an integer, export the highest NUM levels as
1307 numbered sections and lower levels as unnumbered sections."
1308 (let* ((heading (cdr (assoc 'heading subcontent)))
1309 (level (- (cdr (assoc 'level subcontent))
1310 org-export-latex-add-level))
1311 (occur (number-to-string (cdr (assoc 'occur subcontent))))
1312 (content (cdr (assoc 'content subcontent)))
1313 (subcontent (cadr (assoc 'subcontent subcontent)))
1314 (label (org-get-text-property-any 0 'target heading))
1315 (label-list (cons label (cdr (assoc label
1316 org-export-target-aliases))))
1317 (sectioning org-export-latex-sectioning)
1318 (depth org-export-latex-sectioning-depth)
1319 main-heading sub-heading ctnt)
1320 (when (symbolp (car sectioning))
1321 (setq sectioning (funcall (car sectioning) level heading))
1322 (when sectioning
1323 (setq heading (car sectioning)
1324 sectioning (cdr sectioning)
1325 ;; target property migh have changed...
1326 label (org-get-text-property-any 0 'target heading)
1327 label-list (cons label (cdr (assoc label
1328 org-export-target-aliases)))))
1329 (if sectioning (setq sectioning (make-list 10 sectioning)))
1330 (setq depth (if sectioning 10000 0)))
1331 (if (string-match "[ \t]*\\\\\\\\[ \t]*" heading)
1332 (setq main-heading (substring heading 0 (match-beginning 0))
1333 sub-heading (substring heading (match-end 0))))
1334 (setq heading (org-export-latex-fontify-headline heading)
1335 sub-heading (and sub-heading
1336 (org-export-latex-fontify-headline sub-heading))
1337 main-heading (and main-heading
1338 (org-export-latex-fontify-headline main-heading)))
1339 (cond
1340 ;; Normal conversion
1341 ((<= level depth)
1342 (let* ((sec (nth (1- level) sectioning))
1343 (num (if (integerp num)
1344 (>= num level)
1345 num))
1346 start end)
1347 (if (consp (cdr sec))
1348 (setq start (nth (if num 0 2) sec)
1349 end (nth (if num 1 3) sec))
1350 (setq start (if num (car sec) (cdr sec))))
1351 (insert (format start (if main-heading main-heading heading)
1352 (or sub-heading "")))
1353 (insert "\n")
1354 (when label
1355 (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
1356 label-list "\n") "\n"))
1357 (insert (org-export-latex-content content))
1358 (cond ((stringp subcontent) (insert subcontent))
1359 ((listp subcontent)
1360 (while (org-looking-back "\n\n") (backward-delete-char 1))
1361 (org-export-latex-sub subcontent)))
1362 (when (and end (string-match "[^ \t]" end))
1363 (let ((hook (org-get-text-property-any 0 'org-insert-hook end)))
1364 (and (functionp hook) (funcall hook)))
1365 (insert end "\n"))))
1366 ;; At a level under the hl option: we can drop this subsection
1367 ((> level depth)
1368 (cond ((eq org-export-latex-low-levels 'description)
1369 (if (string-match "% ends low level$"
1370 (buffer-substring (point-at-bol 0) (point)))
1371 (delete-region (point-at-bol 0) (point))
1372 (insert "\\begin{description}\n"))
1373 (insert (format "\n\\item[%s]%s~\n"
1374 heading
1375 (if label (format "\\label{%s}" label) "")))
1376 (insert (org-export-latex-content content))
1377 (cond ((stringp subcontent) (insert subcontent))
1378 ((listp subcontent) (org-export-latex-sub subcontent)))
1379 (insert "\\end{description} % ends low level\n"))
1380 ((memq org-export-latex-low-levels '(itemize enumerate))
1381 (if (string-match "% ends low level$"
1382 (buffer-substring (point-at-bol 0) (point)))
1383 (delete-region (point-at-bol 0) (point))
1384 (insert (format "\\begin{%s}\n"
1385 (symbol-name org-export-latex-low-levels))))
1386 (let ((ctnt (org-export-latex-content content)))
1387 (insert (format (if (not (equal (replace-regexp-in-string "\n" "" ctnt) ""))
1388 "\n\\item %s\\\\\n%s%%"
1389 "\n\\item %s\n%s%%")
1390 heading
1391 (if label (format "\\label{%s}" label) "")))
1392 (insert ctnt))
1393 (cond ((stringp subcontent) (insert subcontent))
1394 ((listp subcontent) (org-export-latex-sub subcontent)))
1395 (insert (format "\\end{%s} %% ends low level\n"
1396 (symbol-name org-export-latex-low-levels))))
1398 ((and (listp org-export-latex-low-levels)
1399 org-export-latex-low-levels)
1400 (if (string-match "% ends low level$"
1401 (buffer-substring (point-at-bol 0) (point)))
1402 (delete-region (point-at-bol 0) (point))
1403 (insert (car org-export-latex-low-levels) "\n"))
1404 (insert (format (nth 2 org-export-latex-low-levels)
1405 heading
1406 (if label (format "\\label{%s}" label) "")))
1407 (insert (org-export-latex-content content))
1408 (cond ((stringp subcontent) (insert subcontent))
1409 ((listp subcontent) (org-export-latex-sub subcontent)))
1410 (insert (nth 1 org-export-latex-low-levels)
1411 " %% ends low level\n"))
1413 ((stringp org-export-latex-low-levels)
1414 (insert (format org-export-latex-low-levels heading) "\n")
1415 (when label (insert (format "\\label{%s}\n" label)))
1416 (insert (org-export-latex-content content))
1417 (cond ((stringp subcontent) (insert subcontent))
1418 ((listp subcontent) (org-export-latex-sub subcontent)))))))))
1420 ;;; Exporting internals:
1421 (defun org-export-latex-set-initial-vars (ext-plist level)
1422 "Store org local variables required for LaTeX export.
1423 EXT-PLIST is an optional additional plist.
1424 LEVEL indicates the default depth for export."
1425 (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
1426 org-export-latex-done-keywords org-done-keywords
1427 org-export-latex-not-done-keywords org-not-done-keywords
1428 org-export-latex-complex-heading-re org-complex-heading-regexp
1429 org-export-latex-display-custom-times org-display-custom-times
1430 org-export-latex-all-targets-re
1431 (org-make-target-link-regexp (org-all-targets))
1432 org-export-latex-options-plist
1433 (org-combine-plists (org-default-export-plist) ext-plist
1434 (org-infile-export-plist))
1435 org-export-latex-class
1436 (or (and (org-region-active-p)
1437 (save-excursion
1438 (goto-char (region-beginning))
1439 (and (looking-at org-complex-heading-regexp)
1440 (org-entry-get nil "LaTeX_CLASS" 'selective))))
1441 (save-excursion
1442 (save-restriction
1443 (widen)
1444 (goto-char (point-min))
1445 (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([-/a-zA-Z]+\\)" nil t)
1446 (match-string 1))))
1447 (plist-get org-export-latex-options-plist :latex-class)
1448 org-export-latex-default-class)
1449 org-export-latex-class-options
1450 (or (and (org-region-active-p)
1451 (save-excursion
1452 (goto-char (region-beginning))
1453 (and (looking-at org-complex-heading-regexp)
1454 (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
1455 (save-excursion
1456 (save-restriction
1457 (widen)
1458 (goto-char (point-min))
1459 (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
1460 (match-string 1))))
1461 (plist-get org-export-latex-options-plist :latex-class-options))
1462 org-export-latex-class
1463 (or (car (assoc org-export-latex-class org-export-latex-classes))
1464 (error "No definition for class `%s' in `org-export-latex-classes'"
1465 org-export-latex-class))
1466 org-export-latex-header
1467 (cadr (assoc org-export-latex-class org-export-latex-classes))
1468 org-export-latex-sectioning
1469 (cddr (assoc org-export-latex-class org-export-latex-classes))
1470 org-export-latex-sectioning-depth
1471 (or level
1472 (let ((hl-levels
1473 (plist-get org-export-latex-options-plist :headline-levels))
1474 (sec-depth (length org-export-latex-sectioning)))
1475 (if (> hl-levels sec-depth) sec-depth hl-levels))))
1476 (when (and org-export-latex-class-options
1477 (string-match "\\S-" org-export-latex-class-options)
1478 (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?"
1479 org-export-latex-header))
1480 (setq org-export-latex-header
1481 (concat (substring org-export-latex-header 0 (match-end 1))
1482 org-export-latex-class-options
1483 (substring org-export-latex-header (match-end 0))))))
1485 (defvar org-export-latex-format-toc-function
1486 'org-export-latex-format-toc-default
1487 "The function formatting returning the string to create the table of contents.
1488 The function mus take one parameter, the depth of the table of contents.")
1490 (defun org-export-latex-make-header (title opt-plist)
1491 "Make the LaTeX header and return it as a string.
1492 TITLE is the current title from the buffer or region.
1493 OPT-PLIST is the options plist for current buffer."
1494 (let ((toc (plist-get opt-plist :table-of-contents))
1495 (author (org-export-apply-macros-in-string
1496 (plist-get opt-plist :author)))
1497 (email (replace-regexp-in-string
1498 "_" "\\\\_"
1499 (org-export-apply-macros-in-string
1500 (plist-get opt-plist :email))))
1501 (description (org-export-apply-macros-in-string
1502 (plist-get opt-plist :description)))
1503 (keywords (org-export-apply-macros-in-string
1504 (plist-get opt-plist :keywords))))
1505 (concat
1506 (if (plist-get opt-plist :time-stamp-file)
1507 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1508 ;; insert LaTeX custom header and packages from the list
1509 (org-splice-latex-header
1510 (org-export-apply-macros-in-string org-export-latex-header)
1511 org-export-latex-default-packages-alist
1512 org-export-latex-packages-alist nil
1513 (org-export-apply-macros-in-string
1514 (plist-get opt-plist :latex-header-extra)))
1515 ;; append another special variable
1516 (org-export-apply-macros-in-string org-export-latex-append-header)
1517 ;; define alert if not yet defined
1518 "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
1519 ;; insert the title
1520 (format
1521 "\n\n\\title{%s}\n"
1522 (org-export-latex-fontify-headline title))
1523 ;; insert author info
1524 (if (plist-get opt-plist :author-info)
1525 (format "\\author{%s%s}\n"
1526 (org-export-latex-fontify-headline (or author user-full-name))
1527 (if (and (plist-get opt-plist :email-info) email
1528 (string-match "\\S-" email))
1529 (format "\\thanks{%s}" email)
1530 ""))
1531 (format "%%\\author{%s}\n"
1532 (org-export-latex-fontify-headline (or author user-full-name))))
1533 ;; insert the date
1534 (format "\\date{%s}\n"
1535 (format-time-string
1536 (or (plist-get opt-plist :date)
1537 org-export-latex-date-format)))
1538 ;; add some hyperref options
1539 (format org-export-latex-hyperref-options-format
1540 (org-export-latex-fontify-headline keywords)
1541 (org-export-latex-fontify-headline description)
1542 (org-version))
1543 ;; beginning of the document
1544 "\n\\begin{document}\n\n"
1545 ;; insert the title command
1546 (when (string-match "\\S-" title)
1547 (if (string-match "%s" org-export-latex-title-command)
1548 (format org-export-latex-title-command title)
1549 org-export-latex-title-command))
1550 "\n\n"
1551 ;; table of contents
1552 (when (and org-export-with-toc
1553 (plist-get opt-plist :section-numbers))
1554 (funcall org-export-latex-format-toc-function
1555 (cond ((numberp toc)
1556 (min toc (plist-get opt-plist :headline-levels)))
1557 (toc (plist-get opt-plist :headline-levels))))))))
1559 (defun org-export-latex-format-toc-default (depth)
1560 (when depth
1561 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
1562 depth)))
1564 (defun org-export-latex-first-lines (opt-plist &optional beg end)
1565 "Export the first lines before first headline.
1566 If BEG is non-nil, it is the beginning of the region.
1567 If END is non-nil, it is the end of the region."
1568 (save-excursion
1569 (goto-char (or beg (point-min)))
1570 (let* ((pt (point))
1571 (end (if (re-search-forward
1572 (concat "^" (org-get-limited-outline-regexp)) end t)
1573 (goto-char (match-beginning 0))
1574 (goto-char (or end (point-max))))))
1575 (prog1
1576 (org-export-latex-content
1577 (org-export-preprocess-string
1578 (buffer-substring pt end)
1579 :for-backend 'latex
1580 :emph-multiline t
1581 :add-text nil
1582 :comments nil
1583 :skip-before-1st-heading nil
1584 :LaTeX-fragments nil
1585 :timestamps (plist-get opt-plist :timestamps)
1586 :footnotes (plist-get opt-plist :footnotes)))
1587 (org-unmodified
1588 (let ((inhibit-read-only t)
1589 (limit (max pt (1- end))))
1590 (add-text-properties pt limit
1591 '(:org-license-to-kill t))
1592 (save-excursion
1593 (goto-char pt)
1594 (while (re-search-forward "^[ \t]*#\\+.*\n?" limit t)
1595 (let ((case-fold-search t))
1596 (unless (org-string-match-p
1597 "^[ \t]*#\\+\\(attr_\\|caption\\>\\|label\\>\\)"
1598 (match-string 0))
1599 (remove-text-properties (match-beginning 0) (match-end 0)
1600 '(:org-license-to-kill t))))))))))))
1603 (defvar org-export-latex-header-defs nil
1604 "The header definitions that might be used in the LaTeX body.")
1606 (defun org-export-latex-content (content &optional exclude-list)
1607 "Convert CONTENT string to LaTeX.
1608 Don't perform conversions that are in EXCLUDE-LIST. Recognized
1609 conversion types are: quotation-marks, emphasis, sub-superscript,
1610 links, keywords, lists, tables, fixed-width"
1611 (with-temp-buffer
1612 (org-install-letbind)
1613 (insert content)
1614 (unless (memq 'timestamps exclude-list)
1615 (org-export-latex-time-stamps))
1616 (unless (memq 'quotation-marks exclude-list)
1617 (org-export-latex-quotation-marks))
1618 (unless (memq 'emphasis exclude-list)
1619 (when (plist-get org-export-latex-options-plist :emphasize)
1620 (org-export-latex-fontify)))
1621 (unless (memq 'sub-superscript exclude-list)
1622 (org-export-latex-special-chars
1623 (plist-get org-export-latex-options-plist :sub-superscript)))
1624 (unless (memq 'links exclude-list)
1625 (org-export-latex-links))
1626 (unless (memq 'keywords exclude-list)
1627 (org-export-latex-keywords))
1628 (unless (memq 'lists exclude-list)
1629 (org-export-latex-lists))
1630 (unless (memq 'tables exclude-list)
1631 (org-export-latex-tables
1632 (plist-get org-export-latex-options-plist :tables)))
1633 (unless (memq 'fixed-width exclude-list)
1634 (org-export-latex-fixed-width
1635 (plist-get org-export-latex-options-plist :fixed-width)))
1636 ;; return string
1637 (buffer-substring (point-min) (point-max))))
1639 (defun org-export-latex-protect-string (s)
1640 "Add the org-protected property to string S."
1641 (add-text-properties 0 (length s) '(org-protected t) s) s)
1643 (defun org-export-latex-protect-char-in-string (char-list string)
1644 "Add org-protected text-property to char from CHAR-LIST in STRING."
1645 (with-temp-buffer
1646 (save-match-data
1647 (insert string)
1648 (goto-char (point-min))
1649 (while (re-search-forward (regexp-opt char-list) nil t)
1650 (add-text-properties (match-beginning 0)
1651 (match-end 0) '(org-protected t)))
1652 (buffer-string))))
1654 (defun org-export-latex-keywords-maybe (&optional remove-list)
1655 "Maybe remove keywords depending on rules in REMOVE-LIST."
1656 (goto-char (point-min))
1657 (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
1658 (case-fold-search nil)
1659 (todo-markup org-export-latex-todo-keyword-markup)
1660 fmt)
1661 ;; convert TODO keywords
1662 (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
1663 (if (plist-get remove-list :todo)
1664 (replace-match "")
1665 (setq fmt (cond
1666 ((stringp todo-markup) todo-markup)
1667 ((and (consp todo-markup) (stringp (car todo-markup)))
1668 (if (member (match-string 1) org-export-latex-done-keywords)
1669 (cdr todo-markup) (car todo-markup)))
1670 (t (cdr (or (assoc (match-string 1) todo-markup)
1671 (car todo-markup))))))
1672 (replace-match (org-export-latex-protect-string
1673 (format fmt (match-string 1))) t t)))
1674 ;; convert priority string
1675 (when (re-search-forward "\\[\\\\#.\\]" nil t)
1676 (if (plist-get remove-list :priority)
1677 (replace-match "")
1678 (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
1679 ;; convert tags
1680 (when (re-search-forward "\\(:[a-zA-Z0-9_@#%]+\\)+:" nil t)
1681 (if (or (not org-export-with-tags)
1682 (plist-get remove-list :tags))
1683 (replace-match "")
1684 (replace-match
1685 (org-export-latex-protect-string
1686 (format org-export-latex-tag-markup
1687 (save-match-data
1688 (replace-regexp-in-string
1689 "\\([_#]\\)" "\\\\\\1" (match-string 0)))))
1690 t t)))))
1692 (defun org-export-latex-fontify-headline (string)
1693 "Fontify special words in STRING."
1694 (with-temp-buffer
1695 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
1696 ;; the beginning of the buffer - inserting "\n" is safe here though.
1697 (insert "\n" string)
1699 ;; Preserve math snippets
1701 (let* ((matchers (plist-get org-format-latex-options :matchers))
1702 (re-list org-latex-regexps)
1703 beg end re e m n block off)
1704 ;; Check the different regular expressions
1705 (while (setq e (pop re-list))
1706 (setq m (car e) re (nth 1 e) n (nth 2 e)
1707 block (if (nth 3 e) "\n\n" ""))
1708 (setq off (if (member m '("$" "$1")) 1 0))
1709 (when (and (member m matchers) (not (equal m "begin")))
1710 (goto-char (point-min))
1711 (while (re-search-forward re nil t)
1712 (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
1713 (add-text-properties beg end
1714 '(org-protected t org-latex-math t))))))
1716 ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
1717 (goto-char (point-min))
1718 (let ((case-fold-search nil))
1719 (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
1720 (unless (eq (char-before (match-beginning 1)) ?\\)
1721 (org-if-unprotected-1
1722 (replace-match (org-export-latex-protect-string
1723 (concat "\\" (match-string 1)
1724 "{}")) t t)))))
1725 (goto-char (point-min))
1726 (let ((re (concat "\\\\\\([a-zA-Z]+\\)"
1727 "\\(?:<[^<>\n]*>\\)*"
1728 "\\(?:\\[[^][\n]*?\\]\\)*"
1729 "\\(?:<[^<>\n]*>\\)*"
1730 "\\("
1731 (org-create-multibrace-regexp "{" "}" 3)
1732 "\\)\\{1,3\\}")))
1733 (while (re-search-forward re nil t)
1734 (unless (or
1735 ;; check for comment line
1736 (save-excursion (goto-char (match-beginning 0))
1737 (org-in-indented-comment-line))
1738 ;; Check if this is a defined entity, so that is may need conversion
1739 (org-entity-get (match-string 1)))
1740 (add-text-properties (match-beginning 0) (match-end 0)
1741 '(org-protected t)))))
1742 (when (plist-get org-export-latex-options-plist :emphasize)
1743 (org-export-latex-fontify))
1744 (org-export-latex-time-stamps)
1745 (org-export-latex-quotation-marks)
1746 (org-export-latex-keywords-maybe)
1747 (org-export-latex-special-chars
1748 (plist-get org-export-latex-options-plist :sub-superscript))
1749 (org-export-latex-links)
1750 (org-trim (buffer-string))))
1752 (defun org-export-latex-time-stamps ()
1753 "Format time stamps."
1754 (goto-char (point-min))
1755 (let ((org-display-custom-times org-export-latex-display-custom-times))
1756 (while (re-search-forward org-ts-regexp-both nil t)
1757 (org-if-unprotected-at (1- (point))
1758 (replace-match
1759 (org-export-latex-protect-string
1760 (format (if (string= "<" (substring (match-string 0) 0 1))
1761 org-export-latex-timestamp-markup
1762 org-export-latex-timestamp-inactive-markup)
1763 (substring (org-translate-time (match-string 0)) 1 -1)))
1764 t t)))))
1766 (defun org-export-latex-quotation-marks ()
1767 "Export quotation marks depending on language conventions."
1768 (mapc (lambda(l)
1769 (goto-char (point-min))
1770 (while (re-search-forward (car l) nil t)
1771 (let ((rpl (concat (match-string 1)
1772 (org-export-latex-protect-string
1773 (copy-sequence (cdr l))))))
1774 (org-if-unprotected-1
1775 (replace-match rpl t t)))))
1776 (cdr (or (assoc (plist-get org-export-latex-options-plist :language)
1777 org-export-latex-quotes)
1778 ;; falls back on english
1779 (assoc "en" org-export-latex-quotes)))))
1781 (defun org-export-latex-special-chars (sub-superscript)
1782 "Export special characters to LaTeX.
1783 If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
1784 See the `org-export-latex.el' code for a complete conversion table."
1785 (goto-char (point-min))
1786 (mapc (lambda(c)
1787 (goto-char (point-min))
1788 (while (re-search-forward c nil t)
1789 ;; Put the point where to check for org-protected
1790 (unless (get-text-property (match-beginning 2) 'org-protected)
1791 (cond ((member (match-string 2) '("\\$" "$"))
1792 (if (equal (match-string 2) "\\$")
1794 (replace-match "\\$" t t)))
1795 ((member (match-string 2) '("&" "%" "#"))
1796 (if (equal (match-string 1) "\\")
1797 (replace-match (match-string 2) t t)
1798 (replace-match (concat (match-string 1) "\\"
1799 (match-string 2)) t t)
1800 (backward-char 1)))
1801 ((equal (match-string 2) "...")
1802 (replace-match
1803 (concat (match-string 1)
1804 (org-export-latex-protect-string "\\ldots{}")) t t))
1805 ((equal (match-string 2) "~")
1806 (cond ((equal (match-string 1) "\\") nil)
1807 ((eq 'org-link (get-text-property 0 'face (match-string 2)))
1808 (replace-match (concat (match-string 1) "\\~") t t))
1809 (t (replace-match
1810 (org-export-latex-protect-string
1811 (concat (match-string 1) "\\~{}")) t t))))
1812 ((member (match-string 2) '("{" "}"))
1813 (unless (save-match-data (org-inside-latex-math-p))
1814 (if (equal (match-string 1) "\\")
1815 (replace-match (match-string 2) t t)
1816 (replace-match (concat (match-string 1) "\\"
1817 (match-string 2)) t t)))))
1818 (unless (save-match-data (or (org-inside-latex-math-p) (org-at-table-p)))
1819 (cond ((equal (match-string 2) "\\")
1820 (replace-match (or (save-match-data
1821 (org-export-latex-treat-backslash-char
1822 (match-string 1)
1823 (or (match-string 3) "")))
1824 "") t t)
1825 (when (and (get-text-property (1- (point)) 'org-entity)
1826 (looking-at "{}"))
1827 ;; OK, this was an entity replacement, and the user
1828 ;; had terminated the entity with {}. Make sure
1829 ;; {} is protected as well, and remove the extra {}
1830 ;; inserted by the conversion.
1831 (put-text-property (point) (+ 2 (point)) 'org-protected t)
1832 (if (save-excursion (goto-char (max (- (point) 2) (point-min)))
1833 (looking-at "{}"))
1834 (replace-match ""))
1835 (forward-char 2))
1836 (backward-char 1))
1837 ((member (match-string 2) '("_" "^"))
1838 (replace-match (or (save-match-data
1839 (org-export-latex-treat-sub-super-char
1840 sub-superscript
1841 (match-string 2)
1842 (match-string 1)
1843 (match-string 3))) "") t t)
1844 (backward-char 1)))))))
1845 '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
1846 "\\(\\(\\\\?\\$\\)\\)"
1847 "\\([a-zA-Z0-9()]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-zA-Z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-zA-Z0-9]+}\\|([a-zA-Z0-9]+)\\)"
1848 "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|\\([&#%{}\"]\\|[a-zA-Z][a-zA-Z0-9]*\\)\\)"
1849 "\\(^\\|.\\)\\([&#%{}~]\\|\\.\\.\\.\\)"
1850 ;; (?\< . "\\textless{}")
1851 ;; (?\> . "\\textgreater{}")
1854 (defun org-inside-latex-math-p ()
1855 (get-text-property (point) 'org-latex-math))
1857 (defun org-export-latex-treat-sub-super-char
1858 (subsup char string-before string-after)
1859 "Convert the \"_\" and \"^\" characters to LaTeX.
1860 SUBSUP corresponds to the ^: option in the #+OPTIONS line.
1861 Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
1862 (cond ((equal string-before "\\")
1863 (concat string-before char string-after))
1864 ((and (string-match "\\S-+" string-after))
1865 ;; this is part of a math formula
1866 (cond ((eq 'org-link (get-text-property 0 'face char))
1867 (concat string-before "\\" char string-after))
1868 ((save-match-data (org-inside-latex-math-p))
1869 (if subsup
1870 (cond ((eq 1 (length string-after))
1871 (concat string-before char string-after))
1872 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
1873 (format "%s%s{%s}" string-before char
1874 (match-string 1 string-after))))))
1875 ((and (> (length string-after) 1)
1876 (or (eq subsup t)
1877 (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
1878 (or (string-match "[{]?\\([^}]+\\)[}]?" string-after)
1879 (string-match "[(]?\\([^)]+\\)[)]?" string-after)))
1881 (org-export-latex-protect-string
1882 (format "%s$%s{%s}$" string-before char
1883 (if (and (> (match-end 1) (1+ (match-beginning 1)))
1884 (not (equal (substring string-after 0 2) "{\\")))
1885 (concat "\\mathrm{" (match-string 1 string-after) "}")
1886 (match-string 1 string-after)))))
1887 ((eq subsup t) (concat string-before "$" char string-after "$"))
1888 (t (org-export-latex-protect-string
1889 (concat string-before "\\" char "{}" string-after)))))
1890 (t (org-export-latex-protect-string
1891 (concat string-before "\\" char "{}" string-after)))))
1893 (defun org-export-latex-treat-backslash-char (string-before string-after)
1894 "Convert the \"$\" special character to LaTeX.
1895 The conversion is made depending of STRING-BEFORE and STRING-AFTER."
1896 (let ((ass (org-entity-get string-after)))
1897 (cond
1898 (ass (org-add-props
1899 (if (nth 2 ass)
1900 (concat string-before
1901 (org-export-latex-protect-string
1902 (concat "$" (nth 1 ass) "$")))
1903 (concat string-before (org-export-latex-protect-string
1904 (nth 1 ass))))
1905 nil 'org-entity t))
1906 ((and (not (string-match "^[ \n\t]" string-after))
1907 (not (string-match "[ \t]\\'\\|^" string-before)))
1908 ;; backslash is inside a word
1909 (concat string-before
1910 (org-export-latex-protect-string
1911 (concat "\\textbackslash{}" string-after))))
1912 ((not (or (equal string-after "")
1913 (string-match "^[ \t\n]" string-after)))
1914 ;; backslash might escape a character (like \#) or a user TeX
1915 ;; macro (like \setcounter)
1916 (concat string-before
1917 (org-export-latex-protect-string (concat "\\" string-after))))
1918 ((and (string-match "^[ \t\n]" string-after)
1919 (string-match "[ \t\n]\\'" string-before))
1920 ;; backslash is alone, convert it to $\backslash$
1921 (org-export-latex-protect-string
1922 (concat string-before "\\textbackslash{}" string-after)))
1923 (t (org-export-latex-protect-string
1924 (concat string-before "\\textbackslash{}" string-after))))))
1926 (defun org-export-latex-keywords ()
1927 "Convert special keywords to LaTeX."
1928 (goto-char (point-min))
1929 (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
1930 (replace-match (format org-export-latex-timestamp-keyword-markup
1931 (match-string 0)) t t)
1932 (save-excursion
1933 (beginning-of-line 1)
1934 (unless (looking-at ".*\n[ \t]*\n")
1935 (end-of-line 1)
1936 (insert "\n")))))
1938 (defun org-export-latex-fixed-width (opt)
1939 "When OPT is non-nil convert fixed-width sections to LaTeX."
1940 (goto-char (point-min))
1941 (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
1942 (unless (get-text-property (point) 'org-example)
1943 (if opt
1944 (progn (goto-char (match-beginning 0))
1945 (insert "\\begin{verbatim}\n")
1946 (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
1947 (replace-match (concat (match-string 1)
1948 (match-string 2)) t t)
1949 (forward-line))
1950 (insert "\\end{verbatim}\n"))
1951 (progn (goto-char (match-beginning 0))
1952 (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
1953 (replace-match (concat "%" (match-string 1)
1954 (match-string 2)) t t)
1955 (forward-line)))))))
1957 (defvar org-table-last-alignment) ; defined in org-table.el
1958 (defvar org-table-last-column-widths) ; defined in org-table.el
1959 (declare-function orgtbl-to-latex "org-table" (table params) t)
1960 (defun org-export-latex-tables (insert)
1961 "Convert tables to LaTeX and INSERT it."
1962 ;; First, get the table.el tables
1963 (goto-char (point-min))
1964 (while (re-search-forward "^[ \t]*\\(\\+-[-+]*\\+\\)[ \t]*\n[ \t]*|" nil t)
1965 (org-if-unprotected
1966 (require 'table)
1967 (org-export-latex-convert-table.el-table)))
1969 ;; And now the Org-mode tables
1970 (goto-char (point-min))
1971 (while (re-search-forward "^\\([ \t]*\\)|" nil t)
1972 (org-if-unprotected-at (1- (point))
1973 (org-table-align)
1974 (let* ((beg (org-table-begin))
1975 (end (org-table-end))
1976 (raw-table (buffer-substring beg end))
1977 (org-table-last-alignment (copy-sequence org-table-last-alignment))
1978 (org-table-last-column-widths (copy-sequence
1979 org-table-last-column-widths))
1980 fnum fields line lines olines gr colgropen line-fmt align
1981 caption width shortn label attr hfmt floatp placement
1982 longtblp tblenv tabular-env)
1983 (if org-export-latex-tables-verbatim
1984 (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
1985 "\\end{verbatim}\n")))
1986 (apply 'delete-region (list beg end))
1987 (insert (org-export-latex-protect-string tbl)))
1988 (progn
1989 (setq caption (org-find-text-property-in-string
1990 'org-caption raw-table)
1991 shortn (org-find-text-property-in-string
1992 'org-caption-shortn raw-table)
1993 attr (org-find-text-property-in-string
1994 'org-attributes raw-table)
1995 label (org-find-text-property-in-string
1996 'org-label raw-table)
1997 longtblp (and attr (stringp attr)
1998 (string-match "\\<longtable\\>" attr))
1999 tblenv (if (and attr (stringp attr))
2000 (cond ((string-match "\\<sidewaystable\\>" attr)
2001 "sidewaystable")
2002 ((or (string-match (regexp-quote "table*") attr)
2003 (string-match "\\<multicolumn\\>" attr))
2004 "table*")
2005 (t "table"))
2006 "table")
2007 tabular-env
2008 (if (and attr (stringp attr)
2009 (string-match "\\(tabular.\\)" attr))
2010 (match-string 1 attr)
2011 org-export-latex-tabular-environment)
2012 width (and attr (stringp attr)
2013 (string-match "\\<width=\\([^ \t\n\r]+\\)" attr)
2014 (match-string 1 attr))
2015 align (and attr (stringp attr)
2016 (string-match "\\<align=\\([^ \t\n\r]+\\)" attr)
2017 (match-string 1 attr))
2018 hfmt (and attr (stringp attr)
2019 (string-match "\\<hfmt=\\(\\S-+\\)" attr)
2020 (match-string 1 attr))
2021 floatp (or caption label (string= "table*" tblenv))
2022 placement (if (and attr
2023 (stringp attr)
2024 (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
2025 (match-string 1 attr)
2026 (concat
2027 "[" org-latex-default-figure-position "]")))
2028 (setq caption (and caption (org-export-latex-fontify-headline caption)))
2029 (setq lines (org-split-string raw-table "\n"))
2030 (apply 'delete-region (list beg end))
2031 (when org-export-table-remove-special-lines
2032 (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
2033 (when org-table-clean-did-remove-column
2034 (pop org-table-last-alignment)
2035 (pop org-table-last-column-widths))
2036 ;; make a format string to reflect alignment
2037 (setq olines lines)
2038 (while (and (not line-fmt) (setq line (pop olines)))
2039 (unless (string-match "^[ \t]*|-" line)
2040 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2041 (setq fnum (make-vector (length fields) 0))
2042 (setq line-fmt
2043 (mapconcat
2044 (lambda (x)
2045 (setq gr (pop org-table-colgroup-info))
2046 (format "%s%%s%s"
2047 (cond ((eq gr :start)
2048 (prog1 (if colgropen "|" "|")
2049 (setq colgropen t)))
2050 ((eq gr :startend)
2051 (prog1 (if colgropen "|" "|")
2052 (setq colgropen nil)))
2053 (t ""))
2054 (if (memq gr '(:end :startend))
2055 (progn (setq colgropen nil) "|")
2056 "")))
2057 fnum ""))))
2058 ;; fix double || in line-fmt
2059 (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
2060 ;; maybe remove the first and last "|"
2061 (when (and (not org-export-latex-tables-column-borders)
2062 (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
2063 (setq line-fmt (match-string 2 line-fmt)))
2064 ;; format alignment
2065 (unless align
2066 (setq align (apply 'format
2067 (cons line-fmt
2068 (mapcar (lambda (x) (if x "r" "l"))
2069 org-table-last-alignment)))))
2070 ;; prepare the table to send to orgtbl-to-latex
2071 (setq lines
2072 (mapcar
2073 (lambda(elem)
2074 (or (and (string-match "[ \t]*|-+" elem) 'hline)
2075 (org-split-string
2076 (progn (set-text-properties 0 (length elem) nil elem)
2077 (org-trim elem)) "|")))
2078 lines))
2079 (when insert
2080 (insert (org-export-latex-protect-string
2081 (concat
2082 (if longtblp
2083 (concat "\\begin{longtable}{" align "}\n")
2084 (if floatp
2085 (format "\\begin{%s}%s\n" tblenv placement)))
2086 (if (and floatp org-export-latex-table-caption-above)
2087 (format
2088 "\\caption%s{%s} %s"
2089 (if shortn (concat "[" shortn "]") "")
2090 (or caption "")
2091 (if label (format "\\label{%s}" label) "")))
2092 (if (and longtblp caption org-export-latex-table-caption-above)
2093 "\\\\\n" "\n")
2094 (if (and org-export-latex-tables-centered (not longtblp))
2095 "\\begin{center}\n")
2096 (if (not longtblp)
2097 (format "\\begin{%s}%s{%s}\n"
2098 tabular-env
2099 (if width (format "{%s}" width) "")
2100 align))
2101 (orgtbl-to-latex
2102 lines
2103 `(:tstart ,org-export-latex-tables-tstart
2104 :tend ,org-export-latex-tables-tend
2105 :hline ,org-export-latex-tables-hline
2106 :skipheadrule ,longtblp
2107 :hfmt ,hfmt
2108 :hlend ,(if longtblp
2109 (format "\\\\
2111 \\endhead
2112 %s\\multicolumn{%d}{r}{Continued on next page}\\
2113 \\endfoot
2114 \\endlastfoot"
2115 org-export-latex-tables-hline
2116 org-export-latex-tables-hline
2117 (length org-table-last-alignment))
2118 nil)))
2119 (if (not longtblp) (format "\n\\end{%s}" tabular-env))
2120 (if longtblp "\n" (if org-export-latex-tables-centered
2121 "\n\\end{center}\n" "\n"))
2122 (if (and floatp (not org-export-latex-table-caption-above))
2123 (format
2124 "\\caption%s{%s} %s"
2125 (if shortn (concat "[" shortn "]") "")
2126 (or caption "")
2127 (if label (format "\\label{%s}" label) "")))
2128 (if longtblp
2129 "\\end{longtable}"
2130 (if floatp (format "\\end{%s}" tblenv)))))
2131 "\n\n"))))))))
2133 (defun org-export-latex-convert-table.el-table ()
2134 "Replace table.el table at point with LaTeX code."
2135 (let (tbl caption shortn label line floatp attr align rmlines)
2136 (setq line (buffer-substring (point-at-bol) (point-at-eol))
2137 label (org-get-text-property-any 0 'org-label line)
2138 caption (org-get-text-property-any 0 'org-caption line)
2139 shortn (org-get-text-property-any 0 'org-caption-shortn line)
2140 attr (org-get-text-property-any 0 'org-attributes line)
2141 align (and attr (stringp attr)
2142 (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
2143 (match-string 1 attr))
2144 rmlines (and attr (stringp attr)
2145 (string-match "\\<rmlines\\>" attr))
2146 floatp (or label caption))
2147 (and (get-buffer "*org-export-table*")
2148 (kill-buffer (get-buffer "*org-export-table*")))
2149 (table-generate-source 'latex "*org-export-table*" "caption")
2150 (setq tbl (with-current-buffer "*org-export-table*"
2151 (buffer-string)))
2152 (while (string-match "^%.*\n" tbl)
2153 (setq tbl (replace-match "" t t tbl)))
2154 ;; fix the hlines
2155 (when rmlines
2156 (let ((n 0) lines)
2157 (setq lines (mapcar (lambda (x)
2158 (if (string-match "^\\\\hline$" x)
2159 (progn
2160 (setq n (1+ n))
2161 (if (= n 2) x nil))
2163 (org-split-string tbl "\n")))
2164 (setq tbl (mapconcat 'identity (delq nil lines) "\n"))))
2165 (when (and align (string-match "\\\\begin{tabular}{.*}" tbl))
2166 (setq tbl (replace-match (concat "\\begin{tabular}{" align "}")
2167 t t tbl)))
2168 (and (get-buffer "*org-export-table*")
2169 (kill-buffer (get-buffer "*org-export-table*")))
2170 (beginning-of-line 0)
2171 (while (looking-at "[ \t]*\\(|\\|\\+-\\)")
2172 (delete-region (point) (1+ (point-at-eol))))
2173 (when org-export-latex-tables-centered
2174 (setq tbl (concat "\\begin{center}\n" tbl "\\end{center}")))
2175 (when floatp
2176 (setq tbl (concat "\\begin{table}\n"
2177 (if (not org-export-latex-table-caption-above) tbl)
2178 (format "\\caption%s{%s%s}\n"
2179 (if shortn (format "[%s]" shortn) "")
2180 (if label (format "\\label{%s}" label) "")
2181 (or caption ""))
2182 (if org-export-latex-table-caption-above tbl)
2183 "\n\\end{table}\n")))
2184 (insert (org-export-latex-protect-string tbl))))
2186 (defun org-export-latex-fontify ()
2187 "Convert fontification to LaTeX."
2188 (goto-char (point-min))
2189 (while (re-search-forward org-emph-re nil t)
2190 ;; The match goes one char after the *string*, except at the end of a line
2191 (let ((emph (assoc (match-string 3)
2192 org-export-latex-emphasis-alist))
2193 (beg (match-beginning 0))
2194 (end (match-end 0))
2195 rpl s)
2196 (unless emph
2197 (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
2198 (match-string 3)))
2199 (unless (or (and (get-text-property (- (point) 2) 'org-protected)
2200 (not (get-text-property
2201 (- (point) 2) 'org-verbatim-emph)))
2202 (equal (char-after (match-beginning 3))
2203 (char-after (1+ (match-beginning 3))))
2204 (save-excursion
2205 (goto-char (match-beginning 1))
2206 (save-match-data
2207 (and (org-at-table-p)
2208 (string-match
2209 "[|\n]" (buffer-substring beg end)))))
2210 (and (equal (match-string 3) "+")
2211 (save-match-data
2212 (string-match "\\`-+\\'" (match-string 4)))))
2213 (setq s (match-string 4))
2214 (setq rpl (concat (match-string 1)
2215 (org-export-latex-emph-format (cadr emph)
2216 (match-string 4))
2217 (match-string 5)))
2218 (if (caddr emph)
2219 (setq rpl (org-export-latex-protect-string rpl))
2220 (save-match-data
2221 (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
2222 (progn
2223 (add-text-properties (match-beginning 1) (match-end 1)
2224 '(org-protected t) rpl)
2225 (add-text-properties (match-beginning 3) (match-end 3)
2226 '(org-protected t) rpl)))))
2227 (replace-match rpl t t)))
2228 (backward-char)))
2230 (defun org-export-latex-emph-format (format string)
2231 "Format an emphasis string and handle the \\verb special case."
2232 (when (member format '("\\verb" "\\protectedtexttt"))
2233 (save-match-data
2234 (if (equal format "\\verb")
2235 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2236 (catch 'exit
2237 (loop for i from 0 to (1- (length ll)) do
2238 (if (not (string-match (regexp-quote (substring ll i (1+ i)))
2239 string))
2240 (progn
2241 (setq format (concat "\\verb" (substring ll i (1+ i))
2242 "%s" (substring ll i (1+ i))))
2243 (throw 'exit nil))))))
2244 (let ((start 0)
2245 (trans '(("\\" . "\\textbackslash{}")
2246 ("~" . "\\textasciitilde{}")
2247 ("^" . "\\textasciicircum{}")))
2248 (rtn "") char)
2249 (while (string-match "[\\{}$%&_#~^]" string)
2250 (setq char (match-string 0 string))
2251 (if (> (match-beginning 0) 0)
2252 (setq rtn (concat rtn (substring string
2253 0 (match-beginning 0)))))
2254 (setq string (substring string (1+ (match-beginning 0))))
2255 (setq char (or (cdr (assoc char trans)) (concat "\\" char))
2256 rtn (concat rtn char)))
2257 (setq string (concat rtn string) format "\\texttt{%s}")
2258 (while (string-match "--" string)
2259 (setq string (replace-match "-{}-" t t string)))))))
2260 (format format string))
2262 (defun org-export-latex-links ()
2263 ;; Make sure to use the LaTeX hyperref and graphicx package
2264 ;; or send some warnings.
2265 "Convert links to LaTeX."
2266 (goto-char (point-min))
2267 (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
2268 (org-if-unprotected-1
2269 (goto-char (match-beginning 0))
2270 (let* ((re-radio org-export-latex-all-targets-re)
2271 (remove (list (match-beginning 0) (match-end 0)))
2272 (raw-path (org-extract-attributes (match-string 3)))
2273 (full-raw-path (concat (match-string 1) raw-path))
2274 (desc (match-string 5))
2275 (type (or (match-string 2)
2276 (if (or (file-name-absolute-p raw-path)
2277 (string-match "^\\.\\.?/" raw-path))
2278 "file")))
2279 (coderefp (equal type "coderef"))
2280 (caption (org-find-text-property-in-string 'org-caption raw-path))
2281 (shortn (org-find-text-property-in-string 'org-caption-shortn raw-path))
2282 (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
2283 (plist-get org-export-latex-options-plist :latex-image-options)))
2284 (label (org-find-text-property-in-string 'org-label raw-path))
2285 imgp radiop fnc
2286 ;; define the path of the link
2287 (path (cond
2288 ((member type '("coderef"))
2289 raw-path)
2290 ((member type '("http" "https" "ftp"))
2291 (concat type ":" raw-path))
2292 ((and re-radio (string-match re-radio raw-path))
2293 (setq radiop t))
2294 ((equal type "mailto")
2295 (concat type ":" raw-path))
2296 ((equal type "file")
2297 (if (and (org-file-image-p
2298 (expand-file-name
2299 raw-path)
2300 org-export-latex-inline-image-extensions)
2301 (or (get-text-property 0 'org-no-description
2302 raw-path)
2303 (equal desc full-raw-path)))
2304 (setq imgp t)
2305 (progn (when (string-match "\\(.+\\)::.+" raw-path)
2306 (setq raw-path (match-string 1 raw-path)))
2307 (if (file-exists-p raw-path)
2308 (concat type "://" (expand-file-name raw-path))
2309 (concat type "://" (org-export-directory
2310 :LaTeX org-export-latex-options-plist)
2311 raw-path))))))))
2312 ;; process with link inserting
2313 (apply 'delete-region remove)
2314 (setq caption (and caption (org-export-latex-fontify-headline caption)))
2315 (cond ((and imgp
2316 (plist-get org-export-latex-options-plist :inline-images))
2317 ;; OK, we need to inline an image
2318 (insert
2319 (org-export-latex-format-image raw-path caption label attr shortn)))
2320 (coderefp
2321 (insert (format
2322 (org-export-get-coderef-format path desc)
2323 (cdr (assoc path org-export-code-refs)))))
2324 (radiop (insert (format org-export-latex-hyperref-format
2325 (org-solidify-link-text raw-path) desc)))
2326 ((not type)
2327 (insert (format org-export-latex-hyperref-format
2328 (org-remove-initial-hash
2329 (org-solidify-link-text raw-path))
2330 desc)))
2331 (path
2332 (when (org-at-table-p)
2333 ;; There is a strange problem when we have a link in a table,
2334 ;; ampersands then cause a problem. I think this must be
2335 ;; a LaTeX issue, but we here implement a work-around anyway.
2336 (setq path (org-export-latex-protect-amp path)
2337 desc (org-export-latex-protect-amp desc)))
2338 (insert
2339 (if (string-match "%s.*%s" org-export-latex-href-format)
2340 (format org-export-latex-href-format path desc)
2341 (format org-export-latex-href-format path))))
2343 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2344 ;; The link protocol has a function for formatting the link
2345 (insert
2346 (save-match-data
2347 (funcall fnc (org-link-unescape raw-path) desc 'latex))))
2348 ;; Unrecognized path type
2349 (t (insert (format org-export-latex-link-with-unknown-path-format desc))))))))
2352 (defun org-export-latex-format-image (path caption label attr &optional shortn)
2353 "Format the image element, depending on user settings."
2354 (let (ind floatp wrapp multicolumnp placement figenv)
2355 (setq floatp (or caption label))
2356 (setq ind (org-get-text-property-any 0 'original-indentation path))
2357 (when (and attr (stringp attr))
2358 (if (string-match "[ \t]*\\<wrap\\>" attr)
2359 (setq wrapp t floatp nil attr (replace-match "" t t attr)))
2360 (if (string-match "[ \t]*\\<float\\>" attr)
2361 (setq wrapp nil floatp t attr (replace-match "" t t attr)))
2362 (if (string-match "[ \t]*\\<multicolumn\\>" attr)
2363 (setq multicolumnp t attr (replace-match "" t t attr))))
2365 (setq placement
2366 (cond
2367 (wrapp "{l}{0.5\\textwidth}")
2368 (floatp (concat "[" org-latex-default-figure-position "]"))
2369 (t "")))
2371 (when (and attr (stringp attr)
2372 (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
2373 (setq placement (match-string 1 attr)
2374 attr (replace-match "" t t attr)))
2375 (setq attr (and attr (org-trim attr)))
2376 (when (or (not attr) (= (length attr) 0))
2377 (setq attr (cond (floatp "width=0.7\\textwidth")
2378 (wrapp "width=0.48\\textwidth")
2379 (t attr))))
2380 (setq figenv
2381 (cond
2382 (wrapp "\\begin{wrapfigure}%placement
2383 \\centering
2384 \\includegraphics[%attr]{%path}
2385 \\caption%shortn{%labelcmd%caption}
2386 \\end{wrapfigure}")
2387 (multicolumnp "\\begin{figure*}%placement
2388 \\centering
2389 \\includegraphics[%attr]{%path}
2390 \\caption%shortn{%labelcmd%caption}
2391 \\end{figure*}")
2392 (floatp "\\begin{figure}%placement
2393 \\centering
2394 \\includegraphics[%attr]{%path}
2395 \\caption%shortn{%labelcmd%caption}
2396 \\end{figure}")
2397 (t "\\includegraphics[%attr]{%path}")))
2400 (setq figenv (mapconcat 'identity (split-string figenv "\n")
2401 (save-excursion (beginning-of-line 1)
2402 (looking-at "[ \t]*")
2403 (concat "\n" (match-string 0)))))
2405 (if (and (not label) (not caption)
2406 (string-match "^\\\\caption{.*\n" figenv))
2407 (setq figenv (replace-match "" t t figenv)))
2408 (org-add-props
2409 (org-fill-template
2410 figenv
2411 (list (cons "path"
2412 (if (file-name-absolute-p path)
2413 (expand-file-name path)
2414 path))
2415 (cons "attr" attr)
2416 (cons "shortn" (if shortn (format "[%s]" shortn) ""))
2417 (cons "labelcmd" (if label (format "\\label{%s}"
2418 label)""))
2419 (cons "caption" (or caption ""))
2420 (cons "placement" (or placement ""))))
2421 nil 'original-indentation ind)))
2423 (defun org-export-latex-protect-amp (s)
2424 (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
2425 (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
2426 t t s)))
2429 (defun org-remove-initial-hash (s)
2430 (if (string-match "\\`#" s)
2431 (substring s 1)
2433 (defvar org-latex-entities) ; defined below
2434 (defvar org-latex-entities-regexp) ; defined below
2436 (defun org-export-latex-preprocess (parameters)
2437 "Clean stuff in the LaTeX export."
2438 ;; Replace footnotes.
2439 (when (plist-get parameters :footnotes)
2440 (goto-char (point-min))
2441 (let (ref)
2442 (while (setq ref (org-footnote-get-next-reference))
2443 (let* ((beg (nth 1 ref))
2444 (lbl (car ref))
2445 (def (nth 1 (assoc (string-to-number lbl)
2446 (mapcar (lambda (e) (cdr e))
2447 org-export-footnotes-seen)))))
2448 ;; Fix body for footnotes ending on a link or a list and
2449 ;; remove definition from buffer.
2450 (setq def
2451 (concat def
2452 (if (string-match "ORG-LIST-END-MARKER\\'" def)
2453 "\n" " ")))
2454 (org-footnote-delete-definitions lbl)
2455 ;; Compute string to insert (FNOTE), and protect the outside
2456 ;; macro from further transformation. When footnote at
2457 ;; point is referring to a previously defined footnote, use
2458 ;; \footnotemark. Otherwise, use \footnote.
2459 (let ((fnote (if (member lbl org-export-latex-footmark-seen)
2460 (org-export-latex-protect-string
2461 (format "\\footnotemark[%s]" lbl))
2462 (push lbl org-export-latex-footmark-seen)
2463 (concat (org-export-latex-protect-string "\\footnote{")
2465 (org-export-latex-protect-string "}"))))
2466 ;; Check if another footnote is immediately following.
2467 ;; If so, add a separator in-between.
2468 (sep (org-export-latex-protect-string
2469 (if (save-excursion (goto-char (1- (nth 2 ref)))
2470 (let ((next (org-footnote-get-next-reference)))
2471 (and next (= (nth 1 next) (nth 2 ref)))))
2472 org-export-latex-footnote-separator ""))))
2473 (when (org-at-heading-p)
2474 (setq fnote (concat (org-export-latex-protect-string "\\protect")
2475 fnote)))
2476 ;; Ensure a footnote at column 0 cannot end a list
2477 ;; containing it.
2478 (put-text-property 0 (length fnote) 'original-indentation 1000 fnote)
2479 ;; Replace footnote reference with FNOTE and, maybe, SEP.
2480 ;; `save-excursion' is required if there are two footnotes
2481 ;; in a row. In that case, point would be left at the
2482 ;; beginning of the second one, and
2483 ;; `org-footnote-get-next-reference' would then skip it.
2484 (goto-char beg)
2485 (delete-region beg (nth 2 ref))
2486 (save-excursion (insert fnote sep)))))))
2488 ;; Remove footnote section tag for LaTeX
2489 (goto-char (point-min))
2490 (while (re-search-forward
2491 (concat "^" footnote-section-tag-regexp) nil t)
2492 (org-if-unprotected
2493 (replace-match "")))
2494 ;; Remove any left-over footnote definition.
2495 (mapc (lambda (fn) (org-footnote-delete-definitions (car fn)))
2496 org-export-footnotes-data)
2497 (mapc (lambda (fn) (org-footnote-delete-definitions fn))
2498 org-export-latex-footmark-seen)
2500 ;; Preserve line breaks
2501 (goto-char (point-min))
2502 (while (re-search-forward "\\\\\\\\" nil t)
2503 (add-text-properties (match-beginning 0) (match-end 0)
2504 '(org-protected t)))
2506 ;; Preserve latex environments
2507 (goto-char (point-min))
2508 (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
2509 (org-if-unprotected
2510 (let* ((start (progn (beginning-of-line) (point)))
2511 (end (and (re-search-forward
2512 (concat "^[ \t]*\\\\end{"
2513 (regexp-quote (match-string 1))
2514 "}") nil t)
2515 (point-at-eol))))
2516 (if end
2517 (add-text-properties start end '(org-protected t))
2518 (goto-char (point-at-eol))))))
2520 ;; Preserve math snippets
2521 (let* ((matchers (plist-get org-format-latex-options :matchers))
2522 (re-list org-latex-regexps)
2523 beg end re e m n block off)
2524 ;; Check the different regular expressions
2525 (while (setq e (pop re-list))
2526 (setq m (car e) re (nth 1 e) n (nth 2 e)
2527 block (if (nth 3 e) "\n\n" ""))
2528 (setq off (if (member m '("$" "$1")) 1 0))
2529 (when (and (member m matchers) (not (equal m "begin")))
2530 (goto-char (point-min))
2531 (while (re-search-forward re nil t)
2532 (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
2533 (add-text-properties beg end '(org-protected t org-latex-math t))))))
2535 ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
2536 (goto-char (point-min))
2537 (let ((case-fold-search nil))
2538 (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
2539 (unless (eq (char-before (match-beginning 1)) ?\\)
2540 (org-if-unprotected-1
2541 (replace-match (org-export-latex-protect-string
2542 (concat "\\" (match-string 1)
2543 "{}")) t t)))))
2545 ;; Convert blockquotes
2546 (goto-char (point-min))
2547 (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
2548 (org-replace-match-keep-properties "\\begin{quote}" t t))
2549 (goto-char (point-min))
2550 (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
2551 (org-replace-match-keep-properties "\\end{quote}" t t))
2553 ;; Convert verse
2554 (goto-char (point-min))
2555 (while (search-forward "ORG-VERSE-START" nil t)
2556 (org-replace-match-keep-properties "\\begin{verse}" t t)
2557 (beginning-of-line 2)
2558 (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
2559 (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
2560 (goto-char (match-end 1))
2561 (org-replace-match-keep-properties
2562 (org-export-latex-protect-string
2563 (concat "\\hspace*{1cm}" (match-string 2))) t t)
2564 (beginning-of-line 1))
2565 (if (looking-at "[ \t]*$")
2566 (insert (org-export-latex-protect-string "\\vspace*{1em}"))
2567 (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
2568 (end-of-line 1)
2569 (insert "\\\\")))
2570 (beginning-of-line 2))
2571 (and (looking-at "[ \t]*ORG-VERSE-END.*")
2572 (org-replace-match-keep-properties "\\end{verse}" t t)))
2574 ;; Convert #+INDEX to LaTeX \\index.
2575 (goto-char (point-min))
2576 (let ((case-fold-search t) entry)
2577 (while (re-search-forward
2578 "^[ \t]*#\\+index:[ \t]*\\([^ \t\r\n].*?\\)[ \t]*$"
2579 nil t)
2580 (setq entry
2581 (save-match-data
2582 (org-export-latex-protect-string
2583 (org-export-latex-fontify-headline (match-string 1)))))
2584 (replace-match (format "\\index{%s}" entry) t t)))
2586 ;; Convert center
2587 (goto-char (point-min))
2588 (while (search-forward "ORG-CENTER-START" nil t)
2589 (org-replace-match-keep-properties "\\begin{center}" t t))
2590 (goto-char (point-min))
2591 (while (search-forward "ORG-CENTER-END" nil t)
2592 (org-replace-match-keep-properties "\\end{center}" t t))
2594 (run-hooks 'org-export-latex-after-blockquotes-hook)
2596 ;; Convert horizontal rules
2597 (goto-char (point-min))
2598 (while (re-search-forward "^[ \t]*-\\{5,\\}[ \t]*$" nil t)
2599 (org-if-unprotected
2600 (replace-match (org-export-latex-protect-string "\\hrule") t t)))
2602 ;; Protect LaTeX commands like \command[...]{...} or \command{...}
2603 (goto-char (point-min))
2604 (let ((re (concat
2605 "\\\\\\([a-zA-Z]+\\*?\\)"
2606 "\\(?:<[^<>\n]*>\\)*"
2607 "\\(?:\\[[^][\n]*?\\]\\)*"
2608 "\\(?:<[^<>\n]*>\\)*"
2609 "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}")))
2610 (while (re-search-forward re nil t)
2611 (unless (or
2612 ;; Check for comment line.
2613 (save-excursion (goto-char (match-beginning 0))
2614 (org-in-indented-comment-line))
2615 ;; Check if this is a defined entity, so that is may
2616 ;; need conversion.
2617 (org-entity-get (match-string 1))
2618 ;; Do not protect interior of footnotes. Those have
2619 ;; already been taken care of earlier in the function.
2620 ;; Yet, keep looking inside them for more commands.
2621 (and (equal (match-string 1) "footnote")
2622 (goto-char (match-end 1))))
2623 (add-text-properties (match-beginning 0) (match-end 0)
2624 '(org-protected t)))))
2626 ;; Special case for \nbsp
2627 (goto-char (point-min))
2628 (while (re-search-forward "\\\\nbsp\\({}\\|\\>\\)" nil t)
2629 (org-if-unprotected
2630 (replace-match (org-export-latex-protect-string "~"))))
2632 ;; Protect LaTeX entities
2633 (goto-char (point-min))
2634 (while (re-search-forward org-latex-entities-regexp nil t)
2635 (org-if-unprotected
2636 (add-text-properties (match-beginning 0) (match-end 0)
2637 '(org-protected t))))
2639 ;; Replace radio links
2640 (goto-char (point-min))
2641 (while (re-search-forward
2642 (concat "<<<?" org-export-latex-all-targets-re
2643 ">>>?\\((INVISIBLE)\\)?") nil t)
2644 (org-if-unprotected-at (+ (match-beginning 0) 2)
2645 (replace-match
2646 (concat
2647 (org-export-latex-protect-string
2648 (format "\\label{%s}" (save-match-data (org-solidify-link-text
2649 (match-string 1)))))
2650 (if (match-string 2) "" (match-string 1)))
2651 t t)))
2653 ;; Delete @<...> constructs
2654 ;; Thanks to Daniel Clemente for this regexp
2655 (goto-char (point-min))
2656 (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
2657 (org-if-unprotected
2658 (replace-match ""))))
2660 (defun org-export-latex-fix-inputenc ()
2661 "Set the coding system in inputenc to what the buffer is."
2662 (let* ((cs buffer-file-coding-system)
2663 (opt (or (ignore-errors (latexenc-coding-system-to-inputenc cs))
2664 "utf8")))
2665 (when opt
2666 ;; Translate if that is requested
2667 (setq opt (or (cdr (assoc opt org-export-latex-inputenc-alist)) opt))
2668 ;; find the \usepackage statement and replace the option
2669 (goto-char (point-min))
2670 (while (re-search-forward "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
2671 nil t)
2672 (goto-char (match-beginning 1))
2673 (delete-region (match-beginning 1) (match-end 1))
2674 (insert opt))
2675 (and buffer-file-name
2676 (save-buffer)))))
2678 ;;; List handling:
2680 (defun org-export-latex-lists ()
2681 "Convert plain text lists in current buffer into LaTeX lists."
2682 ;; `org-list-end-re' output has changed since preprocess from
2683 ;; org-exp.el. Make sure it is taken into account.
2684 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
2685 (mapc
2686 (lambda (e)
2687 ;; For each type of context allowed for list export (E), find
2688 ;; every list, parse it, delete it and insert resulting
2689 ;; conversion to latex (RES), while keeping the same
2690 ;; `original-indentation' property.
2691 (let (res)
2692 (goto-char (point-min))
2693 (while (re-search-forward (org-item-beginning-re) nil t)
2694 (when (and (eq (get-text-property (point) 'list-context) e)
2695 (not (get-text-property (point) 'org-example)))
2696 (beginning-of-line)
2697 (setq res
2698 (org-list-to-latex
2699 ;; Narrowing is needed because we're converting
2700 ;; from inner functions to outer ones.
2701 (save-restriction
2702 (narrow-to-region (point) (point-max))
2703 (org-list-parse-list t))
2704 org-export-latex-list-parameters))
2705 ;; Extend previous value of original-indentation to the
2706 ;; whole string
2707 (insert (org-add-props res nil 'original-indentation
2708 (org-find-text-property-in-string
2709 'original-indentation res)))))))
2710 ;; List of allowed contexts for export, and the default one.
2711 (append org-list-export-context '(nil)))))
2713 (defconst org-latex-entities
2714 '("\\!"
2715 "\\'"
2716 "\\+"
2717 "\\,"
2718 "\\-"
2719 "\\:"
2720 "\\;"
2721 "\\<"
2722 "\\="
2723 "\\>"
2724 "\\Huge"
2725 "\\LARGE"
2726 "\\Large"
2727 "\\Styles"
2728 "\\\\"
2729 "\\`"
2730 "\\\""
2731 "\\addcontentsline"
2732 "\\address"
2733 "\\addtocontents"
2734 "\\addtocounter"
2735 "\\addtolength"
2736 "\\addvspace"
2737 "\\alph"
2738 "\\appendix"
2739 "\\arabic"
2740 "\\author"
2741 "\\begin{array}"
2742 "\\begin{center}"
2743 "\\begin{description}"
2744 "\\begin{enumerate}"
2745 "\\begin{eqnarray}"
2746 "\\begin{equation}"
2747 "\\begin{figure}"
2748 "\\begin{flushleft}"
2749 "\\begin{flushright}"
2750 "\\begin{itemize}"
2751 "\\begin{list}"
2752 "\\begin{minipage}"
2753 "\\begin{picture}"
2754 "\\begin{quotation}"
2755 "\\begin{quote}"
2756 "\\begin{tabbing}"
2757 "\\begin{table}"
2758 "\\begin{tabular}"
2759 "\\begin{thebibliography}"
2760 "\\begin{theorem}"
2761 "\\begin{titlepage}"
2762 "\\begin{verbatim}"
2763 "\\begin{verse}"
2764 "\\bf"
2765 "\\bf"
2766 "\\bibitem"
2767 "\\bigskip"
2768 "\\cdots"
2769 "\\centering"
2770 "\\circle"
2771 "\\cite"
2772 "\\cleardoublepage"
2773 "\\clearpage"
2774 "\\cline"
2775 "\\closing"
2776 "\\dashbox"
2777 "\\date"
2778 "\\ddots"
2779 "\\dotfill"
2780 "\\em"
2781 "\\fbox"
2782 "\\flushbottom"
2783 "\\fnsymbol"
2784 "\\footnote"
2785 "\\footnotemark"
2786 "\\footnotesize"
2787 "\\footnotetext"
2788 "\\frac"
2789 "\\frame"
2790 "\\framebox"
2791 "\\hfill"
2792 "\\hline"
2793 "\\hrulespace"
2794 "\\hspace"
2795 "\\huge"
2796 "\\hyphenation"
2797 "\\include"
2798 "\\includeonly"
2799 "\\indent"
2800 "\\input"
2801 "\\it"
2802 "\\kill"
2803 "\\label"
2804 "\\large"
2805 "\\ldots"
2806 "\\line"
2807 "\\linebreak"
2808 "\\linethickness"
2809 "\\listoffigures"
2810 "\\listoftables"
2811 "\\location"
2812 "\\makebox"
2813 "\\maketitle"
2814 "\\mark"
2815 "\\mbox"
2816 "\\medskip"
2817 "\\multicolumn"
2818 "\\multiput"
2819 "\\newcommand"
2820 "\\newcounter"
2821 "\\newenvironment"
2822 "\\newfont"
2823 "\\newlength"
2824 "\\newline"
2825 "\\newpage"
2826 "\\newsavebox"
2827 "\\newtheorem"
2828 "\\nocite"
2829 "\\nofiles"
2830 "\\noindent"
2831 "\\nolinebreak"
2832 "\\nopagebreak"
2833 "\\normalsize"
2834 "\\onecolumn"
2835 "\\opening"
2836 "\\oval"
2837 "\\overbrace"
2838 "\\overline"
2839 "\\pagebreak"
2840 "\\pagenumbering"
2841 "\\pageref"
2842 "\\pagestyle"
2843 "\\par"
2844 "\\parbox"
2845 "\\put"
2846 "\\raggedbottom"
2847 "\\raggedleft"
2848 "\\raggedright"
2849 "\\raisebox"
2850 "\\ref"
2851 "\\rm"
2852 "\\roman"
2853 "\\rule"
2854 "\\savebox"
2855 "\\sc"
2856 "\\scriptsize"
2857 "\\setcounter"
2858 "\\setlength"
2859 "\\settowidth"
2860 "\\sf"
2861 "\\shortstack"
2862 "\\signature"
2863 "\\sl"
2864 "\\small"
2865 "\\smallskip"
2866 "\\sqrt"
2867 "\\tableofcontents"
2868 "\\telephone"
2869 "\\thanks"
2870 "\\thispagestyle"
2871 "\\tiny"
2872 "\\title"
2873 "\\tt"
2874 "\\twocolumn"
2875 "\\typein"
2876 "\\typeout"
2877 "\\underbrace"
2878 "\\underline"
2879 "\\usebox"
2880 "\\usecounter"
2881 "\\value"
2882 "\\vdots"
2883 "\\vector"
2884 "\\verb"
2885 "\\vfill"
2886 "\\vline"
2887 "\\vspace")
2888 "A list of LaTeX commands to be protected when performing conversion.")
2890 (defconst org-latex-entities-regexp
2891 (let (names rest)
2892 (dolist (x org-latex-entities)
2893 (if (string-match "[a-zA-Z]$" x)
2894 (push x names)
2895 (push x rest)))
2896 (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
2897 "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
2899 (provide 'org-export-latex)
2900 (provide 'org-latex)
2902 ;;; org-latex.el ends here