annotate lisp/textmodes/org-export-latex.el @ 83982:50edbbeae27a

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