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