vc-hooks.el workaround for bug#11490
[emacs.git] / lisp / org / org-latex.el
blob9ce84f14e92f8ac518bd060631d01c511ea293fe
1 ;;; org-latex.el --- LaTeX exporter for org-mode
2 ;;
3 ;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
4 ;;
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: org-latex.el
7 ;; Author: Bastien Guerry <bzg AT gnu DOT org>
8 ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
9 ;; Keywords: org, wp, tex
10 ;; Description: Converts an org-mode buffer into LaTeX
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Commentary:
29 ;; This library implements a LaTeX exporter for org-mode.
31 ;; It is part of Org and will be autoloaded
33 ;; The interactive functions are similar to those of the HTML exporter:
35 ;; M-x `org-export-as-latex'
36 ;; M-x `org-export-as-pdf'
37 ;; M-x `org-export-as-pdf-and-open'
38 ;; M-x `org-export-as-latex-batch'
39 ;; M-x `org-export-as-latex-to-buffer'
40 ;; M-x `org-export-region-as-latex'
41 ;; M-x `org-replace-region-by-latex'
43 ;;; Code:
45 (eval-when-compile
46 (require 'cl))
48 (require 'footnote)
49 (require 'org)
50 (require 'org-exp)
51 (require 'org-macs)
52 (require 'org-beamer)
54 ;;; Variables:
55 (defvar org-export-latex-class nil)
56 (defvar org-export-latex-class-options nil)
57 (defvar org-export-latex-header nil)
58 (defvar org-export-latex-append-header nil)
59 (defvar org-export-latex-options-plist nil)
60 (defvar org-export-latex-todo-keywords-1 nil)
61 (defvar org-export-latex-complex-heading-re nil)
62 (defvar org-export-latex-not-done-keywords nil)
63 (defvar org-export-latex-done-keywords nil)
64 (defvar org-export-latex-display-custom-times nil)
65 (defvar org-export-latex-all-targets-re nil)
66 (defvar org-export-latex-add-level 0)
67 (defvar org-export-latex-footmark-seen nil
68 "List of footnotes markers seen so far by exporter.")
69 (defvar org-export-latex-sectioning "")
70 (defvar org-export-latex-sectioning-depth 0)
71 (defvar org-export-latex-special-keyword-regexp
72 (concat "\\<\\(" org-scheduled-string "\\|"
73 org-deadline-string "\\|"
74 org-closed-string"\\)")
75 "Regexp matching special time planning keywords plus the time after it.")
76 (defvar org-re-quote) ; dynamically scoped from org.el
77 (defvar org-commentsp) ; dynamically scoped from org.el
79 ;;; User variables:
81 (defgroup org-export-latex nil
82 "Options for exporting Org-mode files to LaTeX."
83 :tag "Org Export LaTeX"
84 :group 'org-export)
86 (defcustom org-export-latex-default-class "article"
87 "The default LaTeX class."
88 :group 'org-export-latex
89 :type '(string :tag "LaTeX class"))
91 (defcustom org-export-latex-classes
92 '(("article"
93 "\\documentclass[11pt]{article}"
94 ("\\section{%s}" . "\\section*{%s}")
95 ("\\subsection{%s}" . "\\subsection*{%s}")
96 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
97 ("\\paragraph{%s}" . "\\paragraph*{%s}")
98 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
99 ("report"
100 "\\documentclass[11pt]{report}"
101 ("\\part{%s}" . "\\part*{%s}")
102 ("\\chapter{%s}" . "\\chapter*{%s}")
103 ("\\section{%s}" . "\\section*{%s}")
104 ("\\subsection{%s}" . "\\subsection*{%s}")
105 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
106 ("book"
107 "\\documentclass[11pt]{book}"
108 ("\\part{%s}" . "\\part*{%s}")
109 ("\\chapter{%s}" . "\\chapter*{%s}")
110 ("\\section{%s}" . "\\section*{%s}")
111 ("\\subsection{%s}" . "\\subsection*{%s}")
112 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
113 ("beamer"
114 "\\documentclass{beamer}"
115 org-beamer-sectioning
117 "Alist of LaTeX classes and associated header and structure.
118 If #+LaTeX_CLASS is set in the buffer, use its value and the
119 associated information. Here is the structure of each cell:
121 \(class-name
122 header-string
123 (numbered-section . unnumbered-section\)
124 ...\)
126 The header string
127 -----------------
129 The HEADER-STRING is the header that will be inserted into the LaTeX file.
130 It should contain the \\documentclass macro, and anything else that is needed
131 for this setup. To this header, the following commands will be added:
133 - Calls to \\usepackage for all packages mentioned in the variables
134 `org-export-latex-default-packages-alist' and
135 `org-export-latex-packages-alist'. Thus, your header definitions should
136 avoid to also request these packages.
138 - Lines specified via \"#+LaTeX_HEADER:\"
140 If you need more control about the sequence in which the header is built
141 up, or if you want to exclude one of these building blocks for a particular
142 class, you can use the following macro-like placeholders.
144 [DEFAULT-PACKAGES] \\usepackage statements for default packages
145 [NO-DEFAULT-PACKAGES] do not include any of the default packages
146 [PACKAGES] \\usepackage statements for packages
147 [NO-PACKAGES] do not include the packages
148 [EXTRA] the stuff from #+LaTeX_HEADER
149 [NO-EXTRA] do not include #+LaTeX_HEADER stuff
150 [BEAMER-HEADER-EXTRA] the beamer extra headers
152 So a header like
154 \\documentclass{article}
155 [NO-DEFAULT-PACKAGES]
156 [EXTRA]
157 \\providecommand{\\alert}[1]{\\textbf{#1}}
158 [PACKAGES]
160 will omit the default packages, and will include the #+LaTeX_HEADER lines,
161 then have a call to \\providecommand, and then place \\usepackage commands
162 based on the content of `org-export-latex-packages-alist'.
164 If your header or `org-export-latex-default-packages-alist' inserts
165 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be replaced with
166 a coding system derived from `buffer-file-coding-system'. See also the
167 variable `org-export-latex-inputenc-alist' for a way to influence this
168 mechanism.
170 The sectioning structure
171 ------------------------
173 The sectioning structure of the class is given by the elements following
174 the header string. For each sectioning level, a number of strings is
175 specified. A %s formatter is mandatory in each section string and will
176 be replaced by the title of the section.
178 Instead of a cons cell (numbered . unnumbered), you can also provide a list
179 of 2 or 4 elements,
181 (numbered-open numbered-close)
185 (numbered-open numbered-close unnumbered-open unnumbered-close)
187 providing opening and closing strings for a LaTeX environment that should
188 represent the document section. The opening clause should have a %s
189 to represent the section title.
191 Instead of a list of sectioning commands, you can also specify a
192 function name. That function will be called with two parameters,
193 the (reduced) level of the headline, and the headline text. The function
194 must return a cons cell with the (possibly modified) headline text, and the
195 sectioning list in the cdr."
196 :group 'org-export-latex
197 :type '(repeat
198 (list (string :tag "LaTeX class")
199 (string :tag "LaTeX header")
200 (repeat :tag "Levels" :inline t
201 (choice
202 (cons :tag "Heading"
203 (string :tag " numbered")
204 (string :tag "unnumbered"))
205 (list :tag "Environment"
206 (string :tag "Opening (numbered)")
207 (string :tag "Closing (numbered)")
208 (string :tag "Opening (unnumbered)")
209 (string :tag "Closing (unnumbered)"))
210 (function :tag "Hook computing sectioning"))))))
212 (defcustom org-export-latex-inputenc-alist nil
213 "Alist of inputenc coding system names, and what should really be used.
214 For example, adding an entry
216 (\"utf8\" . \"utf8x\")
218 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
219 are written as utf8 files."
220 :group 'org-export-latex
221 :version "24.1"
222 :type '(repeat
223 (cons
224 (string :tag "Derived from buffer")
225 (string :tag "Use this instead"))))
228 (defcustom org-export-latex-emphasis-alist
229 '(("*" "\\textbf{%s}" nil)
230 ("/" "\\emph{%s}" nil)
231 ("_" "\\underline{%s}" nil)
232 ("+" "\\st{%s}" nil)
233 ("=" "\\protectedtexttt" t)
234 ("~" "\\verb" t))
235 "Alist of LaTeX expressions to convert emphasis fontifiers.
236 Each element of the list is a list of three elements.
237 The first element is the character used as a marker for fontification.
238 The second element is a format string to wrap fontified text with.
239 If it is \"\\verb\", Org will automatically select a delimiter
240 character that is not in the string. \"\\protectedtexttt\" will use \\texttt
241 to typeset and try to protect special characters.
242 The third element decides whether to protect converted text from other
243 conversions."
244 :group 'org-export-latex
245 :type 'alist)
247 (defcustom org-export-latex-title-command "\\maketitle"
248 "The command used to insert the title just after \\begin{document}.
249 If this string contains the formatting specification \"%s\" then
250 it will be used as a format string, passing the title as an
251 argument."
252 :group 'org-export-latex
253 :type 'string)
255 (defcustom org-export-latex-import-inbuffer-stuff nil
256 "Non-nil means define TeX macros for Org's inbuffer definitions.
257 For example \orgTITLE for #+TITLE."
258 :group 'org-export-latex
259 :type 'boolean)
261 (defcustom org-export-latex-date-format
262 "\\today"
263 "Format string for \\date{...}."
264 :group 'org-export-latex
265 :type 'string)
267 (defcustom org-export-latex-todo-keyword-markup "\\textbf{%s}"
268 "Markup for TODO keywords, as a printf format.
269 This can be a single format for all keywords, a cons cell with separate
270 formats for not-done and done states, or an association list with setup
271 for individual keywords. If a keyword shows up for which there is no
272 markup defined, the first one in the association list will be used."
273 :group 'org-export-latex
274 :type '(choice
275 (string :tag "Default")
276 (cons :tag "Distinguish undone and done"
277 (string :tag "Not-DONE states")
278 (string :tag "DONE states"))
279 (repeat :tag "Per keyword markup"
280 (cons
281 (string :tag "Keyword")
282 (string :tag "Markup")))))
284 (defcustom org-export-latex-tag-markup "\\textbf{%s}"
285 "Markup for tags, as a printf format."
286 :group 'org-export-latex
287 :version "24.1"
288 :type 'string)
290 (defcustom org-export-latex-timestamp-markup "\\textit{%s}"
291 "A printf format string to be applied to time stamps."
292 :group 'org-export-latex
293 :type 'string)
295 (defcustom org-export-latex-timestamp-inactive-markup "\\textit{%s}"
296 "A printf format string to be applied to inactive time stamps."
297 :group 'org-export-latex
298 :version "24.1"
299 :type 'string)
301 (defcustom org-export-latex-timestamp-keyword-markup "\\texttt{%s}"
302 "A printf format string to be applied to time stamps."
303 :group 'org-export-latex
304 :type 'string)
306 (defcustom org-export-latex-href-format "\\href{%s}{%s}"
307 "A printf format string to be applied to href links.
308 The format must contain either two %s instances or just one.
309 If it contains two %s instances, the first will be filled with
310 the link, the second with the link description. If it contains
311 only one, the %s will be filled with the link."
312 :group 'org-export-latex
313 :version "24.1"
314 :type 'string)
316 (defcustom org-export-latex-hyperref-format "\\hyperref[%s]{%s}"
317 "A printf format string to be applied to hyperref links.
318 The format must contain one or two %s instances. The first one
319 will be filled with the link, the second with its description."
320 :group 'org-export-latex
321 :version "24.1"
322 :type 'string)
324 (defcustom org-export-latex-hyperref-options-format
325 "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={Emacs Org-mode version %s}}\n"
326 "A format string for hyperref options.
327 When non-nil, it must contain three %s format specifications
328 which will respectively be replaced by the document's keywords,
329 its description and the Org's version number, as a string. Set
330 this option to the empty string if you don't want to include
331 hyperref options altogether."
332 :type 'string
333 :version "24.3"
334 :group 'org-export-latex)
336 (defcustom org-export-latex-footnote-separator "\\textsuperscript{,}\\,"
337 "Text used to separate footnotes."
338 :group 'org-export-latex
339 :version "24.1"
340 :type 'string)
342 (defcustom org-export-latex-quotes
343 '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
344 ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
345 "Alist for quotes to use when converting english double-quotes.
347 The CAR of each item in this alist is the language code.
348 The CDR of each item in this alist is a list of three CONS:
349 - the first CONS defines the opening quote;
350 - the second CONS defines the closing quote;
351 - the last CONS defines single quotes.
353 For each item in a CONS, the first string is a regexp
354 for allowed characters before/after the quote, the second
355 string defines the replacement string for this quote."
356 :group 'org-export-latex
357 :version "24.1"
358 :type '(list
359 (cons :tag "Opening quote"
360 (string :tag "Regexp for char before")
361 (string :tag "Replacement quote "))
362 (cons :tag "Closing quote"
363 (string :tag "Regexp for char after ")
364 (string :tag "Replacement quote "))
365 (cons :tag "Single quote"
366 (string :tag "Regexp for char before")
367 (string :tag "Replacement quote "))))
369 (defcustom org-export-latex-tables-verbatim nil
370 "When non-nil, tables are exported verbatim."
371 :group 'org-export-latex
372 :type 'boolean)
374 (defcustom org-export-latex-tables-centered t
375 "When non-nil, tables are exported in a center environment."
376 :group 'org-export-latex
377 :type 'boolean)
379 (defcustom org-export-latex-table-caption-above t
380 "When non-nil, the caption is set above the table. When nil,
381 the caption is set below the table."
382 :group 'org-export-latex
383 :version "24.1"
384 :type 'boolean)
386 (defcustom org-export-latex-tables-column-borders nil
387 "When non-nil, grouping columns can cause outer vertical lines in tables.
388 When nil, grouping causes only separation lines between groups."
389 :group 'org-export-latex
390 :type 'boolean)
392 (defcustom org-export-latex-tables-tstart nil
393 "LaTeX command for top rule for tables."
394 :group 'org-export-latex
395 :version "24.1"
396 :type '(choice
397 (const :tag "Nothing" nil)
398 (string :tag "String")
399 (const :tag "Booktabs default: \\toprule" "\\toprule")))
401 (defcustom org-export-latex-tables-hline "\\hline"
402 "LaTeX command to use for a rule somewhere in the middle of a table."
403 :group 'org-export-latex
404 :version "24.1"
405 :type '(choice
406 (string :tag "String")
407 (const :tag "Standard: \\hline" "\\hline")
408 (const :tag "Booktabs default: \\midrule" "\\midrule")))
410 (defcustom org-export-latex-tables-tend nil
411 "LaTeX command for bottom rule for tables."
412 :group 'org-export-latex
413 :version "24.1"
414 :type '(choice
415 (const :tag "Nothing" nil)
416 (string :tag "String")
417 (const :tag "Booktabs default: \\bottomrule" "\\bottomrule")))
419 (defcustom org-export-latex-low-levels 'itemize
420 "How to convert sections below the current level of sectioning.
421 This is specified by the `org-export-headline-levels' option or the
422 value of \"H:\" in Org's #+OPTION line.
424 This can be either nil (skip the sections), `description', `itemize',
425 or `enumerate' (convert the sections as the corresponding list type), or
426 a string to be used instead of \\section{%s}. In this latter case,
427 the %s stands here for the inserted headline and is mandatory.
429 It may also be a list of three string to define a user-defined environment
430 that should be used. The first string should be the like
431 \"\\begin{itemize}\", the second should be like \"\\item %s %s\" with up
432 to two occurrences of %s for the title and a label, respectively. The third
433 string should be like \"\\end{itemize\"."
434 :group 'org-export-latex
435 :type '(choice (const :tag "Ignore" nil)
436 (const :tag "Convert as descriptive list" description)
437 (const :tag "Convert as itemized list" itemize)
438 (const :tag "Convert as enumerated list" enumerate)
439 (list :tag "User-defined environment"
440 :value ("\\begin{itemize}" "\\end{itemize}" "\\item %s")
441 (string :tag "Start")
442 (string :tag "End")
443 (string :tag "item"))
444 (string :tag "Use a section string" :value "\\subparagraph{%s}")))
446 (defcustom org-export-latex-list-parameters
447 '(:cbon "$\\boxtimes$" :cboff "$\\Box$" :cbtrans "$\\boxminus$")
448 "Parameters for the LaTeX list exporter.
449 These parameters will be passed on to `org-list-to-latex', which in turn
450 will pass them (combined with the LaTeX default list parameters) to
451 `org-list-to-generic'."
452 :group 'org-export-latex
453 :type 'plist)
455 (defcustom org-export-latex-verbatim-wrap
456 '("\\begin{verbatim}\n" . "\\end{verbatim}")
457 "Environment to be wrapped around a fixed-width section in LaTeX export.
458 This is a cons with two strings, to be added before and after the
459 fixed-with text.
461 Defaults to \\begin{verbatim} and \\end{verbatim}."
462 :group 'org-export-translation
463 :group 'org-export-latex
464 :type '(cons (string :tag "Open")
465 (string :tag "Close")))
467 (defcustom org-export-latex-listings nil
468 "Non-nil means export source code using the listings package.
469 This package will fontify source code, possibly even with color.
470 If you want to use this, you also need to make LaTeX use the
471 listings package, and if you want to have color, the color
472 package. Just add these to `org-export-latex-packages-alist',
473 for example using customize, or with something like
475 (require 'org-latex)
476 (add-to-list 'org-export-latex-packages-alist '(\"\" \"listings\"))
477 (add-to-list 'org-export-latex-packages-alist '(\"\" \"color\"))
479 Alternatively,
481 (setq org-export-latex-listings 'minted)
483 causes source code to be exported using the minted package as
484 opposed to listings. If you want to use minted, you need to add
485 the minted package to `org-export-latex-packages-alist', for
486 example using customize, or with
488 (require 'org-latex)
489 (add-to-list 'org-export-latex-packages-alist '(\"\" \"minted\"))
491 In addition, it is necessary to install
492 pygments (http://pygments.org), and to configure the variable
493 `org-latex-to-pdf-process' so that the -shell-escape option is
494 passed to pdflatex.
496 :group 'org-export-latex
497 :type 'boolean)
499 (defcustom org-export-latex-listings-langs
500 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
501 (c "C") (cc "C++")
502 (fortran "fortran")
503 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
504 (html "HTML") (xml "XML")
505 (tex "TeX") (latex "TeX")
506 (shell-script "bash")
507 (gnuplot "Gnuplot")
508 (ocaml "Caml") (caml "Caml")
509 (sql "SQL") (sqlite "sql"))
510 "Alist mapping languages to their listing language counterpart.
511 The key is a symbol, the major mode symbol without the \"-mode\".
512 The value is the string that should be inserted as the language parameter
513 for the listings package. If the mode name and the listings name are
514 the same, the language does not need an entry in this list - but it does not
515 hurt if it is present."
516 :group 'org-export-latex
517 :type '(repeat
518 (list
519 (symbol :tag "Major mode ")
520 (string :tag "Listings language"))))
522 (defcustom org-export-latex-listings-w-names t
523 "Non-nil means export names of named code blocks.
524 Code blocks exported with the listings package (controlled by the
525 `org-export-latex-listings' variable) can be named in the style
526 of noweb."
527 :group 'org-export-latex
528 :version "24.1"
529 :type 'boolean)
531 (defcustom org-export-latex-minted-langs
532 '((emacs-lisp "common-lisp")
533 (cc "c++")
534 (cperl "perl")
535 (shell-script "bash")
536 (caml "ocaml"))
537 "Alist mapping languages to their minted language counterpart.
538 The key is a symbol, the major mode symbol without the \"-mode\".
539 The value is the string that should be inserted as the language parameter
540 for the minted package. If the mode name and the listings name are
541 the same, the language does not need an entry in this list - but it does not
542 hurt if it is present.
544 Note that minted uses all lower case for language identifiers,
545 and that the full list of language identifiers can be obtained
546 with:
547 pygmentize -L lexers
549 :group 'org-export-latex
550 :version "24.1"
551 :type '(repeat
552 (list
553 (symbol :tag "Major mode ")
554 (string :tag "Listings language"))))
556 (defcustom org-export-latex-listings-options nil
557 "Association list of options for the latex listings package.
559 These options are supplied as a comma-separated list to the
560 \\lstset command. Each element of the association list should be
561 a list containing two strings: the name of the option, and the
562 value. For example,
564 (setq org-export-latex-listings-options
565 '((\"basicstyle\" \"\\small\")
566 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
568 will typeset the code in a small size font with underlined, bold
569 black keywords.
571 Note that the same options will be applied to blocks of all
572 languages."
573 :group 'org-export-latex
574 :version "24.1"
575 :type '(repeat
576 (list
577 (string :tag "Listings option name ")
578 (string :tag "Listings option value"))))
580 (defcustom org-export-latex-minted-options nil
581 "Association list of options for the latex minted package.
583 These options are supplied within square brackets in
584 \\begin{minted} environments. Each element of the alist should be
585 a list containing two strings: the name of the option, and the
586 value. For example,
588 (setq org-export-latex-minted-options
589 '((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
591 will result in src blocks being exported with
593 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
595 as the start of the minted environment. Note that the same
596 options will be applied to blocks of all languages."
597 :group 'org-export-latex
598 :version "24.1"
599 :type '(repeat
600 (list
601 (string :tag "Minted option name ")
602 (string :tag "Minted option value"))))
604 (defvar org-export-latex-custom-lang-environments nil
605 "Association list mapping languages to language-specific latex
606 environments used during export of src blocks by the listings
607 and minted latex packages. For example,
609 (setq org-export-latex-custom-lang-environments
610 '((python \"pythoncode\")))
612 would have the effect that if org encounters begin_src python
613 during latex export it will output
615 \\begin{pythoncode}
616 <src block body>
617 \\end{pythoncode}")
619 (defcustom org-export-latex-remove-from-headlines
620 '(:todo nil :priority nil :tags nil)
621 "A plist of keywords to remove from headlines. OBSOLETE.
622 Non-nil means remove this keyword type from the headline.
624 Don't remove the keys, just change their values.
626 Obsolete, this variable is no longer used. Use the separate
627 variables `org-export-with-todo-keywords', `org-export-with-priority',
628 and `org-export-with-tags' instead."
629 :type 'plist
630 :group 'org-export-latex)
632 (defcustom org-export-latex-image-default-option "width=.9\\linewidth"
633 "Default option for images."
634 :group 'org-export-latex
635 :type 'string)
637 (defcustom org-latex-default-figure-position "htb"
638 "Default position for latex figures."
639 :group 'org-export-latex
640 :version "24.1"
641 :type 'string)
643 (defcustom org-export-latex-tabular-environment "tabular"
644 "Default environment used to build tables."
645 :group 'org-export-latex
646 :version "24.1"
647 :type 'string)
649 (defcustom org-export-latex-link-with-unknown-path-format "\\texttt{%s}"
650 "Format string for links with unknown path type."
651 :group 'org-export-latex
652 :version "24.3"
653 :type 'string)
655 (defcustom org-export-latex-inline-image-extensions
656 '("pdf" "jpeg" "jpg" "png" "ps" "eps")
657 "Extensions of image files that can be inlined into LaTeX.
658 Note that the image extension *actually* allowed depend on the way the
659 LaTeX file is processed. When used with pdflatex, pdf, jpg and png images
660 are OK. When processing through dvi to Postscript, only ps and eps are
661 allowed. The default we use here encompasses both."
662 :group 'org-export-latex
663 :type '(repeat (string :tag "Extension")))
665 (defcustom org-export-latex-coding-system nil
666 "Coding system for the exported LaTeX file."
667 :group 'org-export-latex
668 :type 'coding-system)
670 (defgroup org-export-pdf nil
671 "Options for exporting Org-mode files to PDF, via LaTeX."
672 :tag "Org Export PDF"
673 :group 'org-export-latex
674 :group 'org-export)
676 (defcustom org-latex-to-pdf-process
677 '("pdflatex -interaction nonstopmode -output-directory %o %f"
678 "pdflatex -interaction nonstopmode -output-directory %o %f"
679 "pdflatex -interaction nonstopmode -output-directory %o %f")
680 "Commands to process a LaTeX file to a PDF file and process latex
681 fragments to pdf files.By default,this is a list of strings,and each of
682 strings will be given to the shell as a command. %f in the command will
683 be replaced by the full file name, %b by the file base name (i.e. without
684 extension) and %o by the base directory of the file.
686 If you set `org-create-formula-image-program'
687 `org-export-with-LaTeX-fragments' to 'imagemagick, you can add a
688 sublist which contains your own command(s) for LaTeX fragments
689 previewing, like this:
691 '(\"xelatex -interaction nonstopmode -output-directory %o %f\"
692 \"xelatex -interaction nonstopmode -output-directory %o %f\"
693 ;; use below command(s) to convert latex fragments
694 (\"xelatex %f\"))
696 With no such sublist, the default command used to convert LaTeX
697 fragments will be the first string in the list.
699 The reason why this is a list is that it usually takes several runs of
700 `pdflatex', maybe mixed with a call to `bibtex'. Org does not have a clever
701 mechanism to detect which of these commands have to be run to get to a stable
702 result, and it also does not do any error checking.
704 By default, Org uses 3 runs of `pdflatex' to do the processing. If you
705 have texi2dvi on your system and if that does not cause the infamous
706 egrep/locale bug:
708 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
710 then `texi2dvi' is the superior choice. Org does offer it as one
711 of the customize options.
713 Alternatively, this may be a Lisp function that does the processing, so you
714 could use this to apply the machinery of AUCTeX or the Emacs LaTeX mode.
715 This function should accept the file name as its single argument."
716 :group 'org-export-pdf
717 :type '(choice
718 (repeat :tag "Shell command sequence"
719 (string :tag "Shell command"))
720 (const :tag "2 runs of pdflatex"
721 ("pdflatex -interaction nonstopmode -output-directory %o %f"
722 "pdflatex -interaction nonstopmode -output-directory %o %f"))
723 (const :tag "3 runs of pdflatex"
724 ("pdflatex -interaction nonstopmode -output-directory %o %f"
725 "pdflatex -interaction nonstopmode -output-directory %o %f"
726 "pdflatex -interaction nonstopmode -output-directory %o %f"))
727 (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
728 ("pdflatex -interaction nonstopmode -output-directory %o %f"
729 "bibtex %b"
730 "pdflatex -interaction nonstopmode -output-directory %o %f"
731 "pdflatex -interaction nonstopmode -output-directory %o %f"))
732 (const :tag "2 runs of xelatex"
733 ("xelatex -interaction nonstopmode -output-directory %o %f"
734 "xelatex -interaction nonstopmode -output-directory %o %f"))
735 (const :tag "3 runs of xelatex"
736 ("xelatex -interaction nonstopmode -output-directory %o %f"
737 "xelatex -interaction nonstopmode -output-directory %o %f"
738 "xelatex -interaction nonstopmode -output-directory %o %f"))
739 (const :tag "xelatex,bibtex,xelatex,xelatex"
740 ("xelatex -interaction nonstopmode -output-directory %o %f"
741 "bibtex %b"
742 "xelatex -interaction nonstopmode -output-directory %o %f"
743 "xelatex -interaction nonstopmode -output-directory %o %f"))
744 (const :tag "texi2dvi"
745 ("texi2dvi -p -b -c -V %f"))
746 (const :tag "rubber"
747 ("rubber -d --into %o %f"))
748 (function)))
750 (defcustom org-export-pdf-logfiles
751 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
752 "The list of file extensions to consider as LaTeX logfiles."
753 :group 'org-export-pdf
754 :version "24.1"
755 :type '(repeat (string :tag "Extension")))
757 (defcustom org-export-pdf-remove-logfiles t
758 "Non-nil means remove the logfiles produced by PDF production.
759 These are the .aux, .log, .out, and .toc files."
760 :group 'org-export-pdf
761 :type 'boolean)
763 ;;; Hooks
765 (defvar org-export-latex-after-initial-vars-hook nil
766 "Hook run before LaTeX export.
767 The exact moment is after the initial variables like org-export-latex-class
768 have been determined from the environment.")
770 (defvar org-export-latex-after-blockquotes-hook nil
771 "Hook run during LaTeX export, after blockquote, verse, center are done.")
773 (defvar org-export-latex-final-hook nil
774 "Hook run in the finalized LaTeX buffer.")
776 (defvar org-export-latex-after-save-hook nil
777 "Hook run in the finalized LaTeX buffer, after it has been saved.")
779 ;;; Autoload functions:
781 ;;;###autoload
782 (defun org-export-as-latex-batch ()
783 "Call `org-export-as-latex', may be used in batch processing.
784 For example:
786 emacs --batch
787 --load=$HOME/lib/emacs/org.el
788 --eval \"(setq org-export-headline-levels 2)\"
789 --visit=MyFile --funcall org-export-as-latex-batch"
790 (org-export-as-latex org-export-headline-levels))
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
2295 raw-path)
2296 org-export-latex-inline-image-extensions)
2297 (or (get-text-property 0 'org-no-description
2298 raw-path)
2299 (equal desc full-raw-path)))
2300 (setq imgp t)
2301 (progn (when (string-match "\\(.+\\)::.+" raw-path)
2302 (setq raw-path (match-string 1 raw-path)))
2303 (if (file-exists-p raw-path)
2304 (concat type "://" (expand-file-name raw-path))
2305 (concat type "://" (org-export-directory
2306 :LaTeX org-export-latex-options-plist)
2307 raw-path))))))))
2308 ;; process with link inserting
2309 (apply 'delete-region remove)
2310 (setq caption (and caption (org-export-latex-fontify-headline caption)))
2311 (cond ((and imgp
2312 (plist-get org-export-latex-options-plist :inline-images))
2313 ;; OK, we need to inline an image
2314 (insert
2315 (org-export-latex-format-image raw-path caption label attr shortn)))
2316 (coderefp
2317 (insert (format
2318 (org-export-get-coderef-format path desc)
2319 (cdr (assoc path org-export-code-refs)))))
2320 (radiop (insert (format org-export-latex-hyperref-format
2321 (org-solidify-link-text raw-path) desc)))
2322 ((not type)
2323 (insert (format org-export-latex-hyperref-format
2324 (org-remove-initial-hash
2325 (org-solidify-link-text raw-path))
2326 desc)))
2327 (path
2328 (when (org-at-table-p)
2329 ;; There is a strange problem when we have a link in a table,
2330 ;; ampersands then cause a problem. I think this must be
2331 ;; a LaTeX issue, but we here implement a work-around anyway.
2332 (setq path (org-export-latex-protect-amp path)
2333 desc (org-export-latex-protect-amp desc)))
2334 (insert
2335 (if (string-match "%s.*%s" org-export-latex-href-format)
2336 (format org-export-latex-href-format path desc)
2337 (format org-export-latex-href-format path))))
2339 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
2340 ;; The link protocol has a function for formatting the link
2341 (insert
2342 (save-match-data
2343 (funcall fnc (org-link-unescape raw-path) desc 'latex))))
2344 ;; Unrecognized path type
2345 (t (insert (format org-export-latex-link-with-unknown-path-format desc))))))))
2348 (defun org-export-latex-format-image (path caption label attr &optional shortn)
2349 "Format the image element, depending on user settings."
2350 (let (ind floatp wrapp multicolumnp placement figenv)
2351 (setq floatp (or caption label))
2352 (setq ind (org-get-text-property-any 0 'original-indentation path))
2353 (when (and attr (stringp attr))
2354 (if (string-match "[ \t]*\\<wrap\\>" attr)
2355 (setq wrapp t floatp nil attr (replace-match "" t t attr)))
2356 (if (string-match "[ \t]*\\<float\\>" attr)
2357 (setq wrapp nil floatp t attr (replace-match "" t t attr)))
2358 (if (string-match "[ \t]*\\<multicolumn\\>" attr)
2359 (setq multicolumnp t attr (replace-match "" t t attr))))
2361 (setq placement
2362 (cond
2363 (wrapp "{l}{0.5\\textwidth}")
2364 (floatp (concat "[" org-latex-default-figure-position "]"))
2365 (t "")))
2367 (when (and attr (stringp attr)
2368 (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
2369 (setq placement (match-string 1 attr)
2370 attr (replace-match "" t t attr)))
2371 (setq attr (and attr (org-trim attr)))
2372 (when (or (not attr) (= (length attr) 0))
2373 (setq attr (cond (floatp "width=0.7\\textwidth")
2374 (wrapp "width=0.48\\textwidth")
2375 (t attr))))
2376 (setq figenv
2377 (cond
2378 (wrapp "\\begin{wrapfigure}%placement
2379 \\centering
2380 \\includegraphics[%attr]{%path}
2381 \\caption%shortn{%labelcmd%caption}
2382 \\end{wrapfigure}")
2383 (multicolumnp "\\begin{figure*}%placement
2384 \\centering
2385 \\includegraphics[%attr]{%path}
2386 \\caption%shortn{%labelcmd%caption}
2387 \\end{figure*}")
2388 (floatp "\\begin{figure}%placement
2389 \\centering
2390 \\includegraphics[%attr]{%path}
2391 \\caption%shortn{%labelcmd%caption}
2392 \\end{figure}")
2393 (t "\\includegraphics[%attr]{%path}")))
2396 (setq figenv (mapconcat 'identity (split-string figenv "\n")
2397 (save-excursion (beginning-of-line 1)
2398 (looking-at "[ \t]*")
2399 (concat "\n" (match-string 0)))))
2401 (if (and (not label) (not caption)
2402 (string-match "^\\\\caption{.*\n" figenv))
2403 (setq figenv (replace-match "" t t figenv)))
2404 (org-add-props
2405 (org-fill-template
2406 figenv
2407 (list (cons "path"
2408 (if (file-name-absolute-p path)
2409 (expand-file-name path)
2410 path))
2411 (cons "attr" attr)
2412 (cons "shortn" (if shortn (format "[%s]" shortn) ""))
2413 (cons "labelcmd" (if label (format "\\label{%s}"
2414 label)""))
2415 (cons "caption" (or caption ""))
2416 (cons "placement" (or placement ""))))
2417 nil 'original-indentation ind)))
2419 (defun org-export-latex-protect-amp (s)
2420 (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
2421 (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
2422 t t s)))
2425 (defun org-remove-initial-hash (s)
2426 (if (string-match "\\`#" s)
2427 (substring s 1)
2429 (defvar org-latex-entities) ; defined below
2430 (defvar org-latex-entities-regexp) ; defined below
2432 (defun org-export-latex-preprocess (parameters)
2433 "Clean stuff in the LaTeX export."
2434 ;; Replace footnotes.
2435 (when (plist-get parameters :footnotes)
2436 (goto-char (point-min))
2437 (let (ref)
2438 (while (setq ref (org-footnote-get-next-reference))
2439 (let* ((beg (nth 1 ref))
2440 (lbl (car ref))
2441 (def (nth 1 (assoc (string-to-number lbl)
2442 (mapcar (lambda (e) (cdr e))
2443 org-export-footnotes-seen)))))
2444 ;; Fix body for footnotes ending on a link or a list and
2445 ;; remove definition from buffer.
2446 (setq def
2447 (concat def
2448 (if (string-match "ORG-LIST-END-MARKER\\'" def)
2449 "\n" " ")))
2450 (org-footnote-delete-definitions lbl)
2451 ;; Compute string to insert (FNOTE), and protect the outside
2452 ;; macro from further transformation. When footnote at
2453 ;; point is referring to a previously defined footnote, use
2454 ;; \footnotemark. Otherwise, use \footnote.
2455 (let ((fnote (if (member lbl org-export-latex-footmark-seen)
2456 (org-export-latex-protect-string
2457 (format "\\footnotemark[%s]" lbl))
2458 (push lbl org-export-latex-footmark-seen)
2459 (concat (org-export-latex-protect-string "\\footnote{")
2461 (org-export-latex-protect-string "}"))))
2462 ;; Check if another footnote is immediately following.
2463 ;; If so, add a separator in-between.
2464 (sep (org-export-latex-protect-string
2465 (if (save-excursion (goto-char (1- (nth 2 ref)))
2466 (let ((next (org-footnote-get-next-reference)))
2467 (and next (= (nth 1 next) (nth 2 ref)))))
2468 org-export-latex-footnote-separator ""))))
2469 (when (org-at-heading-p)
2470 (setq fnote (concat (org-export-latex-protect-string "\\protect")
2471 fnote)))
2472 ;; Ensure a footnote at column 0 cannot end a list
2473 ;; containing it.
2474 (put-text-property 0 (length fnote) 'original-indentation 1000 fnote)
2475 ;; Replace footnote reference with FNOTE and, maybe, SEP.
2476 ;; `save-excursion' is required if there are two footnotes
2477 ;; in a row. In that case, point would be left at the
2478 ;; beginning of the second one, and
2479 ;; `org-footnote-get-next-reference' would then skip it.
2480 (goto-char beg)
2481 (delete-region beg (nth 2 ref))
2482 (save-excursion (insert fnote sep)))))))
2484 ;; Remove footnote section tag for LaTeX
2485 (goto-char (point-min))
2486 (while (re-search-forward
2487 (concat "^" footnote-section-tag-regexp) nil t)
2488 (org-if-unprotected
2489 (replace-match "")))
2490 ;; Remove any left-over footnote definition.
2491 (mapc (lambda (fn) (org-footnote-delete-definitions (car fn)))
2492 org-export-footnotes-data)
2493 (mapc (lambda (fn) (org-footnote-delete-definitions fn))
2494 org-export-latex-footmark-seen)
2496 ;; Preserve line breaks
2497 (goto-char (point-min))
2498 (while (re-search-forward "\\\\\\\\" nil t)
2499 (add-text-properties (match-beginning 0) (match-end 0)
2500 '(org-protected t)))
2502 ;; Preserve latex environments
2503 (goto-char (point-min))
2504 (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
2505 (org-if-unprotected
2506 (let* ((start (progn (beginning-of-line) (point)))
2507 (end (and (re-search-forward
2508 (concat "^[ \t]*\\\\end{"
2509 (regexp-quote (match-string 1))
2510 "}") nil t)
2511 (point-at-eol))))
2512 (if end
2513 (add-text-properties start end '(org-protected t))
2514 (goto-char (point-at-eol))))))
2516 ;; Preserve math snippets
2517 (let* ((matchers (plist-get org-format-latex-options :matchers))
2518 (re-list org-latex-regexps)
2519 beg end re e m n block off)
2520 ;; Check the different regular expressions
2521 (while (setq e (pop re-list))
2522 (setq m (car e) re (nth 1 e) n (nth 2 e)
2523 block (if (nth 3 e) "\n\n" ""))
2524 (setq off (if (member m '("$" "$1")) 1 0))
2525 (when (and (member m matchers) (not (equal m "begin")))
2526 (goto-char (point-min))
2527 (while (re-search-forward re nil t)
2528 (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
2529 (add-text-properties beg end '(org-protected t org-latex-math t))))))
2531 ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
2532 (goto-char (point-min))
2533 (let ((case-fold-search nil))
2534 (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
2535 (unless (eq (char-before (match-beginning 1)) ?\\)
2536 (org-if-unprotected-1
2537 (replace-match (org-export-latex-protect-string
2538 (concat "\\" (match-string 1)
2539 "{}")) t t)))))
2541 ;; Convert blockquotes
2542 (goto-char (point-min))
2543 (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
2544 (org-replace-match-keep-properties "\\begin{quote}" t t))
2545 (goto-char (point-min))
2546 (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
2547 (org-replace-match-keep-properties "\\end{quote}" t t))
2549 ;; Convert verse
2550 (goto-char (point-min))
2551 (while (search-forward "ORG-VERSE-START" nil t)
2552 (org-replace-match-keep-properties "\\begin{verse}" t t)
2553 (beginning-of-line 2)
2554 (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
2555 (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
2556 (goto-char (match-end 1))
2557 (org-replace-match-keep-properties
2558 (org-export-latex-protect-string
2559 (concat "\\hspace*{1cm}" (match-string 2))) t t)
2560 (beginning-of-line 1))
2561 (if (looking-at "[ \t]*$")
2562 (insert (org-export-latex-protect-string "\\vspace*{1em}"))
2563 (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
2564 (end-of-line 1)
2565 (insert "\\\\")))
2566 (beginning-of-line 2))
2567 (and (looking-at "[ \t]*ORG-VERSE-END.*")
2568 (org-replace-match-keep-properties "\\end{verse}" t t)))
2570 ;; Convert #+INDEX to LaTeX \\index.
2571 (goto-char (point-min))
2572 (let ((case-fold-search t) entry)
2573 (while (re-search-forward
2574 "^[ \t]*#\\+index:[ \t]*\\([^ \t\r\n].*?\\)[ \t]*$"
2575 nil t)
2576 (setq entry
2577 (save-match-data
2578 (org-export-latex-protect-string
2579 (org-export-latex-fontify-headline (match-string 1)))))
2580 (replace-match (format "\\index{%s}" entry) t t)))
2582 ;; Convert center
2583 (goto-char (point-min))
2584 (while (search-forward "ORG-CENTER-START" nil t)
2585 (org-replace-match-keep-properties "\\begin{center}" t t))
2586 (goto-char (point-min))
2587 (while (search-forward "ORG-CENTER-END" nil t)
2588 (org-replace-match-keep-properties "\\end{center}" t t))
2590 (run-hooks 'org-export-latex-after-blockquotes-hook)
2592 ;; Convert horizontal rules
2593 (goto-char (point-min))
2594 (while (re-search-forward "^[ \t]*-\\{5,\\}[ \t]*$" nil t)
2595 (org-if-unprotected
2596 (replace-match (org-export-latex-protect-string "\\hrule") t t)))
2598 ;; Protect LaTeX commands like \command[...]{...} or \command{...}
2599 (goto-char (point-min))
2600 (let ((re (concat
2601 "\\\\\\([a-zA-Z]+\\*?\\)"
2602 "\\(?:<[^<>\n]*>\\)*"
2603 "\\(?:\\[[^][\n]*?\\]\\)*"
2604 "\\(?:<[^<>\n]*>\\)*"
2605 "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}")))
2606 (while (re-search-forward re nil t)
2607 (unless (or
2608 ;; Check for comment line.
2609 (save-excursion (goto-char (match-beginning 0))
2610 (org-in-indented-comment-line))
2611 ;; Check if this is a defined entity, so that is may
2612 ;; need conversion.
2613 (org-entity-get (match-string 1))
2614 ;; Do not protect interior of footnotes. Those have
2615 ;; already been taken care of earlier in the function.
2616 ;; Yet, keep looking inside them for more commands.
2617 (and (equal (match-string 1) "footnote")
2618 (goto-char (match-end 1))))
2619 (add-text-properties (match-beginning 0) (match-end 0)
2620 '(org-protected t)))))
2622 ;; Special case for \nbsp
2623 (goto-char (point-min))
2624 (while (re-search-forward "\\\\nbsp\\({}\\|\\>\\)" nil t)
2625 (org-if-unprotected
2626 (replace-match (org-export-latex-protect-string "~"))))
2628 ;; Protect LaTeX entities
2629 (goto-char (point-min))
2630 (while (re-search-forward org-latex-entities-regexp nil t)
2631 (org-if-unprotected
2632 (add-text-properties (match-beginning 0) (match-end 0)
2633 '(org-protected t))))
2635 ;; Replace radio links
2636 (goto-char (point-min))
2637 (while (re-search-forward
2638 (concat "<<<?" org-export-latex-all-targets-re
2639 ">>>?\\((INVISIBLE)\\)?") nil t)
2640 (org-if-unprotected-at (+ (match-beginning 0) 2)
2641 (replace-match
2642 (concat
2643 (org-export-latex-protect-string
2644 (format "\\label{%s}" (save-match-data (org-solidify-link-text
2645 (match-string 1)))))
2646 (if (match-string 2) "" (match-string 1)))
2647 t t)))
2649 ;; Delete @<...> constructs
2650 ;; Thanks to Daniel Clemente for this regexp
2651 (goto-char (point-min))
2652 (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
2653 (org-if-unprotected
2654 (replace-match ""))))
2656 (defun org-export-latex-fix-inputenc ()
2657 "Set the coding system in inputenc to what the buffer is."
2658 (let* ((cs buffer-file-coding-system)
2659 (opt (or (ignore-errors (latexenc-coding-system-to-inputenc cs))
2660 "utf8")))
2661 (when opt
2662 ;; Translate if that is requested
2663 (setq opt (or (cdr (assoc opt org-export-latex-inputenc-alist)) opt))
2664 ;; find the \usepackage statement and replace the option
2665 (goto-char (point-min))
2666 (while (re-search-forward "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
2667 nil t)
2668 (goto-char (match-beginning 1))
2669 (delete-region (match-beginning 1) (match-end 1))
2670 (insert opt))
2671 (and buffer-file-name
2672 (save-buffer)))))
2674 ;;; List handling:
2676 (defun org-export-latex-lists ()
2677 "Convert plain text lists in current buffer into LaTeX lists."
2678 ;; `org-list-end-re' output has changed since preprocess from
2679 ;; org-exp.el. Make sure it is taken into account.
2680 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
2681 (mapc
2682 (lambda (e)
2683 ;; For each type of context allowed for list export (E), find
2684 ;; every list, parse it, delete it and insert resulting
2685 ;; conversion to latex (RES), while keeping the same
2686 ;; `original-indentation' property.
2687 (let (res)
2688 (goto-char (point-min))
2689 (while (re-search-forward (org-item-beginning-re) nil t)
2690 (when (and (eq (get-text-property (point) 'list-context) e)
2691 (not (get-text-property (point) 'org-example)))
2692 (beginning-of-line)
2693 (setq res
2694 (org-list-to-latex
2695 ;; Narrowing is needed because we're converting
2696 ;; from inner functions to outer ones.
2697 (save-restriction
2698 (narrow-to-region (point) (point-max))
2699 (org-list-parse-list t))
2700 org-export-latex-list-parameters))
2701 ;; Extend previous value of original-indentation to the
2702 ;; whole string
2703 (insert (org-add-props res nil 'original-indentation
2704 (org-find-text-property-in-string
2705 'original-indentation res)))))))
2706 ;; List of allowed contexts for export, and the default one.
2707 (append org-list-export-context '(nil)))))
2709 (defconst org-latex-entities
2710 '("\\!"
2711 "\\'"
2712 "\\+"
2713 "\\,"
2714 "\\-"
2715 "\\:"
2716 "\\;"
2717 "\\<"
2718 "\\="
2719 "\\>"
2720 "\\Huge"
2721 "\\LARGE"
2722 "\\Large"
2723 "\\Styles"
2724 "\\\\"
2725 "\\`"
2726 "\\\""
2727 "\\addcontentsline"
2728 "\\address"
2729 "\\addtocontents"
2730 "\\addtocounter"
2731 "\\addtolength"
2732 "\\addvspace"
2733 "\\alph"
2734 "\\appendix"
2735 "\\arabic"
2736 "\\author"
2737 "\\begin{array}"
2738 "\\begin{center}"
2739 "\\begin{description}"
2740 "\\begin{enumerate}"
2741 "\\begin{eqnarray}"
2742 "\\begin{equation}"
2743 "\\begin{figure}"
2744 "\\begin{flushleft}"
2745 "\\begin{flushright}"
2746 "\\begin{itemize}"
2747 "\\begin{list}"
2748 "\\begin{minipage}"
2749 "\\begin{picture}"
2750 "\\begin{quotation}"
2751 "\\begin{quote}"
2752 "\\begin{tabbing}"
2753 "\\begin{table}"
2754 "\\begin{tabular}"
2755 "\\begin{thebibliography}"
2756 "\\begin{theorem}"
2757 "\\begin{titlepage}"
2758 "\\begin{verbatim}"
2759 "\\begin{verse}"
2760 "\\bf"
2761 "\\bf"
2762 "\\bibitem"
2763 "\\bigskip"
2764 "\\cdots"
2765 "\\centering"
2766 "\\circle"
2767 "\\cite"
2768 "\\cleardoublepage"
2769 "\\clearpage"
2770 "\\cline"
2771 "\\closing"
2772 "\\dashbox"
2773 "\\date"
2774 "\\ddots"
2775 "\\dotfill"
2776 "\\em"
2777 "\\fbox"
2778 "\\flushbottom"
2779 "\\fnsymbol"
2780 "\\footnote"
2781 "\\footnotemark"
2782 "\\footnotesize"
2783 "\\footnotetext"
2784 "\\frac"
2785 "\\frame"
2786 "\\framebox"
2787 "\\hfill"
2788 "\\hline"
2789 "\\hrulespace"
2790 "\\hspace"
2791 "\\huge"
2792 "\\hyphenation"
2793 "\\include"
2794 "\\includeonly"
2795 "\\indent"
2796 "\\input"
2797 "\\it"
2798 "\\kill"
2799 "\\label"
2800 "\\large"
2801 "\\ldots"
2802 "\\line"
2803 "\\linebreak"
2804 "\\linethickness"
2805 "\\listoffigures"
2806 "\\listoftables"
2807 "\\location"
2808 "\\makebox"
2809 "\\maketitle"
2810 "\\mark"
2811 "\\mbox"
2812 "\\medskip"
2813 "\\multicolumn"
2814 "\\multiput"
2815 "\\newcommand"
2816 "\\newcounter"
2817 "\\newenvironment"
2818 "\\newfont"
2819 "\\newlength"
2820 "\\newline"
2821 "\\newpage"
2822 "\\newsavebox"
2823 "\\newtheorem"
2824 "\\nocite"
2825 "\\nofiles"
2826 "\\noindent"
2827 "\\nolinebreak"
2828 "\\nopagebreak"
2829 "\\normalsize"
2830 "\\onecolumn"
2831 "\\opening"
2832 "\\oval"
2833 "\\overbrace"
2834 "\\overline"
2835 "\\pagebreak"
2836 "\\pagenumbering"
2837 "\\pageref"
2838 "\\pagestyle"
2839 "\\par"
2840 "\\parbox"
2841 "\\put"
2842 "\\raggedbottom"
2843 "\\raggedleft"
2844 "\\raggedright"
2845 "\\raisebox"
2846 "\\ref"
2847 "\\rm"
2848 "\\roman"
2849 "\\rule"
2850 "\\savebox"
2851 "\\sc"
2852 "\\scriptsize"
2853 "\\setcounter"
2854 "\\setlength"
2855 "\\settowidth"
2856 "\\sf"
2857 "\\shortstack"
2858 "\\signature"
2859 "\\sl"
2860 "\\small"
2861 "\\smallskip"
2862 "\\sqrt"
2863 "\\tableofcontents"
2864 "\\telephone"
2865 "\\thanks"
2866 "\\thispagestyle"
2867 "\\tiny"
2868 "\\title"
2869 "\\tt"
2870 "\\twocolumn"
2871 "\\typein"
2872 "\\typeout"
2873 "\\underbrace"
2874 "\\underline"
2875 "\\usebox"
2876 "\\usecounter"
2877 "\\value"
2878 "\\vdots"
2879 "\\vector"
2880 "\\verb"
2881 "\\vfill"
2882 "\\vline"
2883 "\\vspace")
2884 "A list of LaTeX commands to be protected when performing conversion.")
2886 (defconst org-latex-entities-regexp
2887 (let (names rest)
2888 (dolist (x org-latex-entities)
2889 (if (string-match "[a-zA-Z]$" x)
2890 (push x names)
2891 (push x rest)))
2892 (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
2893 "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
2895 (provide 'org-export-latex)
2896 (provide 'org-latex)
2898 ;; Local variables:
2899 ;; generated-autoload-file: "org-loaddefs.el"
2900 ;; End:
2902 ;;; org-latex.el ends here