annotate lisp/textmodes/org-export-latex.el @ 85759:906f71611b65

(browse-url-text-xterm): Renamed from browse-url-lynx-xterm and made generic. (browse-url-text-emacs): Likewise. (browse-url-text-browser): New variable. (browse-url-text-emacs-args): Renamed from browse-url-lynx-emacs-args. (browse-url-text-input-field, browse-url-text-input-attempts) (browse-url-kde-program): Likewise.
author Richard M. Stallman <rms@gnu.org>
date Mon, 29 Oct 2007 13:55:06 +0000
parents 5032dc6e8d82
children 86f143f19d08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1 ;;; org-export-latex.el --- LaTeX exporter for org-mode
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
2 ;;
85749
5032dc6e8d82 Revert down-casing of copyright header.
Glenn Morris <rgm@gnu.org>
parents: 85554
diff changeset
3 ;; Copyright (C) 2007 Free Software Foundation, Inc.
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
4 ;;
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
5 ;; Emacs Lisp Archive Entry
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
6 ;; Filename: org-export-latex.el
85554
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
7 ;; Version: 5.12
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
8 ;; Author: Bastien Guerry <bzg AT altern DOT org>
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
9 ;; Maintainer: Bastien Guerry <bzg AT altern DOT org>
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
10 ;; Keywords: org, wp, tex
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
11 ;; Description: Converts an org-mode buffer into LaTeX
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
12 ;; URL: http://www.cognition.ens.fr/~guerry/u/org-export-latex.el
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
13 ;;
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
14 ;; This file is part of GNU Emacs.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
15 ;;
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
16 ;; GNU Emacs is free software; you can redistribute it and/or modify it
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
17 ;; under the terms of the GNU General Public License as published by the
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
18 ;; Free Software Foundation; either version 3, or (at your option) any
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
19 ;; later version.
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
20 ;;
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
21 ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
22 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
23 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
24 ;; more details.
85749
5032dc6e8d82 Revert down-casing of copyright header.
Glenn Morris <rgm@gnu.org>
parents: 85554
diff changeset
25 ;;
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
26 ;; You should have received a copy of the GNU General Public License along
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
27 ;; with GNU Emacs; see the file COPYING. If not, write to the Free Software
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
28 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
29 ;; 02110-1301, USA.
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
30 ;;
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
31 ;;; Commentary:
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
32 ;;
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
33 ;; This library implements a LaTeX exporter for org-mode.
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
34 ;;
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
35 ;; Put this file into your load-path and the following into your ~/.emacs:
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
36 ;; (require 'org-export-latex)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
37 ;;
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
38 ;; The interactive functions are similar to those of the HTML exporter:
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
39 ;;
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
40 ;; M-x `org-export-as-latex'
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
41 ;; M-x `org-export-as-latex-batch'
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
42 ;; M-x `org-export-as-latex-to-buffer'
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
43 ;; M-x `org-export-region-as-latex'
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
44 ;; M-x `org-replace-region-by-latex'
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
45 ;;
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
46 ;;; Code:
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
47
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
48 (eval-when-compile
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
49 (require 'cl))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
50
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
51 (require 'footnote)
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
52 (require 'org)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
53
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
54 ;;; Variables:
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
55 (defvar org-latex-options-plist nil)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
56 (defvar org-latex-todo-keywords-1 nil)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
57 (defvar org-latex-all-targets-regexp nil)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
58 (defvar org-latex-add-level 0)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
59 (defvar org-latex-sectioning-depth 0)
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
60 (defvar org-export-latex-list-beginning-re
85554
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
61 "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) +?")
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
62
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
63 (defvar org-latex-special-string-regexps
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
64 '(org-ts-regexp
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
65 org-scheduled-string
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
66 org-deadline-string
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
67 org-clock-string)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
68 "A list of regexps to convert as special keywords.")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
69
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
70 (defvar latexp) ; dynamically scoped from org.el
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
71 (defvar re-quote) ; dynamically scoped from org.el
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
72 (defvar commentsp) ; dynamically scoped from org.el
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
73
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
74 ;;; Custom variables:
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
75 (defcustom org-export-latex-sectioning-alist
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
76 '((1 "\\section{%s}" "\\section*{%s}")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
77 (2 "\\subsection{%s}" "\\subsection*{%s}")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
78 (3 "\\subsubsection{%s}" "\\subsubsection*{%s}")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
79 (4 "\\paragraph{%s}" "\\paragraph*{%s}")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
80 (5 "\\subparagraph{%s}" "\\subparagraph*{%s}"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
81 "Alist of LaTeX commands for inserting sections.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
82 Here is the structure of each cell:
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
83
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
84 \(level unnumbered-section numbered-section\)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
85
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
86 The %s formatter will be replaced by the title of the section."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
87 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
88 :type 'alist)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
89
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
90 (defcustom org-export-latex-emphasis-alist
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
91 '(("*" "\\textbf{%s}" nil)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
92 ("/" "\\emph{%s}" nil)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
93 ("_" "\\underline{%s}" nil)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
94 ("+" "\\texttt{%s}" nil)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
95 ("=" "\\texttt{%s}" nil))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
96 "Alist of LaTeX expressions to convert emphasis fontifiers.
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
97 Each element of the list is a list of three elements.
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
98 The first element is the character used as a marker for fontification.
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
99 The second element is a formatting string to wrap fontified text with.
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
100 The third element decides whether to protect converted text from other
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
101 conversions."
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
102 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
103 :type 'alist)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
104
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
105 (defcustom org-export-latex-preamble
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
106 "\\documentclass[11pt,a4paper]{article}
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
107 \\usepackage[utf8]{inputenc}
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
108 \\usepackage[T1]{fontenc}
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
109 \\usepackage{hyperref}"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
110 "Preamble to be inserted at the very beginning of the LaTeX export."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
111 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
112 :type 'string)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
113
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
114 (defcustom org-export-latex-title-command "\\maketitle"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
115 "The command used to insert the title just after \\begin{document}.
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
116 If this string contains the formatting specification \"%s\" then
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
117 it will be used as a formatting string, passing the title as an
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
118 argument."
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
119 :group 'org-export-latex
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
120 :type 'string)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
121
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
122 (defcustom org-export-latex-date-format
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
123 "%d %B %Y"
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
124 "Format string for \\date{...}."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
125 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
126 :type 'string)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
127
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
128 (defcustom org-export-latex-tables-verbatim nil
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
129 "When non-nil, export tables as verbatim."
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
130 :group 'org-export-latex
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
131 :type 'boolean)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
132
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
133 (defcustom org-export-latex-packages-alist nil
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
134 "Alist of packages to be inserted in the preamble.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
135 Each cell is of the forma \( option . package \).
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
136
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
137 For example:
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
138
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
139 \(setq org-export-latex-packages-alist
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
140 '((\"french\" \"babel\"))"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
141 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
142 :type 'alist)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
143
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
144 (defcustom org-export-latex-low-levels 'description
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
145 "How to convert sections below the current level of sectioning,
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
146 as specified by `org-export-headline-levels' or the value of \"H:\"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
147 in Org's #+OPTION line.
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
148
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
149 This can be either nil (skip the sections), 'description (convert
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
150 the sections as descriptive lists) or a string to be used instead
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
151 of \\section{%s}. In this latter case, the %s stands here for the
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
152 inserted headline and is mandatory."
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
153 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
154 :type '(choice (const :tag "Ignore" nil)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
155 (symbol :tag "Convert as descriptive list" description)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
156 (string :tag "Use a section string" :value "\\subparagraph{%s}")))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
157
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
158 (defcustom org-export-latex-remove-from-headlines
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
159 '(:todo t :priority t :tags t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
160 "A plist of keywords to remove from headlines.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
161 Non-nil means remove this keyword type from the headline.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
162
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
163 Don't remove the keys, just change their values."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
164 :type 'plist
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
165 :group 'org-export-latex)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
166
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
167 (defcustom org-export-latex-image-default-option "width=10em"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
168 "Default option for images."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
169 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
170 :type '(string))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
171
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
172 (defcustom org-export-latex-coding-system nil
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
173 "Coding system for the exported LaTex file."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
174 :group 'org-export-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
175 :type 'coding-system)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
176
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
177 ;; FIXME Do we want this one?
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
178 ;; (defun org-export-as-latex-and-open (arg) ...)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
179
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
180 ;;; Autoload functions:
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
181 ;;;###autoload
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
182 (defun org-export-as-latex-batch ()
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
183 "Call `org-export-as-latex', may be used in batch processing as
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
184 emacs --batch
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
185 --load=$HOME/lib/emacs/org.el
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
186 --eval \"(setq org-export-headline-levels 2)\"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
187 --visit=MyFile --funcall org-export-as-latex-batch"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
188 (org-export-as-latex org-export-headline-levels 'hidden))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
189
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
190 ;;;###autoload
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
191 (defun org-export-as-latex-to-buffer (arg)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
192 "Call `org-exort-as-latex` with output to a temporary buffer.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
193 No file is created. The prefix ARG is passed through to `org-export-as-latex'."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
194 (interactive "P")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
195 (org-export-as-latex arg nil nil "*Org LaTeX Export*")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
196 (switch-to-buffer-other-window "*Org LaTeX Export*"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
197
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
198 ;;;###autoload
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
199 (defun org-replace-region-by-latex (beg end)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
200 "Replace the region from BEG to END with its LaTeX export.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
201 It assumes the region has `org-mode' syntax, and then convert it to
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
202 LaTeX. This can be used in any buffer. For example, you could
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
203 write an itemized list in `org-mode' syntax in an LaTeX buffer and
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
204 then use this command to convert it."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
205 (interactive "r")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
206 (let (reg latex buf)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
207 (save-window-excursion
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
208 (if (org-mode-p)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
209 (setq latex (org-export-region-as-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
210 beg end t 'string))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
211 (setq reg (buffer-substring beg end)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
212 buf (get-buffer-create "*Org tmp*"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
213 (save-excursion
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
214 (set-buffer buf)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
215 (erase-buffer)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
216 (insert reg)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
217 (org-mode)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
218 (setq latex (org-export-region-as-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
219 (point-min) (point-max) t 'string)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
220 (kill-buffer buf)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
221 (delete-region beg end)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
222 (insert latex)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
223
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
224 ;;;###autoload
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
225 (defun org-export-region-as-latex (beg end &optional body-only buffer)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
226 "Convert region from BEG to END in `org-mode' buffer to LaTeX.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
227 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
228 contents, and only produce the region of converted text, useful for
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
229 cut-and-paste operations.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
230 If BUFFER is a buffer or a string, use/create that buffer as a target
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
231 of the converted LaTeX. If BUFFER is the symbol `string', return the
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
232 produced LaTeX as a string and leave not buffer behind. For example,
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
233 a Lisp program could call this function in the following way:
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
234
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
235 (setq latex (org-export-region-as-latex beg end t 'string))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
236
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
237 When called interactively, the output buffer is selected, and shown
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
238 in a window. A non-interactive call will only retunr the buffer."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
239 (interactive "r\nP")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
240 (when (interactive-p)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
241 (setq buffer "*Org LaTeX Export*"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
242 (let ((transient-mark-mode t) (zmacs-regions t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
243 rtn)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
244 (goto-char end)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
245 (set-mark (point)) ;; to activate the region
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
246 (goto-char beg)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
247 (setq rtn (org-export-as-latex
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
248 nil nil nil
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
249 buffer body-only))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
250 (if (fboundp 'deactivate-mark) (deactivate-mark))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
251 (if (and (interactive-p) (bufferp rtn))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
252 (switch-to-buffer-other-window rtn)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
253 rtn)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
254
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
255 ;;;###autoload
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
256 (defun org-export-as-latex (arg &optional hidden ext-plist
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
257 to-buffer body-only)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
258 "Export current buffer to a LaTeX file."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
259 (interactive "P")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
260 ;; Make sure we have a file name when we need it.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
261 (when (and (not (or to-buffer body-only))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
262 (not buffer-file-name))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
263 (if (buffer-base-buffer)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
264 (org-set-local 'buffer-file-name
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
265 (with-current-buffer (buffer-base-buffer)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
266 buffer-file-name))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
267 (error "Need a file name to be able to export")))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
268
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
269 (message "Exporting to LaTeX...")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
270 (org-update-radio-target-regexp)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
271 (org-export-latex-set-initial-vars ext-plist)
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
272 (let* ((wcf (current-window-configuration))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
273 (opt-plist org-latex-options-plist)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
274 (filename (concat (file-name-as-directory
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
275 (org-export-directory :LaTeX ext-plist))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
276 (file-name-sans-extension
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
277 (file-name-nondirectory ;sans-extension
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
278 buffer-file-name)) ".tex"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
279 (filename (if (equal (file-truename filename)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
280 (file-truename buffer-file-name))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
281 (concat filename ".tex")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
282 filename))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
283 (buffer (if to-buffer
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
284 (cond
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
285 ((eq to-buffer 'string) (get-buffer-create
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
286 "*Org LaTeX Export*"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
287 (t (get-buffer-create to-buffer)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
288 (find-file-noselect filename)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
289 (region-p (org-region-active-p))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
290 (odd org-odd-levels-only)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
291 (preamble (org-export-latex-make-preamble opt-plist))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
292 (skip (plist-get opt-plist :skip-before-1st-heading))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
293 (text (plist-get opt-plist :text))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
294 (first-lines (if skip "" (org-export-latex-first-lines)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
295 (coding-system (and (boundp 'buffer-file-coding-system)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
296 buffer-file-coding-system))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
297 (coding-system-for-write (or org-export-latex-coding-system
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
298 coding-system))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
299 (save-buffer-coding-system (or org-export-latex-coding-system
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
300 coding-system))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
301 (region (buffer-substring
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
302 (if region-p (region-beginning) (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
303 (if region-p (region-end) (point-max))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
304 (string-for-export
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
305 (org-cleaned-string-for-export
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
306 region :emph-multiline t
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
307 :for-LaTeX t
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
308 :comments nil
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
309 :add-text (if (eq to-buffer 'string) nil text)
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
310 :skip-before-1st-heading skip
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
311 :LaTeX-fragments nil)))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
312
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
313 (set-buffer buffer)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
314 (erase-buffer)
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
315
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
316 (and (fboundp 'set-buffer-file-coding-system)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
317 (set-buffer-file-coding-system coding-system-for-write))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
318
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
319 ;; insert the preamble and initial document commands
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
320 (unless (or (eq to-buffer 'string) body-only)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
321 (insert preamble))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
322
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
323 ;; insert text found in #+TEXT
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
324 (when (and text (not (eq to-buffer 'string)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
325 (insert (org-export-latex-content text) "\n\n"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
326
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
327 ;; insert lines before the first headline
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
328 (unless (or skip (eq to-buffer 'string))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
329 (insert first-lines))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
330
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
331 ;; handle the case where the region does not begin with a section
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
332 (when region-p
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
333 (insert (with-temp-buffer
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
334 (insert string-for-export)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
335 (org-export-latex-first-lines))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
336
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
337 ;; export the content of headlines
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
338 (org-export-latex-global
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
339 (with-temp-buffer
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
340 (insert string-for-export)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
341 (goto-char (point-min))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
342 (when (re-search-forward "^\\(\\*+\\) " nil t)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
343 (let* ((asters (length (match-string 1)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
344 (level (if odd (- asters 2) (- asters 1))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
345 (setq org-latex-add-level
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
346 (if odd (1- (/ (1+ asters) 2)) (1- asters)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
347 (org-export-latex-parse-global level odd)))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
348
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
349 ;; finalization
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
350 (unless body-only (insert "\n\\end{document}"))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
351 (or to-buffer (save-buffer))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
352 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
353 (message "Exporting to LaTeX...done")
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
354 (prog1
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
355 (if (eq to-buffer 'string)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
356 (prog1 (buffer-substring (point-min) (point-max))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
357 (kill-buffer (current-buffer)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
358 (current-buffer))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
359 (set-window-configuration wcf))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
360
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
361
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
362 ;;; Parsing functions:
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
363 (defun org-export-latex-parse-global (level odd)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
364 "Parse the current buffer recursively, starting at LEVEL.
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
365 If ODD is non-nil, assume the buffer only contains odd sections.
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
366 Return A list reflecting the document structure."
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
367 (save-excursion
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
368 (goto-char (point-min))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
369 (let* ((cnt 0) output
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
370 (depth org-latex-sectioning-depth))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
371 (while (re-search-forward
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
372 (concat "^\\(\\(?:\\*\\)\\{"
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
373 (number-to-string (+ (if odd 2 1) level))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
374 "\\}\\) \\(.*\\)$")
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
375 ;; make sure that there is no upper heading
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
376 (when (> level 0)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
377 (save-excursion
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
378 (save-match-data
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
379 (re-search-forward
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
380 (concat "^\\(\\(?:\\*\\)\\{"
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
381 (number-to-string level)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
382 "\\}\\) \\(.*\\)$") nil t)))) t)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
383 (setq cnt (1+ cnt))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
384 (let* ((pos (match-beginning 0))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
385 (heading (match-string 2))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
386 (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
387 (save-excursion
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
388 (narrow-to-region
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
389 (point)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
390 (save-match-data
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
391 (if (re-search-forward
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
392 (concat "^\\(\\(?:\\*\\)\\{"
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
393 (number-to-string (+ (if odd 2 1) level))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
394 "\\}\\) \\(.*\\)$") nil t)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
395 (match-beginning 0)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
396 (point-max))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
397 (goto-char (point-min))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
398 (setq output
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
399 (append output
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
400 (list
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
401 (list
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
402 `(pos . ,pos)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
403 `(level . ,nlevel)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
404 `(occur . ,cnt)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
405 `(heading . ,heading)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
406 `(content . ,(org-export-latex-parse-content))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
407 `(subcontent . ,(org-export-latex-parse-subcontent
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
408 level odd)))))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
409 (widen)))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
410 (list output))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
411
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
412 (defun org-export-latex-parse-list (&optional delete)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
413 "Parse the list at point.
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
414 Return a list containing first level items as strings and
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
415 sublevels as list of strings."
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
416 (let ((start (point))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
417 ;; Find the end of the list
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
418 (end (save-excursion
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
419 (catch 'exit
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
420 (while (or (looking-at org-export-latex-list-beginning-re)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
421 (looking-at "^[ \t]+\\|^$"))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
422 (if (eq (point) (point-max))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
423 (throw 'exit (point-max)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
424 (forward-line 1))) (point)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
425 output itemsep)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
426 (while (re-search-forward org-export-latex-list-beginning-re end t)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
427 (setq itemsep (if (save-match-data
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
428 (string-match "^[0-9]" (match-string 2)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
429 "[0-9]+\\(?:\\.\\|)\\)" "[-+]"))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
430 (let* ((indent1 (match-string 1))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
431 (nextitem (save-excursion
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
432 (save-match-data
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
433 (or (and (re-search-forward
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
434 (concat "^" indent1 itemsep " *?") end t)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
435 (match-beginning 0)) end))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
436 (item (buffer-substring
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
437 (point)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
438 (or (and (re-search-forward
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
439 org-export-latex-list-beginning-re end t)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
440 (goto-char (match-beginning 0)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
441 (goto-char end))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
442 (nextindent (match-string 1))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
443 (item (org-trim item))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
444 (item (if (string-match "^\\[.+\\]" item)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
445 (replace-match "\\\\texttt{\\&}"
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
446 t nil item) item)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
447 (push item output)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
448 (when (> (length nextindent)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
449 (length indent1))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
450 (narrow-to-region (point) nextitem)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
451 (push (org-export-latex-parse-list) output)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
452 (widen))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
453 (when delete (delete-region start end))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
454 (setq output (nreverse output))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
455 (push (if (string-match "^\\[0" itemsep)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
456 'ordered 'unordered) output)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
457
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
458 (defun org-export-latex-parse-content ()
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
459 "Extract the content of a section."
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
460 (let ((beg (point))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
461 (end (if (re-search-forward "^\\(\\*\\)+ .*$" nil t)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
462 (progn (beginning-of-line) (point))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
463 (point-max))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
464 (buffer-substring beg end)))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
465
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
466 (defun org-export-latex-parse-subcontent (level odd)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
467 "Extract the subcontent of a section at LEVEL.
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
468 If ODD Is non-nil, assume subcontent only contains odd sections."
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
469 (if (not (re-search-forward
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
470 (concat "^\\(\\(?:\\*\\)\\{"
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
471 (number-to-string (+ (if odd 4 2) level))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
472 "\\}\\) \\(.*\\)$")
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
473 nil t))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
474 nil ; subcontent is nil
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
475 (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
476
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
477 ;;; Rendering functions:
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
478 (defun org-export-latex-global (content)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
479 "Export CONTENT to LaTeX.
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
480 CONTENT is an element of the list produced by
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
481 `org-export-latex-parse-global'."
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
482 (if (eq (car content) 'subcontent)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
483 (mapc 'org-export-latex-sub (cdr content))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
484 (org-export-latex-sub (car content))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
485
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
486 (defun org-export-latex-sub (subcontent)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
487 "Export the list SUBCONTENT to LaTeX.
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
488 SUBCONTENT is an alist containing information about the headline
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
489 and its content."
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
490 (let ((num (plist-get org-latex-options-plist :section-numbers)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
491 (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
492
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
493 (defun org-export-latex-subcontent (subcontent num)
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
494 "Export each cell of SUBCONTENT to LaTeX."
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
495 (let ((heading (org-export-latex-fontify-headline
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
496 (cdr (assoc 'heading subcontent))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
497 (level (- (cdr (assoc 'level subcontent))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
498 org-latex-add-level))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
499 (occur (number-to-string (cdr (assoc 'occur subcontent))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
500 (content (cdr (assoc 'content subcontent)))
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
501 (subcontent (cadr (assoc 'subcontent subcontent))))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
502 (cond
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
503 ;; Normal conversion
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
504 ((<= level org-latex-sectioning-depth)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
505 (let ((sec (assoc level org-export-latex-sectioning-alist)))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
506 (insert (format (if num (cadr sec) (caddr sec)) heading) "\n"))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
507 (insert (org-export-latex-content content))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
508 (cond ((stringp subcontent) (insert subcontent))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
509 ((listp subcontent) (org-export-latex-sub subcontent))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
510 ;; At a level under the hl option: we can drop this subsection
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
511 ((> level org-latex-sectioning-depth)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
512 (cond ((eq org-export-latex-low-levels 'description)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
513 (insert (format "\\begin{description}\n\n\\item[%s]\n\n" heading))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
514 (insert (org-export-latex-content content))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
515 (cond ((stringp subcontent) (insert subcontent))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
516 ((listp subcontent) (org-export-latex-sub subcontent)))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
517 (insert "\\end{description}\n"))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
518 ((stringp org-export-latex-low-levels)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
519 (insert (format org-export-latex-low-levels heading) "\n")
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
520 (insert (org-export-latex-content content))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
521 (cond ((stringp subcontent) (insert subcontent))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
522 ((listp subcontent) (org-export-latex-sub subcontent)))))))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
523
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
524
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
525 ;;; Exporting internals:
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
526 (defun org-export-latex-protect-string (string)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
527 "Prevent further conversion for STRING by adding the
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
528 org-protect property."
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
529 (add-text-properties
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
530 0 (length string) '(org-protected t) string) string)
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
531
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
532 (defun org-export-latex-protect-char-in-string (char-list string)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
533 "Add org-protected text-property to char from CHAR-LIST in STRING."
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
534 (with-temp-buffer
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
535 (save-match-data
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
536 (insert string)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
537 (goto-char (point-min))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
538 (while (re-search-forward (regexp-opt char-list) nil t)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
539 (add-text-properties (match-beginning 0)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
540 (match-end 0) '(org-protected t)))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
541 (buffer-string))))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
542
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
543 (defun org-export-latex-set-initial-vars (ext-plist)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
544 "Store org local variables required for LaTeX export.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
545 EXT-PLIST is an optional additional plist."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
546 (setq org-latex-todo-keywords-1 org-todo-keywords-1
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
547 org-latex-all-targets-regexp
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
548 (org-make-target-link-regexp (org-all-targets))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
549 org-latex-options-plist
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
550 (org-combine-plists (org-default-export-plist) ext-plist
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
551 (org-infile-export-plist))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
552 org-latex-sectioning-depth
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
553 (let ((hl-levels (plist-get org-latex-options-plist :headline-levels))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
554 (sec-depth (length org-export-latex-sectioning-alist)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
555 ;; Fall back on org-export-latex-sectioning-alist length if
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
556 ;; headline-levels goes beyond it
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
557 (if (> hl-levels sec-depth) sec-depth hl-levels))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
558
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
559 (defun org-export-latex-make-preamble (opt-plist)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
560 "Make the LaTeX preamble and return it as a string.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
561 Argument OPT-PLIST is the options plist for current buffer."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
562 (let ((toc (plist-get opt-plist :table-of-contents)))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
563 (concat
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
564 (if (plist-get opt-plist :time-stamp-file)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
565 (format-time-string "% Created %Y-%m-%d %a %H:%M\n"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
566
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
567 ;; insert LaTeX custom preamble
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
568 org-export-latex-preamble "\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
569
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
570 ;; insert information on LaTeX packages
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
571 (when org-export-latex-packages-alist
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
572 (mapconcat (lambda(p)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
573 (if (equal "" (car p))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
574 (format "\\usepackage{%s}" (cadr p))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
575 (format "\\usepackage[%s]{%s}"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
576 (car p) (cadr p))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
577 org-export-latex-packages-alist "\n"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
578
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
579 ;; insert the title
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
580 (format
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
581 "\\title{%s}\n"
85554
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
582 ;; convert the title
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
583 (org-export-latex-content
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
584 (or (plist-get opt-plist :title)
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
585 (and (not
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
586 (plist-get opt-plist :skip-before-1st-heading))
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
587 (org-export-grab-title-from-buffer))
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
588 (and buffer-file-name
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
589 (file-name-sans-extension
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
590 (file-name-nondirectory buffer-file-name)))
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
591 "UNTITLED")))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
592
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
593 ;; insert author info
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
594 (if (plist-get opt-plist :author-info)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
595 (format "\\author{%s}\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
596 (or (plist-get opt-plist :author) user-full-name))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
597 (format "%%\\author{%s}\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
598 (or (plist-get opt-plist :author) user-full-name)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
599
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
600 ;; insert the date
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
601 (format "\\date{%s}\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
602 (format-time-string
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
603 (or (plist-get opt-plist :date)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
604 org-export-latex-date-format)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
605
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
606 ;; beginning of the document
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
607 "\n\\begin{document}\n\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
608
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
609 ;; insert the title command
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
610 (if (string-match "%s" org-export-latex-title-command)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
611 (format org-export-latex-title-command
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
612 (plist-get opt-plist :title))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
613 org-export-latex-title-command)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
614 "\n\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
615
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
616 ;; table of contents
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
617 (when (and org-export-with-toc
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
618 (plist-get opt-plist :section-numbers))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
619 (cond ((numberp toc)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
620 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
621 (min toc (plist-get opt-plist :headline-levels))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
622 (toc (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
623 (plist-get opt-plist :headline-levels))))))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
624
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
625 (defun org-export-latex-first-lines (&optional comments)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
626 "Export the first lines before first headline.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
627 COMMENTS is either nil to replace them with the empty string or a
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
628 formatting string like %%%%s if we want to comment them out."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
629 (save-excursion
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
630 (goto-char (point-min))
85554
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
631 (let* ((pt (point))
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
632 (end (if (and (re-search-forward "^\\*" nil t)
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
633 (not (eq pt (match-beginning 0))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
634 (goto-char (match-beginning 0))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
635 (goto-char (point-max)))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
636 (org-export-latex-content
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
637 (org-cleaned-string-for-export
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
638 (buffer-substring (point-min) end)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
639 :for-LaTeX t
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
640 :emph-multiline t
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
641 :add-text nil
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
642 :comments nil
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
643 :skip-before-1st-heading nil
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
644 :LaTeX-fragments nil)))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
645
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
646 (defun org-export-latex-keywords-maybe (remove-list)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
647 "Maybe remove keywords depending on rules in REMOVE-LIST."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
648 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
649 (let ((re-todo (mapconcat 'identity org-latex-todo-keywords-1 "\\|")))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
650 ;; convert TODO keywords
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
651 (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
652 (if (plist-get remove-list :todo)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
653 (replace-match "")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
654 (replace-match (format "\\texttt{%s}" (match-string 1)) t t)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
655 ;; convert priority string
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
656 (when (re-search-forward "\\[\\\\#.\\]" nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
657 (if (plist-get remove-list :priority)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
658 (replace-match "")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
659 (replace-match (format "\\texttt{%s}" (match-string 0)) t t)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
660 ;; convert tags
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
661 (when (re-search-forward "\\(:[a-zA-Z0-9]+\\)+:" nil t)
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
662 (if (or (not org-export-with-tags)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
663 (plist-get remove-list :tags))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
664 (replace-match "")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
665 (replace-match (format "\\texttt{%s}" (match-string 0)) t t)))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
666
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
667 (defun org-export-latex-fontify-headline (headline)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
668 "Fontify special words in a HEADLINE."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
669 (with-temp-buffer
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
670 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
671 ;; the beginning of the buffer - inserting "\n" is safe here though.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
672 (insert "\n" headline)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
673 (goto-char (point-min))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
674 (when (plist-get org-latex-options-plist :emphasize)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
675 (org-export-latex-fontify))
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
676 (org-export-latex-special-chars
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
677 (plist-get org-latex-options-plist :sub-superscript))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
678 (org-export-latex-keywords-maybe
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
679 org-export-latex-remove-from-headlines)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
680 (org-export-latex-links)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
681 (org-trim (buffer-substring-no-properties (point-min) (point-max)))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
682
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
683 (defun org-export-latex-content (content)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
684 "Convert CONTENT string to LaTeX."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
685 (with-temp-buffer
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
686 (insert content)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
687 (org-export-latex-quotation-marks)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
688 (when (plist-get org-latex-options-plist :emphasize)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
689 (org-export-latex-fontify))
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
690 (org-export-latex-special-chars
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
691 (plist-get org-latex-options-plist :sub-superscript))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
692 (org-export-latex-links)
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
693 (org-export-latex-keywords
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
694 (plist-get org-latex-options-plist :timestamps))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
695 (org-export-latex-lists)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
696 (org-export-latex-tables
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
697 (plist-get org-latex-options-plist :tables))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
698 (org-export-latex-fixed-width
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
699 (plist-get org-latex-options-plist :fixed-width))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
700 ;; return string
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
701 (buffer-substring (point-min) (point-max))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
702
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
703 (defun org-export-latex-quotation-marks ()
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
704 "Export question marks depending on language conventions.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
705 Local definition of the language overrides
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
706 `org-export-latex-quotation-marks-convention' which overrides
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
707 `org-export-default-language'."
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
708 (let* ((lang (plist-get org-latex-options-plist :language))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
709 (quote-rpl (if (equal lang "fr")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
710 '(("\\(\\s-\\)\"" "«~")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
711 ("\\(\\S-\\)\"" "~»")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
712 ("\\(\\s-\\)'" "`"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
713 '(("\\(\\s-\\)\"" "``")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
714 ("\\(\\S-\\)\"" "''")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
715 ("\\(\\s-\\)'" "`")))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
716 (mapc (lambda(l) (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
717 (while (re-search-forward (car l) nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
718 (let ((rpl (concat (match-string 1) (cadr l))))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
719 (org-export-latex-protect-string rpl)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
720 (org-if-unprotected
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
721 (replace-match rpl t t))))) quote-rpl)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
722
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
723 ;; | chars/string in Org | normal environment | math environment |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
724 ;; |-----------------------+-----------------------+-----------------------|
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
725 ;; | & # % $ | \& \# \% \$ | \& \# \% \$ |
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
726 ;; | { } _ ^ \ | \{ \} \_ \^ \\ | { } _ ^ \ |
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
727 ;; |-----------------------+-----------------------+-----------------------|
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
728 ;; | a_b and a^b | $a_b$ and $a^b$ | a_b and a^b |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
729 ;; | a_abc and a_{abc} | $a_a$bc and $a_{abc}$ | a_abc and a_{abc} |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
730 ;; | \tau and \mu | $\tau$ and $\mu$ | \tau and \mu |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
731 ;; |-----------------------+-----------------------+-----------------------|
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
732 ;; | \_ \^ | \_ \^ | \_ \^ |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
733 ;; | \(a=\mu\mbox{m}\) | \(a=\mu\mbox{m}\) | \(a=\mu\mbox{m}\) |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
734 ;; | \[\beta^2-a=0\] | \[\beta^2-a=0\] | \[\beta^2-a=0\] |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
735 ;; | $x=22\tau$ | $x=22\tau$ | $x=22\tau$ |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
736 ;; | $$\alpha=\sqrt{a^3}$$ | $$\alpha=\sqrt{a^3}$$ | $$\alpha=\sqrt{a^3}$$ |
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
737
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
738 (defun org-export-latex-special-chars (sub-superscript)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
739 "Export special characters to LaTeX.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
740 If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
741 See the `org-export-latex.el' code for a complete conversion table."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
742 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
743 (mapc (lambda(c)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
744 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
745 (while (re-search-forward c nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
746 ;; Put the point where to check for org-protected
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
747 (unless (get-text-property (match-beginning 2) 'org-protected)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
748 (cond ((member (match-string 2) '("\\$" "$"))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
749 (if (equal (match-string 2) "\\$")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
750 (replace-match (concat (match-string 1) "$"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
751 (match-string 3)) t t)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
752 (replace-match (concat (match-string 1) "\\$"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
753 (match-string 3)) t t)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
754 ((member (match-string 2) '("&" "%" "#"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
755 (if (equal (match-string 1) "\\")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
756 (replace-match (match-string 2) t t)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
757 (replace-match (concat (match-string 1) "\\"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
758 (match-string 2)) t t)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
759 ((equal (match-string 2) "~")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
760 (cond ((equal (match-string 1) "\\") nil)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
761 ((eq 'org-link (get-text-property 0 'face (match-string 2)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
762 (replace-match (concat (match-string 1) "\\~") t t))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
763 (t (replace-match
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
764 (org-export-latex-protect-string
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
765 (concat (match-string 1) "\\~{}")) t t))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
766 ((member (match-string 2) '("{" "}"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
767 (unless (save-match-data (org-inside-LaTeX-fragment-p))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
768 (if (equal (match-string 1) "\\")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
769 (replace-match (match-string 2) t t)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
770 (replace-match (concat (match-string 1) "\\"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
771 (match-string 2)) t t)))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
772 (unless (save-match-data (org-inside-LaTeX-fragment-p))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
773 (cond ((equal (match-string 2) "\\")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
774 (replace-match (or (save-match-data
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
775 (org-export-latex-treat-backslash-char
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
776 (match-string 1)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
777 (match-string 3))) "") t t))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
778 ((member (match-string 2) '("_" "^"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
779 (replace-match (or (save-match-data
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
780 (org-export-latex-treat-sub-super-char
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
781 sub-superscript
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
782 (match-string 1)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
783 (match-string 2)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
784 (match-string 3))) "") t t)))))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
785 '("^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
786 "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\([a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
787 "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
788 "\\(.\\|^\\)\\(&\\)"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
789 "\\(.\\|^\\)\\(#\\)"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
790 "\\(.\\|^\\)\\(%\\)"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
791 "\\(.\\|^\\)\\({\\)"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
792 "\\(.\\|^\\)\\(}\\)"
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
793 "\\(.\\|^\\)\\(~\\)"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
794 ;; (?\< . "\\textless{}")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
795 ;; (?\> . "\\textgreater{}")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
796 )))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
797
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
798 (defun org-export-latex-treat-sub-super-char
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
799 (subsup string-before char string-after)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
800 "Convert the \"_\" and \"^\" characters to LaTeX.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
801 SUBSUP corresponds to the ^: option in the #+OPTIONS line.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
802 Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
803 (cond ((equal string-before "\\")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
804 (concat string-before char string-after))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
805 ;; this is part of a math formula
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
806 ((and (string-match "\\S-+" string-before)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
807 (string-match "\\S-+" string-after))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
808 (cond ((eq 'org-link (get-text-property 0 'face char))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
809 (concat string-before "\\" char string-after))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
810 ((save-match-data (org-inside-LaTeX-fragment-p))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
811 (if subsup
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
812 (cond ((eq 1 (length string-after))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
813 (concat string-before char string-after))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
814 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
815 (format "%s%s{%s}" string-before char
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
816 (match-string 1 string-after))))))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
817 ((and subsup
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
818 (> (length string-after) 1)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
819 (string-match "[({]?\\([^)}]+\\)[)}]?" string-after))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
820 (format "$%s%s{%s}$" string-before char
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
821 (match-string 1 string-after)))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
822 (subsup (concat "$" string-before char string-after "$"))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
823 (t (org-export-latex-protect-string
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
824 (concat string-before "\\" char "{}" string-after)))))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
825 (t (org-export-latex-protect-string
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
826 (concat string-before "\\" char "{}" string-after)))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
827
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
828 (defun org-export-latex-treat-backslash-char (string-before string-after)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
829 "Convert the \"$\" special character to LaTeX.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
830 The conversion is made depending of STRING-BEFORE and STRING-AFTER."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
831 (cond ((member (list string-after) org-html-entities)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
832 ;; backslash is part of a special entity (like "\alpha")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
833 (concat string-before "$\\"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
834 (or (cdar (member (list string-after) org-html-entities))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
835 string-after) "$"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
836 ((and (not (string-match "^[ \n\t]" string-after))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
837 (not (string-match "[ \t]\\'\\|^" string-before)))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
838 ;; backslash is inside a word
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
839 (org-export-latex-protect-string
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
840 (concat string-before "\\textbackslash{}" string-after)))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
841 ((not (or (equal string-after "")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
842 (string-match "^[ \t\n]" string-after)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
843 ;; backslash might escape a character (like \#) or a user TeX
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
844 ;; macro (like \setcounter)
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
845 (org-export-latex-protect-string
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
846 (concat string-before "\\" string-after)))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
847 ((and (string-match "^[ \t\n]" string-after)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
848 (string-match "[ \t\n]\\'" string-before))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
849 ;; backslash is alone, convert it to $\backslash$
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
850 (org-export-latex-protect-string
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
851 (concat string-before "\\textbackslash{}" string-after)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
852 (t (org-export-latex-protect-string
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
853 (concat string-before "\\textbackslash{}" string-after)))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
854
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
855 (defun org-export-latex-keywords (timestamps)
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
856 "Convert special keywords to LaTeX.
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
857 Regexps are those from `org-latex-special-string-regexps'."
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
858 (let ((rg org-latex-special-string-regexps) r)
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
859 (while (setq r (pop rg))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
860 (goto-char (point-min))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
861 (while (re-search-forward (eval r) nil t)
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
862 (if (not timestamps)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
863 (replace-match (format "\\\\texttt{%s}" (match-string 0)) t)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
864 (replace-match ""))))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
865
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
866 (defun org-export-latex-fixed-width (opt)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
867 "When OPT is non-nil convert fixed-width sections to LaTeX."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
868 (goto-char (point-min))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
869 ;; FIXME the search shouldn't be performed on already converted text
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
870 (while (re-search-forward "^[ \t]*:" nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
871 (if opt
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
872 (progn (goto-char (match-beginning 0))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
873 (insert "\\begin{verbatim}\n")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
874 (while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
875 (replace-match (concat (match-string 1)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
876 (match-string 2)) t t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
877 (forward-line))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
878 (insert "\\end{verbatim}\n\n"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
879 (progn (goto-char (match-beginning 0))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
880 (while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
881 (replace-match (concat "%" (match-string 1)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
882 (match-string 2)) t t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
883 (forward-line))))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
884
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
885 (defun org-export-latex-lists ()
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
886 "Convert lists to LaTeX."
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
887 (goto-char (point-min))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
888 (while (re-search-forward org-export-latex-list-beginning-re nil t)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
889 (beginning-of-line)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
890 (org-export-list-to-latex
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
891 (org-export-latex-parse-list t))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
892
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
893 (defun org-export-list-to-generic (list params)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
894 "Convert a LIST parsed through `org-export-latex-parse-list' to other formats.
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
895
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
896 Valid parameters are
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
897
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
898 :ustart String to start an unordered list
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
899 :uend String to end an unordered list
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
900
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
901 :ostart String to start an ordered list
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
902 :oend String to end an ordered list
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
903
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
904 :splice When set to t, return only list body lines, don't wrap
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
905 them into :[u/o]start and :[u/o]end. Default is nil.
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
906
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
907 :istart String to start a list item
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
908 :iend String to end a list item
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
909 :isep String to separate items
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
910 :lsep String to separate sublists"
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
911 (interactive)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
912 (let* ((p params) sublist
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
913 (splicep (plist-get p :splice))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
914 (ostart (plist-get p :ostart))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
915 (oend (plist-get p :oend))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
916 (ustart (plist-get p :ustart))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
917 (uend (plist-get p :uend))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
918 (istart (plist-get p :istart))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
919 (iend (plist-get p :iend))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
920 (isep (plist-get p :isep))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
921 (lsep (plist-get p :lsep)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
922 (let ((wrapper
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
923 (cond ((eq (car list) 'ordered)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
924 (concat ostart "\n%s" oend "\n"))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
925 ((eq (car list) 'unordered)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
926 (concat ustart "\n%s" uend "\n"))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
927 rtn)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
928 (while (setq sublist (pop list))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
929 (cond ((symbolp sublist) nil)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
930 ((stringp sublist)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
931 (setq rtn (concat rtn istart sublist iend isep)))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
932 (t
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
933 (setq rtn (concat rtn ;; previous list
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
934 lsep ;; list separator
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
935 (org-export-list-to-generic sublist p)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
936 lsep ;; list separator
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
937 )))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
938 (format wrapper rtn))))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
939
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
940 (defun org-export-list-to-latex (list)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
941 "Convert LIST into a LaTeX list."
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
942 (insert
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
943 (org-export-list-to-generic
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
944 list '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
945 :ustart "\\begin{itemize}" :uend "\\end{itemize}"
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
946 :istart "\\item " :iend ""
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
947 :isep "\n" :lsep "\n"))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
948 ;; Add a trailing \n after list conversion
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
949 "\n"))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
950
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
951 ;; FIXME Use org-export-highlight-first-table-line ?
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
952 (defun org-export-latex-tables (insert)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
953 "Convert tables to LaTeX and INSERT it."
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
954 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
955 (while (re-search-forward "^\\([ \t]*\\)|" nil t)
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
956 ;; FIXME really need to save-excursion?
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
957 (save-excursion (org-table-align))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
958 (let* ((beg (org-table-begin))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
959 (end (org-table-end))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
960 (raw-table (buffer-substring-no-properties beg end))
85554
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
961 fnum fields line lines olines gr colgropen line-fmt align)
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
962 (if org-export-latex-tables-verbatim
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
963 (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
964 "\\end{verbatim}\n")))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
965 (apply 'delete-region (list beg end))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
966 (insert tbl))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
967 (progn
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
968 (setq lines (split-string raw-table "\n" t))
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
969 (apply 'delete-region (list beg end))
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
970 (when org-export-table-remove-special-lines
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
971 (setq lines (org-table-clean-before-export lines)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
972 ;; make a formatting string to reflect aligment
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
973 (setq olines lines)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
974 (while (and (not line-fmt) (setq line (pop olines)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
975 (unless (string-match "^[ \t]*|-" line)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
976 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
977 (setq fnum (make-vector (length fields) 0))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
978 (setq line-fmt
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
979 (mapconcat
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
980 (lambda (x)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
981 (setq gr (pop org-table-colgroup-info))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
982 (format "%s%%s%s"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
983 (cond ((eq gr ':start)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
984 (prog1 (if colgropen "|" "")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
985 (setq colgropen t)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
986 ((eq gr ':startend)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
987 (prog1 (if colgropen "|" "|")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
988 (setq colgropen nil)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
989 (t ""))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
990 (if (memq gr '(:end :startend))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
991 (progn (setq colgropen nil) "|")
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
992 "")))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
993 fnum ""))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
994 ;; maybe remove the first and last "|"
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
995 (when (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
996 (setq line-fmt (match-string 2 line-fmt)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
997 ;; format alignment
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
998 (setq align (apply 'format
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
999 (cons line-fmt
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1000 (mapcar (lambda (x) (if x "r" "l"))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1001 org-table-last-alignment))))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1002 ;; prepare the table to send to orgtbl-to-latex
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1003 (setq lines
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1004 (mapcar
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1005 (lambda(elem)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1006 (or (and (string-match "[ \t]*|-+" elem) 'hline)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1007 (split-string (org-trim elem) "|" t)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1008 lines))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1009 (when insert
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1010 (insert (orgtbl-to-latex
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1011 lines `(:tstart ,(concat "\\begin{tabular}{" align "}")))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1012 "\n\n")))))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1013
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1014 (defun org-export-latex-fontify ()
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1015 "Convert fontification to LaTeX."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1016 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1017 (while (re-search-forward org-emph-re nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1018 ;; The match goes one char after the *string*
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1019 (let ((emph (assoc (match-string 3)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1020 org-export-latex-emphasis-alist))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1021 rpl)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1022 (unless (get-text-property (1- (point)) 'org-protected)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1023 (setq rpl (concat (match-string 1)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1024 (format (org-export-latex-protect-char-in-string
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1025 '("\\" "{" "}") (cadr emph))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1026 (match-string 4))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1027 (match-string 5)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1028 (if (caddr emph)
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1029 (setq rpl (org-export-latex-protect-string rpl)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1030 (replace-match rpl t t)))
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1031 (backward-char)))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1032
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1033 (defun org-export-latex-links ()
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1034 ;; Make sure to use the LaTeX hyperref and graphicx package
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1035 ;; or send some warnings.
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1036 "Convert links to LaTeX."
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1037 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1038 (while (re-search-forward org-bracket-link-analytic-regexp nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1039 (org-if-unprotected
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1040 (goto-char (match-beginning 0))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1041 (let* ((re-radio org-latex-all-targets-regexp)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1042 (remove (list (match-beginning 0) (match-end 0)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1043 (type (match-string 2))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1044 (raw-path (match-string 3))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1045 (full-raw-path (concat (match-string 1) raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1046 (desc (match-string 5))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1047 imgp radiop
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1048 ;; define the path of the link
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1049 (path (cond
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1050 ((member type '("http" "https" "ftp"))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1051 (concat type ":" raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1052 ((and re-radio (string-match re-radio raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1053 (setq radiop t))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1054 ((equal type "mailto")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1055 (concat type ":" raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1056 ((equal type "file")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1057 (if (and (or (org-file-image-p (expand-file-name raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1058 (string-match "\\.eps$" raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1059 (equal desc full-raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1060 (setq imgp t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1061 (progn (when (string-match "\\(.+\\)::.+" raw-path)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1062 (setq raw-path (match-string 1 raw-path)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1063 (if (file-exists-p raw-path)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1064 (concat type "://" (expand-file-name raw-path))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1065 (concat type "://" (org-export-directory
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1066 :LaTeX org-latex-options-plist)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1067 raw-path))))))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1068 ;; process with link inserting
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1069 (apply 'delete-region remove)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1070 (cond ((and imgp (plist-get org-latex-options-plist :inline-images))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1071 (insert (format "\\includegraphics[%s]{%s}"
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1072 ;; image option should be set be a comment line
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1073 org-export-latex-image-default-option
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1074 (expand-file-name raw-path))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1075 ;; FIXME: what about caption? image properties?
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1076 (radiop (insert (format "\\hyperref[%s]{%s}" raw-path desc)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1077 (path (insert (format "\\href{%s}{%s}" path desc)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1078 (t (insert "\\texttt{" desc "}")))))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1079
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1080 (defun org-export-latex-cleaned-string
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1081 ;; FIXME remove commentsp call in org.el and here
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1082 (&optional commentsp)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1083 "Clean stuff in the LaTeX export."
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1084
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1085 ;; Preserve line breaks
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1086 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1087 (while (re-search-forward "\\\\\\\\" nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1088 (add-text-properties (match-beginning 0) (match-end 0)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1089 '(org-protected t)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1090
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1091 ;; Convert LaTeX to \LaTeX{}
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1092 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1093 (let ((case-fold-search nil) rpl)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1094 (while (re-search-forward "\\([^+_]\\)LaTeX" nil t)
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1095 (replace-match (org-export-latex-protect-string
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1096 (concat (match-string 1) "\\LaTeX{}")) t t)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1097
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1098 ;; Convert horizontal rules
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1099 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1100 (while (re-search-forward "^----+.$" nil t)
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1101 (replace-match (org-export-latex-protect-string "\\hrule") t t))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1102
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1103 ;; Protect LaTeX \commands{...}
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1104 (goto-char (point-min))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1105 (while (re-search-forward "\\\\[a-zA-Z]+\\(?:\\[.*\\]\\)?{.*}" nil t)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1106 (add-text-properties (match-beginning 0) (match-end 0)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1107 '(org-protected t)))
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1108
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1109 ;; Replace radio links
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1110 (goto-char (point-min))
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1111 (while (re-search-forward
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1112 (concat "<<<?" org-latex-all-targets-regexp
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1113 ">>>?\\((INVISIBLE)\\)?") nil t)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1114 (replace-match
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1115 (org-export-latex-protect-string
84933
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1116 (format "\\label{%s}%s"(match-string 1)
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1117 (if (match-string 2) "" (match-string 1)))) t t))
d6e2d9d9924a 2007-09-26 Bastien Guerry <bzg@altern.org>
John Wiegley <johnw@newartisans.com>
parents: 84394
diff changeset
1118
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1119 ;; Delete @<...> constructs
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1120 (goto-char (point-min))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1121 ;; Thanks to Daniel Clemente for this regexp
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1122 (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1123 (replace-match ""))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1124
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1125 ;; When converting to LaTeX, replace footnotes
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1126 ;; FIXME: don't protect footnotes from conversion
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1127 (when (plist-get org-latex-options-plist :footnotes)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1128 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1129 (while (re-search-forward "\\[[0-9]+\\]" nil t)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1130 (when (save-match-data
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1131 (save-excursion (beginning-of-line)
85153
c3969e15712b Installed version 5.11b of org-mode
John Wiegley <johnw@newartisans.com>
parents: 84933
diff changeset
1132 (looking-at "[^:|#]")))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1133 (let ((foot-beg (match-beginning 0))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1134 (foot-end (match-end 0))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1135 (foot-prefix (match-string 0))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1136 footnote footnote-rpl)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1137 (when (and (re-search-forward (regexp-quote foot-prefix) nil t))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1138 (replace-match "")
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1139 (let ((end (save-excursion
85554
5b20f92e9f29 Installed org-mode 5.13d
John Wiegley <johnw@newartisans.com>
parents: 85156
diff changeset
1140 (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1141 (match-beginning 0) (point-max)))))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1142 (setq footnote
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1143 (concat
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1144 (org-trim (buffer-substring (point) end))
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1145 ;; FIXME stupid workaround for cases where
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1146 ;; `org-bracket-link-analytic-regexp' matches
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1147 ;; }. as part of the link.
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1148 " "))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1149 (delete-region (point) end)))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1150 (goto-char foot-beg)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1151 (delete-region foot-beg foot-end)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1152 (setq footnote-rpl (format "\\footnote{%s}" footnote))
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1153 (add-text-properties 0 10 '(org-protected t) footnote-rpl)
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1154 (add-text-properties (1- (length footnote-rpl))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1155 (length footnote-rpl)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1156 '(org-protected t) footnote-rpl)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1157 (insert footnote-rpl))))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1158
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1159 ;; Replace footnote section tag for LaTeX
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1160 (goto-char (point-min))
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1161 (while (re-search-forward
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1162 (concat "^" footnote-section-tag-regexp) nil t)
84384
a32093d94b4a Updated to org-mode 5.08
John Wiegley <johnw@newartisans.com>
parents: 83725
diff changeset
1163 (replace-match ""))))
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1164
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1165 (provide 'org-export-latex)
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1166
84394
380656116258 * textmodes/org-export-latex.el: arch-tag restored.
Carsten Dominik <dominik@science.uva.nl>
parents: 84384
diff changeset
1167 ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
82752
b0315a14fb58 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1168 ;;; org-export-latex.el ends here