org-html.el (org-html-handle-links): Fix bug in setting the attribute for link with...
[org-mode.git] / lisp / org-latex.el
blob609bcbee1037f07576ffbd3bbaee020b03125009
1 ;;; org-latex.el --- LaTeX exporter for org-mode
2 ;;
3 ;; Copyright (C) 2007-2013 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))
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 "*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 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 ext-plist to-buffer body-only pub-dir)
860 "Export current buffer to a LaTeX file.
861 If there is an active region, export only the region. The prefix
862 ARG specifies how many levels of the outline should become
863 headlines. The default is 3. Lower levels will be exported
864 depending on `org-export-latex-low-levels'. The default is to
865 convert them as description lists.
866 EXT-PLIST is a property list with external parameters overriding
867 org-mode's default settings, but still inferior to file-local settings.
868 When TO-BUFFER is non-nil, create a buffer with that name and export
869 to that buffer. If TO-BUFFER is the symbol `string', don't leave any
870 buffer behind and just return the resulting LaTeX as a string, with
871 no LaTeX header.
872 When BODY-ONLY is set, don't produce the file header and footer,
873 simply return the content of \\begin{document}...\\end{document},
874 without even the \\begin{document} and \\end{document} commands.
875 When PUB-DIR is set, use this as the publishing directory."
876 (interactive "P")
877 (when (and (not body-only) arg (listp arg)) (setq body-only t))
878 (run-hooks 'org-export-first-hook)
880 ;; Make sure we have a file name when we need it.
881 (when (and (not (or to-buffer body-only))
882 (not buffer-file-name))
883 (if (buffer-base-buffer)
884 (org-set-local 'buffer-file-name
885 (with-current-buffer (buffer-base-buffer)
886 buffer-file-name))
887 (error "Need a file name to be able to export")))
889 (message "Exporting to LaTeX...")
890 (org-unmodified
891 (let ((inhibit-read-only t))
892 (remove-text-properties (point-min) (point-max)
893 '(:org-license-to-kill nil))))
894 (org-update-radio-target-regexp)
895 (org-export-latex-set-initial-vars ext-plist arg)
896 (setq org-export-opt-plist org-export-latex-options-plist
897 org-export-footnotes-data (org-footnote-all-labels 'with-defs)
898 org-export-footnotes-seen nil
899 org-export-latex-footmark-seen nil)
900 (org-install-letbind)
901 (run-hooks 'org-export-latex-after-initial-vars-hook)
902 (let* ((wcf (current-window-configuration))
903 (opt-plist
904 (org-export-process-option-filters org-export-latex-options-plist))
905 (region-p (org-region-active-p))
906 (rbeg (and region-p (region-beginning)))
907 (rend (and region-p (region-end)))
908 (subtree-p
909 (if (plist-get opt-plist :ignore-subtree-p)
911 (when region-p
912 (save-excursion
913 (goto-char rbeg)
914 (and (org-at-heading-p)
915 (>= (org-end-of-subtree t t) rend))))))
916 (opt-plist (setq org-export-opt-plist
917 (if subtree-p
918 (org-export-add-subtree-options opt-plist rbeg)
919 opt-plist)))
920 ;; Make sure the variable contains the updated values.
921 (org-export-latex-options-plist (setq org-export-opt-plist opt-plist))
922 ;; The following two are dynamically scoped into other
923 ;; routines below.
924 (org-current-export-dir
925 (or pub-dir (org-export-directory :html opt-plist)))
926 (org-current-export-file buffer-file-name)
927 (title (or (and subtree-p (org-export-get-title-from-subtree))
928 (plist-get opt-plist :title)
929 (and (not
930 (plist-get opt-plist :skip-before-1st-heading))
931 (org-export-grab-title-from-buffer))
932 (and buffer-file-name
933 (file-name-sans-extension
934 (file-name-nondirectory buffer-file-name)))
935 "No Title"))
936 (filename
937 (and (not to-buffer)
938 (concat
939 (file-name-as-directory
940 (or pub-dir
941 (org-export-directory :LaTeX org-export-latex-options-plist)))
942 (file-name-sans-extension
943 (or (and subtree-p
944 (org-entry-get rbeg "EXPORT_FILE_NAME" t))
945 (file-name-nondirectory ;sans-extension
946 (or buffer-file-name
947 (error "Don't know which export file to use")))))
948 ".tex")))
949 (filename
950 (and filename
951 (if (equal (file-truename filename)
952 (file-truename (or buffer-file-name "dummy.org")))
953 (concat filename ".tex")
954 filename)))
955 (auto-insert nil); Avoid any auto-insert stuff for the new file
956 (TeX-master (boundp 'TeX-master))
957 (buffer (if to-buffer
958 (if (eq to-buffer 'string)
959 (get-buffer-create "*Org LaTeX Export*")
960 (get-buffer-create to-buffer))
961 (find-file-noselect filename)))
962 (odd org-odd-levels-only)
963 (header (org-export-latex-make-header title opt-plist))
964 (skip (cond (subtree-p nil)
965 (region-p nil)
966 (t (plist-get opt-plist :skip-before-1st-heading))))
967 (text (plist-get opt-plist :text))
968 (org-export-preprocess-hook
969 (cons
970 `(lambda () (org-set-local 'org-complex-heading-regexp
971 ,org-export-latex-complex-heading-re))
972 org-export-preprocess-hook))
973 (first-lines (if skip "" (org-export-latex-first-lines
974 opt-plist
975 (if subtree-p
976 (save-excursion
977 (goto-char rbeg)
978 (point-at-bol 2))
979 rbeg)
980 (if region-p rend))))
981 (coding-system (and (boundp 'buffer-file-coding-system)
982 buffer-file-coding-system))
983 (coding-system-for-write (or org-export-latex-coding-system
984 coding-system))
985 (save-buffer-coding-system (or org-export-latex-coding-system
986 coding-system))
987 (region (buffer-substring
988 (if region-p (region-beginning) (point-min))
989 (if region-p (region-end) (point-max))))
990 (text
991 (and text (string-match "\\S-" text)
992 (org-export-preprocess-string
993 text
994 :emph-multiline t
995 :for-backend 'latex
996 :comments nil
997 :tags (plist-get opt-plist :tags)
998 :priority (plist-get opt-plist :priority)
999 :footnotes (plist-get opt-plist :footnotes)
1000 :drawers (plist-get opt-plist :drawers)
1001 :timestamps (plist-get opt-plist :timestamps)
1002 :todo-keywords (plist-get opt-plist :todo-keywords)
1003 :tasks (plist-get opt-plist :tasks)
1004 :add-text nil
1005 :skip-before-1st-heading skip
1006 :select-tags nil
1007 :exclude-tags nil
1008 :LaTeX-fragments nil)))
1009 (string-for-export
1010 (org-export-preprocess-string
1011 region
1012 :emph-multiline t
1013 :for-backend 'latex
1014 :comments nil
1015 :tags (plist-get opt-plist :tags)
1016 :priority (plist-get opt-plist :priority)
1017 :footnotes (plist-get opt-plist :footnotes)
1018 :drawers (plist-get opt-plist :drawers)
1019 :timestamps (plist-get opt-plist :timestamps)
1020 :todo-keywords (plist-get opt-plist :todo-keywords)
1021 :tasks (plist-get opt-plist :tasks)
1022 :add-text (if (eq to-buffer 'string) nil text)
1023 :skip-before-1st-heading skip
1024 :select-tags (plist-get opt-plist :select-tags)
1025 :exclude-tags (plist-get opt-plist :exclude-tags)
1026 :LaTeX-fragments nil)))
1028 (set-buffer buffer)
1029 (erase-buffer)
1030 (org-install-letbind)
1032 (and (fboundp 'set-buffer-file-coding-system)
1033 (set-buffer-file-coding-system coding-system-for-write))
1035 ;; insert the header and initial document commands
1036 (unless (or (eq to-buffer 'string) body-only)
1037 (insert header))
1039 ;; insert text found in #+TEXT
1040 (when (and text (not (eq to-buffer 'string)))
1041 (insert (org-export-latex-content
1042 text '(lists tables fixed-width keywords))
1043 "\n\n"))
1045 ;; insert lines before the first headline
1046 (unless (or skip (string-match "^\\*" first-lines))
1047 (insert first-lines))
1049 ;; export the content of headlines
1050 (org-export-latex-global
1051 (with-temp-buffer
1052 (insert string-for-export)
1053 (goto-char (point-min))
1054 (when (re-search-forward "^\\(\\*+\\) " nil t)
1055 (let* ((asters (length (match-string 1)))
1056 (level (if odd (- asters 2) (- asters 1))))
1057 (setq org-export-latex-add-level
1058 (if odd (1- (/ (1+ asters) 2)) (1- asters)))
1059 (org-export-latex-parse-global level odd)))))
1061 ;; finalization
1062 (unless body-only (insert "\n\\end{document}"))
1064 ;; Attach description terms to the \item macro
1065 (goto-char (point-min))
1066 (while (re-search-forward "^[ \t]*\\\\item\\([ \t]+\\)\\[" nil t)
1067 (delete-region (match-beginning 1) (match-end 1)))
1069 ;; Relocate the table of contents
1070 (goto-char (point-min))
1071 (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
1072 (goto-char (point-min))
1073 (while (re-search-forward "\\\\tableofcontents\\>[ \t]*\n?" nil t)
1074 (replace-match ""))
1075 (goto-char (point-min))
1076 (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
1077 (replace-match "\\tableofcontents" t t)))
1079 ;; Cleanup forced line ends in items where they are not needed
1080 (goto-char (point-min))
1081 (while (re-search-forward
1082 "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*\n\\\\begin"
1083 nil t)
1084 (delete-region (match-beginning 1) (match-end 1)))
1085 (goto-char (point-min))
1086 (while (re-search-forward
1087 "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*"
1088 nil t)
1089 (if (looking-at "[\n \t]+")
1090 (replace-match "\n")))
1092 ;; Ensure we have a final newline
1093 (goto-char (point-max))
1094 (or (eq (char-before) ?\n)
1095 (insert ?\n))
1097 (run-hooks 'org-export-latex-final-hook)
1098 (if to-buffer
1099 (unless (eq major-mode 'latex-mode) (latex-mode))
1100 (save-buffer))
1101 (org-export-latex-fix-inputenc)
1102 (run-hooks 'org-export-latex-after-save-hook)
1103 (goto-char (point-min))
1104 (or (org-export-push-to-kill-ring "LaTeX")
1105 (message "Exporting to LaTeX...done"))
1106 (prog1
1107 (if (eq to-buffer 'string)
1108 (prog1 (buffer-substring (point-min) (point-max))
1109 (kill-buffer (current-buffer)))
1110 (current-buffer))
1111 (set-window-configuration wcf))))
1113 ;;;###autoload
1114 (defun org-export-as-pdf (arg &optional hidden ext-plist
1115 to-buffer body-only pub-dir)
1116 "Export as LaTeX, then process through to PDF."
1117 (interactive "P")
1118 (message "Exporting to PDF...")
1119 (let* ((wconfig (current-window-configuration))
1120 (lbuf (org-export-as-latex arg ext-plist to-buffer body-only pub-dir))
1121 (file (buffer-file-name lbuf))
1122 (base (file-name-sans-extension (buffer-file-name lbuf)))
1123 (pdffile (concat base ".pdf"))
1124 (cmds (if (eq org-export-latex-listings 'minted)
1125 ;; automatically add -shell-escape when needed
1126 (mapcar (lambda (cmd)
1127 (replace-regexp-in-string
1128 "pdflatex " "pdflatex -shell-escape " cmd))
1129 org-latex-to-pdf-process)
1130 org-latex-to-pdf-process))
1131 (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
1132 (bibtex-p (with-current-buffer lbuf
1133 (save-excursion
1134 (goto-char (point-min))
1135 (re-search-forward "\\\\bibliography{" nil t))))
1136 cmd output-dir errors)
1137 (with-current-buffer outbuf (erase-buffer))
1138 (message (concat "Processing LaTeX file " file "..."))
1139 (setq output-dir (file-name-directory file))
1140 (with-current-buffer lbuf
1141 (save-excursion
1142 (if (and cmds (symbolp cmds))
1143 (funcall cmds (shell-quote-argument file))
1144 (while cmds
1145 (setq cmd (pop cmds))
1146 (cond
1147 ((not (listp cmd))
1148 (while (string-match "%b" cmd)
1149 (setq cmd (replace-match
1150 (save-match-data
1151 (shell-quote-argument base))
1152 t t cmd)))
1153 (while (string-match "%f" cmd)
1154 (setq cmd (replace-match
1155 (save-match-data
1156 (shell-quote-argument file))
1157 t t cmd)))
1158 (while (string-match "%o" cmd)
1159 (setq cmd (replace-match
1160 (save-match-data
1161 (shell-quote-argument output-dir))
1162 t t cmd)))
1163 (shell-command cmd outbuf)))))))
1164 (message (concat "Processing LaTeX file " file "...done"))
1165 (setq errors (org-export-latex-get-error outbuf))
1166 (if (not (file-exists-p pdffile))
1167 (error (concat "PDF file " pdffile " was not produced"
1168 (if errors (concat ":" errors "") "")))
1169 (set-window-configuration wconfig)
1170 (when org-export-pdf-remove-logfiles
1171 (dolist (ext org-export-pdf-logfiles)
1172 (setq file (concat base "." ext))
1173 (and (file-exists-p file) (delete-file file))))
1174 (message (concat
1175 "Exporting to PDF...done"
1176 (if errors
1177 (concat ", with some errors:" errors)
1178 "")))
1179 pdffile)))
1181 (defun org-export-latex-get-error (buf)
1182 "Collect the kinds of errors that remain in pdflatex processing."
1183 (with-current-buffer buf
1184 (save-excursion
1185 (goto-char (point-max))
1186 (when (re-search-backward "^[ \t]*This is pdf.*?TeX.*?Version" nil t)
1187 ;; OK, we are at the location of the final run
1188 (let ((pos (point)) (errors "") (case-fold-search t))
1189 (if (re-search-forward "Reference.*?undefined" nil t)
1190 (setq errors (concat errors " [undefined reference]")))
1191 (goto-char pos)
1192 (if (re-search-forward "Citation.*?undefined" nil t)
1193 (setq errors (concat errors " [undefined citation]")))
1194 (goto-char pos)
1195 (if (re-search-forward "Undefined control sequence" nil t)
1196 (setq errors (concat errors " [undefined control sequence]")))
1197 (and (org-string-nw-p errors) errors))))))
1199 ;;;###autoload
1200 (defun org-export-as-pdf-and-open (arg)
1201 "Export as LaTeX, then process through to PDF, and open."
1202 (interactive "P")
1203 (let ((pdffile (org-export-as-pdf arg)))
1204 (if pdffile
1205 (progn
1206 (org-open-file pdffile)
1207 (when org-export-kill-product-buffer-when-displayed
1208 (kill-buffer (find-buffer-visiting
1209 (concat (file-name-sans-extension (buffer-file-name))
1210 ".tex")))))
1211 (error "PDF file was not produced"))))
1213 ;;; Parsing functions:
1215 (defun org-export-latex-parse-global (level odd)
1216 "Parse the current buffer recursively, starting at LEVEL.
1217 If ODD is non-nil, assume the buffer only contains odd sections.
1218 Return a list reflecting the document structure."
1219 (save-excursion
1220 (goto-char (point-min))
1221 (let* ((cnt 0) output
1222 (depth org-export-latex-sectioning-depth))
1223 (while (org-re-search-forward-unprotected
1224 (concat "^\\(\\(?:\\*\\)\\{"
1225 (number-to-string (+ (if odd 2 1) level))
1226 "\\}\\) \\(.*\\)$")
1227 ;; make sure that there is no upper heading
1228 (when (> level 0)
1229 (save-excursion
1230 (save-match-data
1231 (org-re-search-forward-unprotected
1232 (concat "^\\(\\(?:\\*\\)\\{"
1233 (number-to-string level)
1234 "\\}\\) \\(.*\\)$") nil t)))) t)
1235 (setq cnt (1+ cnt))
1236 (let* ((pos (match-beginning 0))
1237 (heading (match-string 2))
1238 (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
1239 (save-excursion
1240 (narrow-to-region
1241 (point)
1242 (save-match-data
1243 (if (org-re-search-forward-unprotected
1244 (concat "^\\(\\(?:\\*\\)\\{"
1245 (number-to-string (+ (if odd 2 1) level))
1246 "\\}\\) \\(.*\\)$") nil t)
1247 (match-beginning 0)
1248 (point-max))))
1249 (goto-char (point-min))
1250 (setq output
1251 (append output
1252 (list
1253 (list
1254 `(pos . ,pos)
1255 `(level . ,nlevel)
1256 `(occur . ,cnt)
1257 `(heading . ,heading)
1258 `(content . ,(org-export-latex-parse-content))
1259 `(subcontent . ,(org-export-latex-parse-subcontent
1260 level odd)))))))
1261 (widen)))
1262 (list output))))
1264 (defun org-export-latex-parse-content ()
1265 "Extract the content of a section."
1266 (let ((beg (point))
1267 (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
1268 (progn (beginning-of-line) (point))
1269 (point-max))))
1270 (buffer-substring beg end)))
1272 (defun org-export-latex-parse-subcontent (level odd)
1273 "Extract the subcontent of a section at LEVEL.
1274 If ODD Is non-nil, assume subcontent only contains odd sections."
1275 (if (not (org-re-search-forward-unprotected
1276 (concat "^\\(\\(?:\\*\\)\\{"
1277 (number-to-string (+ (if odd 4 2) level))
1278 "\\}\\) \\(.*\\)$")
1279 nil t))
1280 nil ; subcontent is nil
1281 (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
1283 ;;; Rendering functions:
1284 (defun org-export-latex-global (content)
1285 "Export CONTENT to LaTeX.
1286 CONTENT is an element of the list produced by
1287 `org-export-latex-parse-global'."
1288 (if (eq (car content) 'subcontent)
1289 (mapc 'org-export-latex-sub (cdr content))
1290 (org-export-latex-sub (car content))))
1292 (defun org-export-latex-sub (subcontent)
1293 "Export the list SUBCONTENT to LaTeX.
1294 SUBCONTENT is an alist containing information about the headline
1295 and its content."
1296 (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
1297 (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
1299 (defun org-export-latex-subcontent (subcontent num)
1300 "Export each cell of SUBCONTENT to LaTeX.
1301 If NUM is non-nil export numbered sections, otherwise use unnumbered
1302 sections. If NUM is an integer, export the highest NUM levels as
1303 numbered sections and lower levels as unnumbered sections."
1304 (let* ((heading (cdr (assoc 'heading subcontent)))
1305 (level (- (cdr (assoc 'level subcontent))
1306 org-export-latex-add-level))
1307 (occur (number-to-string (cdr (assoc 'occur subcontent))))
1308 (content (cdr (assoc 'content subcontent)))
1309 (subcontent (cadr (assoc 'subcontent subcontent)))
1310 (label (org-get-text-property-any 0 'target heading))
1311 (label-list (cons label (cdr (assoc label
1312 org-export-target-aliases))))
1313 (sectioning org-export-latex-sectioning)
1314 (depth org-export-latex-sectioning-depth)
1315 main-heading sub-heading ctnt)
1316 (when (symbolp (car sectioning))
1317 (setq sectioning (funcall (car sectioning) level heading))
1318 (when sectioning
1319 (setq heading (car sectioning)
1320 sectioning (cdr sectioning)
1321 ;; target property migh have changed...
1322 label (org-get-text-property-any 0 'target heading)
1323 label-list (cons label (cdr (assoc label
1324 org-export-target-aliases)))))
1325 (if sectioning (setq sectioning (make-list 10 sectioning)))
1326 (setq depth (if sectioning 10000 0)))
1327 (if (string-match "[ \t]*\\\\\\\\[ \t]*" heading)
1328 (setq main-heading (substring heading 0 (match-beginning 0))
1329 sub-heading (substring heading (match-end 0))))
1330 (setq heading (org-export-latex-fontify-headline heading)
1331 sub-heading (and sub-heading
1332 (org-export-latex-fontify-headline sub-heading))
1333 main-heading (and main-heading
1334 (org-export-latex-fontify-headline main-heading)))
1335 (cond
1336 ;; Normal conversion
1337 ((<= level depth)
1338 (let* ((sec (nth (1- level) sectioning))
1339 (num (if (integerp num)
1340 (>= num level)
1341 num))
1342 start end)
1343 (if (consp (cdr sec))
1344 (setq start (nth (if num 0 2) sec)
1345 end (nth (if num 1 3) sec))
1346 (setq start (if num (car sec) (cdr sec))))
1347 (insert (format start (if main-heading main-heading heading)
1348 (or sub-heading "")))
1349 (insert "\n")
1350 (when label
1351 (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
1352 label-list "\n") "\n"))
1353 (insert (org-export-latex-content content))
1354 (cond ((stringp subcontent) (insert subcontent))
1355 ((listp subcontent)
1356 (while (org-looking-back "\n\n") (backward-delete-char 1))
1357 (org-export-latex-sub subcontent)))
1358 (when (and end (string-match "[^ \t]" end))
1359 (let ((hook (org-get-text-property-any 0 'org-insert-hook end)))
1360 (and (functionp hook) (funcall hook)))
1361 (insert end "\n"))))
1362 ;; At a level under the hl option: we can drop this subsection
1363 ((> level depth)
1364 (cond ((eq org-export-latex-low-levels 'description)
1365 (if (string-match "% ends low level$"
1366 (buffer-substring (point-at-bol 0) (point)))
1367 (delete-region (point-at-bol 0) (point))
1368 (insert "\\begin{description}\n"))
1369 (insert (format "\n\\item[%s]%s~\n"
1370 heading
1371 (if label (format "\\label{%s}" label) "")))
1372 (insert (org-export-latex-content content))
1373 (cond ((stringp subcontent) (insert subcontent))
1374 ((listp subcontent) (org-export-latex-sub subcontent)))
1375 (insert "\\end{description} % ends low level\n"))
1376 ((memq org-export-latex-low-levels '(itemize enumerate))
1377 (if (string-match "% ends low level$"
1378 (buffer-substring (point-at-bol 0) (point)))
1379 (delete-region (point-at-bol 0) (point))
1380 (insert (format "\\begin{%s}\n"
1381 (symbol-name org-export-latex-low-levels))))
1382 (let ((ctnt (org-export-latex-content content)))
1383 (insert (format (if (not (equal (replace-regexp-in-string "\n" "" ctnt) ""))
1384 "\n\\item %s\\\\\n%s%%"
1385 "\n\\item %s\n%s%%")
1386 heading
1387 (if label (format "\\label{%s}" label) "")))
1388 (insert ctnt))
1389 (cond ((stringp subcontent) (insert subcontent))
1390 ((listp subcontent) (org-export-latex-sub subcontent)))
1391 (insert (format "\\end{%s} %% ends low level\n"
1392 (symbol-name org-export-latex-low-levels))))
1394 ((and (listp org-export-latex-low-levels)
1395 org-export-latex-low-levels)
1396 (if (string-match "% ends low level$"
1397 (buffer-substring (point-at-bol 0) (point)))
1398 (delete-region (point-at-bol 0) (point))
1399 (insert (car org-export-latex-low-levels) "\n"))
1400 (insert (format (nth 2 org-export-latex-low-levels)
1401 heading
1402 (if label (format "\\label{%s}" label) "")))
1403 (insert (org-export-latex-content content))
1404 (cond ((stringp subcontent) (insert subcontent))
1405 ((listp subcontent) (org-export-latex-sub subcontent)))
1406 (insert (nth 1 org-export-latex-low-levels)
1407 " %% ends low level\n"))
1409 ((stringp org-export-latex-low-levels)
1410 (insert (format org-export-latex-low-levels heading) "\n")
1411 (when label (insert (format "\\label{%s}\n" label)))
1412 (insert (org-export-latex-content content))
1413 (cond ((stringp subcontent) (insert subcontent))
1414 ((listp subcontent) (org-export-latex-sub subcontent)))))))))
1416 ;;; Exporting internals:
1417 (defun org-export-latex-set-initial-vars (ext-plist level)
1418 "Store org local variables required for LaTeX export.
1419 EXT-PLIST is an optional additional plist.
1420 LEVEL indicates the default depth for export."
1421 (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
1422 org-export-latex-done-keywords org-done-keywords
1423 org-export-latex-not-done-keywords org-not-done-keywords
1424 org-export-latex-complex-heading-re org-complex-heading-regexp
1425 org-export-latex-display-custom-times org-display-custom-times
1426 org-export-latex-all-targets-re
1427 (org-make-target-link-regexp (org-all-targets))
1428 org-export-latex-options-plist
1429 (org-combine-plists (org-default-export-plist) ext-plist
1430 (org-infile-export-plist))
1431 org-export-latex-class
1432 (or (and (org-region-active-p)
1433 (save-excursion
1434 (goto-char (region-beginning))
1435 (and (looking-at org-complex-heading-regexp)
1436 (org-entry-get nil "LaTeX_CLASS" 'selective))))
1437 (save-excursion
1438 (save-restriction
1439 (widen)
1440 (goto-char (point-min))
1441 (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([-/a-zA-Z]+\\)" nil t)
1442 (match-string 1))))
1443 (plist-get org-export-latex-options-plist :latex-class)
1444 org-export-latex-default-class)
1445 org-export-latex-class-options
1446 (or (and (org-region-active-p)
1447 (save-excursion
1448 (goto-char (region-beginning))
1449 (and (looking-at org-complex-heading-regexp)
1450 (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
1451 (save-excursion
1452 (save-restriction
1453 (widen)
1454 (goto-char (point-min))
1455 (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
1456 (match-string 1))))
1457 (plist-get org-export-latex-options-plist :latex-class-options))
1458 org-export-latex-class
1459 (or (car (assoc org-export-latex-class org-export-latex-classes))
1460 (error "No definition for class `%s' in `org-export-latex-classes'"
1461 org-export-latex-class))
1462 org-export-latex-header
1463 (cadr (assoc org-export-latex-class org-export-latex-classes))
1464 org-export-latex-sectioning
1465 (cddr (assoc org-export-latex-class org-export-latex-classes))
1466 org-export-latex-sectioning-depth
1467 (or level
1468 (let ((hl-levels
1469 (plist-get org-export-latex-options-plist :headline-levels))
1470 (sec-depth (length org-export-latex-sectioning)))
1471 (if (> hl-levels sec-depth) sec-depth hl-levels))))
1472 (when (and org-export-latex-class-options
1473 (string-match "\\S-" org-export-latex-class-options)
1474 (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?"
1475 org-export-latex-header))
1476 (setq org-export-latex-header
1477 (concat (substring org-export-latex-header 0 (match-end 1))
1478 org-export-latex-class-options
1479 (substring org-export-latex-header (match-end 0))))))
1481 (defvar org-export-latex-format-toc-function
1482 'org-export-latex-format-toc-default
1483 "The function formatting returning the string to create the table of contents.
1484 The function mus take one parameter, the depth of the table of contents.")
1486 (defun org-export-latex-make-header (title opt-plist)
1487 "Make the LaTeX header and return it as a string.
1488 TITLE is the current title from the buffer or region.
1489 OPT-PLIST is the options plist for current buffer."
1490 (let ((toc (plist-get opt-plist :table-of-contents))
1491 (author (org-export-apply-macros-in-string
1492 (plist-get opt-plist :author)))
1493 (email (replace-regexp-in-string
1494 "_" "\\\\_"
1495 (org-export-apply-macros-in-string
1496 (plist-get opt-plist :email))))
1497 (description (org-export-apply-macros-in-string
1498 (plist-get opt-plist :description)))
1499 (keywords (org-export-apply-macros-in-string
1500 (plist-get opt-plist :keywords))))
1501 (concat
1502 (if (plist-get opt-plist :time-stamp-file)
1503 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1504 ;; insert LaTeX custom header and packages from the list
1505 (org-splice-latex-header
1506 (org-export-apply-macros-in-string org-export-latex-header)
1507 org-export-latex-default-packages-alist
1508 org-export-latex-packages-alist nil
1509 (org-export-apply-macros-in-string
1510 (plist-get opt-plist :latex-header-extra)))
1511 ;; append another special variable
1512 (org-export-apply-macros-in-string org-export-latex-append-header)
1513 ;; define alert if not yet defined
1514 "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
1515 ;; insert the title
1516 (format
1517 "\n\n\\title{%s}\n"
1518 (org-export-latex-fontify-headline title))
1519 ;; insert author info
1520 (if (plist-get opt-plist :author-info)
1521 (format "\\author{%s%s}\n"
1522 (org-export-latex-fontify-headline (or author user-full-name))
1523 (if (and (plist-get opt-plist :email-info) email
1524 (string-match "\\S-" email))
1525 (format "\\thanks{%s}" email)
1526 ""))
1527 (format "%%\\author{%s}\n"
1528 (org-export-latex-fontify-headline (or author user-full-name))))
1529 ;; insert the date
1530 (format "\\date{%s}\n"
1531 (format-time-string
1532 (or (plist-get opt-plist :date)
1533 org-export-latex-date-format)))
1534 ;; add some hyperref options
1535 (format org-export-latex-hyperref-options-format
1536 (org-export-latex-fontify-headline keywords)
1537 (org-export-latex-fontify-headline description)
1538 (org-version))
1539 ;; beginning of the document
1540 "\n\\begin{document}\n\n"
1541 ;; insert the title command
1542 (when (string-match "\\S-" title)
1543 (if (string-match "%s" org-export-latex-title-command)
1544 (format org-export-latex-title-command title)
1545 org-export-latex-title-command))
1546 "\n\n"
1547 ;; table of contents
1548 (when (and org-export-with-toc
1549 (plist-get opt-plist :section-numbers))
1550 (funcall org-export-latex-format-toc-function
1551 (cond ((numberp toc)
1552 (min toc (plist-get opt-plist :headline-levels)))
1553 (toc (plist-get opt-plist :headline-levels))))))))
1555 (defun org-export-latex-format-toc-default (depth)
1556 (when depth
1557 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
1558 depth)))
1560 (defun org-export-latex-first-lines (opt-plist &optional beg end)
1561 "Export the first lines before first headline.
1562 If BEG is non-nil, it is the beginning of the region.
1563 If END is non-nil, it is the end of the region."
1564 (save-excursion
1565 (goto-char (or beg (point-min)))
1566 (let* ((pt (point))
1567 (end (if (re-search-forward
1568 (concat "^" (org-get-limited-outline-regexp)) end t)
1569 (goto-char (match-beginning 0))
1570 (goto-char (or end (point-max))))))
1571 (prog1
1572 (org-export-latex-content
1573 (org-export-preprocess-string
1574 (buffer-substring pt end)
1575 :for-backend 'latex
1576 :emph-multiline t
1577 :add-text nil
1578 :comments nil
1579 :skip-before-1st-heading nil
1580 :LaTeX-fragments nil
1581 :timestamps (plist-get opt-plist :timestamps)
1582 :footnotes (plist-get opt-plist :footnotes)))
1583 (org-unmodified
1584 (let ((inhibit-read-only t)
1585 (limit (max pt (1- end))))
1586 (add-text-properties pt limit
1587 '(:org-license-to-kill t))
1588 (save-excursion
1589 (goto-char pt)
1590 (while (re-search-forward "^[ \t]*#\\+.*\n?" limit t)
1591 (let ((case-fold-search t))
1592 (unless (org-string-match-p
1593 "^[ \t]*#\\+\\(attr_\\|caption\\>\\|label\\>\\)"
1594 (match-string 0))
1595 (remove-text-properties (match-beginning 0) (match-end 0)
1596 '(:org-license-to-kill t))))))))))))
1599 (defvar org-export-latex-header-defs nil
1600 "The header definitions that might be used in the LaTeX body.")
1602 (defun org-export-latex-content (content &optional exclude-list)
1603 "Convert CONTENT string to LaTeX.
1604 Don't perform conversions that are in EXCLUDE-LIST. Recognized
1605 conversion types are: quotation-marks, emphasis, sub-superscript,
1606 links, keywords, lists, tables, fixed-width"
1607 (with-temp-buffer
1608 (org-install-letbind)
1609 (insert content)
1610 (unless (memq 'timestamps exclude-list)
1611 (org-export-latex-time-stamps))
1612 (unless (memq 'quotation-marks exclude-list)
1613 (org-export-latex-quotation-marks))
1614 (unless (memq 'emphasis exclude-list)
1615 (when (plist-get org-export-latex-options-plist :emphasize)
1616 (org-export-latex-fontify)))
1617 (unless (memq 'sub-superscript exclude-list)
1618 (org-export-latex-special-chars
1619 (plist-get org-export-latex-options-plist :sub-superscript)))
1620 (unless (memq 'links exclude-list)
1621 (org-export-latex-links))
1622 (unless (memq 'keywords exclude-list)
1623 (org-export-latex-keywords))
1624 (unless (memq 'lists exclude-list)
1625 (org-export-latex-lists))
1626 (unless (memq 'tables exclude-list)
1627 (org-export-latex-tables
1628 (plist-get org-export-latex-options-plist :tables)))
1629 (unless (memq 'fixed-width exclude-list)
1630 (org-export-latex-fixed-width
1631 (plist-get org-export-latex-options-plist :fixed-width)))
1632 ;; return string
1633 (buffer-substring (point-min) (point-max))))
1635 (defun org-export-latex-protect-string (s)
1636 "Add the org-protected property to string S."
1637 (add-text-properties 0 (length s) '(org-protected t) s) s)
1639 (defun org-export-latex-protect-char-in-string (char-list string)
1640 "Add org-protected text-property to char from CHAR-LIST in STRING."
1641 (with-temp-buffer
1642 (save-match-data
1643 (insert string)
1644 (goto-char (point-min))
1645 (while (re-search-forward (regexp-opt char-list) nil t)
1646 (add-text-properties (match-beginning 0)
1647 (match-end 0) '(org-protected t)))
1648 (buffer-string))))
1650 (defun org-export-latex-keywords-maybe (&optional remove-list)
1651 "Maybe remove keywords depending on rules in REMOVE-LIST."
1652 (goto-char (point-min))
1653 (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
1654 (case-fold-search nil)
1655 (todo-markup org-export-latex-todo-keyword-markup)
1656 fmt)
1657 ;; convert TODO keywords
1658 (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
1659 (if (plist-get remove-list :todo)
1660 (replace-match "")
1661 (setq fmt (cond
1662 ((stringp todo-markup) todo-markup)
1663 ((and (consp todo-markup) (stringp (car todo-markup)))
1664 (if (member (match-string 1) org-export-latex-done-keywords)
1665 (cdr todo-markup) (car todo-markup)))
1666 (t (cdr (or (assoc (match-string 1) todo-markup)
1667 (car todo-markup))))))
1668 (replace-match (org-export-latex-protect-string
1669 (format fmt (match-string 1))) t t)))
1670 ;; convert priority string
1671 (when (re-search-forward "\\[\\\\#.\\]" nil t)
1672 (if (plist-get remove-list :priority)
1673 (replace-match "")
1674 (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
1675 ;; convert tags
1676 (when (re-search-forward "\\(:[a-zA-Z0-9_@#%]+\\)+:" nil t)
1677 (if (or (not org-export-with-tags)
1678 (plist-get remove-list :tags))
1679 (replace-match "")
1680 (replace-match
1681 (org-export-latex-protect-string
1682 (format org-export-latex-tag-markup
1683 (save-match-data
1684 (replace-regexp-in-string
1685 "\\([_#]\\)" "\\\\\\1" (match-string 0)))))
1686 t t)))))
1688 (defun org-export-latex-fontify-headline (string)
1689 "Fontify special words in STRING."
1690 (with-temp-buffer
1691 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
1692 ;; the beginning of the buffer - inserting "\n" is safe here though.
1693 (insert "\n" string)
1695 ;; Preserve math snippets
1697 (let* ((matchers (plist-get org-format-latex-options :matchers))
1698 (re-list org-latex-regexps)
1699 beg end re e m n block off)
1700 ;; Check the different regular expressions
1701 (while (setq e (pop re-list))
1702 (setq m (car e) re (nth 1 e) n (nth 2 e)
1703 block (if (nth 3 e) "\n\n" ""))
1704 (setq off (if (member m '("$" "$1")) 1 0))
1705 (when (and (member m matchers) (not (equal m "begin")))
1706 (goto-char (point-min))
1707 (while (re-search-forward re nil t)
1708 (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
1709 (add-text-properties beg end
1710 '(org-protected t org-latex-math t))))))
1712 ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
1713 (goto-char (point-min))
1714 (let ((case-fold-search nil))
1715 (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
1716 (unless (eq (char-before (match-beginning 1)) ?\\)
1717 (org-if-unprotected-1
1718 (replace-match (org-export-latex-protect-string
1719 (concat "\\" (match-string 1)
1720 "{}")) t t)))))
1721 (goto-char (point-min))
1722 (let ((re (concat "\\\\\\([a-zA-Z]+\\)"
1723 "\\(?:<[^<>\n]*>\\)*"
1724 "\\(?:\\[[^][\n]*?\\]\\)*"
1725 "\\(?:<[^<>\n]*>\\)*"
1726 "\\("
1727 (org-create-multibrace-regexp "{" "}" 3)
1728 "\\)\\{1,3\\}")))
1729 (while (re-search-forward re nil t)
1730 (unless (or
1731 ;; check for comment line
1732 (save-excursion (goto-char (match-beginning 0))
1733 (org-in-indented-comment-line))
1734 ;; Check if this is a defined entity, so that is may need conversion
1735 (org-entity-get (match-string 1)))
1736 (add-text-properties (match-beginning 0) (match-end 0)
1737 '(org-protected t)))))
1738 (when (plist-get org-export-latex-options-plist :emphasize)
1739 (org-export-latex-fontify))
1740 (org-export-latex-time-stamps)
1741 (org-export-latex-quotation-marks)
1742 (org-export-latex-keywords-maybe)
1743 (org-export-latex-special-chars
1744 (plist-get org-export-latex-options-plist :sub-superscript))
1745 (org-export-latex-links)
1746 (org-trim (buffer-string))))
1748 (defun org-export-latex-time-stamps ()
1749 "Format time stamps."
1750 (goto-char (point-min))
1751 (let ((org-display-custom-times org-export-latex-display-custom-times))
1752 (while (re-search-forward org-ts-regexp-both nil t)
1753 (org-if-unprotected-at (1- (point))
1754 (replace-match
1755 (org-export-latex-protect-string
1756 (format (if (string= "<" (substring (match-string 0) 0 1))
1757 org-export-latex-timestamp-markup
1758 org-export-latex-timestamp-inactive-markup)
1759 (substring (org-translate-time (match-string 0)) 1 -1)))
1760 t t)))))
1762 (defun org-export-latex-quotation-marks ()
1763 "Export quotation marks depending on language conventions."
1764 (mapc (lambda(l)
1765 (goto-char (point-min))
1766 (while (re-search-forward (car l) nil t)
1767 (let ((rpl (concat (match-string 1)
1768 (org-export-latex-protect-string
1769 (copy-sequence (cdr l))))))
1770 (org-if-unprotected-1
1771 (replace-match rpl t t)))))
1772 (cdr (or (assoc (plist-get org-export-latex-options-plist :language)
1773 org-export-latex-quotes)
1774 ;; falls back on english
1775 (assoc "en" org-export-latex-quotes)))))
1777 (defun org-export-latex-special-chars (sub-superscript)
1778 "Export special characters to LaTeX.
1779 If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
1780 See the `org-export-latex.el' code for a complete conversion table."
1781 (goto-char (point-min))
1782 (mapc (lambda(c)
1783 (goto-char (point-min))
1784 (while (re-search-forward c nil t)
1785 ;; Put the point where to check for org-protected
1786 (unless (get-text-property (match-beginning 2) 'org-protected)
1787 (cond ((member (match-string 2) '("\\$" "$"))
1788 (if (equal (match-string 2) "\\$")
1790 (replace-match "\\$" t t)))
1791 ((member (match-string 2) '("&" "%" "#"))
1792 (if (equal (match-string 1) "\\")
1793 (replace-match (match-string 2) t t)
1794 (replace-match (concat (match-string 1) "\\"
1795 (match-string 2)) t t)
1796 (backward-char 1)))
1797 ((equal (match-string 2) "...")
1798 (replace-match
1799 (concat (match-string 1)
1800 (org-export-latex-protect-string "\\ldots{}")) t t))
1801 ((equal (match-string 2) "~")
1802 (cond ((equal (match-string 1) "\\") nil)
1803 ((eq 'org-link (get-text-property 0 'face (match-string 2)))
1804 (replace-match (concat (match-string 1) "\\~") t t))
1805 (t (replace-match
1806 (org-export-latex-protect-string
1807 (concat (match-string 1) "\\~{}")) t t))))
1808 ((member (match-string 2) '("{" "}"))
1809 (unless (save-match-data (org-inside-latex-math-p))
1810 (if (equal (match-string 1) "\\")
1811 (replace-match (match-string 2) t t)
1812 (replace-match (concat (match-string 1) "\\"
1813 (match-string 2)) t t)))))
1814 (unless (save-match-data (or (org-inside-latex-math-p) (org-at-table-p)))
1815 (cond ((equal (match-string 2) "\\")
1816 (replace-match (or (save-match-data
1817 (org-export-latex-treat-backslash-char
1818 (match-string 1)
1819 (or (match-string 3) "")))
1820 "") t t)
1821 (when (and (get-text-property (1- (point)) 'org-entity)
1822 (looking-at "{}"))
1823 ;; OK, this was an entity replacement, and the user
1824 ;; had terminated the entity with {}. Make sure
1825 ;; {} is protected as well, and remove the extra {}
1826 ;; inserted by the conversion.
1827 (put-text-property (point) (+ 2 (point)) 'org-protected t)
1828 (if (save-excursion (goto-char (max (- (point) 2) (point-min)))
1829 (looking-at "{}"))
1830 (replace-match ""))
1831 (forward-char 2))
1832 (backward-char 1))
1833 ((member (match-string 2) '("_" "^"))
1834 (replace-match (or (save-match-data
1835 (org-export-latex-treat-sub-super-char
1836 sub-superscript
1837 (match-string 2)
1838 (match-string 1)
1839 (match-string 3))) "") t t)
1840 (backward-char 1)))))))
1841 '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
1842 "\\(\\(\\\\?\\$\\)\\)"
1843 "\\([a-zA-Z0-9()]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-zA-Z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-zA-Z0-9]+}\\|([a-zA-Z0-9]+)\\)"
1844 "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|\\([&#%{}\"]\\|[a-zA-Z][a-zA-Z0-9]*\\)\\)"
1845 "\\(^\\|.\\)\\([&#%{}~]\\|\\.\\.\\.\\)"
1846 ;; (?\< . "\\textless{}")
1847 ;; (?\> . "\\textgreater{}")
1850 (defun org-inside-latex-math-p ()
1851 (get-text-property (point) 'org-latex-math))
1853 (defun org-export-latex-treat-sub-super-char
1854 (subsup char string-before string-after)
1855 "Convert the \"_\" and \"^\" characters to LaTeX.
1856 SUBSUP corresponds to the ^: option in the #+OPTIONS line.
1857 Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
1858 (cond ((equal string-before "\\")
1859 (concat string-before char string-after))
1860 ((and (string-match "\\S-+" string-after))
1861 ;; this is part of a math formula
1862 (cond ((eq 'org-link (get-text-property 0 'face char))
1863 (concat string-before "\\" char string-after))
1864 ((save-match-data (org-inside-latex-math-p))
1865 (if subsup
1866 (cond ((eq 1 (length string-after))
1867 (concat string-before char string-after))
1868 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
1869 (format "%s%s{%s}" string-before char
1870 (match-string 1 string-after))))))
1871 ((and (> (length string-after) 1)
1872 (or (eq subsup t)
1873 (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
1874 (or (string-match "[{]?\\([^}]+\\)[}]?" string-after)
1875 (string-match "[(]?\\([^)]+\\)[)]?" string-after)))
1877 (org-export-latex-protect-string
1878 (format "%s$%s{%s}$" string-before char
1879 (if (and (> (match-end 1) (1+ (match-beginning 1)))
1880 (not (equal (substring string-after 0 2) "{\\")))
1881 (concat "\\mathrm{" (match-string 1 string-after) "}")
1882 (match-string 1 string-after)))))
1883 ((eq subsup t) (concat string-before "$" char string-after "$"))
1884 (t (org-export-latex-protect-string
1885 (concat string-before "\\" char "{}" string-after)))))
1886 (t (org-export-latex-protect-string
1887 (concat string-before "\\" char "{}" string-after)))))
1889 (defun org-export-latex-treat-backslash-char (string-before string-after)
1890 "Convert the \"$\" special character to LaTeX.
1891 The conversion is made depending of STRING-BEFORE and STRING-AFTER."
1892 (let ((ass (org-entity-get string-after)))
1893 (cond
1894 (ass (org-add-props
1895 (if (nth 2 ass)
1896 (concat string-before
1897 (org-export-latex-protect-string
1898 (concat "$" (nth 1 ass) "$")))
1899 (concat string-before (org-export-latex-protect-string
1900 (nth 1 ass))))
1901 nil 'org-entity t))
1902 ((and (not (string-match "^[ \n\t]" string-after))
1903 (not (string-match "[ \t]\\'\\|^" string-before)))
1904 ;; backslash is inside a word
1905 (concat string-before
1906 (org-export-latex-protect-string
1907 (concat "\\textbackslash{}" string-after))))
1908 ((not (or (equal string-after "")
1909 (string-match "^[ \t\n]" string-after)))
1910 ;; backslash might escape a character (like \#) or a user TeX
1911 ;; macro (like \setcounter)
1912 (concat string-before
1913 (org-export-latex-protect-string (concat "\\" string-after))))
1914 ((and (string-match "^[ \t\n]" string-after)
1915 (string-match "[ \t\n]\\'" string-before))
1916 ;; backslash is alone, convert it to $\backslash$
1917 (org-export-latex-protect-string
1918 (concat string-before "\\textbackslash{}" string-after)))
1919 (t (org-export-latex-protect-string
1920 (concat string-before "\\textbackslash{}" string-after))))))
1922 (defun org-export-latex-keywords ()
1923 "Convert special keywords to LaTeX."
1924 (goto-char (point-min))
1925 (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
1926 (replace-match (format org-export-latex-timestamp-keyword-markup
1927 (match-string 0)) t t)
1928 (save-excursion
1929 (beginning-of-line 1)
1930 (unless (looking-at ".*\n[ \t]*\n")
1931 (end-of-line 1)
1932 (insert "\n")))))
1934 (defun org-export-latex-fixed-width (opt)
1935 "When OPT is non-nil convert fixed-width sections to LaTeX."
1936 (goto-char (point-min))
1937 (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
1938 (unless (get-text-property (point) 'org-example)
1939 (if opt
1940 (progn (goto-char (match-beginning 0))
1941 (insert "\\begin{verbatim}\n")
1942 (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
1943 (replace-match (concat (match-string 1)
1944 (match-string 2)) t t)
1945 (forward-line))
1946 (insert "\\end{verbatim}\n"))
1947 (progn (goto-char (match-beginning 0))
1948 (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
1949 (replace-match (concat "%" (match-string 1)
1950 (match-string 2)) t t)
1951 (forward-line)))))))
1953 (defvar org-table-last-alignment) ; defined in org-table.el
1954 (defvar org-table-last-column-widths) ; defined in org-table.el
1955 (declare-function orgtbl-to-latex "org-table" (table params) t)
1956 (defun org-export-latex-tables (insert)
1957 "Convert tables to LaTeX and INSERT it."
1958 ;; First, get the table.el tables
1959 (goto-char (point-min))
1960 (while (re-search-forward "^[ \t]*\\(\\+-[-+]*\\+\\)[ \t]*\n[ \t]*|" nil t)
1961 (org-if-unprotected
1962 (require 'table)
1963 (org-export-latex-convert-table.el-table)))
1965 ;; And now the Org-mode tables
1966 (goto-char (point-min))
1967 (while (re-search-forward "^\\([ \t]*\\)|" nil t)
1968 (org-if-unprotected-at (1- (point))
1969 (org-table-align)
1970 (let* ((beg (org-table-begin))
1971 (end (org-table-end))
1972 (raw-table (buffer-substring beg end))
1973 (org-table-last-alignment (copy-sequence org-table-last-alignment))
1974 (org-table-last-column-widths (copy-sequence
1975 org-table-last-column-widths))
1976 fnum fields line lines olines gr colgropen line-fmt align
1977 caption width shortn label attr hfmt floatp placement
1978 longtblp tblenv tabular-env)
1979 (if org-export-latex-tables-verbatim
1980 (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
1981 "\\end{verbatim}\n")))
1982 (apply 'delete-region (list beg end))
1983 (insert (org-export-latex-protect-string tbl)))
1984 (progn
1985 (setq caption (org-find-text-property-in-string
1986 'org-caption raw-table)
1987 shortn (org-find-text-property-in-string
1988 'org-caption-shortn raw-table)
1989 attr (org-find-text-property-in-string
1990 'org-attributes raw-table)
1991 label (org-find-text-property-in-string
1992 'org-label raw-table)
1993 longtblp (and attr (stringp attr)
1994 (string-match "\\<longtable\\>" attr))
1995 tblenv (if (and attr (stringp attr))
1996 (cond ((string-match "\\<sidewaystable\\>" attr)
1997 "sidewaystable")
1998 ((or (string-match (regexp-quote "table*") attr)
1999 (string-match "\\<multicolumn\\>" attr))
2000 "table*")
2001 (t "table"))
2002 "table")
2003 tabular-env
2004 (if (and attr (stringp attr)
2005 (string-match "\\(tabular.\\)" attr))
2006 (match-string 1 attr)
2007 org-export-latex-tabular-environment)
2008 width (and attr (stringp attr)
2009 (string-match "\\<width=\\([^ \t\n\r]+\\)" attr)
2010 (match-string 1 attr))
2011 align (and attr (stringp attr)
2012 (string-match "\\<align=\\([^ \t\n\r]+\\)" attr)
2013 (match-string 1 attr))
2014 hfmt (and attr (stringp attr)
2015 (string-match "\\<hfmt=\\(\\S-+\\)" attr)
2016 (match-string 1 attr))
2017 floatp (or caption label (string= "table*" tblenv))
2018 placement (if (and attr
2019 (stringp attr)
2020 (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
2021 (match-string 1 attr)
2022 (concat
2023 "[" org-latex-default-figure-position "]")))
2024 (setq caption (and caption (org-export-latex-fontify-headline caption)))
2025 (setq lines (org-split-string raw-table "\n"))
2026 (apply 'delete-region (list beg end))
2027 (when org-export-table-remove-special-lines
2028 (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
2029 (when org-table-clean-did-remove-column
2030 (pop org-table-last-alignment)
2031 (pop org-table-last-column-widths))
2032 ;; make a format string to reflect alignment
2033 (setq olines lines)
2034 (while (and (not line-fmt) (setq line (pop olines)))
2035 (unless (string-match "^[ \t]*|-" line)
2036 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
2037 (setq fnum (make-vector (length fields) 0))
2038 (setq line-fmt
2039 (mapconcat
2040 (lambda (x)
2041 (setq gr (pop org-table-colgroup-info))
2042 (format "%s%%s%s"
2043 (cond ((eq gr :start)
2044 (prog1 (if colgropen "|" "|")
2045 (setq colgropen t)))
2046 ((eq gr :startend)
2047 (prog1 (if colgropen "|" "|")
2048 (setq colgropen nil)))
2049 (t ""))
2050 (if (memq gr '(:end :startend))
2051 (progn (setq colgropen nil) "|")
2052 "")))
2053 fnum ""))))
2054 ;; fix double || in line-fmt
2055 (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
2056 ;; maybe remove the first and last "|"
2057 (when (and (not org-export-latex-tables-column-borders)
2058 (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
2059 (setq line-fmt (match-string 2 line-fmt)))
2060 ;; format alignment
2061 (unless align
2062 (setq align (apply 'format
2063 (cons line-fmt
2064 (mapcar (lambda (x) (if x "r" "l"))
2065 org-table-last-alignment)))))
2066 ;; prepare the table to send to orgtbl-to-latex
2067 (setq lines
2068 (mapcar
2069 (lambda(elem)
2070 (or (and (string-match "[ \t]*|-+" elem) 'hline)
2071 (org-split-string
2072 (progn (set-text-properties 0 (length elem) nil elem)
2073 (org-trim elem)) "|")))
2074 lines))
2075 (when insert
2076 (insert (org-export-latex-protect-string
2077 (concat
2078 (if longtblp
2079 (concat "\\begin{longtable}{" align "}\n")
2080 (if floatp
2081 (format "\\begin{%s}%s\n" tblenv placement)))
2082 (if (and floatp org-export-latex-table-caption-above)
2083 (format
2084 "\\caption%s{%s} %s"
2085 (if shortn (concat "[" shortn "]") "")
2086 (or caption "")
2087 (if label (format "\\label{%s}" label) "")))
2088 (if (and longtblp caption org-export-latex-table-caption-above)
2089 "\\\\\n" "\n")
2090 (if (and org-export-latex-tables-centered (not longtblp))
2091 "\\begin{center}\n")
2092 (if (not longtblp)
2093 (format "\\begin{%s}%s{%s}\n"
2094 tabular-env
2095 (if width (format "{%s}" width) "")
2096 align))
2097 (orgtbl-to-latex
2098 lines
2099 `(:tstart ,org-export-latex-tables-tstart
2100 :tend ,org-export-latex-tables-tend
2101 :hline ,org-export-latex-tables-hline
2102 :skipheadrule ,longtblp
2103 :hfmt ,hfmt
2104 :hlend ,(if longtblp
2105 (format "\\\\
2107 \\endhead
2108 %s\\multicolumn{%d}{r}{Continued on next page}\\
2109 \\endfoot
2110 \\endlastfoot"
2111 org-export-latex-tables-hline
2112 org-export-latex-tables-hline
2113 (length org-table-last-alignment))
2114 nil)))
2115 (if (not longtblp) (format "\n\\end{%s}" tabular-env))
2116 (if longtblp "\n" (if org-export-latex-tables-centered
2117 "\n\\end{center}\n" "\n"))
2118 (if (and floatp (not org-export-latex-table-caption-above))
2119 (format
2120 "\\caption%s{%s} %s"
2121 (if shortn (concat "[" shortn "]") "")
2122 (or caption "")
2123 (if label (format "\\label{%s}" label) "")))
2124 (if longtblp
2125 "\\end{longtable}"
2126 (if floatp (format "\\end{%s}" tblenv)))))
2127 "\n\n"))))))))
2129 (defun org-export-latex-convert-table.el-table ()
2130 "Replace table.el table at point with LaTeX code."
2131 (let (tbl caption shortn label line floatp attr align rmlines)
2132 (setq line (buffer-substring (point-at-bol) (point-at-eol))
2133 label (org-get-text-property-any 0 'org-label line)
2134 caption (org-get-text-property-any 0 'org-caption line)
2135 shortn (org-get-text-property-any 0 'org-caption-shortn line)
2136 attr (org-get-text-property-any 0 'org-attributes line)
2137 align (and attr (stringp attr)
2138 (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
2139 (match-string 1 attr))
2140 rmlines (and attr (stringp attr)
2141 (string-match "\\<rmlines\\>" attr))
2142 floatp (or label caption))
2143 (and (get-buffer "*org-export-table*")
2144 (kill-buffer (get-buffer "*org-export-table*")))
2145 (table-generate-source 'latex "*org-export-table*" "caption")
2146 (setq tbl (with-current-buffer "*org-export-table*"
2147 (buffer-string)))
2148 (while (string-match "^%.*\n" tbl)
2149 (setq tbl (replace-match "" t t tbl)))
2150 ;; fix the hlines
2151 (when rmlines
2152 (let ((n 0) lines)
2153 (setq lines (mapcar (lambda (x)
2154 (if (string-match "^\\\\hline$" x)
2155 (progn
2156 (setq n (1+ n))
2157 (if (= n 2) x nil))
2159 (org-split-string tbl "\n")))
2160 (setq tbl (mapconcat 'identity (delq nil lines) "\n"))))
2161 (when (and align (string-match "\\\\begin{tabular}{.*}" tbl))
2162 (setq tbl (replace-match (concat "\\begin{tabular}{" align "}")
2163 t t tbl)))
2164 (and (get-buffer "*org-export-table*")
2165 (kill-buffer (get-buffer "*org-export-table*")))
2166 (beginning-of-line 0)
2167 (while (looking-at "[ \t]*\\(|\\|\\+-\\)")
2168 (delete-region (point) (1+ (point-at-eol))))
2169 (when org-export-latex-tables-centered
2170 (setq tbl (concat "\\begin{center}\n" tbl "\\end{center}")))
2171 (when floatp
2172 (setq tbl (concat "\\begin{table}\n"
2173 (if (not org-export-latex-table-caption-above) tbl)
2174 (format "\\caption%s{%s%s}\n"
2175 (if shortn (format "[%s]" shortn) "")
2176 (if label (format "\\label{%s}" label) "")
2177 (or caption ""))
2178 (if org-export-latex-table-caption-above tbl)
2179 "\n\\end{table}\n")))
2180 (insert (org-export-latex-protect-string tbl))))
2182 (defun org-export-latex-fontify ()
2183 "Convert fontification to LaTeX."
2184 (goto-char (point-min))
2185 (while (re-search-forward org-emph-re nil t)
2186 ;; The match goes one char after the *string*, except at the end of a line
2187 (let ((emph (assoc (match-string 3)
2188 org-export-latex-emphasis-alist))
2189 (beg (match-beginning 0))
2190 (end (match-end 0))
2191 rpl s)
2192 (unless emph
2193 (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
2194 (match-string 3)))
2195 (unless (or (and (get-text-property (- (point) 2) 'org-protected)
2196 (not (get-text-property
2197 (- (point) 2) 'org-verbatim-emph)))
2198 (equal (char-after (match-beginning 3))
2199 (char-after (1+ (match-beginning 3))))
2200 (save-excursion
2201 (goto-char (match-beginning 1))
2202 (save-match-data
2203 (and (org-at-table-p)
2204 (string-match
2205 "[|\n]" (buffer-substring beg end)))))
2206 (and (equal (match-string 3) "+")
2207 (save-match-data
2208 (string-match "\\`-+\\'" (match-string 4)))))
2209 (setq s (match-string 4))
2210 (setq rpl (concat (match-string 1)
2211 (org-export-latex-emph-format (cadr emph)
2212 (match-string 4))
2213 (match-string 5)))
2214 (if (caddr emph)
2215 (setq rpl (org-export-latex-protect-string rpl))
2216 (save-match-data
2217 (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
2218 (progn
2219 (add-text-properties (match-beginning 1) (match-end 1)
2220 '(org-protected t) rpl)
2221 (add-text-properties (match-beginning 3) (match-end 3)
2222 '(org-protected t) rpl)))))
2223 (replace-match rpl t t)))
2224 (backward-char)))
2226 (defun org-export-latex-emph-format (format string)
2227 "Format an emphasis string and handle the \\verb special case."
2228 (when (member format '("\\verb" "\\protectedtexttt"))
2229 (save-match-data
2230 (if (equal format "\\verb")
2231 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2232 (catch 'exit
2233 (loop for i from 0 to (1- (length ll)) do
2234 (if (not (string-match (regexp-quote (substring ll i (1+ i)))
2235 string))
2236 (progn
2237 (setq format (concat "\\verb" (substring ll i (1+ i))
2238 "%s" (substring ll i (1+ i))))
2239 (throw 'exit nil))))))
2240 (let ((start 0)
2241 (trans '(("\\" . "\\textbackslash{}")
2242 ("~" . "\\textasciitilde{}")
2243 ("^" . "\\textasciicircum{}")))
2244 (rtn "") char)
2245 (while (string-match "[\\{}$%&_#~^]" string)
2246 (setq char (match-string 0 string))
2247 (if (> (match-beginning 0) 0)
2248 (setq rtn (concat rtn (substring string
2249 0 (match-beginning 0)))))
2250 (setq string (substring string (1+ (match-beginning 0))))
2251 (setq char (or (cdr (assoc char trans)) (concat "\\" char))
2252 rtn (concat rtn char)))
2253 (setq string (concat rtn string) format "\\texttt{%s}")
2254 (while (string-match "--" string)
2255 (setq string (replace-match "-{}-" t t string)))))))
2256 (format format string))
2258 (defun org-export-latex-links ()
2259 ;; Make sure to use the LaTeX hyperref and graphicx package
2260 ;; or send some warnings.
2261 "Convert links to LaTeX."
2262 (goto-char (point-min))
2263 (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
2264 (org-if-unprotected-1
2265 (goto-char (match-beginning 0))
2266 (let* ((re-radio org-export-latex-all-targets-re)
2267 (remove (list (match-beginning 0) (match-end 0)))
2268 (raw-path (org-extract-attributes (match-string 3)))
2269 (full-raw-path (concat (match-string 1) raw-path))
2270 (desc (match-string 5))
2271 (type (or (match-string 2)
2272 (if (or (file-name-absolute-p raw-path)
2273 (string-match "^\\.\\.?/" raw-path))
2274 "file")))
2275 (coderefp (equal type "coderef"))
2276 (caption (org-find-text-property-in-string 'org-caption raw-path))
2277 (shortn (org-find-text-property-in-string 'org-caption-shortn raw-path))
2278 (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
2279 (plist-get org-export-latex-options-plist :latex-image-options)))
2280 (label (org-find-text-property-in-string 'org-label raw-path))
2281 imgp radiop fnc
2282 ;; define the path of the link
2283 (path (cond
2284 ((member type '("coderef"))
2285 raw-path)
2286 ((member type '("http" "https" "ftp"))
2287 (concat type ":" raw-path))
2288 ((and re-radio (string-match re-radio raw-path))
2289 (setq radiop t))
2290 ((equal type "mailto")
2291 (concat type ":" raw-path))
2292 ((equal type "file")
2293 (if (and (org-file-image-p
2294 (expand-file-name (org-link-unescape raw-path))
2295 org-export-latex-inline-image-extensions)
2296 (or (get-text-property 0 'org-no-description raw-path)
2297 (equal desc full-raw-path)))
2298 (setq imgp t)
2299 (progn (setq raw-path (org-link-unescape raw-path))
2300 (when (string-match "\\(.+\\)::.+" raw-path)
2301 (setq raw-path (match-string 1 raw-path)))
2302 (if (file-exists-p raw-path)
2303 (concat type "://" (expand-file-name raw-path))
2304 (concat type "://" (org-export-directory
2305 :LaTeX org-export-latex-options-plist)
2306 raw-path))))))))
2307 ;; process with link inserting
2308 (apply 'delete-region remove)
2309 (setq caption (and caption (org-export-latex-fontify-headline caption)))
2310 (cond ((and imgp
2311 (plist-get org-export-latex-options-plist :inline-images))
2312 ;; OK, we need to inline an image
2313 (insert
2314 (org-export-latex-format-image raw-path caption label attr shortn)))
2315 (coderefp
2316 (insert (format
2317 (org-export-get-coderef-format path desc)
2318 (cdr (assoc path org-export-code-refs)))))
2319 (radiop (insert (format org-export-latex-hyperref-format
2320 (org-solidify-link-text raw-path) desc)))
2321 ((not type)
2322 (insert (format org-export-latex-hyperref-format
2323 (org-remove-initial-hash
2324 (org-solidify-link-text raw-path))
2325 desc)))
2326 (path
2327 (when (org-at-table-p)
2328 ;; There is a strange problem when we have a link in a table,
2329 ;; ampersands then cause a problem. I think this must be
2330 ;; a LaTeX issue, but we here implement a work-around anyway.
2331 (setq path (org-export-latex-protect-amp path)
2332 desc (org-export-latex-protect-amp desc)))
2333 (insert
2334 (if (string-match "%s.*%s" org-export-latex-href-format)
2335 (format org-export-latex-href-format path desc)
2336 (format org-export-latex-href-format path))))
2338 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2339 ;; The link protocol has a function for formatting the link
2340 (insert
2341 (save-match-data
2342 (funcall fnc (org-link-unescape raw-path) desc 'latex))))
2343 ;; Unrecognized path type
2344 (t (insert (format org-export-latex-link-with-unknown-path-format desc))))))))
2347 (defun org-export-latex-format-image (path caption label attr &optional shortn)
2348 "Format the image element, depending on user settings."
2349 (let (ind floatp wrapp multicolumnp placement figenv)
2350 (setq floatp (or caption label))
2351 (setq ind (org-get-text-property-any 0 'original-indentation path))
2352 (when (and attr (stringp attr))
2353 (if (string-match "[ \t]*\\<wrap\\>" attr)
2354 (setq wrapp t floatp nil attr (replace-match "" t t attr)))
2355 (if (string-match "[ \t]*\\<float\\>" attr)
2356 (setq wrapp nil floatp t attr (replace-match "" t t attr)))
2357 (if (string-match "[ \t]*\\<multicolumn\\>" attr)
2358 (setq multicolumnp t attr (replace-match "" t t attr))))
2360 (setq placement
2361 (cond
2362 (wrapp "{l}{0.5\\textwidth}")
2363 (floatp (concat "[" org-latex-default-figure-position "]"))
2364 (t "")))
2366 (when (and attr (stringp attr)
2367 (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
2368 (setq placement (match-string 1 attr)
2369 attr (replace-match "" t t attr)))
2370 (setq attr (and attr (org-trim attr)))
2371 (when (or (not attr) (= (length attr) 0))
2372 (setq attr (cond (floatp "width=0.7\\textwidth")
2373 (wrapp "width=0.48\\textwidth")
2374 (t attr))))
2375 (setq figenv
2376 (cond
2377 (wrapp "\\begin{wrapfigure}%placement
2378 \\centering
2379 \\includegraphics[%attr]{%path}
2380 \\caption%shortn{%labelcmd%caption}
2381 \\end{wrapfigure}")
2382 (multicolumnp "\\begin{figure*}%placement
2383 \\centering
2384 \\includegraphics[%attr]{%path}
2385 \\caption%shortn{%labelcmd%caption}
2386 \\end{figure*}")
2387 (floatp "\\begin{figure}%placement
2388 \\centering
2389 \\includegraphics[%attr]{%path}
2390 \\caption%shortn{%labelcmd%caption}
2391 \\end{figure}")
2392 (t "\\includegraphics[%attr]{%path}")))
2395 (setq figenv (mapconcat 'identity (split-string figenv "\n")
2396 (save-excursion (beginning-of-line 1)
2397 (looking-at "[ \t]*")
2398 (concat "\n" (match-string 0)))))
2400 (if (and (not label) (not caption)
2401 (string-match "^\\\\caption{.*\n" figenv))
2402 (setq figenv (replace-match "" t t figenv)))
2403 (org-add-props
2404 (org-fill-template
2405 figenv
2406 (list (cons "path"
2407 (if (file-name-absolute-p path)
2408 (expand-file-name path)
2409 path))
2410 (cons "attr" attr)
2411 (cons "shortn" (if shortn (format "[%s]" shortn) ""))
2412 (cons "labelcmd" (if label (format "\\label{%s}"
2413 label)""))
2414 (cons "caption" (or caption ""))
2415 (cons "placement" (or placement ""))))
2416 nil 'original-indentation ind)))
2418 (defun org-export-latex-protect-amp (s)
2419 (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
2420 (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
2421 t t s)))
2424 (defun org-remove-initial-hash (s)
2425 (if (string-match "\\`#" s)
2426 (substring s 1)
2428 (defvar org-latex-entities) ; defined below
2429 (defvar org-latex-entities-regexp) ; defined below
2431 (defun org-export-latex-preprocess (parameters)
2432 "Clean stuff in the LaTeX export."
2433 ;; Replace footnotes.
2434 (when (plist-get parameters :footnotes)
2435 (goto-char (point-min))
2436 (let (ref)
2437 (while (setq ref (org-footnote-get-next-reference))
2438 (let* ((beg (nth 1 ref))
2439 (lbl (car ref))
2440 (def (nth 1 (assoc (string-to-number lbl)
2441 (mapcar (lambda (e) (cdr e))
2442 org-export-footnotes-seen)))))
2443 ;; Fix body for footnotes ending on a link or a list and
2444 ;; remove definition from buffer.
2445 (setq def
2446 (concat def
2447 (if (string-match "ORG-LIST-END-MARKER\\'" def)
2448 "\n" " ")))
2449 (org-footnote-delete-definitions lbl)
2450 ;; Compute string to insert (FNOTE), and protect the outside
2451 ;; macro from further transformation. When footnote at
2452 ;; point is referring to a previously defined footnote, use
2453 ;; \footnotemark. Otherwise, use \footnote.
2454 (let ((fnote (if (member lbl org-export-latex-footmark-seen)
2455 (org-export-latex-protect-string
2456 (format "\\footnotemark[%s]" lbl))
2457 (push lbl org-export-latex-footmark-seen)
2458 (concat (org-export-latex-protect-string "\\footnote{")
2460 (org-export-latex-protect-string "}"))))
2461 ;; Check if another footnote is immediately following.
2462 ;; If so, add a separator in-between.
2463 (sep (org-export-latex-protect-string
2464 (if (save-excursion (goto-char (1- (nth 2 ref)))
2465 (let ((next (org-footnote-get-next-reference)))
2466 (and next (= (nth 1 next) (nth 2 ref)))))
2467 org-export-latex-footnote-separator ""))))
2468 (when (org-at-heading-p)
2469 (setq fnote (concat (org-export-latex-protect-string "\\protect")
2470 fnote)))
2471 ;; Ensure a footnote at column 0 cannot end a list
2472 ;; containing it.
2473 (put-text-property 0 (length fnote) 'original-indentation 1000 fnote)
2474 ;; Replace footnote reference with FNOTE and, maybe, SEP.
2475 ;; `save-excursion' is required if there are two footnotes
2476 ;; in a row. In that case, point would be left at the
2477 ;; beginning of the second one, and
2478 ;; `org-footnote-get-next-reference' would then skip it.
2479 (goto-char beg)
2480 (delete-region beg (nth 2 ref))
2481 (save-excursion (insert fnote sep)))))))
2483 ;; Remove footnote section tag for LaTeX
2484 (goto-char (point-min))
2485 (while (re-search-forward
2486 (concat "^" footnote-section-tag-regexp) nil t)
2487 (org-if-unprotected
2488 (replace-match "")))
2489 ;; Remove any left-over footnote definition.
2490 (mapc (lambda (fn) (org-footnote-delete-definitions (car fn)))
2491 org-export-footnotes-data)
2492 (mapc (lambda (fn) (org-footnote-delete-definitions fn))
2493 org-export-latex-footmark-seen)
2495 ;; Preserve line breaks
2496 (goto-char (point-min))
2497 (while (re-search-forward "\\\\\\\\" nil t)
2498 (add-text-properties (match-beginning 0) (match-end 0)
2499 '(org-protected t)))
2501 ;; Preserve latex environments
2502 (goto-char (point-min))
2503 (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
2504 (org-if-unprotected
2505 (let* ((start (progn (beginning-of-line) (point)))
2506 (end (and (re-search-forward
2507 (concat "^[ \t]*\\\\end{"
2508 (regexp-quote (match-string 1))
2509 "}") nil t)
2510 (point-at-eol))))
2511 (if end
2512 (add-text-properties start end '(org-protected t))
2513 (goto-char (point-at-eol))))))
2515 ;; Preserve math snippets
2516 (let* ((matchers (plist-get org-format-latex-options :matchers))
2517 (re-list org-latex-regexps)
2518 beg end re e m n block off)
2519 ;; Check the different regular expressions
2520 (while (setq e (pop re-list))
2521 (setq m (car e) re (nth 1 e) n (nth 2 e)
2522 block (if (nth 3 e) "\n\n" ""))
2523 (setq off (if (member m '("$" "$1")) 1 0))
2524 (when (and (member m matchers) (not (equal m "begin")))
2525 (goto-char (point-min))
2526 (while (re-search-forward re nil t)
2527 (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
2528 (add-text-properties beg end '(org-protected t org-latex-math t))))))
2530 ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
2531 (goto-char (point-min))
2532 (let ((case-fold-search nil))
2533 (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
2534 (unless (eq (char-before (match-beginning 1)) ?\\)
2535 (org-if-unprotected-1
2536 (replace-match (org-export-latex-protect-string
2537 (concat "\\" (match-string 1)
2538 "{}")) t t)))))
2540 ;; Convert blockquotes
2541 (goto-char (point-min))
2542 (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
2543 (org-replace-match-keep-properties "\\begin{quote}" t t))
2544 (goto-char (point-min))
2545 (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
2546 (org-replace-match-keep-properties "\\end{quote}" t t))
2548 ;; Convert verse
2549 (goto-char (point-min))
2550 (while (search-forward "ORG-VERSE-START" nil t)
2551 (org-replace-match-keep-properties "\\begin{verse}" t t)
2552 (beginning-of-line 2)
2553 (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
2554 (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
2555 (goto-char (match-end 1))
2556 (org-replace-match-keep-properties
2557 (org-export-latex-protect-string
2558 (concat "\\hspace*{1cm}" (match-string 2))) t t)
2559 (beginning-of-line 1))
2560 (if (looking-at "[ \t]*$")
2561 (insert (org-export-latex-protect-string "\\vspace*{1em}"))
2562 (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
2563 (end-of-line 1)
2564 (insert "\\\\")))
2565 (beginning-of-line 2))
2566 (and (looking-at "[ \t]*ORG-VERSE-END.*")
2567 (org-replace-match-keep-properties "\\end{verse}" t t)))
2569 ;; Convert #+INDEX to LaTeX \\index.
2570 (goto-char (point-min))
2571 (let ((case-fold-search t) entry)
2572 (while (re-search-forward
2573 "^[ \t]*#\\+index:[ \t]*\\([^ \t\r\n].*?\\)[ \t]*$"
2574 nil t)
2575 (setq entry
2576 (save-match-data
2577 (org-export-latex-protect-string
2578 (org-export-latex-fontify-headline (match-string 1)))))
2579 (replace-match (format "\\index{%s}" entry) t t)))
2581 ;; Convert center
2582 (goto-char (point-min))
2583 (while (search-forward "ORG-CENTER-START" nil t)
2584 (org-replace-match-keep-properties "\\begin{center}" t t))
2585 (goto-char (point-min))
2586 (while (search-forward "ORG-CENTER-END" nil t)
2587 (org-replace-match-keep-properties "\\end{center}" t t))
2589 (run-hooks 'org-export-latex-after-blockquotes-hook)
2591 ;; Convert horizontal rules
2592 (goto-char (point-min))
2593 (while (re-search-forward "^[ \t]*-\\{5,\\}[ \t]*$" nil t)
2594 (org-if-unprotected
2595 (replace-match (org-export-latex-protect-string "\\hrule") t t)))
2597 ;; Protect LaTeX commands like \command[...]{...} or \command{...}
2598 (goto-char (point-min))
2599 (let ((re (concat
2600 "\\\\\\([a-zA-Z]+\\*?\\)"
2601 "\\(?:<[^<>\n]*>\\)*"
2602 "\\(?:\\[[^][\n]*?\\]\\)*"
2603 "\\(?:<[^<>\n]*>\\)*"
2604 "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}")))
2605 (while (re-search-forward re nil t)
2606 (unless (or
2607 ;; Check for comment line.
2608 (save-excursion (goto-char (match-beginning 0))
2609 (org-in-indented-comment-line))
2610 ;; Check if this is a defined entity, so that is may
2611 ;; need conversion.
2612 (org-entity-get (match-string 1))
2613 ;; Do not protect interior of footnotes. Those have
2614 ;; already been taken care of earlier in the function.
2615 ;; Yet, keep looking inside them for more commands.
2616 (and (equal (match-string 1) "footnote")
2617 (goto-char (match-end 1))))
2618 (add-text-properties (match-beginning 0) (match-end 0)
2619 '(org-protected t)))))
2621 ;; Special case for \nbsp
2622 (goto-char (point-min))
2623 (while (re-search-forward "\\\\nbsp\\({}\\|\\>\\)" nil t)
2624 (org-if-unprotected
2625 (replace-match (org-export-latex-protect-string "~"))))
2627 ;; Protect LaTeX entities
2628 (goto-char (point-min))
2629 (while (re-search-forward org-latex-entities-regexp nil t)
2630 (org-if-unprotected
2631 (add-text-properties (match-beginning 0) (match-end 0)
2632 '(org-protected t))))
2634 ;; Replace radio links
2635 (goto-char (point-min))
2636 (while (re-search-forward
2637 (concat "<<<?" org-export-latex-all-targets-re
2638 ">>>?\\((INVISIBLE)\\)?") nil t)
2639 (org-if-unprotected-at (+ (match-beginning 0) 2)
2640 (replace-match
2641 (concat
2642 (org-export-latex-protect-string
2643 (format "\\label{%s}" (save-match-data (org-solidify-link-text
2644 (match-string 1)))))
2645 (if (match-string 2) "" (match-string 1)))
2646 t t)))
2648 ;; Delete @<...> constructs
2649 ;; Thanks to Daniel Clemente for this regexp
2650 (goto-char (point-min))
2651 (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
2652 (org-if-unprotected
2653 (replace-match ""))))
2655 (defun org-export-latex-fix-inputenc ()
2656 "Set the coding system in inputenc to what the buffer is."
2657 (let* ((cs buffer-file-coding-system)
2658 (opt (or (ignore-errors (latexenc-coding-system-to-inputenc cs))
2659 "utf8")))
2660 (when opt
2661 ;; Translate if that is requested
2662 (setq opt (or (cdr (assoc opt org-export-latex-inputenc-alist)) opt))
2663 ;; find the \usepackage statement and replace the option
2664 (goto-char (point-min))
2665 (while (re-search-forward "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
2666 nil t)
2667 (goto-char (match-beginning 1))
2668 (delete-region (match-beginning 1) (match-end 1))
2669 (insert opt))
2670 (and buffer-file-name
2671 (save-buffer)))))
2673 ;;; List handling:
2675 (defun org-export-latex-lists ()
2676 "Convert plain text lists in current buffer into LaTeX lists."
2677 ;; `org-list-end-re' output has changed since preprocess from
2678 ;; org-exp.el. Make sure it is taken into account.
2679 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
2680 (mapc
2681 (lambda (e)
2682 ;; For each type of context allowed for list export (E), find
2683 ;; every list, parse it, delete it and insert resulting
2684 ;; conversion to latex (RES), while keeping the same
2685 ;; `original-indentation' property.
2686 (let (res)
2687 (goto-char (point-min))
2688 (while (re-search-forward (org-item-beginning-re) nil t)
2689 (when (and (eq (get-text-property (point) 'list-context) e)
2690 (not (get-text-property (point) 'org-example)))
2691 (beginning-of-line)
2692 (setq res
2693 (org-list-to-latex
2694 ;; Narrowing is needed because we're converting
2695 ;; from inner functions to outer ones.
2696 (save-restriction
2697 (narrow-to-region (point) (point-max))
2698 (org-list-parse-list t))
2699 org-export-latex-list-parameters))
2700 ;; Extend previous value of original-indentation to the
2701 ;; whole string
2702 (insert (org-add-props res nil 'original-indentation
2703 (org-find-text-property-in-string
2704 'original-indentation res)))))))
2705 ;; List of allowed contexts for export, and the default one.
2706 (append org-list-export-context '(nil)))))
2708 (defconst org-latex-entities
2709 '("\\!"
2710 "\\'"
2711 "\\+"
2712 "\\,"
2713 "\\-"
2714 "\\:"
2715 "\\;"
2716 "\\<"
2717 "\\="
2718 "\\>"
2719 "\\Huge"
2720 "\\LARGE"
2721 "\\Large"
2722 "\\Styles"
2723 "\\\\"
2724 "\\`"
2725 "\\\""
2726 "\\addcontentsline"
2727 "\\address"
2728 "\\addtocontents"
2729 "\\addtocounter"
2730 "\\addtolength"
2731 "\\addvspace"
2732 "\\alph"
2733 "\\appendix"
2734 "\\arabic"
2735 "\\author"
2736 "\\begin{array}"
2737 "\\begin{center}"
2738 "\\begin{description}"
2739 "\\begin{enumerate}"
2740 "\\begin{eqnarray}"
2741 "\\begin{equation}"
2742 "\\begin{figure}"
2743 "\\begin{flushleft}"
2744 "\\begin{flushright}"
2745 "\\begin{itemize}"
2746 "\\begin{list}"
2747 "\\begin{minipage}"
2748 "\\begin{picture}"
2749 "\\begin{quotation}"
2750 "\\begin{quote}"
2751 "\\begin{tabbing}"
2752 "\\begin{table}"
2753 "\\begin{tabular}"
2754 "\\begin{thebibliography}"
2755 "\\begin{theorem}"
2756 "\\begin{titlepage}"
2757 "\\begin{verbatim}"
2758 "\\begin{verse}"
2759 "\\bf"
2760 "\\bf"
2761 "\\bibitem"
2762 "\\bigskip"
2763 "\\cdots"
2764 "\\centering"
2765 "\\circle"
2766 "\\cite"
2767 "\\cleardoublepage"
2768 "\\clearpage"
2769 "\\cline"
2770 "\\closing"
2771 "\\dashbox"
2772 "\\date"
2773 "\\ddots"
2774 "\\dotfill"
2775 "\\em"
2776 "\\fbox"
2777 "\\flushbottom"
2778 "\\fnsymbol"
2779 "\\footnote"
2780 "\\footnotemark"
2781 "\\footnotesize"
2782 "\\footnotetext"
2783 "\\frac"
2784 "\\frame"
2785 "\\framebox"
2786 "\\hfill"
2787 "\\hline"
2788 "\\hrulespace"
2789 "\\hspace"
2790 "\\huge"
2791 "\\hyphenation"
2792 "\\include"
2793 "\\includeonly"
2794 "\\indent"
2795 "\\input"
2796 "\\it"
2797 "\\kill"
2798 "\\label"
2799 "\\large"
2800 "\\ldots"
2801 "\\line"
2802 "\\linebreak"
2803 "\\linethickness"
2804 "\\listoffigures"
2805 "\\listoftables"
2806 "\\location"
2807 "\\makebox"
2808 "\\maketitle"
2809 "\\mark"
2810 "\\mbox"
2811 "\\medskip"
2812 "\\multicolumn"
2813 "\\multiput"
2814 "\\newcommand"
2815 "\\newcounter"
2816 "\\newenvironment"
2817 "\\newfont"
2818 "\\newlength"
2819 "\\newline"
2820 "\\newpage"
2821 "\\newsavebox"
2822 "\\newtheorem"
2823 "\\nocite"
2824 "\\nofiles"
2825 "\\noindent"
2826 "\\nolinebreak"
2827 "\\nopagebreak"
2828 "\\normalsize"
2829 "\\onecolumn"
2830 "\\opening"
2831 "\\oval"
2832 "\\overbrace"
2833 "\\overline"
2834 "\\pagebreak"
2835 "\\pagenumbering"
2836 "\\pageref"
2837 "\\pagestyle"
2838 "\\par"
2839 "\\parbox"
2840 "\\put"
2841 "\\raggedbottom"
2842 "\\raggedleft"
2843 "\\raggedright"
2844 "\\raisebox"
2845 "\\ref"
2846 "\\rm"
2847 "\\roman"
2848 "\\rule"
2849 "\\savebox"
2850 "\\sc"
2851 "\\scriptsize"
2852 "\\setcounter"
2853 "\\setlength"
2854 "\\settowidth"
2855 "\\sf"
2856 "\\shortstack"
2857 "\\signature"
2858 "\\sl"
2859 "\\small"
2860 "\\smallskip"
2861 "\\sqrt"
2862 "\\tableofcontents"
2863 "\\telephone"
2864 "\\thanks"
2865 "\\thispagestyle"
2866 "\\tiny"
2867 "\\title"
2868 "\\tt"
2869 "\\twocolumn"
2870 "\\typein"
2871 "\\typeout"
2872 "\\underbrace"
2873 "\\underline"
2874 "\\usebox"
2875 "\\usecounter"
2876 "\\value"
2877 "\\vdots"
2878 "\\vector"
2879 "\\verb"
2880 "\\vfill"
2881 "\\vline"
2882 "\\vspace")
2883 "A list of LaTeX commands to be protected when performing conversion.")
2885 (defconst org-latex-entities-regexp
2886 (let (names rest)
2887 (dolist (x org-latex-entities)
2888 (if (string-match "[a-zA-Z]$" x)
2889 (push x names)
2890 (push x rest)))
2891 (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
2892 "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
2894 (provide 'org-export-latex)
2895 (provide 'org-latex)
2897 ;; Local variables:
2898 ;; generated-autoload-file: "org-loaddefs.el"
2899 ;; End:
2901 ;;; org-latex.el ends here