annotate lisp/textmodes/org-export-latex.el @ 84933:d6e2d9d9924a

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