aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Dominik2008-01-18 15:17:35 +0000
committerCarsten Dominik2008-01-18 15:17:35 +0000
commitdb9c3fb18e09517bea7c6f1872d661f579c3cd86 (patch)
tree2ae5e93f8d43da9c835a70e8d24efa22af350f64
parent76ed5e0157c14cf9fcd075db08296bd692a43fc7 (diff)
downloademacs-db9c3fb18e09517bea7c6f1872d661f579c3cd86.tar.gz
emacs-db9c3fb18e09517bea7c6f1872d661f579c3cd86.zip
(org-export-latex-cleaned-string): Fixed.
(org-export-latex-special-chars): Convert "..." in \ldots and skip tables (org-export-latex-fontify-headline): Changed parameter name (org-export-as-latex): Handle export of subtrees (org-export-latex-make-header): New argument TITLE (org-export-latex-content): New argument EXCLUDE-LIST (org-list-parse-list): New name for org-export-latex-parse-list (org-export-latex-make-header): New name for org-export-latex-make-preamble (org-list-to-generic): New name of org-export-list-to-generic (org-list-to-latex): New name of org-export-list-to-latex (org-list-item-begin, org-list-end, org-list-insert-radio-list) (org-list-send-list, org-list-to-texinfo) (org-list-to-html): New functions (org-export-latex-tables-column-borders) (org-export-latex-default-class, org-export-latex-classes) (org-export-latex-classes-sectioning) (org-list-radio-list-templates): New options (org-export-latex-header): New variable (org-latex-entities): New constant (org-export-latex-default-sectioning, org-export-latex-preamble) (org-export-latex-prepare-text-option) (org-export-latex-get-sectioning): Removed
-rw-r--r--doc/misc/ChangeLog21
-rw-r--r--lisp/textmodes/org-export-latex.el1065
2 files changed, 738 insertions, 348 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index d8c801a2054..b9c71b7e7b3 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,24 @@
12008-01-18 Carsten Dominik <dominik@science.uva.nl>
2
3 * org.texi: (Property inheritance): New section
4 (Conventions): New section.
5 (Structure editing): Document C-RET, the prefix arg to the cut/cpy
6 commands, and the new bindings for refiling.
7 (Sparse trees): Document the new special command for sparse trees.
8 (References): Be more clear about the counting of hilines.
9 (Handling links): Document M-p/n for accessing links.
10 (Fast access to TODO states): New section.
11 (Per file keywords): New section.
12 (Property inheritance): New section.
13 (Column attributes): New summary types.
14 (Capturing Column View): New section.
15 (The date/time prompt): Cover the new features in the date/time prompt.
16 Compactify the table of keys for the calendar remote control.
17 (Clocking work time): Document the new :scope parameter.
18 (Remember): Promoted to chapter.
19 (Quoted examples): New section.
20 (Enhancing text): New verbatim environments.
21
12008-01-14 Michael Albinus <michael.albinus@gmx.de> 222008-01-14 Michael Albinus <michael.albinus@gmx.de>
2 23
3 * trampver.texi: Update release number. 24 * trampver.texi: Update release number.
diff --git a/lisp/textmodes/org-export-latex.el b/lisp/textmodes/org-export-latex.el
index d320a166f2b..7624af8aa0e 100644
--- a/lisp/textmodes/org-export-latex.el
+++ b/lisp/textmodes/org-export-latex.el
@@ -1,10 +1,10 @@
1 ;;; org-export-latex.el --- LaTeX exporter for org-mode 1;;; org-export-latex.el --- LaTeX exporter for org-mode
2;; 2;;
3;; Copyright (C) 2007, 2008 Free Software Foundation, Inc. 3;; Copyright (c) 2007, 2008 Free Software Foundation, Inc.
4;; 4;;
5;; Emacs Lisp Archive Entry 5;; Emacs Lisp Archive Entry
6;; Filename: org-export-latex.el 6;; Filename: org-export-latex.el
7;; Version: 5.12 7;; Version: 5.19
8;; Author: Bastien Guerry <bzg AT altern DOT org> 8;; Author: Bastien Guerry <bzg AT altern DOT org>
9;; Maintainer: Bastien Guerry <bzg AT altern DOT org> 9;; Maintainer: Bastien Guerry <bzg AT altern DOT org>
10;; Keywords: org, wp, tex 10;; Keywords: org, wp, tex
@@ -18,31 +18,31 @@
18;; Free Software Foundation; either version 3, or (at your option) any 18;; Free Software Foundation; either version 3, or (at your option) any
19;; later version. 19;; later version.
20;; 20;;
21;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT 21;; GNU Emacs is distributed in the hope that it will be useful, but
22;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22;; WITHOUT ANY WARRANTY; without even the implied warranty of
23;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 23;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24;; more details. 24;; General Public License for more details.
25;; 25;;
26;; You should have received a copy of the GNU General Public License along 26;; You should have received a copy of the GNU General Public License
27;; with GNU Emacs; see the file COPYING. If not, write to the Free Software 27;; along with GNU Emacs; see the file COPYING. If not, write to the Free
28;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 28;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29;; 02110-1301, USA. 29;; MA 02110-1301, USA.
30;; 30;;
31;;; Commentary: 31;;; Commentary:
32;; 32;;
33;; This library implements a LaTeX exporter for org-mode. 33;; This library implements a LaTeX exporter for org-mode.
34;; 34;;
35;; Put this file into your load-path and the following into your ~/.emacs: 35;; Put this file into your load-path and the following into your ~/.emacs:
36;; (require 'org-export-latex) 36;; (require 'org-export-latex)
37;; 37;;
38;; The interactive functions are similar to those of the HTML exporter: 38;; The interactive functions are similar to those of the HTML exporter:
39;; 39;;
40;; M-x `org-export-as-latex' 40;; M-x `org-export-as-latex'
41;; M-x `org-export-as-latex-batch' 41;; M-x `org-export-as-latex-batch'
42;; M-x `org-export-as-latex-to-buffer' 42;; M-x `org-export-as-latex-to-buffer'
43;; M-x `org-export-region-as-latex' 43;; M-x `org-export-region-as-latex'
44;; M-x `org-replace-region-by-latex' 44;; M-x `org-replace-region-by-latex'
45;; 45;;
46;;; Code: 46;;; Code:
47 47
48(eval-when-compile 48(eval-when-compile
@@ -52,15 +52,19 @@
52(require 'org) 52(require 'org)
53 53
54;;; Variables: 54;;; Variables:
55(defvar org-latex-options-plist nil) 55(defvar org-export-latex-class nil)
56(defvar org-latex-todo-keywords-1 nil) 56(defvar org-export-latex-header nil)
57(defvar org-latex-all-targets-regexp nil) 57(defvar org-export-latex-append-header nil)
58(defvar org-latex-add-level 0) 58(defvar org-export-latex-options-plist nil)
59(defvar org-latex-sectioning-depth 0) 59(defvar org-export-latex-todo-keywords-1 nil)
60(defvar org-export-latex-all-targets-re nil)
61(defvar org-export-latex-add-level 0)
62(defvar org-export-latex-sectioning "")
63(defvar org-export-latex-sectioning-depth 0)
60(defvar org-export-latex-list-beginning-re 64(defvar org-export-latex-list-beginning-re
61 "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) +?") 65 "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) +?")
62 66
63(defvar org-latex-special-string-regexps 67(defvar org-export-latex-special-string-regexps
64 '(org-ts-regexp 68 '(org-ts-regexp
65 org-scheduled-string 69 org-scheduled-string
66 org-deadline-string 70 org-deadline-string
@@ -71,28 +75,82 @@
71(defvar re-quote) ; dynamically scoped from org.el 75(defvar re-quote) ; dynamically scoped from org.el
72(defvar commentsp) ; dynamically scoped from org.el 76(defvar commentsp) ; dynamically scoped from org.el
73 77
74;;; Custom variables: 78;;; User variables:
75(defcustom org-export-latex-sectioning-alist
76 '((1 "\\section{%s}" "\\section*{%s}")
77 (2 "\\subsection{%s}" "\\subsection*{%s}")
78 (3 "\\subsubsection{%s}" "\\subsubsection*{%s}")
79 (4 "\\paragraph{%s}" "\\paragraph*{%s}")
80 (5 "\\subparagraph{%s}" "\\subparagraph*{%s}"))
81 "Alist of LaTeX commands for inserting sections.
82Here is the structure of each cell:
83 79
84 \(level unnumbered-section numbered-section\) 80(defcustom org-export-latex-default-class "article"
81 "The default LaTeX class."
82 :group 'org-export-latex
83 :type '(string :tag "LaTeX class"))
85 84
86The %s formatter will be replaced by the title of the section." 85(defcustom org-export-latex-classes
86 '(("article"
87 "\\documentclass[11pt,a4paper]{article}
88\\usepackage[utf8]{inputenc}
89\\usepackage[T1]{fontenc}
90\\usepackage{hyperref}"
91 ("\\section{%s}" . "\\section*{%s}")
92 ("\\subsection{%s}" . "\\subsection*{%s}")
93 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
94 ("\\paragraph{%s}" . "\\paragraph*{%s}")
95 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
96 ("report"
97 "\\documentclass[11pt,a4paper]{report}
98\\usepackage[utf8]{inputenc}
99\\usepackage[T1]{fontenc}
100\\usepackage{hyperref}"
101 ("\\part{%s}" . "\\part*{%s}")
102 ("\\chapter{%s}" . "\\chapter*{%s}")
103 ("\\section{%s}" . "\\section*{%s}")
104 ("\\subsection{%s}" . "\\subsection*{%s}")
105 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
106 ("book"
107 "\\documentclass[11pt,a4paper]{book}
108\\usepackage[utf8]{inputenc}
109\\usepackage[T1]{fontenc}
110\\usepackage{hyperref}"
111 ("\\part{%s}" . "\\part*{%s}")
112 ("\\chapter{%s}" . "\\chapter*{%s}")
113 ("\\section{%s}" . "\\section*{%s}")
114 ("\\subsection{%s}" . "\\subsection*{%s}")
115 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
116 "Alist of LaTeX classes and associated header and structure.
117If #+LaTeX_CLASS is set in the buffer, use its value and the
118associated information. Here is the structure of each cell:
119
120 \(class-name
121 header-string
122 (unnumbered-section numbered-section\)
123 ...\)
124
125A %s formatter is mandatory in each section string and will be
126replaced by the title of the section."
87 :group 'org-export-latex 127 :group 'org-export-latex
88 :type 'alist) 128 :type '(repeat
129 (list (string :tag "LaTeX class")
130 (string :tag "LaTeX header")
131 (cons :tag "Level 1"
132 (string :tag "Numbered")
133 (string :tag "Unnumbered"))
134 (cons :tag "Level 2"
135 (string :tag "Numbered")
136 (string :tag "Unnumbered"))
137 (cons :tag "Level 3"
138 (string :tag "Numbered")
139 (string :tag "Unnumbered"))
140 (cons :tag "Level 4"
141 (string :tag "Numbered")
142 (string :tag "Unnumbered"))
143 (cons :tag "Level 5"
144 (string :tag "Numbered")
145 (string :tag "Unnumbered")))))
89 146
90(defcustom org-export-latex-emphasis-alist 147(defcustom org-export-latex-emphasis-alist
91 '(("*" "\\textbf{%s}" nil) 148 '(("*" "\\textbf{%s}" nil)
92 ("/" "\\emph{%s}" nil) 149 ("/" "\\emph{%s}" nil)
93 ("_" "\\underline{%s}" nil) 150 ("_" "\\underline{%s}" nil)
94 ("+" "\\texttt{%s}" nil) 151 ("+" "\\texttt{%s}" nil)
95 ("=" "\\texttt{%s}" nil)) 152 ("=" "\\texttt{%s}" nil)
153 ("~" "\\texttt{%s}" t))
96 "Alist of LaTeX expressions to convert emphasis fontifiers. 154 "Alist of LaTeX expressions to convert emphasis fontifiers.
97Each element of the list is a list of three elements. 155Each element of the list is a list of three elements.
98The first element is the character used as a marker for fontification. 156The first element is the character used as a marker for fontification.
@@ -102,15 +160,6 @@ conversions."
102 :group 'org-export-latex 160 :group 'org-export-latex
103 :type 'alist) 161 :type 'alist)
104 162
105(defcustom org-export-latex-preamble
106 "\\documentclass[11pt,a4paper]{article}
107\\usepackage[utf8]{inputenc}
108\\usepackage[T1]{fontenc}
109\\usepackage{hyperref}"
110 "Preamble to be inserted at the very beginning of the LaTeX export."
111 :group 'org-export-latex
112 :type 'string)
113
114(defcustom org-export-latex-title-command "\\maketitle" 163(defcustom org-export-latex-title-command "\\maketitle"
115 "The command used to insert the title just after \\begin{document}. 164 "The command used to insert the title just after \\begin{document}.
116If this string contains the formatting specification \"%s\" then 165If this string contains the formatting specification \"%s\" then
@@ -119,7 +168,7 @@ argument."
119 :group 'org-export-latex 168 :group 'org-export-latex
120 :type 'string) 169 :type 'string)
121 170
122(defcustom org-export-latex-date-format 171(defcustom org-export-latex-date-format
123 "%d %B %Y" 172 "%d %B %Y"
124 "Format string for \\date{...}." 173 "Format string for \\date{...}."
125 :group 'org-export-latex 174 :group 'org-export-latex
@@ -130,14 +179,15 @@ argument."
130 :group 'org-export-latex 179 :group 'org-export-latex
131 :type 'boolean) 180 :type 'boolean)
132 181
133(defcustom org-export-latex-packages-alist nil 182(defcustom org-export-latex-tables-column-borders nil
134 "Alist of packages to be inserted in the preamble. 183 "When non-nil, group of columns are surrounded with borders,
135Each cell is of the forma \( option . package \). 184XSeven if these borders are the outside borders of the table."
136 185 :group 'org-export-latex
137For example: 186 :type 'boolean)
138 187
139\(setq org-export-latex-packages-alist 188(defcustom org-export-latex-packages-alist nil
140 '((\"french\" \"babel\"))" 189 "Alist of packages to be inserted in the header.
190Each cell is of the forma \( \"option\" . \"package\" \)."
141 :group 'org-export-latex 191 :group 'org-export-latex
142 :type 'alist) 192 :type 'alist)
143 193
@@ -167,17 +217,42 @@ Don't remove the keys, just change their values."
167(defcustom org-export-latex-image-default-option "width=10em" 217(defcustom org-export-latex-image-default-option "width=10em"
168 "Default option for images." 218 "Default option for images."
169 :group 'org-export-latex 219 :group 'org-export-latex
170 :type '(string)) 220 :type 'string)
171 221
172(defcustom org-export-latex-coding-system nil 222(defcustom org-export-latex-coding-system nil
173 "Coding system for the exported LaTex file." 223 "Coding system for the exported LaTex file."
174 :group 'org-export-latex 224 :group 'org-export-latex
175 :type 'coding-system) 225 :type 'coding-system)
176 226
177;; FIXME Do we want this one? 227(defcustom org-list-radio-list-templates
178;; (defun org-export-as-latex-and-open (arg) ...) 228 '((latex-mode "% BEGIN RECEIVE ORGLST %n
229% END RECEIVE ORGLST %n
230\\begin{comment}
231#+ORGLST: SEND %n org-list-to-latex
232| | |
233\\end{comment}\n")
234 (texinfo-mode "@c BEGIN RECEIVE ORGLST %n
235@c END RECEIVE ORGLST %n
236@ignore
237#+ORGLST: SEND %n org-list-to-texinfo
238| | |
239@end ignore\n")
240 (html-mode "<!-- BEGIN RECEIVE ORGLST %n -->
241<!-- END RECEIVE ORGLST %n -->
242<!--
243#+ORGLST: SEND %n org-list-to-html
244| | |
245-->\n"))
246 "Templates for radio lists in different major modes.
247All occurrences of %n in a template will be replaced with the name of the
248list, obtained by prompting the user."
249 :group 'org-plain-lists
250 :type '(repeat
251 (list (symbol :tag "Major mode")
252 (string :tag "Format"))))
179 253
180;;; Autoload functions: 254;;; Autoload functions:
255
181;;;###autoload 256;;;###autoload
182(defun org-export-as-latex-batch () 257(defun org-export-as-latex-batch ()
183 "Call `org-export-as-latex', may be used in batch processing as 258 "Call `org-export-as-latex', may be used in batch processing as
@@ -199,7 +274,7 @@ No file is created. The prefix ARG is passed through to `org-export-as-latex'."
199(defun org-replace-region-by-latex (beg end) 274(defun org-replace-region-by-latex (beg end)
200 "Replace the region from BEG to END with its LaTeX export. 275 "Replace the region from BEG to END with its LaTeX export.
201It assumes the region has `org-mode' syntax, and then convert it to 276It assumes the region has `org-mode' syntax, and then convert it to
202LaTeX. This can be used in any buffer. For example, you could 277LaTeX. This can be used in any buffer. For example, you could
203write an itemized list in `org-mode' syntax in an LaTeX buffer and 278write an itemized list in `org-mode' syntax in an LaTeX buffer and
204then use this command to convert it." 279then use this command to convert it."
205 (interactive "r") 280 (interactive "r")
@@ -255,7 +330,21 @@ in a window. A non-interactive call will only retunr the buffer."
255;;;###autoload 330;;;###autoload
256(defun org-export-as-latex (arg &optional hidden ext-plist 331(defun org-export-as-latex (arg &optional hidden ext-plist
257 to-buffer body-only) 332 to-buffer body-only)
258 "Export current buffer to a LaTeX file." 333 "Export current buffer to a LaTeX file.
334If there is an active region, export only the region. The prefix
335ARG specifies how many levels of the outline should become
336headlines. The default is 3. Lower levels will be exported
337depending on `org-export-latex-low-levels'. The default is to
338convert them as description lists. When HIDDEN is non-nil, don't
339display the LaTeX buffer. EXT-PLIST is a property list with
340external parameters overriding org-mode's default settings, but
341still inferior to file-local settings. When TO-BUFFER is
342non-nil, create a buffer with that name and export to that
343buffer. If TO-BUFFER is the symbol `string', don't leave any
344buffer behind but just return the resulting LaTeX as a string.
345When BODY-ONLY is set, don't produce the file header and footer,
346simply return the content of \begin{document}...\end{document},
347without even the \begin{document} and \end{document} commands."
259 (interactive "P") 348 (interactive "P")
260 ;; Make sure we have a file name when we need it. 349 ;; Make sure we have a file name when we need it.
261 (when (and (not (or to-buffer body-only)) 350 (when (and (not (or to-buffer body-only))
@@ -268,9 +357,23 @@ in a window. A non-interactive call will only retunr the buffer."
268 357
269 (message "Exporting to LaTeX...") 358 (message "Exporting to LaTeX...")
270 (org-update-radio-target-regexp) 359 (org-update-radio-target-regexp)
271 (org-export-latex-set-initial-vars ext-plist) 360 (org-export-latex-set-initial-vars ext-plist arg)
272 (let* ((wcf (current-window-configuration)) 361 (let* ((wcf (current-window-configuration))
273 (opt-plist org-latex-options-plist) 362 (opt-plist org-export-latex-options-plist)
363 (region-p (org-region-active-p))
364 (subtree-p
365 (when region-p
366 (save-excursion
367 (goto-char (region-beginning))
368 (and (org-at-heading-p)
369 (>= (org-end-of-subtree t t) (region-end))))))
370 (title (or (and subtree-p (org-export-get-title-from-subtree))
371 (plist-get opt-plist :title)
372 (and (not
373 (plist-get opt-plist :skip-before-1st-heading))
374 (org-export-grab-title-from-buffer))
375 (file-name-sans-extension
376 (file-name-nondirectory buffer-file-name))))
274 (filename (concat (file-name-as-directory 377 (filename (concat (file-name-as-directory
275 (org-export-directory :LaTeX ext-plist)) 378 (org-export-directory :LaTeX ext-plist))
276 (file-name-sans-extension 379 (file-name-sans-extension
@@ -286,10 +389,11 @@ in a window. A non-interactive call will only retunr the buffer."
286 "*Org LaTeX Export*")) 389 "*Org LaTeX Export*"))
287 (t (get-buffer-create to-buffer))) 390 (t (get-buffer-create to-buffer)))
288 (find-file-noselect filename))) 391 (find-file-noselect filename)))
289 (region-p (org-region-active-p))
290 (odd org-odd-levels-only) 392 (odd org-odd-levels-only)
291 (preamble (org-export-latex-make-preamble opt-plist)) 393 (header (org-export-latex-make-header title opt-plist))
292 (skip (plist-get opt-plist :skip-before-1st-heading)) 394 (skip (if subtree-p nil
395 ;; never skip first lines when exporting a subtree
396 (plist-get opt-plist :skip-before-1st-heading)))
293 (text (plist-get opt-plist :text)) 397 (text (plist-get opt-plist :text))
294 (first-lines (if skip "" (org-export-latex-first-lines))) 398 (first-lines (if skip "" (org-export-latex-first-lines)))
295 (coding-system (and (boundp 'buffer-file-coding-system) 399 (coding-system (and (boundp 'buffer-file-coding-system)
@@ -310,19 +414,21 @@ in a window. A non-interactive call will only retunr the buffer."
310 :skip-before-1st-heading skip 414 :skip-before-1st-heading skip
311 :LaTeX-fragments nil))) 415 :LaTeX-fragments nil)))
312 416
313 (set-buffer buffer) 417 (set-buffer buffer)
314 (erase-buffer) 418 (erase-buffer)
315 419
316 (and (fboundp 'set-buffer-file-coding-system) 420 (and (fboundp 'set-buffer-file-coding-system)
317 (set-buffer-file-coding-system coding-system-for-write)) 421 (set-buffer-file-coding-system coding-system-for-write))
318 422
319 ;; insert the preamble and initial document commands 423 ;; insert the header and initial document commands
320 (unless (or (eq to-buffer 'string) body-only) 424 (unless (or (eq to-buffer 'string) body-only)
321 (insert preamble)) 425 (insert header))
322 426
323 ;; insert text found in #+TEXT 427 ;; insert text found in #+TEXT
324 (when (and text (not (eq to-buffer 'string))) 428 (when (and text (not (eq to-buffer 'string)))
325 (insert (org-export-latex-content text) "\n\n")) 429 (insert (org-export-latex-content
430 text '(lists tables fixed-width keywords))
431 "\n\n"))
326 432
327 ;; insert lines before the first headline 433 ;; insert lines before the first headline
328 (unless (or skip (eq to-buffer 'string)) 434 (unless (or skip (eq to-buffer 'string))
@@ -342,7 +448,7 @@ in a window. A non-interactive call will only retunr the buffer."
342 (when (re-search-forward "^\\(\\*+\\) " nil t) 448 (when (re-search-forward "^\\(\\*+\\) " nil t)
343 (let* ((asters (length (match-string 1))) 449 (let* ((asters (length (match-string 1)))
344 (level (if odd (- asters 2) (- asters 1)))) 450 (level (if odd (- asters 2) (- asters 1))))
345 (setq org-latex-add-level 451 (setq org-export-latex-add-level
346 (if odd (1- (/ (1+ asters) 2)) (1- asters))) 452 (if odd (1- (/ (1+ asters) 2)) (1- asters)))
347 (org-export-latex-parse-global level odd))))) 453 (org-export-latex-parse-global level odd)))))
348 454
@@ -358,16 +464,16 @@ in a window. A non-interactive call will only retunr the buffer."
358 (current-buffer)) 464 (current-buffer))
359 (set-window-configuration wcf)))) 465 (set-window-configuration wcf))))
360 466
361
362;;; Parsing functions: 467;;; Parsing functions:
468
363(defun org-export-latex-parse-global (level odd) 469(defun org-export-latex-parse-global (level odd)
364 "Parse the current buffer recursively, starting at LEVEL. 470 "Parse the current buffer recursively, starting at LEVEL.
365If ODD is non-nil, assume the buffer only contains odd sections. 471If ODD is non-nil, assume the buffer only contains odd sections.
366Return A list reflecting the document structure." 472Return a list reflecting the document structure."
367 (save-excursion 473 (save-excursion
368 (goto-char (point-min)) 474 (goto-char (point-min))
369 (let* ((cnt 0) output 475 (let* ((cnt 0) output
370 (depth org-latex-sectioning-depth)) 476 (depth org-export-latex-sectioning-depth))
371 (while (re-search-forward 477 (while (re-search-forward
372 (concat "^\\(\\(?:\\*\\)\\{" 478 (concat "^\\(\\(?:\\*\\)\\{"
373 (number-to-string (+ (if odd 2 1) level)) 479 (number-to-string (+ (if odd 2 1) level))
@@ -404,57 +510,11 @@ Return A list reflecting the document structure."
404 `(occur . ,cnt) 510 `(occur . ,cnt)
405 `(heading . ,heading) 511 `(heading . ,heading)
406 `(content . ,(org-export-latex-parse-content)) 512 `(content . ,(org-export-latex-parse-content))
407 `(subcontent . ,(org-export-latex-parse-subcontent 513 `(subcontent . ,(org-export-latex-parse-subcontent
408 level odd))))))) 514 level odd)))))))
409 (widen))) 515 (widen)))
410 (list output)))) 516 (list output))))
411 517
412(defun org-export-latex-parse-list (&optional delete)
413 "Parse the list at point.
414Return a list containing first level items as strings and
415sublevels as list of strings."
416 (let ((start (point))
417 ;; Find the end of the list
418 (end (save-excursion
419 (catch 'exit
420 (while (or (looking-at org-export-latex-list-beginning-re)
421 (looking-at "^[ \t]+\\|^$"))
422 (if (eq (point) (point-max))
423 (throw 'exit (point-max)))
424 (forward-line 1))) (point)))
425 output itemsep)
426 (while (re-search-forward org-export-latex-list-beginning-re end t)
427 (setq itemsep (if (save-match-data
428 (string-match "^[0-9]" (match-string 2)))
429 "[0-9]+\\(?:\\.\\|)\\)" "[-+]"))
430 (let* ((indent1 (match-string 1))
431 (nextitem (save-excursion
432 (save-match-data
433 (or (and (re-search-forward
434 (concat "^" indent1 itemsep " *?") end t)
435 (match-beginning 0)) end))))
436 (item (buffer-substring
437 (point)
438 (or (and (re-search-forward
439 org-export-latex-list-beginning-re end t)
440 (goto-char (match-beginning 0)))
441 (goto-char end))))
442 (nextindent (match-string 1))
443 (item (org-trim item))
444 (item (if (string-match "^\\[.+\\]" item)
445 (replace-match "\\\\texttt{\\&}"
446 t nil item) item)))
447 (push item output)
448 (when (> (length nextindent)
449 (length indent1))
450 (narrow-to-region (point) nextitem)
451 (push (org-export-latex-parse-list) output)
452 (widen))))
453 (when delete (delete-region start end))
454 (setq output (nreverse output))
455 (push (if (string-match "^\\[0" itemsep)
456 'ordered 'unordered) output)))
457
458(defun org-export-latex-parse-content () 518(defun org-export-latex-parse-content ()
459 "Extract the content of a section." 519 "Extract the content of a section."
460 (let ((beg (point)) 520 (let ((beg (point))
@@ -487,7 +547,7 @@ CONTENT is an element of the list produced by
487 "Export the list SUBCONTENT to LaTeX. 547 "Export the list SUBCONTENT to LaTeX.
488SUBCONTENT is an alist containing information about the headline 548SUBCONTENT is an alist containing information about the headline
489and its content." 549and its content."
490 (let ((num (plist-get org-latex-options-plist :section-numbers))) 550 (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
491 (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent))) 551 (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
492 552
493(defun org-export-latex-subcontent (subcontent num) 553(defun org-export-latex-subcontent (subcontent num)
@@ -495,20 +555,20 @@ and its content."
495 (let ((heading (org-export-latex-fontify-headline 555 (let ((heading (org-export-latex-fontify-headline
496 (cdr (assoc 'heading subcontent)))) 556 (cdr (assoc 'heading subcontent))))
497 (level (- (cdr (assoc 'level subcontent)) 557 (level (- (cdr (assoc 'level subcontent))
498 org-latex-add-level)) 558 org-export-latex-add-level))
499 (occur (number-to-string (cdr (assoc 'occur subcontent)))) 559 (occur (number-to-string (cdr (assoc 'occur subcontent))))
500 (content (cdr (assoc 'content subcontent))) 560 (content (cdr (assoc 'content subcontent)))
501 (subcontent (cadr (assoc 'subcontent subcontent)))) 561 (subcontent (cadr (assoc 'subcontent subcontent))))
502 (cond 562 (cond
503 ;; Normal conversion 563 ;; Normal conversion
504 ((<= level org-latex-sectioning-depth) 564 ((<= level org-export-latex-sectioning-depth)
505 (let ((sec (assoc level org-export-latex-sectioning-alist))) 565 (let ((sec (nth (1- level) org-export-latex-sectioning)))
506 (insert (format (if num (cadr sec) (caddr sec)) heading) "\n")) 566 (insert (format (if num (car sec) (cdr sec)) heading) "\n"))
507 (insert (org-export-latex-content content)) 567 (insert (org-export-latex-content content))
508 (cond ((stringp subcontent) (insert subcontent)) 568 (cond ((stringp subcontent) (insert subcontent))
509 ((listp subcontent) (org-export-latex-sub subcontent)))) 569 ((listp subcontent) (org-export-latex-sub subcontent))))
510 ;; At a level under the hl option: we can drop this subsection 570 ;; At a level under the hl option: we can drop this subsection
511 ((> level org-latex-sectioning-depth) 571 ((> level org-export-latex-sectioning-depth)
512 (cond ((eq org-export-latex-low-levels 'description) 572 (cond ((eq org-export-latex-low-levels 'description)
513 (insert (format "\\begin{description}\n\n\\item[%s]\n\n" heading)) 573 (insert (format "\\begin{description}\n\n\\item[%s]\n\n" heading))
514 (insert (org-export-latex-content content)) 574 (insert (org-export-latex-content content))
@@ -521,52 +581,47 @@ and its content."
521 (cond ((stringp subcontent) (insert subcontent)) 581 (cond ((stringp subcontent) (insert subcontent))
522 ((listp subcontent) (org-export-latex-sub subcontent))))))))) 582 ((listp subcontent) (org-export-latex-sub subcontent)))))))))
523 583
524
525;;; Exporting internals: 584;;; Exporting internals:
526(defun org-export-latex-protect-string (string) 585(defun org-export-latex-set-initial-vars (ext-plist level)
527 "Prevent further conversion for STRING by adding the
528org-protect property."
529 (add-text-properties
530 0 (length string) '(org-protected t) string) string)
531
532(defun org-export-latex-protect-char-in-string (char-list string)
533 "Add org-protected text-property to char from CHAR-LIST in STRING."
534 (with-temp-buffer
535 (save-match-data
536 (insert string)
537 (goto-char (point-min))
538 (while (re-search-forward (regexp-opt char-list) nil t)
539 (add-text-properties (match-beginning 0)
540 (match-end 0) '(org-protected t)))
541 (buffer-string))))
542
543(defun org-export-latex-set-initial-vars (ext-plist)
544 "Store org local variables required for LaTeX export. 586 "Store org local variables required for LaTeX export.
545EXT-PLIST is an optional additional plist." 587EXT-PLIST is an optional additional plist.
546 (setq org-latex-todo-keywords-1 org-todo-keywords-1 588LEVEL indicates the default depth for export."
547 org-latex-all-targets-regexp 589 (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
590 org-export-latex-all-targets-re
548 (org-make-target-link-regexp (org-all-targets)) 591 (org-make-target-link-regexp (org-all-targets))
549 org-latex-options-plist 592 org-export-latex-options-plist
550 (org-combine-plists (org-default-export-plist) ext-plist 593 (org-combine-plists (org-default-export-plist) ext-plist
551 (org-infile-export-plist)) 594 (org-infile-export-plist))
552 org-latex-sectioning-depth 595 org-export-latex-class
553 (let ((hl-levels (plist-get org-latex-options-plist :headline-levels)) 596 (save-excursion
554 (sec-depth (length org-export-latex-sectioning-alist))) 597 (goto-char (point-min))
555 ;; Fall back on org-export-latex-sectioning-alist length if 598 (if (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t)
556 ;; headline-levels goes beyond it 599 (assoc (match-string 1) org-export-latex-classes))
557 (if (> hl-levels sec-depth) sec-depth hl-levels)))) 600 (match-string 1)
558 601 org-export-latex-default-class))
559(defun org-export-latex-make-preamble (opt-plist) 602 org-export-latex-header
560 "Make the LaTeX preamble and return it as a string. 603 (cadr (assoc org-export-latex-class org-export-latex-classes))
561Argument OPT-PLIST is the options plist for current buffer." 604 org-export-latex-sectioning
562 (let ((toc (plist-get opt-plist :table-of-contents))) 605 (cddr (assoc org-export-latex-class org-export-latex-classes))
563 (concat 606 org-export-latex-sectioning-depth
607 (or level
608 (let ((hl-levels
609 (plist-get org-export-latex-options-plist :headline-levels))
610 (sec-depth (length org-export-latex-sectioning)))
611 (if (> hl-levels sec-depth) sec-depth hl-levels)))))
612
613(defun org-export-latex-make-header (title opt-plist)
614 "Make the LaTeX header and return it as a string.
615TITLE is the current title from the buffer or region.
616OPT-PLIST is the options plist for current buffer."
617 (let ((toc (plist-get opt-plist :table-of-contents))
618 (author (plist-get opt-plist :author)))
619 (concat
564 (if (plist-get opt-plist :time-stamp-file) 620 (if (plist-get opt-plist :time-stamp-file)
565 (format-time-string "% Created %Y-%m-%d %a %H:%M\n")) 621 (format-time-string "% Created %Y-%m-%d %a %H:%M\n"))
566 622 ;; insert LaTeX custom header
567 ;; insert LaTeX custom preamble 623 org-export-latex-header
568 org-export-latex-preamble "\n" 624 "\n"
569
570 ;; insert information on LaTeX packages 625 ;; insert information on LaTeX packages
571 (when org-export-latex-packages-alist 626 (when org-export-latex-packages-alist
572 (mapconcat (lambda(p) 627 (mapconcat (lambda(p)
@@ -575,46 +630,34 @@ Argument OPT-PLIST is the options plist for current buffer."
575 (format "\\usepackage[%s]{%s}" 630 (format "\\usepackage[%s]{%s}"
576 (car p) (cadr p)))) 631 (car p) (cadr p))))
577 org-export-latex-packages-alist "\n")) 632 org-export-latex-packages-alist "\n"))
578 633 ;; insert additional commands in the header
634 org-export-latex-append-header
579 ;; insert the title 635 ;; insert the title
580 (format 636 (format
581 "\\title{%s}\n" 637 "\n\n\\title{%s}\n"
582 ;; convert the title 638 ;; convert the title
583 (org-export-latex-content 639 (org-export-latex-content
584 (or (plist-get opt-plist :title) 640 title '(lists tables fixed-width keywords)))
585 (and (not
586 (plist-get opt-plist :skip-before-1st-heading))
587 (org-export-grab-title-from-buffer))
588 (and buffer-file-name
589 (file-name-sans-extension
590 (file-name-nondirectory buffer-file-name)))
591 "UNTITLED")))
592
593 ;; insert author info 641 ;; insert author info
594 (if (plist-get opt-plist :author-info) 642 (if (plist-get opt-plist :author-info)
595 (format "\\author{%s}\n" 643 (format "\\author{%s}\n"
596 (or (plist-get opt-plist :author) user-full-name)) 644 (or author user-full-name))
597 (format "%%\\author{%s}\n" 645 (format "%%\\author{%s}\n"
598 (or (plist-get opt-plist :author) user-full-name))) 646 (or author user-full-name)))
599
600 ;; insert the date 647 ;; insert the date
601 (format "\\date{%s}\n" 648 (format "\\date{%s}\n"
602 (format-time-string 649 (format-time-string
603 (or (plist-get opt-plist :date) 650 (or (plist-get opt-plist :date)
604 org-export-latex-date-format))) 651 org-export-latex-date-format)))
605
606 ;; beginning of the document 652 ;; beginning of the document
607 "\n\\begin{document}\n\n" 653 "\n\\begin{document}\n\n"
608
609 ;; insert the title command 654 ;; insert the title command
610 (if (string-match "%s" org-export-latex-title-command) 655 (if (string-match "%s" org-export-latex-title-command)
611 (format org-export-latex-title-command 656 (format org-export-latex-title-command title)
612 (plist-get opt-plist :title))
613 org-export-latex-title-command) 657 org-export-latex-title-command)
614 "\n\n" 658 "\n\n"
615
616 ;; table of contents 659 ;; table of contents
617 (when (and org-export-with-toc 660 (when (and org-export-with-toc
618 (plist-get opt-plist :section-numbers)) 661 (plist-get opt-plist :section-numbers))
619 (cond ((numberp toc) 662 (cond ((numberp toc)
620 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n" 663 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n"
@@ -628,8 +671,9 @@ COMMENTS is either nil to replace them with the empty string or a
628formatting string like %%%%s if we want to comment them out." 671formatting string like %%%%s if we want to comment them out."
629 (save-excursion 672 (save-excursion
630 (goto-char (point-min)) 673 (goto-char (point-min))
674 (if (org-at-heading-p) (beginning-of-line 2))
631 (let* ((pt (point)) 675 (let* ((pt (point))
632 (end (if (and (re-search-forward "^\\*" nil t) 676 (end (if (and (re-search-forward "^\\* " nil t)
633 (not (eq pt (match-beginning 0)))) 677 (not (eq pt (match-beginning 0))))
634 (goto-char (match-beginning 0)) 678 (goto-char (match-beginning 0))
635 (goto-char (point-max))))) 679 (goto-char (point-max)))))
@@ -643,10 +687,58 @@ formatting string like %%%%s if we want to comment them out."
643 :skip-before-1st-heading nil 687 :skip-before-1st-heading nil
644 :LaTeX-fragments nil))))) 688 :LaTeX-fragments nil)))))
645 689
690(defun org-export-latex-content (content &optional exclude-list)
691 "Convert CONTENT string to LaTeX.
692Don't perform conversions that are in EXCLUDE-LIST. Recognized
693conversion types are: quotation-marks, emphasis, sub-superscript,
694links, keywords, lists, tables, fixed-width"
695 (with-temp-buffer
696 (insert content)
697 (unless (memq 'quotation-marks exclude-list)
698 (org-export-latex-quotation-marks))
699 (unless (memq 'emphasis exclude-list)
700 (when (plist-get org-export-latex-options-plist :emphasize)
701 (org-export-latex-fontify)))
702 (unless (memq 'sub-superscript exclude-list)
703 (org-export-latex-special-chars
704 (plist-get org-export-latex-options-plist :sub-superscript)))
705 (unless (memq 'links exclude-list)
706 (org-export-latex-links))
707 (unless (memq 'keywords exclude-list)
708 (org-export-latex-keywords
709 (plist-get org-export-latex-options-plist :timestamps)))
710 (unless (memq 'lists exclude-list)
711 (org-export-latex-lists))
712 (unless (memq 'tables exclude-list)
713 (org-export-latex-tables
714 (plist-get org-export-latex-options-plist :tables)))
715 (unless (memq 'fixed-width exclude-list)
716 (org-export-latex-fixed-width
717 (plist-get org-export-latex-options-plist :fixed-width)))
718 ;; return string
719 (buffer-substring (point-min) (point-max))))
720
721(defun org-export-latex-protect-string (s)
722 "Prevent further conversion for string S by adding the
723org-protect property."
724 (add-text-properties 0 (length s) '(org-protected t) s) s)
725
726(defun org-export-latex-protect-char-in-string (char-list string)
727 "Add org-protected text-property to char from CHAR-LIST in STRING."
728 (with-temp-buffer
729 (save-match-data
730 (insert string)
731 (goto-char (point-min))
732 (while (re-search-forward (regexp-opt char-list) nil t)
733 (add-text-properties (match-beginning 0)
734 (match-end 0) '(org-protected t)))
735 (buffer-string))))
736
646(defun org-export-latex-keywords-maybe (remove-list) 737(defun org-export-latex-keywords-maybe (remove-list)
647 "Maybe remove keywords depending on rules in REMOVE-LIST." 738 "Maybe remove keywords depending on rules in REMOVE-LIST."
648 (goto-char (point-min)) 739 (goto-char (point-min))
649 (let ((re-todo (mapconcat 'identity org-latex-todo-keywords-1 "\\|"))) 740 (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
741 (case-fold-search nil))
650 ;; convert TODO keywords 742 ;; convert TODO keywords
651 (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t) 743 (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
652 (if (plist-get remove-list :todo) 744 (if (plist-get remove-list :todo)
@@ -664,48 +756,25 @@ formatting string like %%%%s if we want to comment them out."
664 (replace-match "") 756 (replace-match "")
665 (replace-match (format "\\texttt{%s}" (match-string 0)) t t))))) 757 (replace-match (format "\\texttt{%s}" (match-string 0)) t t)))))
666 758
667(defun org-export-latex-fontify-headline (headline) 759(defun org-export-latex-fontify-headline (string)
668 "Fontify special words in a HEADLINE." 760 "Fontify special words in string."
669 (with-temp-buffer 761 (with-temp-buffer
670 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at 762 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
671 ;; the beginning of the buffer - inserting "\n" is safe here though. 763 ;; the beginning of the buffer - inserting "\n" is safe here though.
672 (insert "\n" headline) 764 (insert "\n" string)
673 (goto-char (point-min)) 765 (goto-char (point-min))
674 (when (plist-get org-latex-options-plist :emphasize) 766 (when (plist-get org-export-latex-options-plist :emphasize)
675 (org-export-latex-fontify)) 767 (org-export-latex-fontify))
676 (org-export-latex-special-chars 768 (org-export-latex-special-chars
677 (plist-get org-latex-options-plist :sub-superscript)) 769 (plist-get org-export-latex-options-plist :sub-superscript))
678 (org-export-latex-keywords-maybe 770 (org-export-latex-keywords-maybe
679 org-export-latex-remove-from-headlines) 771 org-export-latex-remove-from-headlines)
680 (org-export-latex-links) 772 (org-export-latex-links)
681 (org-trim (buffer-substring-no-properties (point-min) (point-max))))) 773 (org-trim (buffer-substring-no-properties (point-min) (point-max)))))
682 774
683(defun org-export-latex-content (content)
684 "Convert CONTENT string to LaTeX."
685 (with-temp-buffer
686 (insert content)
687 (org-export-latex-quotation-marks)
688 (when (plist-get org-latex-options-plist :emphasize)
689 (org-export-latex-fontify))
690 (org-export-latex-special-chars
691 (plist-get org-latex-options-plist :sub-superscript))
692 (org-export-latex-links)
693 (org-export-latex-keywords
694 (plist-get org-latex-options-plist :timestamps))
695 (org-export-latex-lists)
696 (org-export-latex-tables
697 (plist-get org-latex-options-plist :tables))
698 (org-export-latex-fixed-width
699 (plist-get org-latex-options-plist :fixed-width))
700 ;; return string
701 (buffer-substring (point-min) (point-max))))
702
703(defun org-export-latex-quotation-marks () 775(defun org-export-latex-quotation-marks ()
704 "Export question marks depending on language conventions. 776 "Export question marks depending on language conventions."
705Local definition of the language overrides 777 (let* ((lang (plist-get org-export-latex-options-plist :language))
706`org-export-latex-quotation-marks-convention' which overrides
707`org-export-default-language'."
708 (let* ((lang (plist-get org-latex-options-plist :language))
709 (quote-rpl (if (equal lang "fr") 778 (quote-rpl (if (equal lang "fr")
710 '(("\\(\\s-\\)\"" "«~") 779 '(("\\(\\s-\\)\"" "«~")
711 ("\\(\\S-\\)\"" "~»") 780 ("\\(\\S-\\)\"" "~»")
@@ -720,21 +789,6 @@ Local definition of the language overrides
720 (org-if-unprotected 789 (org-if-unprotected
721 (replace-match rpl t t))))) quote-rpl))) 790 (replace-match rpl t t))))) quote-rpl)))
722 791
723;; | chars/string in Org | normal environment | math environment |
724;; |-----------------------+-----------------------+-----------------------|
725;; | & # % $ | \& \# \% \$ | \& \# \% \$ |
726;; | { } _ ^ \ | \{ \} \_ \^ \\ | { } _ ^ \ |
727;; |-----------------------+-----------------------+-----------------------|
728;; | a_b and a^b | $a_b$ and $a^b$ | a_b and a^b |
729;; | a_abc and a_{abc} | $a_a$bc and $a_{abc}$ | a_abc and a_{abc} |
730;; | \tau and \mu | $\tau$ and $\mu$ | \tau and \mu |
731;; |-----------------------+-----------------------+-----------------------|
732;; | \_ \^ | \_ \^ | \_ \^ |
733;; | \(a=\mu\mbox{m}\) | \(a=\mu\mbox{m}\) | \(a=\mu\mbox{m}\) |
734;; | \[\beta^2-a=0\] | \[\beta^2-a=0\] | \[\beta^2-a=0\] |
735;; | $x=22\tau$ | $x=22\tau$ | $x=22\tau$ |
736;; | $$\alpha=\sqrt{a^3}$$ | $$\alpha=\sqrt{a^3}$$ | $$\alpha=\sqrt{a^3}$$ |
737
738(defun org-export-latex-special-chars (sub-superscript) 792(defun org-export-latex-special-chars (sub-superscript)
739 "Export special characters to LaTeX. 793 "Export special characters to LaTeX.
740If SUB-SUPERSCRIPT is non-nil, convert \\ and ^. 794If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
@@ -744,7 +798,8 @@ See the `org-export-latex.el' code for a complete conversion table."
744 (goto-char (point-min)) 798 (goto-char (point-min))
745 (while (re-search-forward c nil t) 799 (while (re-search-forward c nil t)
746 ;; Put the point where to check for org-protected 800 ;; Put the point where to check for org-protected
747 (unless (get-text-property (match-beginning 2) 'org-protected) 801 (unless (or (get-text-property (match-beginning 2) 'org-protected)
802 (org-at-table-p))
748 (cond ((member (match-string 2) '("\\$" "$")) 803 (cond ((member (match-string 2) '("\\$" "$"))
749 (if (equal (match-string 2) "\\$") 804 (if (equal (match-string 2) "\\$")
750 (replace-match (concat (match-string 1) "$" 805 (replace-match (concat (match-string 1) "$"
@@ -756,11 +811,15 @@ See the `org-export-latex.el' code for a complete conversion table."
756 (replace-match (match-string 2) t t) 811 (replace-match (match-string 2) t t)
757 (replace-match (concat (match-string 1) "\\" 812 (replace-match (concat (match-string 1) "\\"
758 (match-string 2)) t t))) 813 (match-string 2)) t t)))
814 ((equal (match-string 2) "...")
815 (replace-match
816 (concat (match-string 1)
817 (org-export-latex-protect-string "\\ldots{}")) t t))
759 ((equal (match-string 2) "~") 818 ((equal (match-string 2) "~")
760 (cond ((equal (match-string 1) "\\") nil) 819 (cond ((equal (match-string 1) "\\") nil)
761 ((eq 'org-link (get-text-property 0 'face (match-string 2))) 820 ((eq 'org-link (get-text-property 0 'face (match-string 2)))
762 (replace-match (concat (match-string 1) "\\~") t t)) 821 (replace-match (concat (match-string 1) "\\~") t t))
763 (t (replace-match 822 (t (replace-match
764 (org-export-latex-protect-string 823 (org-export-latex-protect-string
765 (concat (match-string 1) "\\~{}")) t t)))) 824 (concat (match-string 1) "\\~{}")) t t))))
766 ((member (match-string 2) '("{" "}")) 825 ((member (match-string 2) '("{" "}"))
@@ -791,6 +850,7 @@ See the `org-export-latex.el' code for a complete conversion table."
791 "\\(.\\|^\\)\\({\\)" 850 "\\(.\\|^\\)\\({\\)"
792 "\\(.\\|^\\)\\(}\\)" 851 "\\(.\\|^\\)\\(}\\)"
793 "\\(.\\|^\\)\\(~\\)" 852 "\\(.\\|^\\)\\(~\\)"
853 "\\(.\\|^\\)\\(\\.\\.\\.\\)"
794 ;; (?\< . "\\textless{}") 854 ;; (?\< . "\\textless{}")
795 ;; (?\> . "\\textgreater{}") 855 ;; (?\> . "\\textgreater{}")
796 ))) 856 )))
@@ -812,7 +872,7 @@ Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
812 (cond ((eq 1 (length string-after)) 872 (cond ((eq 1 (length string-after))
813 (concat string-before char string-after)) 873 (concat string-before char string-after))
814 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after) 874 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
815 (format "%s%s{%s}" string-before char 875 (format "%s%s{%s}" string-before char
816 (match-string 1 string-after)))))) 876 (match-string 1 string-after))))))
817 ((and subsup 877 ((and subsup
818 (> (length string-after) 1) 878 (> (length string-after) 1)
@@ -842,7 +902,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
842 (string-match "^[ \t\n]" string-after))) 902 (string-match "^[ \t\n]" string-after)))
843 ;; backslash might escape a character (like \#) or a user TeX 903 ;; backslash might escape a character (like \#) or a user TeX
844 ;; macro (like \setcounter) 904 ;; macro (like \setcounter)
845 (org-export-latex-protect-string 905 (org-export-latex-protect-string
846 (concat string-before "\\" string-after))) 906 (concat string-before "\\" string-after)))
847 ((and (string-match "^[ \t\n]" string-after) 907 ((and (string-match "^[ \t\n]" string-after)
848 (string-match "[ \t\n]\\'" string-before)) 908 (string-match "[ \t\n]\\'" string-before))
@@ -854,19 +914,18 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
854 914
855(defun org-export-latex-keywords (timestamps) 915(defun org-export-latex-keywords (timestamps)
856 "Convert special keywords to LaTeX. 916 "Convert special keywords to LaTeX.
857Regexps are those from `org-latex-special-string-regexps'." 917Regexps are those from `org-export-latex-special-string-regexps'."
858 (let ((rg org-latex-special-string-regexps) r) 918 (let ((rg org-export-latex-special-string-regexps) r)
859 (while (setq r (pop rg)) 919 (while (setq r (pop rg))
860 (goto-char (point-min)) 920 (goto-char (point-min))
861 (while (re-search-forward (eval r) nil t) 921 (while (re-search-forward (eval r) nil t)
862 (if (not timestamps) 922 (if (not timestamps)
863 (replace-match (format "\\\\texttt{%s}" (match-string 0)) t) 923 (replace-match (format "\\\\texttt{%s}" (match-string 0)) t)
864 (replace-match "")))))) 924 (replace-match ""))))))
865 925
866(defun org-export-latex-fixed-width (opt) 926(defun org-export-latex-fixed-width (opt)
867 "When OPT is non-nil convert fixed-width sections to LaTeX." 927 "When OPT is non-nil convert fixed-width sections to LaTeX."
868 (goto-char (point-min)) 928 (goto-char (point-min))
869 ;; FIXME the search shouldn't be performed on already converted text
870 (while (re-search-forward "^[ \t]*:" nil t) 929 (while (re-search-forward "^[ \t]*:" nil t)
871 (if opt 930 (if opt
872 (progn (goto-char (match-beginning 0)) 931 (progn (goto-char (match-beginning 0))
@@ -882,73 +941,6 @@ Regexps are those from `org-latex-special-string-regexps'."
882 (match-string 2)) t t) 941 (match-string 2)) t t)
883 (forward-line)))))) 942 (forward-line))))))
884 943
885(defun org-export-latex-lists ()
886 "Convert lists to LaTeX."
887 (goto-char (point-min))
888 (while (re-search-forward org-export-latex-list-beginning-re nil t)
889 (beginning-of-line)
890 (org-export-list-to-latex
891 (org-export-latex-parse-list t))))
892
893(defun org-export-list-to-generic (list params)
894 "Convert a LIST parsed through `org-export-latex-parse-list' to other formats.
895
896Valid parameters are
897
898:ustart String to start an unordered list
899:uend String to end an unordered list
900
901:ostart String to start an ordered list
902:oend String to end an ordered list
903
904:splice When set to t, return only list body lines, don't wrap
905 them into :[u/o]start and :[u/o]end. Default is nil.
906
907:istart String to start a list item
908:iend String to end a list item
909:isep String to separate items
910:lsep String to separate sublists"
911 (interactive)
912 (let* ((p params) sublist
913 (splicep (plist-get p :splice))
914 (ostart (plist-get p :ostart))
915 (oend (plist-get p :oend))
916 (ustart (plist-get p :ustart))
917 (uend (plist-get p :uend))
918 (istart (plist-get p :istart))
919 (iend (plist-get p :iend))
920 (isep (plist-get p :isep))
921 (lsep (plist-get p :lsep)))
922 (let ((wrapper
923 (cond ((eq (car list) 'ordered)
924 (concat ostart "\n%s" oend "\n"))
925 ((eq (car list) 'unordered)
926 (concat ustart "\n%s" uend "\n"))))
927 rtn)
928 (while (setq sublist (pop list))
929 (cond ((symbolp sublist) nil)
930 ((stringp sublist)
931 (setq rtn (concat rtn istart sublist iend isep)))
932 (t
933 (setq rtn (concat rtn ;; previous list
934 lsep ;; list separator
935 (org-export-list-to-generic sublist p)
936 lsep ;; list separator
937 )))))
938 (format wrapper rtn))))
939
940(defun org-export-list-to-latex (list)
941 "Convert LIST into a LaTeX list."
942 (insert
943 (org-export-list-to-generic
944 list '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
945 :ustart "\\begin{itemize}" :uend "\\end{itemize}"
946 :istart "\\item " :iend ""
947 :isep "\n" :lsep "\n"))
948 ;; Add a trailing \n after list conversion
949 "\n"))
950
951;; FIXME Use org-export-highlight-first-table-line ?
952(defun org-export-latex-tables (insert) 944(defun org-export-latex-tables (insert)
953 "Convert tables to LaTeX and INSERT it." 945 "Convert tables to LaTeX and INSERT it."
954 (goto-char (point-min)) 946 (goto-char (point-min))
@@ -975,7 +967,7 @@ Valid parameters are
975 (unless (string-match "^[ \t]*|-" line) 967 (unless (string-match "^[ \t]*|-" line)
976 (setq fields (org-split-string line "[ \t]*|[ \t]*")) 968 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
977 (setq fnum (make-vector (length fields) 0)) 969 (setq fnum (make-vector (length fields) 0))
978 (setq line-fmt 970 (setq line-fmt
979 (mapconcat 971 (mapconcat
980 (lambda (x) 972 (lambda (x)
981 (setq gr (pop org-table-colgroup-info)) 973 (setq gr (pop org-table-colgroup-info))
@@ -991,18 +983,21 @@ Valid parameters are
991 (progn (setq colgropen nil) "|") 983 (progn (setq colgropen nil) "|")
992 ""))) 984 "")))
993 fnum "")))) 985 fnum ""))))
986 ;; fix double || in line-fmt
987 (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
994 ;; maybe remove the first and last "|" 988 ;; maybe remove the first and last "|"
995 (when (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt) 989 (when (and (not org-export-latex-tables-column-borders)
990 (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
996 (setq line-fmt (match-string 2 line-fmt))) 991 (setq line-fmt (match-string 2 line-fmt)))
997 ;; format alignment 992 ;; format alignment
998 (setq align (apply 'format 993 (setq align (apply 'format
999 (cons line-fmt 994 (cons line-fmt
1000 (mapcar (lambda (x) (if x "r" "l")) 995 (mapcar (lambda (x) (if x "r" "l"))
1001 org-table-last-alignment)))) 996 org-table-last-alignment))))
1002 ;; prepare the table to send to orgtbl-to-latex 997 ;; prepare the table to send to orgtbl-to-latex
1003 (setq lines 998 (setq lines
1004 (mapcar 999 (mapcar
1005 (lambda(elem) 1000 (lambda(elem)
1006 (or (and (string-match "[ \t]*|-+" elem) 'hline) 1001 (or (and (string-match "[ \t]*|-+" elem) 'hline)
1007 (split-string (org-trim elem) "|" t))) 1002 (split-string (org-trim elem) "|" t)))
1008 lines)) 1003 lines))
@@ -1016,8 +1011,8 @@ Valid parameters are
1016 (goto-char (point-min)) 1011 (goto-char (point-min))
1017 (while (re-search-forward org-emph-re nil t) 1012 (while (re-search-forward org-emph-re nil t)
1018 ;; The match goes one char after the *string* 1013 ;; The match goes one char after the *string*
1019 (let ((emph (assoc (match-string 3) 1014 (let ((emph (assoc (match-string 3)
1020 org-export-latex-emphasis-alist)) 1015 org-export-latex-emphasis-alist))
1021 rpl) 1016 rpl)
1022 (unless (get-text-property (1- (point)) 'org-protected) 1017 (unless (get-text-property (1- (point)) 'org-protected)
1023 (setq rpl (concat (match-string 1) 1018 (setq rpl (concat (match-string 1)
@@ -1025,7 +1020,7 @@ Valid parameters are
1025 '("\\" "{" "}") (cadr emph)) 1020 '("\\" "{" "}") (cadr emph))
1026 (match-string 4)) 1021 (match-string 4))
1027 (match-string 5))) 1022 (match-string 5)))
1028 (if (caddr emph) 1023 (if (caddr emph)
1029 (setq rpl (org-export-latex-protect-string rpl))) 1024 (setq rpl (org-export-latex-protect-string rpl)))
1030 (replace-match rpl t t))) 1025 (replace-match rpl t t)))
1031 (backward-char))) 1026 (backward-char)))
@@ -1038,7 +1033,7 @@ Valid parameters are
1038 (while (re-search-forward org-bracket-link-analytic-regexp nil t) 1033 (while (re-search-forward org-bracket-link-analytic-regexp nil t)
1039 (org-if-unprotected 1034 (org-if-unprotected
1040 (goto-char (match-beginning 0)) 1035 (goto-char (match-beginning 0))
1041 (let* ((re-radio org-latex-all-targets-regexp) 1036 (let* ((re-radio org-export-latex-all-targets-re)
1042 (remove (list (match-beginning 0) (match-end 0))) 1037 (remove (list (match-beginning 0) (match-end 0)))
1043 (type (match-string 2)) 1038 (type (match-string 2))
1044 (raw-path (match-string 3)) 1039 (raw-path (match-string 3))
@@ -1063,22 +1058,22 @@ Valid parameters are
1063 (if (file-exists-p raw-path) 1058 (if (file-exists-p raw-path)
1064 (concat type "://" (expand-file-name raw-path)) 1059 (concat type "://" (expand-file-name raw-path))
1065 (concat type "://" (org-export-directory 1060 (concat type "://" (org-export-directory
1066 :LaTeX org-latex-options-plist) 1061 :LaTeX org-export-latex-options-plist)
1067 raw-path)))))))) 1062 raw-path))))))))
1068 ;; process with link inserting 1063 ;; process with link inserting
1069 (apply 'delete-region remove) 1064 (apply 'delete-region remove)
1070 (cond ((and imgp (plist-get org-latex-options-plist :inline-images)) 1065 (cond ((and imgp (plist-get org-export-latex-options-plist :inline-images))
1071 (insert (format "\\includegraphics[%s]{%s}" 1066 (insert (format "\\includegraphics[%s]{%s}"
1072 ;; image option should be set be a comment line 1067 ;; image option should be set be a comment line
1073 org-export-latex-image-default-option 1068 org-export-latex-image-default-option
1074 (expand-file-name raw-path)))) 1069 (expand-file-name raw-path))))
1075 ;; FIXME: what about caption? image properties?
1076 (radiop (insert (format "\\hyperref[%s]{%s}" raw-path desc))) 1070 (radiop (insert (format "\\hyperref[%s]{%s}" raw-path desc)))
1077 (path (insert (format "\\href{%s}{%s}" path desc))) 1071 (path (insert (format "\\href{%s}{%s}" path desc)))
1078 (t (insert "\\texttt{" desc "}"))))))) 1072 (t (insert "\\texttt{" desc "}")))))))
1079 1073
1080(defun org-export-latex-cleaned-string (&optional commentsp) 1074(defvar org-latex-entities) ; defined below
1081 ;; FIXME remove commentsp call in org.el and here 1075
1076(defun org-export-latex-cleaned-string ()
1082 "Clean stuff in the LaTeX export." 1077 "Clean stuff in the LaTeX export."
1083 1078
1084 ;; Preserve line breaks 1079 ;; Preserve line breaks
@@ -1091,7 +1086,7 @@ Valid parameters are
1091 (goto-char (point-min)) 1086 (goto-char (point-min))
1092 (let ((case-fold-search nil) rpl) 1087 (let ((case-fold-search nil) rpl)
1093 (while (re-search-forward "\\([^+_]\\)LaTeX" nil t) 1088 (while (re-search-forward "\\([^+_]\\)LaTeX" nil t)
1094 (replace-match (org-export-latex-protect-string 1089 (replace-match (org-export-latex-protect-string
1095 (concat (match-string 1) "\\LaTeX{}")) t t))) 1090 (concat (match-string 1) "\\LaTeX{}")) t t)))
1096 1091
1097 ;; Convert horizontal rules 1092 ;; Convert horizontal rules
@@ -1099,19 +1094,25 @@ Valid parameters are
1099 (while (re-search-forward "^----+.$" nil t) 1094 (while (re-search-forward "^----+.$" nil t)
1100 (replace-match (org-export-latex-protect-string "\\hrule") t t)) 1095 (replace-match (org-export-latex-protect-string "\\hrule") t t))
1101 1096
1102 ;; Protect LaTeX \commands{...} 1097 ;; Protect LaTeX commands like \commad[...]{...} or \command{...}
1103 (goto-char (point-min)) 1098 (goto-char (point-min))
1104 (while (re-search-forward "\\\\[a-zA-Z]+\\(?:\\[.*\\]\\)?{.*}" nil t) 1099 (while (re-search-forward "\\\\[a-zA-Z]+\\(?:\\[.*\\]\\)?{.*}" nil t)
1105 (add-text-properties (match-beginning 0) (match-end 0) 1100 (add-text-properties (match-beginning 0) (match-end 0)
1106 '(org-protected t))) 1101 '(org-protected t)))
1107 1102
1103 ;; Protect LaTeX entities
1104 (goto-char (point-min))
1105 (while (re-search-forward (regexp-opt org-latex-entities) nil t)
1106 (add-text-properties (match-beginning 0) (match-end 0)
1107 '(org-protected t)))
1108
1108 ;; Replace radio links 1109 ;; Replace radio links
1109 (goto-char (point-min)) 1110 (goto-char (point-min))
1110 (while (re-search-forward 1111 (while (re-search-forward
1111 (concat "<<<?" org-latex-all-targets-regexp 1112 (concat "<<<?" org-export-latex-all-targets-re
1112 ">>>?\\((INVISIBLE)\\)?") nil t) 1113 ">>>?\\((INVISIBLE)\\)?") nil t)
1113 (replace-match 1114 (replace-match
1114 (org-export-latex-protect-string 1115 (org-export-latex-protect-string
1115 (format "\\label{%s}%s"(match-string 1) 1116 (format "\\label{%s}%s"(match-string 1)
1116 (if (match-string 2) "" (match-string 1)))) t t)) 1117 (if (match-string 2) "" (match-string 1)))) t t))
1117 1118
@@ -1123,7 +1124,7 @@ Valid parameters are
1123 1124
1124 ;; When converting to LaTeX, replace footnotes 1125 ;; When converting to LaTeX, replace footnotes
1125 ;; FIXME: don't protect footnotes from conversion 1126 ;; FIXME: don't protect footnotes from conversion
1126 (when (plist-get org-latex-options-plist :footnotes) 1127 (when (plist-get org-export-latex-options-plist :footnotes)
1127 (goto-char (point-min)) 1128 (goto-char (point-min))
1128 (while (re-search-forward "\\[[0-9]+\\]" nil t) 1129 (while (re-search-forward "\\[[0-9]+\\]" nil t)
1129 (when (save-match-data 1130 (when (save-match-data
@@ -1133,34 +1134,402 @@ Valid parameters are
1133 (foot-end (match-end 0)) 1134 (foot-end (match-end 0))
1134 (foot-prefix (match-string 0)) 1135 (foot-prefix (match-string 0))
1135 footnote footnote-rpl) 1136 footnote footnote-rpl)
1136 (when (and (re-search-forward (regexp-quote foot-prefix) nil t)) 1137 (save-excursion
1137 (replace-match "") 1138 (when (search-forward foot-prefix nil t)
1138 (let ((end (save-excursion 1139 (replace-match "")
1139 (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t) 1140 (let ((end (save-excursion
1140 (match-beginning 0) (point-max))))) 1141 (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
1141 (setq footnote 1142 (match-beginning 0) (point-max)))))
1142 (concat 1143 (setq footnote (concat (org-trim (buffer-substring (point) end))
1143 (org-trim (buffer-substring (point) end)) 1144 " ")) ; prevent last } being part of a link
1144 ;; FIXME stupid workaround for cases where 1145 (delete-region (point) end))
1145 ;; `org-bracket-link-analytic-regexp' matches 1146 (goto-char foot-beg)
1146 ;; }. as part of the link. 1147 (delete-region foot-beg foot-end)
1147 " ")) 1148 (unless (null footnote)
1148 (delete-region (point) end))) 1149 (setq footnote-rpl (format "\\footnote{%s}" footnote))
1149 (goto-char foot-beg) 1150 (add-text-properties 0 10 '(org-protected t) footnote-rpl)
1150 (delete-region foot-beg foot-end) 1151 (add-text-properties (1- (length footnote-rpl))
1151 (setq footnote-rpl (format "\\footnote{%s}" footnote)) 1152 (length footnote-rpl)
1152 (add-text-properties 0 10 '(org-protected t) footnote-rpl) 1153 '(org-protected t) footnote-rpl)
1153 (add-text-properties (1- (length footnote-rpl)) 1154 (insert footnote-rpl)))))))
1154 (length footnote-rpl) 1155
1155 '(org-protected t) footnote-rpl)
1156 (insert footnote-rpl))))
1157
1158 ;; Replace footnote section tag for LaTeX 1156 ;; Replace footnote section tag for LaTeX
1159 (goto-char (point-min)) 1157 (goto-char (point-min))
1160 (while (re-search-forward 1158 (while (re-search-forward
1161 (concat "^" footnote-section-tag-regexp) nil t) 1159 (concat "^" footnote-section-tag-regexp) nil t)
1162 (replace-match "")))) 1160 (replace-match ""))))
1163 1161
1162;;; List handling:
1163
1164(defun org-export-latex-lists ()
1165 "Replace plain text lists in current buffer into LaTeX lists."
1166 "Convert lists to LaTeX."
1167 (goto-char (point-min))
1168 (while (re-search-forward org-export-latex-list-beginning-re nil t)
1169 (beginning-of-line)
1170 (insert (org-list-to-latex (org-list-parse-list t)) "\n")))
1171
1172(defun org-list-parse-list (&optional delete)
1173 "Parse the list at point.
1174Return a list containing first level items as strings and
1175sublevels as a list of strings."
1176 (let ((start (org-list-item-begin))
1177 (end (org-list-end))
1178 output itemsep)
1179 (while (re-search-forward org-export-latex-list-beginning-re end t)
1180 (setq itemsep (if (save-match-data
1181 (string-match "^[0-9]" (match-string 2)))
1182 "[0-9]+\\(?:\\.\\|)\\)" "[-+]"))
1183 (let* ((indent1 (match-string 1))
1184 (nextitem (save-excursion
1185 (save-match-data
1186 (or (and (re-search-forward
1187 (concat "^" indent1 itemsep " *?") end t)
1188 (match-beginning 0)) end))))
1189 (item (buffer-substring
1190 (point)
1191 (or (and (re-search-forward
1192 org-export-latex-list-beginning-re end t)
1193 (goto-char (match-beginning 0)))
1194 (goto-char end))))
1195 (nextindent (match-string 1))
1196 (item (org-trim item))
1197 (item (if (string-match "^\\[.+\\]" item)
1198 (replace-match "\\\\texttt{\\&}"
1199 t nil item) item)))
1200 (push item output)
1201 (when (> (length nextindent)
1202 (length indent1))
1203 (narrow-to-region (point) nextitem)
1204 (push (org-list-parse-list) output)
1205 (widen))))
1206 (when delete (delete-region start end))
1207 (setq output (nreverse output))
1208 (push (if (string-match "^\\[0" itemsep)
1209 'ordered 'unordered) output)))
1210
1211(defun org-list-item-begin ()
1212 "Find the beginning of the list item and return its position."
1213 (save-excursion
1214 (if (not (or (looking-at org-export-latex-list-beginning-re)
1215 (re-search-backward
1216 org-export-latex-list-beginning-re nil t)))
1217 (progn (goto-char (point-min)) (point))
1218 (match-beginning 0))))
1219
1220(defun org-list-end ()
1221 "Find the end of the list and return its position."
1222 (save-excursion
1223 (catch 'exit
1224 (while (or (looking-at org-export-latex-list-beginning-re)
1225 (looking-at "^[ \t]+\\|^$"))
1226 (if (eq (point) (point-max))
1227 (throw 'exit (point-max)))
1228 (forward-line 1))) (point)))
1229
1230(defun org-list-insert-radio-list ()
1231 "Insert a radio list template appropriate for this major mode."
1232 (interactive)
1233 (let* ((e (assq major-mode org-list-radio-list-templates))
1234 (txt (nth 1 e))
1235 name pos)
1236 (unless e (error "No radio list setup defined for %s" major-mode))
1237 (setq name (read-string "List name: "))
1238 (while (string-match "%n" txt)
1239 (setq txt (replace-match name t t txt)))
1240 (or (bolp) (insert "\n"))
1241 (setq pos (point))
1242 (insert txt)
1243 (goto-char pos)))
1244
1245(defun org-list-send-list (&optional maybe)
1246 "Send a tranformed version of this list to the receiver position.
1247With argument MAYBE, fail quietly if no transformation is defined for
1248this list."
1249 (interactive)
1250 (catch 'exit
1251 (unless (org-at-item-p) (error "Not at a list"))
1252 (save-excursion
1253 (goto-char (org-list-item-begin))
1254 (beginning-of-line 0)
1255 (unless (looking-at "#\\+ORGLST: *SEND +\\([a-zA-Z0-9_]+\\) +\\([^ \t\r\n]+\\)\\( +.*\\)?")
1256 (if maybe
1257 (throw 'exit nil)
1258 (error "Don't know how to transform this list"))))
1259 (let* ((name (match-string 1))
1260 beg
1261 (transform (intern (match-string 2)))
1262 (txt (buffer-substring-no-properties
1263 (org-list-item-begin)
1264 (org-list-end)))
1265 (list (org-list-parse-list)))
1266 (unless (fboundp transform)
1267 (error "No such transformation function %s" transform))
1268 (setq txt (funcall transform list))
1269 ;; Find the insertion place
1270 (save-excursion
1271 (goto-char (point-min))
1272 (unless (re-search-forward
1273 (concat "BEGIN RECEIVE ORGLST +" name "\\([ \t]\\|$\\)") nil t)
1274 (error "Don't know where to insert translated list"))
1275 (goto-char (match-beginning 0))
1276 (beginning-of-line 2)
1277 (setq beg (point))
1278 (unless (re-search-forward (concat "END RECEIVE ORGLST +" name) nil t)
1279 (error "Cannot find end of insertion region"))
1280 (beginning-of-line 1)
1281 (delete-region beg (point))
1282 (goto-char beg)
1283 (insert txt "\n"))
1284 (message "List converted and installed at receiver location"))))
1285
1286(defun org-list-to-generic (list params)
1287 "Convert a LIST parsed through `org-list-parse-list' to other formats.
1288
1289Valid parameters are
1290
1291:ustart String to start an unordered list
1292:uend String to end an unordered list
1293
1294:ostart String to start an ordered list
1295:oend String to end an ordered list
1296
1297:splice When set to t, return only list body lines, don't wrap
1298 them into :[u/o]start and :[u/o]end. Default is nil.
1299
1300:istart String to start a list item
1301:iend String to end a list item
1302:isep String to separate items
1303:lsep String to separate sublists"
1304 (interactive)
1305 (let* ((p params) sublist
1306 (splicep (plist-get p :splice))
1307 (ostart (plist-get p :ostart))
1308 (oend (plist-get p :oend))
1309 (ustart (plist-get p :ustart))
1310 (uend (plist-get p :uend))
1311 (istart (plist-get p :istart))
1312 (iend (plist-get p :iend))
1313 (isep (plist-get p :isep))
1314 (lsep (plist-get p :lsep)))
1315 (let ((wrapper
1316 (cond ((eq (car list) 'ordered)
1317 (concat ostart "\n%s" oend "\n"))
1318 ((eq (car list) 'unordered)
1319 (concat ustart "\n%s" uend "\n"))))
1320 rtn)
1321 (while (setq sublist (pop list))
1322 (cond ((symbolp sublist) nil)
1323 ((stringp sublist)
1324 (setq rtn (concat rtn istart sublist iend isep)))
1325 (t
1326 (setq rtn (concat rtn ;; previous list
1327 lsep ;; list separator
1328 (org-list-to-generic sublist p)
1329 lsep ;; list separator
1330 )))))
1331 (format wrapper rtn))))
1332
1333(defun org-list-to-latex (list)
1334 "Convert LIST into a LaTeX list."
1335 (org-list-to-generic
1336 list '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
1337 :ustart "\\begin{itemize}" :uend "\\end{itemize}"
1338 :istart "\\item " :iend ""
1339 :isep "\n" :lsep "\n")))
1340
1341(defun org-list-to-html (list)
1342 "Convert LIST into a HTML list."
1343 (org-list-to-generic
1344 list '(:splicep nil :ostart "<ol>" :oend "</ol>"
1345 :ustart "<ul>" :uend "</ul>"
1346 :istart "<li>" :iend "</li>"
1347 :isep "\n" :lsep "\n")))
1348
1349(defun org-list-to-texinfo (list)
1350 "Convert LIST into a Texinfo list."
1351 (org-list-to-generic
1352 list '(:splicep nil :ostart "@itemize @minus" :oend "@end itemize"
1353 :ustart "@enumerate" :uend "@end enumerate"
1354 :istart "@item\n" :iend ""
1355 :isep "\n" :lsep "\n")))
1356
1357(defconst org-latex-entities
1358 '("\\!"
1359 "\\'"
1360 "\\+"
1361 "\\,"
1362 "\\-"
1363 "\\:"
1364 "\\;"
1365 "\\<"
1366 "\\="
1367 "\\>"
1368 "\\Huge"
1369 "\\LARGE"
1370 "\\Large"
1371 "\\Styles"
1372 "\\\\"
1373 "\\`"
1374 "\\addcontentsline"
1375 "\\address"
1376 "\\addtocontents"
1377 "\\addtocounter"
1378 "\\addtolength"
1379 "\\addvspace"
1380 "\\alph"
1381 "\\appendix"
1382 "\\arabic"
1383 "\\author"
1384 "\\begin{array}"
1385 "\\begin{center}"
1386 "\\begin{description}"
1387 "\\begin{enumerate}"
1388 "\\begin{eqnarray}"
1389 "\\begin{equation}"
1390 "\\begin{figure}"
1391 "\\begin{flushleft}"
1392 "\\begin{flushright}"
1393 "\\begin{itemize}"
1394 "\\begin{list}"
1395 "\\begin{minipage}"
1396 "\\begin{picture}"
1397 "\\begin{quotation}"
1398 "\\begin{quote}"
1399 "\\begin{tabbing}"
1400 "\\begin{table}"
1401 "\\begin{tabular}"
1402 "\\begin{thebibliography}"
1403 "\\begin{theorem}"
1404 "\\begin{titlepage}"
1405 "\\begin{verbatim}"
1406 "\\begin{verse}"
1407 "\\bf"
1408 "\\bf"
1409 "\\bibitem"
1410 "\\bigskip"
1411 "\\cdots"
1412 "\\centering"
1413 "\\circle"
1414 "\\cite"
1415 "\\cleardoublepage"
1416 "\\clearpage"
1417 "\\cline"
1418 "\\closing"
1419 "\\dashbox"
1420 "\\date"
1421 "\\ddots"
1422 "\\dotfill"
1423 "\\em"
1424 "\\fbox"
1425 "\\flushbottom"
1426 "\\fnsymbol"
1427 "\\footnote"
1428 "\\footnotemark"
1429 "\\footnotesize"
1430 "\\footnotetext"
1431 "\\frac"
1432 "\\frame"
1433 "\\framebox"
1434 "\\hfill"
1435 "\\hline"
1436 "\\hrulespace"
1437 "\\hspace"
1438 "\\huge"
1439 "\\hyphenation"
1440 "\\include"
1441 "\\includeonly"
1442 "\\indent"
1443 "\\input"
1444 "\\it"
1445 "\\kill"
1446 "\\label"
1447 "\\large"
1448 "\\ldots"
1449 "\\line"
1450 "\\linebreak"
1451 "\\linethickness"
1452 "\\listoffigures"
1453 "\\listoftables"
1454 "\\location"
1455 "\\makebox"
1456 "\\maketitle"
1457 "\\mark"
1458 "\\mbox"
1459 "\\medskip"
1460 "\\multicolumn"
1461 "\\multiput"
1462 "\\newcommand"
1463 "\\newcounter"
1464 "\\newenvironment"
1465 "\\newfont"
1466 "\\newlength"
1467 "\\newline"
1468 "\\newpage"
1469 "\\newsavebox"
1470 "\\newtheorem"
1471 "\\nocite"
1472 "\\nofiles"
1473 "\\noindent"
1474 "\\nolinebreak"
1475 "\\nopagebreak"
1476 "\\normalsize"
1477 "\\onecolumn"
1478 "\\opening"
1479 "\\oval"
1480 "\\overbrace"
1481 "\\overline"
1482 "\\pagebreak"
1483 "\\pagenumbering"
1484 "\\pageref"
1485 "\\pagestyle"
1486 "\\par"
1487 "\\parbox"
1488 "\\put"
1489 "\\raggedbottom"
1490 "\\raggedleft"
1491 "\\raggedright"
1492 "\\raisebox"
1493 "\\ref"
1494 "\\rm"
1495 "\\roman"
1496 "\\rule"
1497 "\\savebox"
1498 "\\sc"
1499 "\\scriptsize"
1500 "\\setcounter"
1501 "\\setlength"
1502 "\\settowidth"
1503 "\\sf"
1504 "\\shortstack"
1505 "\\signature"
1506 "\\sl"
1507 "\\small"
1508 "\\smallskip"
1509 "\\sqrt"
1510 "\\tableofcontents"
1511 "\\telephone"
1512 "\\thanks"
1513 "\\thispagestyle"
1514 "\\tiny"
1515 "\\title"
1516 "\\tt"
1517 "\\twocolumn"
1518 "\\typein"
1519 "\\typeout"
1520 "\\underbrace"
1521 "\\underline"
1522 "\\usebox"
1523 "\\usecounter"
1524 "\\value"
1525 "\\vdots"
1526 "\\vector"
1527 "\\verb"
1528 "\\vfill"
1529 "\\vline"
1530 "\\vspace")
1531 "A list of LaTeX commands to be protected when performing conversion.")
1532
1164(provide 'org-export-latex) 1533(provide 'org-export-latex)
1165 1534
1166;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad 1535;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad