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