comparison lisp/org/org-export-latex.el @ 99139:8fa7ef477c04

2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-agenda.el (org-format-agenda-item) (org-agenda-filter-make-matcher): Make sure tags are stored and compared donwcased. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org.el (org-insert-todo-heading): Fix bug with force-heading argument. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-exp.el (org-export-as-ascii): Handle the case that we are bulishing from an indirect buffer. * org-table.el (org-table-copy-down): Fix bug with time stamp increment. * org-mouse.el (org-mouse-features): New option. (org-mode-hook): Turn on features depending on `org-mouse-features'. * org.el (org-insert-heading-respect-content): Force heading creation. (org-insert-heading): keep the folding state of the heading before the inserted one. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-archive.el (org-archive-to-archive-sibling): Handle top level headlines better. 2008-10-26 Bastien Guerry <bzg@altern.org> * org-export-latex.el (org-export-latex-classes): Added \usepackage{graphicx} to the default list of packages. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-agenda.el (org-agenda-filter): Renamed from `org-agenda-filter-tags'. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org.el (org-entry-properties): Add CATEGORY property, iven if it is not defined as a property in this entry. (org-add-log-note): Mask prefix argument when immediately storing the note. * org-agenda.el (org-agenda-filter-effort-default-operator): New option. 2008-10-26 James TD Smith <ahktenzero@mohorovi.cc> * org.el (org-add-log-setup): Bugfix; code to find insertion point after drawers was skipping ahead one line too many, so notes were inserted after the first note instead of before it. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-agenda.el (org-agenda-filter-tags,org-agenda-filter-form): New variables. (org-prepare-agenda): Reset the filter tags. (org-agenda-filter-by-tag, org-agenda-filter-by-tag-show-all): Show filter tags in mode line. * org-table.el (orgtbl-to-html): Bind `html-table-tag' for the formatter. * org-export-latex.el (org-latex-entities-regexp): New constant. (org-export-as-pdf): Use two calls to `shell-command'. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-export-latex.el (org-export-latex-treat-sub-super-char): Honor the {} value of the subsuperscript setting. Make sure that longer subsuperscripts are typeset in a roman font. * org.el (org-clock-update-time-maybe): Compute negative clock intervals correctly. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org.el (org-add-log-setup): Respect `org-log-state-notes-insert-after-drawers'. (org-log-state-notes-insert-after-drawers): New option. (org-todo-trigger-tag-changes): New function. (org-todo): Call `org-todo-trigger-tag-changes'. 2008-10-26 James TD Smith <ahktenzero@mohorovi.cc> * org.el (org-add-log-setup): Only skip drawers if the are immediately after the scheduling keywords. * org-clock.el (org-clock-in-switch-to-state): Allow this to be a function (org-clock-in): If `org-clock-in-switch-to-state' is a function, call it with the current todo state to get the state to switch to when clocking in. (org-clock-in): Use org-indent-line-function to indent clock lines. (org-clock-find-position): Fix indentation of empty clock drawers. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-publish.el (org-publish-org-to): Handle case when org-export-to-pdf does return a file name, not a buffer. (org-publish-org-to-pdf): New function. * org-export-latex.el (org-export-as-pdf) (org-export-as-pdf-and-open): New commands. * org-table.el (org-table-eval-formula): Avoid parsing Calc's HMS forms as ranges. * org-export-latex.el (org-export-latex-lists): Ignore lists-like things in protexted regions. 2008-10-26 Carsten Dominik <dominik@science.uva.nl> * org-export-latex.el (org-export-latex-preprocess): Improve quoting of LaTeX environments.
author Carsten Dominik <dominik@science.uva.nl>
date Sat, 25 Oct 2008 21:32:46 +0000
parents e1cc41b9282d
children e3acb52d33e1
comparison
equal deleted inserted replaced
99138:a479c7f4849d 99139:8fa7ef477c04
2 ;; 2 ;;
3 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc. 3 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Emacs Lisp Archive Entry 5 ;; Emacs Lisp Archive Entry
6 ;; Filename: org-export-latex.el 6 ;; Filename: org-export-latex.el
7 ;; Version: 6.09a 7 ;; Version: 6.10c
8 ;; Author: Bastien Guerry <bzg AT altern DOT org> 8 ;; Author: Bastien Guerry <bzg AT altern DOT org>
9 ;; Maintainer: Bastien Guerry <bzg AT altern DOT org> 9 ;; Maintainer: Bastien Guerry <bzg AT altern DOT org>
10 ;; Keywords: org, wp, tex 10 ;; Keywords: org, wp, tex
11 ;; Description: Converts an org-mode buffer into LaTeX 11 ;; Description: Converts an org-mode buffer into LaTeX
12 ;; URL: http://www.cognition.ens.fr/~guerry/u/org-export-latex.el 12 ;; URL: http://www.cognition.ens.fr/~guerry/u/org-export-latex.el
34 ;; (require 'org-export-latex) 34 ;; (require 'org-export-latex)
35 ;; 35 ;;
36 ;; The interactive functions are similar to those of the HTML exporter: 36 ;; The interactive functions are similar to those of the HTML exporter:
37 ;; 37 ;;
38 ;; M-x `org-export-as-latex' 38 ;; M-x `org-export-as-latex'
39 ;; M-x `org-export-as-pdf'
40 ;; M-x `org-export-as-pdf-and-open'
39 ;; M-x `org-export-as-latex-batch' 41 ;; M-x `org-export-as-latex-batch'
40 ;; M-x `org-export-as-latex-to-buffer' 42 ;; M-x `org-export-as-latex-to-buffer'
41 ;; M-x `org-export-region-as-latex' 43 ;; M-x `org-export-region-as-latex'
42 ;; M-x `org-replace-region-by-latex' 44 ;; M-x `org-replace-region-by-latex'
43 ;; 45 ;;
86 (defcustom org-export-latex-classes 88 (defcustom org-export-latex-classes
87 '(("article" 89 '(("article"
88 "\\documentclass[11pt,a4paper]{article} 90 "\\documentclass[11pt,a4paper]{article}
89 \\usepackage[utf8]{inputenc} 91 \\usepackage[utf8]{inputenc}
90 \\usepackage[T1]{fontenc} 92 \\usepackage[T1]{fontenc}
93 \\usepackage{graphicx}
91 \\usepackage{hyperref}" 94 \\usepackage{hyperref}"
92 ("\\section{%s}" . "\\section*{%s}") 95 ("\\section{%s}" . "\\section*{%s}")
93 ("\\subsection{%s}" . "\\subsection*{%s}") 96 ("\\subsection{%s}" . "\\subsection*{%s}")
94 ("\\subsubsection{%s}" . "\\subsubsection*{%s}") 97 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
95 ("\\paragraph{%s}" . "\\paragraph*{%s}") 98 ("\\paragraph{%s}" . "\\paragraph*{%s}")
96 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")) 99 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
97 ("report" 100 ("report"
98 "\\documentclass[11pt,a4paper]{report} 101 "\\documentclass[11pt,a4paper]{report}
99 \\usepackage[utf8]{inputenc} 102 \\usepackage[utf8]{inputenc}
100 \\usepackage[T1]{fontenc} 103 \\usepackage[T1]{fontenc}
104 \\usepackage{graphicx}
101 \\usepackage{hyperref}" 105 \\usepackage{hyperref}"
102 ("\\part{%s}" . "\\part*{%s}") 106 ("\\part{%s}" . "\\part*{%s}")
103 ("\\chapter{%s}" . "\\chapter*{%s}") 107 ("\\chapter{%s}" . "\\chapter*{%s}")
104 ("\\section{%s}" . "\\section*{%s}") 108 ("\\section{%s}" . "\\section*{%s}")
105 ("\\subsection{%s}" . "\\subsection*{%s}") 109 ("\\subsection{%s}" . "\\subsection*{%s}")
106 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")) 110 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
107 ("book" 111 ("book"
108 "\\documentclass[11pt,a4paper]{book} 112 "\\documentclass[11pt,a4paper]{book}
109 \\usepackage[utf8]{inputenc} 113 \\usepackage[utf8]{inputenc}
110 \\usepackage[T1]{fontenc} 114 \\usepackage[T1]{fontenc}
115 \\usepackage{graphicx}
111 \\usepackage{hyperref}" 116 \\usepackage{hyperref}"
112 ("\\part{%s}" . "\\part*{%s}") 117 ("\\part{%s}" . "\\part*{%s}")
113 ("\\chapter{%s}" . "\\chapter*{%s}") 118 ("\\chapter{%s}" . "\\chapter*{%s}")
114 ("\\section{%s}" . "\\section*{%s}") 119 ("\\section{%s}" . "\\section*{%s}")
115 ("\\subsection{%s}" . "\\subsection*{%s}") 120 ("\\subsection{%s}" . "\\subsection*{%s}")
118 If #+LaTeX_CLASS is set in the buffer, use its value and the 123 If #+LaTeX_CLASS is set in the buffer, use its value and the
119 associated information. Here is the structure of each cell: 124 associated information. Here is the structure of each cell:
120 125
121 \(class-name 126 \(class-name
122 header-string 127 header-string
123 (unnumbered-section numbered-section\) 128 (numbered-section . unnumbered-section\)
124 ...\) 129 ...\)
125 130
126 A %s formatter is mandatory in each section string and will be 131 A %s formatter is mandatory in each section string and will be
127 replaced by the title of the section." 132 replaced by the title of the section.
133
134 Instead of a cons cell (numbered . unnumbered), you can also provide a list
135 of 2-4 elements,
136
137 (numbered-open numbered-close)
138
139 or
140
141 (numbered-open numbered-close unnumbered-open unnumbered-close)
142
143 providing opening and closing strings for an environment that should
144 represent the document section. The opening clause should have a %s
145 to represent the section title."
128 :group 'org-export-latex 146 :group 'org-export-latex
129 :type '(repeat 147 :type '(repeat
130 (list (string :tag "LaTeX class") 148 (list (string :tag "LaTeX class")
131 (string :tag "LaTeX header") 149 (string :tag "LaTeX header")
132 (cons :tag "Level 1" 150 (repeat :tag "Levels" :inline t
133 (string :tag "Numbered") 151 (choice
134 (string :tag "Unnumbered")) 152 (cons :tag "Heading"
135 (cons :tag "Level 2" 153 (string :tag "numbered")
136 (string :tag "Numbered") 154 (string :tag "unnumbered)"))
137 (string :tag "Unnumbered")) 155 (list :tag "Environment"
138 (cons :tag "Level 3" 156 (string :tag "Opening (numbered) ")
139 (string :tag "Numbered") 157 (string :tag "Closing (numbered) ")
140 (string :tag "Unnumbered")) 158 (string :tag "Opening (unnumbered)")
141 (cons :tag "Level 4" 159 (string :tag "Closing (unnumbered)")))))))
142 (string :tag "Numbered")
143 (string :tag "Unnumbered"))
144 (cons :tag "Level 5"
145 (string :tag "Numbered")
146 (string :tag "Unnumbered")))))
147 160
148 (defcustom org-export-latex-emphasis-alist 161 (defcustom org-export-latex-emphasis-alist
149 '(("*" "\\textbf{%s}" nil) 162 '(("*" "\\textbf{%s}" nil)
150 ("/" "\\emph{%s}" nil) 163 ("/" "\\emph{%s}" nil)
151 ("_" "\\underline{%s}" nil) 164 ("_" "\\underline{%s}" nil)
221 234
222 (defcustom org-export-latex-coding-system nil 235 (defcustom org-export-latex-coding-system nil
223 "Coding system for the exported LaTex file." 236 "Coding system for the exported LaTex file."
224 :group 'org-export-latex 237 :group 'org-export-latex
225 :type 'coding-system) 238 :type 'coding-system)
239
240 (defgroup org-export-pdf nil
241 "Options for exporting Org-mode files to PDF, via LaTeX."
242 :tag "Org Export LaTeX"
243 :group 'org-export-latex
244 :group 'org-export)
245
246 (defcustom org-export-pdf-remove-logfiles t
247 "Non-nil means, remove the logfiles produced by PDF production.
248 These are the .aux, .log, .out, and .toc files."
249 :group 'org-export-latex
250 :type 'boolean)
226 251
227 ;;; Autoload functions: 252 ;;; Autoload functions:
228 253
229 ;;;###autoload 254 ;;;###autoload
230 (defun org-export-as-latex-batch () 255 (defun org-export-as-latex-batch ()
452 (prog1 (buffer-substring (point-min) (point-max)) 477 (prog1 (buffer-substring (point-min) (point-max))
453 (kill-buffer (current-buffer))) 478 (kill-buffer (current-buffer)))
454 (current-buffer)) 479 (current-buffer))
455 (set-window-configuration wcf)))) 480 (set-window-configuration wcf))))
456 481
482 ;;;###autoload
483 (defun org-export-as-pdf (arg &optional hidden ext-plist
484 to-buffer body-only pub-dir)
485 "Export as LaTeX, then process through to PDF."
486 (interactive "P")
487 (message "Exporting to PDF...")
488 (let* ((wconfig (current-window-configuration))
489 (lbuf (org-export-as-latex arg hidden ext-plist
490 to-buffer body-only pub-dir))
491 (file (buffer-file-name lbuf))
492 (base (file-name-sans-extension (buffer-file-name lbuf)))
493 (pdffile (concat base ".pdf")))
494 (and (file-exists-p pdffile) (delete-file pdffile))
495 (message "Processing LaTeX file...")
496 (shell-command (format "pdflatex -interaction nonstopmode %s"
497 (shell-quote-argument file)))
498 (shell-command (format "pdflatex -interaction nonstopmode %s"
499 (shell-quote-argument file)))
500 (message "Processing LaTeX file...done")
501 (if (not (file-exists-p pdffile))
502 (error "PDF file was not produced")
503 (set-window-configuration wconfig)
504 (when org-export-pdf-remove-logfiles
505 (dolist (ext '("aux" "log" "out" "toc"))
506 (setq file (concat base "." ext))
507 (and (file-exists-p file) (delete-file file))))
508 (message "Exporting to PDF...done")
509 pdffile)))
510
511 ;;;###autoload
512 (defun org-export-as-pdf-and-open (arg)
513 "Export as LaTeX, then process through to PDF, and open."
514 (interactive "P")
515 (let ((pdffile (org-export-as-pdf arg)))
516 (if pdffile
517 (org-open-file pdffile)
518 (error "PDF file was not produced"))))
519
457 ;;; Parsing functions: 520 ;;; Parsing functions:
458 521
459 (defun org-export-latex-parse-global (level odd) 522 (defun org-export-latex-parse-global (level odd)
460 "Parse the current buffer recursively, starting at LEVEL. 523 "Parse the current buffer recursively, starting at LEVEL.
461 If ODD is non-nil, assume the buffer only contains odd sections. 524 If ODD is non-nil, assume the buffer only contains odd sections.
552 (subcontent (cadr (assoc 'subcontent subcontent))) 615 (subcontent (cadr (assoc 'subcontent subcontent)))
553 (label (org-get-text-property-any 0 'target heading))) 616 (label (org-get-text-property-any 0 'target heading)))
554 (cond 617 (cond
555 ;; Normal conversion 618 ;; Normal conversion
556 ((<= level org-export-latex-sectioning-depth) 619 ((<= level org-export-latex-sectioning-depth)
557 (let ((sec (nth (1- level) org-export-latex-sectioning))) 620 (let* ((sec (nth (1- level) org-export-latex-sectioning))
558 (insert (format (if num (car sec) (cdr sec)) heading) "\n")) 621 start end)
559 (when label (insert (format "\\label{%s}\n" label))) 622 (if (consp (cdr sec))
560 (insert (org-export-latex-content content)) 623 (setq start (nth (if num 0 2) sec)
561 (cond ((stringp subcontent) (insert subcontent)) 624 end (nth (if num 1 3) sec))
562 ((listp subcontent) (org-export-latex-sub subcontent)))) 625 (setq start (if num (car sec) (cdr sec))))
626 (insert (format start heading) "\n")
627 (when label (insert (format "\\label{%s}\n" label)))
628 (insert (org-export-latex-content content))
629 (cond ((stringp subcontent) (insert subcontent))
630 ((listp subcontent) (org-export-latex-sub subcontent)))
631 (if end (insert end "\n"))))
563 ;; At a level under the hl option: we can drop this subsection 632 ;; At a level under the hl option: we can drop this subsection
564 ((> level org-export-latex-sectioning-depth) 633 ((> level org-export-latex-sectioning-depth)
565 (cond ((eq org-export-latex-low-levels 'description) 634 (cond ((eq org-export-latex-low-levels 'description)
566 (insert (format "\\begin{description}\n\n\\item[%s]%s\n\n" 635 (insert (format "\\begin{description}\n\n\\item[%s]%s\n\n"
567 heading 636 heading
875 (cond ((eq 1 (length string-after)) 944 (cond ((eq 1 (length string-after))
876 (concat string-before char string-after)) 945 (concat string-before char string-after))
877 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after) 946 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
878 (format "%s%s{%s}" string-before char 947 (format "%s%s{%s}" string-before char
879 (match-string 1 string-after)))))) 948 (match-string 1 string-after))))))
880 ((and subsup 949 ((and (> (length string-after) 1)
881 (> (length string-after) 1) 950 (or (eq subsup t)
951 (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
882 (string-match "[({]?\\([^)}]+\\)[)}]?" string-after)) 952 (string-match "[({]?\\([^)}]+\\)[)}]?" string-after))
883 (format "$%s%s{%s}$" string-before char 953 (format "%s$%s{%s}$" string-before char
884 (match-string 1 string-after))) 954 (if (> (match-end 1) (1+ (match-beginning 1)))
885 (subsup (concat "$" string-before char string-after "$")) 955 (concat "\\mathrm{" (match-string 1 string-after) "}")
956 (match-string 1 string-after))))
957 ((eq subsup t) (concat string-before "$" char string-after "$"))
886 (t (org-export-latex-protect-string 958 (t (org-export-latex-protect-string
887 (concat string-before "\\" char "{}" string-after))))) 959 (concat string-before "\\" char "{}" string-after)))))
888 (t (org-export-latex-protect-string 960 (t (org-export-latex-protect-string
889 (concat string-before "\\" char "{}" string-after))))) 961 (concat string-before "\\" char "{}" string-after)))))
890 962
1082 (org-solidify-link-text raw-path) desc))) 1154 (org-solidify-link-text raw-path) desc)))
1083 (path (insert (format "\\href{%s}{%s}" path desc))) 1155 (path (insert (format "\\href{%s}{%s}" path desc)))
1084 (t (insert "\\texttt{" desc "}"))))))) 1156 (t (insert "\\texttt{" desc "}")))))))
1085 1157
1086 (defvar org-latex-entities) ; defined below 1158 (defvar org-latex-entities) ; defined below
1159 (defvar org-latex-entities-regexp) ; defined below
1087 1160
1088 (defun org-export-latex-preprocess () 1161 (defun org-export-latex-preprocess ()
1089 "Clean stuff in the LaTeX export." 1162 "Clean stuff in the LaTeX export."
1090 1163
1091 ;; Preserve line breaks 1164 ;; Preserve line breaks
1094 (add-text-properties (match-beginning 0) (match-end 0) 1167 (add-text-properties (match-beginning 0) (match-end 0)
1095 '(org-protected t))) 1168 '(org-protected t)))
1096 1169
1097 ;; Preserve latex environments 1170 ;; Preserve latex environments
1098 (goto-char (point-min)) 1171 (goto-char (point-min))
1099 (while (search-forward "\\begin{" nil t) 1172 (while (re-search-forward "^[ \t]*\\begin{\\([a-zA-Z]+\\)}" nil t)
1100 (let ((start (progn (beginning-of-line) (point))) 1173 (let* ((start (progn (beginning-of-line) (point)))
1101 (end (or (and (search-forward "\\end{" nil t) 1174 (end (or (and (re-search-forward
1102 (end-of-line) (point)) 1175 (concat "^[ \t]*\\end{" (match-string 1) "}" nil t)
1103 (point-max)))) 1176 (point-at-eol)))
1177 (point-max))))
1104 (add-text-properties start end '(org-protected t)))) 1178 (add-text-properties start end '(org-protected t))))
1105 1179
1106 ;; Convert LaTeX to \LaTeX{} 1180 ;; Convert LaTeX to \LaTeX{}
1107 (goto-char (point-min)) 1181 (goto-char (point-min))
1108 (let ((case-fold-search nil) rpl) 1182 (let ((case-fold-search nil) rpl)
1137 (add-text-properties (match-beginning 0) (match-end 0) 1211 (add-text-properties (match-beginning 0) (match-end 0)
1138 '(org-protected t))) 1212 '(org-protected t)))
1139 1213
1140 ;; Protect LaTeX entities 1214 ;; Protect LaTeX entities
1141 (goto-char (point-min)) 1215 (goto-char (point-min))
1142 (while (re-search-forward (regexp-opt org-latex-entities) nil t) 1216 (while (re-search-forward org-latex-entities-regexp nil t)
1143 (add-text-properties (match-beginning 0) (match-end 0) 1217 (add-text-properties (match-beginning 0) (match-end 0)
1144 '(org-protected t))) 1218 '(org-protected t)))
1145 1219
1146 ;; Replace radio links 1220 ;; Replace radio links
1147 (goto-char (point-min)) 1221 (goto-char (point-min))
1202 (defun org-export-latex-lists () 1276 (defun org-export-latex-lists ()
1203 "Replace plain text lists in current buffer into LaTeX lists." 1277 "Replace plain text lists in current buffer into LaTeX lists."
1204 "Convert lists to LaTeX." 1278 "Convert lists to LaTeX."
1205 (goto-char (point-min)) 1279 (goto-char (point-min))
1206 (while (re-search-forward org-list-beginning-re nil t) 1280 (while (re-search-forward org-list-beginning-re nil t)
1207 (beginning-of-line) 1281 (org-if-unprotected
1208 (insert (org-list-to-latex (org-list-parse-list t)) "\n"))) 1282 (beginning-of-line)
1283 (insert (org-list-to-latex (org-list-parse-list t)) "\n"))))
1209 1284
1210 (defconst org-latex-entities 1285 (defconst org-latex-entities
1211 '("\\!" 1286 '("\\!"
1212 "\\'" 1287 "\\'"
1213 "\\+" 1288 "\\+"
1381 "\\vfill" 1456 "\\vfill"
1382 "\\vline" 1457 "\\vline"
1383 "\\vspace") 1458 "\\vspace")
1384 "A list of LaTeX commands to be protected when performing conversion.") 1459 "A list of LaTeX commands to be protected when performing conversion.")
1385 1460
1461 (defconst org-latex-entities-regexp
1462 (let (names rest)
1463 (dolist (x org-latex-entities)
1464 (if (string-match "[a-z][A-Z]$" x)
1465 (push x names)
1466 (push x rest)))
1467 (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
1468 "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
1469
1386 (provide 'org-export-latex) 1470 (provide 'org-export-latex)
1387 1471
1388 ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad 1472 ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
1389 1473
1390 ;;; org-export-latex.el ends here 1474 ;;; org-export-latex.el ends here