diff lisp/org/org-latex.el @ 111880:a7740098b594

Update to Org mode 7.4
author Carsten Dominik <carsten.dominik@gmail.com>
date Sat, 11 Dec 2010 17:42:53 +0100
parents 5cb272c831e8
children 417b1e4d63cd
line wrap: on
line diff
--- a/lisp/org/org-latex.el	Sat Dec 11 17:41:04 2010 +0200
+++ b/lisp/org/org-latex.el	Sat Dec 11 17:42:53 2010 +0100
@@ -4,7 +4,7 @@
 ;;
 ;; Emacs Lisp Archive Entry
 ;; Filename: org-latex.el
-;; Version: 7.3
+;; Version: 7.4
 ;; Author: Bastien Guerry <bzg AT altern DOT org>
 ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
 ;; Keywords: org, wp, tex
@@ -295,7 +295,14 @@
   :group 'org-export-latex
   :type 'string)
 
-(defcustom org-export-latex-hyperref-format "\\href{%s}{%s}"
+(defcustom org-export-latex-href-format "\\href{%s}{%s}"
+  "A printf format string to be applied to href links.
+The format must contain two %s instances.  The first will be filled with
+the link, the second with the link description."
+  :group 'org-export-latex
+  :type 'string)
+
+(defcustom org-export-latex-hyperref-format "\\hyperref[%s]{%s}"
   "A printf format string to be applied to hyperref links.
 The format must contain two %s instances.  The first will be filled with
 the link, the second with the link description."
@@ -453,12 +460,6 @@
 	   (symbol :tag "Major mode       ")
 	   (string :tag "Listings language"))))
 
-(defcustom org-export-latex-minted-with-line-numbers nil
-  "Should source code line numbers be included when exporting
-with the latex minted package?"
-  :group 'org-export-latex
-  :type 'boolean)
-
 (defcustom org-export-latex-remove-from-headlines
   '(:todo nil :priority nil :tags nil)
   "A plist of keywords to remove from headlines.  OBSOLETE.
@@ -1280,12 +1281,13 @@
      (org-export-apply-macros-in-string org-export-latex-append-header)
      ;; define alert if not yet defined
      "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
+     ;; beginning of the document
+     "\n\\begin{document}\n\n"
      ;; insert the title
      (format
       "\n\n\\title{%s}\n"
       ;; convert the title
-      (org-export-latex-content
-       title '(lists tables fixed-width keywords)))
+      (org-export-latex-fontify-headline title))
      ;; insert author info
      (if (plist-get opt-plist :author-info)
 	 (format "\\author{%s}\n"
@@ -1297,8 +1299,6 @@
 	     (format-time-string
 	      (or (plist-get opt-plist :date)
 		  org-export-latex-date-format)))
-     ;; beginning of the document
-     "\n\\begin{document}\n\n"
      ;; insert the title command
      (when (string-match "\\S-" title)
        (if (string-match "%s" org-export-latex-title-command)
@@ -1325,7 +1325,7 @@
   (save-excursion
     (goto-char (or beg (point-min)))
     (let* ((pt (point))
-	   (end (if (re-search-forward "^\\*+ " end t)
+	   (end (if (re-search-forward (org-get-limited-outline-regexp) end t)
 		    (goto-char (match-beginning 0))
 		  (goto-char (or end (point-max))))))
       (prog1
@@ -1452,6 +1452,33 @@
     ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
     ;; the beginning of the buffer - inserting "\n" is safe here though.
     (insert "\n" string)
+
+    ;; Preserve math snippets
+    
+    (let* ((matchers (plist-get org-format-latex-options :matchers))
+	   (re-list org-latex-regexps)
+	   beg end re e m n block off)
+      ;; Check the different regular expressions
+      (while (setq e (pop re-list))
+	(setq m (car e) re (nth 1 e) n (nth 2 e)
+	      block (if (nth 3 e) "\n\n" ""))
+	(setq off (if (member m '("$" "$1")) 1 0))
+	(when (and (member m matchers) (not (equal m "begin")))
+	  (goto-char (point-min))
+	  (while (re-search-forward re nil t)
+	    (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
+	    (add-text-properties beg end
+				 '(org-protected t org-latex-math t))))))
+
+    ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
+    (goto-char (point-min))
+    (let ((case-fold-search nil))
+      (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
+	(unless (eq (char-before (match-beginning 1)) ?\\)
+	  (org-if-unprotected-1
+	   (replace-match (org-export-latex-protect-string
+			   (concat "\\" (match-string 1)
+				   "{}")) t t)))))
     (goto-char (point-min))
     (let ((re (concat "\\\\\\([a-zA-Z]+\\)"
 		      "\\(?:<[^<>\n]*>\\)*"
@@ -2016,10 +2043,10 @@
 	      (insert (format
 		       (org-export-get-coderef-format path desc)
 		       (cdr (assoc path org-export-code-refs)))))
-	     (radiop (insert (format "\\hyperref[%s]{%s}"
+	     (radiop (insert (format org-export-latex-hyperref-format
 				     (org-solidify-link-text raw-path) desc)))
 	     ((not type)
-	      (insert (format "\\hyperref[%s]{%s}"
+	      (insert (format org-export-latex-hyperref-format
 			      (org-remove-initial-hash
 			       (org-solidify-link-text raw-path))
 			      desc)))
@@ -2030,7 +2057,7 @@
 		;; a LaTeX issue, but we here implement a work-around anyway.
 		(setq path (org-export-latex-protect-amp path)
 		      desc (org-export-latex-protect-amp desc)))
-	      (insert (format org-export-latex-hyperref-format path desc)))
+	      (insert (format org-export-latex-href-format path desc)))
 
 	     ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
 	      ;; The link protocol has a function for formatting the link
@@ -2356,7 +2383,7 @@
 			   "\n"
 			   (match-string 1 res))
 		   t t res)))
-      (insert res "\n"))))
+      (insert res))))
 
 (defconst org-latex-entities
  '("\\!"