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