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