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