Browse Source

Manage variables related to both LaTeX export and snippets

* lisp/org.el (org-format-latex-header-extra, org-export-have-math):
  Removed variables.
(org-latex-default-packages-alist): Renamed from
`org-export-latex-default-packages-alist'.
(org-latex-packages-alist): Renamed from
`org-export-latex-packages-alist'.
(org-try-cdlatex-tab, org-cdlatex-underscore-caret,
org-cdlatex-math-modify): Reorder in file.
(org-format-latex): Remove `org-format-latex-header-extra'.
(org-create-formula-image-with-dvipng,
org-create-formula-image-with-imagemagick): Apply variables renaming
and removal.
* lisp/org-entities.el (org-entities-user): Update docstring.
* lisp/ox-latex.el (org-latex-classes, org-latex-listings): Update
  docstring.
(org-latex-guess-inputenc): Renamed from `org-latex--guess-inputenc'.
(org-latex-guess-babel-language): Renamed from
`org-latex--guess-babel-language'.
(org-latex-template): Apply renaming.
* lisp/ox-beamer.el (org-beamer-template): Apply renaming.
* lisp/ob-latex.el (org-babel-execute:latex): Apply variable renaming
  and removal.
(org-babel-latex-tex-to-pdf): Call `org-latex-compile' instead of
copying it.
Nicolas Goaziou 13 years ago
parent
commit
0484c5c64d
5 changed files with 183 additions and 222 deletions
  1. 18 67
      lisp/ob-latex.el
  2. 2 2
      lisp/org-entities.el
  3. 120 113
      lisp/org.el
  4. 4 4
      lisp/ox-beamer.el
  5. 39 36
      lisp/ox-latex.el

+ 18 - 67
lisp/ob-latex.el

@@ -35,19 +35,16 @@
 (declare-function org-create-formula-image "org" (string tofile options buffer))
 (declare-function org-create-formula-image "org" (string tofile options buffer))
 (declare-function org-splice-latex-header "org"
 (declare-function org-splice-latex-header "org"
 		  (tpl def-pkg pkg snippets-p &optional extra))
 		  (tpl def-pkg pkg snippets-p &optional extra))
-(declare-function org-latex--guess-inputenc "ox-latex" (header))
+(declare-function org-latex-guess-inputenc "ox-latex" (header))
+(declare-function org-latex-compile "ox-latex" (file))
+
 (defvar org-babel-tangle-lang-exts)
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex"))
 (add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex"))
 
 
-(defvar org-format-latex-header)
-(defvar org-format-latex-header-extra)
-(defvar org-export-latex-packages-alist)
-(defvar org-export-latex-default-packages-alist)
-(defvar org-export-pdf-logfiles)
-(defvar org-latex-to-pdf-process)
-(defvar org-export-pdf-remove-logfiles)
-(defvar org-format-latex-options)
-(defvar org-export-latex-packages-alist)
+(defvar org-format-latex-header)	  ; From org.el
+(defvar org-format-latex-options)	  ; From org.el
+(defvar org-latex-default-packages-alist) ; From org.el
+(defvar org-latex-packages-alist)	  ; From org.el
 
 
 (defvar org-babel-default-header-args:latex
 (defvar org-babel-default-header-args:latex
   '((:results . "latex") (:exports . "results"))
   '((:results . "latex") (:exports . "results"))
@@ -81,18 +78,17 @@ This function is called by `org-babel-execute-src-block'."
 	     (width (and fit (cdr (assoc :pdfwidth params))))
 	     (width (and fit (cdr (assoc :pdfwidth params))))
 	     (headers (cdr (assoc :headers params)))
 	     (headers (cdr (assoc :headers params)))
 	     (in-buffer (not (string= "no" (cdr (assoc :buffer params)))))
 	     (in-buffer (not (string= "no" (cdr (assoc :buffer params)))))
-	     (org-export-latex-packages-alist
-	      (append (cdr (assoc :packages params))
-		      org-export-latex-packages-alist)))
+	     (org-latex-packages-alist
+	      (append (cdr (assoc :packages params)) org-latex-packages-alist)))
         (cond
         (cond
          ((and (string-match "\\.png$" out-file) (not imagemagick))
          ((and (string-match "\\.png$" out-file) (not imagemagick))
           (org-create-formula-image
           (org-create-formula-image
            body out-file org-format-latex-options in-buffer))
            body out-file org-format-latex-options in-buffer))
          ((or (string-match "\\.pdf$" out-file) imagemagick)
          ((or (string-match "\\.pdf$" out-file) imagemagick)
-	  (require 'ox-latex)
 	  (with-temp-file tex-file
 	  (with-temp-file tex-file
+	    (require 'ox-latex)
 	    (insert
 	    (insert
-	     (org-latex--guess-inputenc
+	     (org-latex-guess-inputenc
 	      (org-splice-latex-header
 	      (org-splice-latex-header
 	       org-format-latex-header
 	       org-format-latex-header
 	       (delq
 	       (delq
@@ -101,9 +97,9 @@ This function is called by `org-babel-execute-src-block'."
 		 (lambda (el)
 		 (lambda (el)
 		   (unless (and (listp el) (string= "hyperref" (cadr el)))
 		   (unless (and (listp el) (string= "hyperref" (cadr el)))
 		     el))
 		     el))
-		 org-export-latex-default-packages-alist))
-	       org-export-latex-packages-alist
-	       org-format-latex-header-extra))
+		 org-latex-default-packages-alist))
+	       org-latex-packages-alist
+	       nil))
 	     (if fit "\n\\usepackage[active, tightpage]{preview}\n" "")
 	     (if fit "\n\\usepackage[active, tightpage]{preview}\n" "")
 	     (if border (format "\\setlength{\\PreviewBorder}{%s}" border) "")
 	     (if border (format "\\setlength{\\PreviewBorder}{%s}" border) "")
 	     (if height (concat "\n" (format "\\pdfpageheight %s" height)) "")
 	     (if height (concat "\n" (format "\\pdfpageheight %s" height)) "")
@@ -114,9 +110,6 @@ This function is called by `org-babel-execute-src-block'."
 			     (mapconcat #'identity headers "\n")
 			     (mapconcat #'identity headers "\n")
 			   headers) "\n")
 			   headers) "\n")
 	       "")
 	       "")
-	     (if org-format-latex-header-extra
-		 (concat "\n" org-format-latex-header-extra)
-	       "")
 	     (if fit
 	     (if fit
 		 (concat "\n\\begin{document}\n\\begin{preview}\n" body
 		 (concat "\n\\begin{document}\n\\begin{preview}\n" body
 			 "\n\\end{preview}\n\\end{document}\n")
 			 "\n\\end{preview}\n\\end{document}\n")
@@ -137,7 +130,6 @@ This function is called by `org-babel-execute-src-block'."
         nil) ;; signal that output has already been written to file
         nil) ;; signal that output has already been written to file
     body))
     body))
 
 
-
 (defun convert-pdf (pdffile out-file im-in-options im-out-options)
 (defun convert-pdf (pdffile out-file im-in-options im-out-options)
   "Generate a file from a pdf file using imagemagick."
   "Generate a file from a pdf file using imagemagick."
   (let ((cmd (concat "convert " im-in-options " " pdffile " "
   (let ((cmd (concat "convert " im-in-options " " pdffile " "
@@ -146,55 +138,14 @@ This function is called by `org-babel-execute-src-block'."
     (shell-command cmd)))
     (shell-command cmd)))
 
 
 (defun org-babel-latex-tex-to-pdf (file)
 (defun org-babel-latex-tex-to-pdf (file)
-  "Generate a pdf file according to the contents FILE.
-Extracted from `org-export-as-pdf' in org-latex.el."
-  (let* ((wconfig (current-window-configuration))
-         (default-directory (file-name-directory file))
-         (base (file-name-sans-extension file))
-         (pdffile (concat base ".pdf"))
-         (cmds org-latex-to-pdf-process)
-         (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
-         output-dir cmd)
-    (with-current-buffer outbuf (erase-buffer))
-    (message (concat "Processing LaTeX file " file "..."))
-    (setq output-dir (file-name-directory file))
-    (if (and cmds (symbolp cmds))
-	(funcall cmds (shell-quote-argument file))
-      (while cmds
-	(setq cmd (pop cmds))
-	(while (string-match "%b" cmd)
-	  (setq cmd (replace-match
-		     (save-match-data
-		       (shell-quote-argument base))
-		     t t cmd)))
-	(while (string-match "%f" cmd)
-	  (setq cmd (replace-match
-		     (save-match-data
-		       (shell-quote-argument file))
-		     t t cmd)))
-	(while (string-match "%o" cmd)
-	  (setq cmd (replace-match
-		     (save-match-data
-		       (shell-quote-argument output-dir))
-		     t t cmd)))
-	(shell-command cmd outbuf)))
-    (message (concat "Processing LaTeX file " file "...done"))
-    (if (not (file-exists-p pdffile))
-	(error (concat "PDF file " pdffile " was not produced"))
-      (set-window-configuration wconfig)
-      (when org-export-pdf-remove-logfiles
-	(dolist (ext org-export-pdf-logfiles)
-	  (setq file (concat base "." ext))
-	  (and (file-exists-p file) (delete-file file))))
-      (message "Exporting to PDF...done")
-      pdffile)))
+  "Generate a pdf file according to the contents FILE."
+  (require 'ox-latex)
+  (org-latex-compile file))
 
 
 (defun org-babel-prep-session:latex (session params)
 (defun org-babel-prep-session:latex (session params)
   "Return an error because LaTeX doesn't support sessions."
   "Return an error because LaTeX doesn't support sessions."
   (error "LaTeX does not support sessions"))
   (error "LaTeX does not support sessions"))
 
 
-(provide 'ob-latex)
-
-
 
 
+(provide 'ob-latex)
 ;;; ob-latex.el ends here
 ;;; ob-latex.el ends here

+ 2 - 2
lisp/org-entities.el

@@ -66,8 +66,8 @@ ASCII replacement    Plain ASCII, no extensions.  Symbols that cannot be
 Latin1 replacement   Use the special characters available in latin1.
 Latin1 replacement   Use the special characters available in latin1.
 utf-8 replacement    Use the special characters available in utf-8.
 utf-8 replacement    Use the special characters available in utf-8.
 
 
-If you define new entities here that require specific LaTeX packages to be
-loaded, add these packages to `org-export-latex-packages-alist'."
+If you define new entities here that require specific LaTeX
+packages to be loaded, add these packages to `org-latex-packages-alist'."
   :group 'org-entities
   :group 'org-entities
   :version "24.1"
   :version "24.1"
   :type '(repeat
   :type '(repeat

+ 120 - 113
lisp/org.el

@@ -3628,14 +3628,12 @@ images at the same place."
   "The document header used for processing LaTeX fragments.
   "The document header used for processing LaTeX fragments.
 It is imperative that this header make sure that no page number
 It is imperative that this header make sure that no page number
 appears on the page.  The package defined in the variables
 appears on the page.  The package defined in the variables
-`org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
-will either replace the placeholder \"[PACKAGES]\" in this header, or they
-will be appended."
+`org-latex-default-packages-alist' and `org-latex-packages-alist'
+will either replace the placeholder \"[PACKAGES]\" in this
+header, or they will be appended."
   :group 'org-latex
   :group 'org-latex
   :type 'string)
   :type 'string)
 
 
-(defvar org-format-latex-header-extra nil)
-
 (defun org-set-packages-alist (var val)
 (defun org-set-packages-alist (var val)
   "Set the packages alist and make sure it has 3 elements per entry."
   "Set the packages alist and make sure it has 3 elements per entry."
   (set var (mapcar (lambda (x)
   (set var (mapcar (lambda (x)
@@ -3645,7 +3643,6 @@ will be appended."
 		   val)))
 		   val)))
 
 
 (defun org-get-packages-alist (var)
 (defun org-get-packages-alist (var)
-
   "Get the packages alist and make sure it has 3 elements per entry."
   "Get the packages alist and make sure it has 3 elements per entry."
   (mapcar (lambda (x)
   (mapcar (lambda (x)
 	    (if (and (consp x) (= (length x) 2))
 	    (if (and (consp x) (= (length x) 2))
@@ -3653,10 +3650,7 @@ will be appended."
 	      x))
 	      x))
 	  (default-value var)))
 	  (default-value var)))
 
 
-;; The following variables are defined here because is it also used
-;; when formatting latex fragments.  Originally it was part of the
-;; LaTeX exporter, which is why the name includes "export".
-(defcustom org-export-latex-default-packages-alist
+(defcustom org-latex-default-packages-alist
   '(("AUTO" "inputenc"  t)
   '(("AUTO" "inputenc"  t)
     ("T1"   "fontenc"   t)
     ("T1"   "fontenc"   t)
     (""     "fixltx2e"  nil)
     (""     "fixltx2e"  nil)
@@ -3671,29 +3665,33 @@ will be appended."
     (""     "latexsym"  t)
     (""     "latexsym"  t)
     (""     "amssymb"   t)
     (""     "amssymb"   t)
     (""     "hyperref"  nil)
     (""     "hyperref"  nil)
-    "\\tolerance=1000"
-    )
+    "\\tolerance=1000")
   "Alist of default packages to be inserted in the header.
   "Alist of default packages to be inserted in the header.
-Change this only if one of the packages here causes an incompatibility
-with another package you are using.
-The packages in this list are needed by one part or another of Org-mode
-to function properly.
+
+Change this only if one of the packages here causes an
+incompatibility with another package you are using.
+
+The packages in this list are needed by one part or another of
+Org mode to function properly:
 
 
 - inputenc, fontenc:  for basic font and character selection
 - inputenc, fontenc:  for basic font and character selection
-- textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
-  for interpreting the entities in `org-entities'.  You can skip some of these
-  packages if you don't use any of the symbols in it.
+- textcomp, marvosymb, wasysym, latexsym, amssym: for various
+  symbols used for interpreting the entities in `org-entities'.
+  You can skip some of these packages if you don't use any of the
+  symbols in it.
 - graphicx: for including images
 - graphicx: for including images
 - float, wrapfig: for figure placement
 - float, wrapfig: for figure placement
 - longtable: for long tables
 - longtable: for long tables
 - hyperref: for cross references
 - hyperref: for cross references
 
 
-Therefore you should not modify this variable unless you know what you
-are doing.  The one reason to change it anyway is that you might be loading
-some other package that conflicts with one of the default packages.
-Each cell is of the format \( \"options\" \"package\" snippet-flag\).
-If SNIPPET-FLAG is t, the package also needs to be included when
-compiling LaTeX snippets into images for inclusion into HTML."
+Therefore you should not modify this variable unless you know
+what you are doing.  The one reason to change it anyway is that
+you might be loading some other package that conflicts with one
+of the default packages.  Each cell is of the format
+\( \"options\" \"package\" snippet-flag).  If SNIPPET-FLAG is t,
+the package also needs to be included when compiling LaTeX
+snippets into images for inclusion into non-LaTeX output."
+  :group 'org-latex
   :group 'org-export-latex
   :group 'org-export-latex
   :set 'org-set-packages-alist
   :set 'org-set-packages-alist
   :get 'org-get-packages-alist
   :get 'org-get-packages-alist
@@ -3706,17 +3704,25 @@ compiling LaTeX snippets into images for inclusion into HTML."
 		 (boolean :tag "Snippet"))
 		 (boolean :tag "Snippet"))
 	   (string :tag "A line of LaTeX"))))
 	   (string :tag "A line of LaTeX"))))
 
 
-(defcustom org-export-latex-packages-alist nil
+(defcustom org-latex-packages-alist nil
   "Alist of packages to be inserted in every LaTeX header.
   "Alist of packages to be inserted in every LaTeX header.
-These will be inserted after `org-export-latex-default-packages-alist'.
-Each cell is of the format \( \"options\" \"package\" snippet-flag \).
-SNIPPET-FLAG, when t, indicates that this package is also needed when
-turning LaTeX snippets into images for inclusion into HTML.
+
+These will be inserted after `org-latex-default-packages-alist'.
+Each cell is of the format:
+
+    \(\"options\" \"package\" snippet-flag)
+
+SNIPPET-FLAG, when t, indicates that this package is also needed
+when turning LaTeX snippets into images for inclusion into
+non-LaTeX output.
+
 Make sure that you only list packages here which:
 Make sure that you only list packages here which:
-- you want in every file
-- do not conflict with the default packages in
-  `org-export-latex-default-packages-alist'
-- do not conflict with the setup in `org-format-latex-header'."
+
+  - you want in every file
+  - do not conflict with the setup in `org-format-latex-header'.
+  - do not conflict with the default packages in
+    `org-latex-default-packages-alist'."
+  :group 'org-latex
   :group 'org-export-latex
   :group 'org-export-latex
   :set 'org-set-packages-alist
   :set 'org-set-packages-alist
   :get 'org-get-packages-alist
   :get 'org-get-packages-alist
@@ -3728,7 +3734,6 @@ Make sure that you only list packages here which:
 		 (boolean :tag "Snippet"))
 		 (boolean :tag "Snippet"))
 	   (string :tag "A line of LaTeX"))))
 	   (string :tag "A line of LaTeX"))))
 
 
-
 (defgroup org-appearance nil
 (defgroup org-appearance nil
   "Settings for Org-mode appearance."
   "Settings for Org-mode appearance."
   :tag "Org Appearance"
   :tag "Org Appearance"
@@ -4035,7 +4040,6 @@ Normal means, no org-mode-specific context."
 (declare-function org-indent-mode "org-indent" (&optional arg))
 (declare-function org-indent-mode "org-indent" (&optional arg))
 (declare-function parse-time-string "parse-time" (string))
 (declare-function parse-time-string "parse-time" (string))
 (declare-function org-attach-reveal "org-attach" (&optional if-exists))
 (declare-function org-attach-reveal "org-attach" (&optional if-exists))
-(declare-function org-latex--guess-inputenc "ox-latex" (header))
 (declare-function orgtbl-send-table "org-table" (&optional maybe))
 (declare-function orgtbl-send-table "org-table" (&optional maybe))
 (defvar remember-data-file)
 (defvar remember-data-file)
 (defvar texmathp-why)
 (defvar texmathp-why)
@@ -4151,7 +4155,7 @@ If TABLE-TYPE is non-nil, also check for table.el-type tables."
 
 
 (declare-function org-export-get-environment "ox"
 (declare-function org-export-get-environment "ox"
 		  (&optional backend subtreep ext-plist))
 		  (&optional backend subtreep ext-plist))
-(declare-function org-latex--guess-inputenc "ox-latex" (header))
+(declare-function org-latex-guess-inputenc "ox-latex" (header))
 
 
 ;; Declare and autoload functions from org-agenda.el
 ;; Declare and autoload functions from org-agenda.el
 
 
@@ -17413,7 +17417,9 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 	  (org-uniquify org-todo-keyword-alist-for-agenda)
 	  (org-uniquify org-todo-keyword-alist-for-agenda)
 	  org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
 	  org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
 
 
-;;;; Embedded LaTeX
+
+
+;;;; CDLaTeX minor mode
 
 
 (defvar org-cdlatex-mode-map (make-sparse-keymap)
 (defvar org-cdlatex-mode-map (make-sparse-keymap)
   "Keymap for the minor `org-cdlatex-mode'.")
   "Keymap for the minor `org-cdlatex-mode'.")
@@ -17463,6 +17469,58 @@ an embedded LaTeX fragment, let texmathp do its job.
   "Unconditionally turn on `org-cdlatex-mode'."
   "Unconditionally turn on `org-cdlatex-mode'."
   (org-cdlatex-mode 1))
   (org-cdlatex-mode 1))
 
 
+(defun org-try-cdlatex-tab ()
+  "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
+It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
+  - inside a LaTeX fragment, or
+  - after the first word in a line, where an abbreviation expansion could
+    insert a LaTeX environment."
+  (when org-cdlatex-mode
+    (cond
+     ;; Before any word on the line: No expansion possible.
+     ((save-excursion (skip-chars-backward " \t") (bolp)) nil)
+     ;; Just after first word on the line: Expand it.  Make sure it
+     ;; cannot happen on headlines, though.
+     ((save-excursion
+	(skip-chars-backward "a-zA-Z0-9*")
+	(skip-chars-backward " \t")
+	(and (bolp) (not (org-at-heading-p))))
+      (cdlatex-tab) t)
+     ((org-inside-LaTeX-fragment-p) (cdlatex-tab) t))))
+
+(defun org-cdlatex-underscore-caret (&optional arg)
+  "Execute `cdlatex-sub-superscript' in LaTeX fragments.
+Revert to the normal definition outside of these fragments."
+  (interactive "P")
+  (if (org-inside-LaTeX-fragment-p)
+      (call-interactively 'cdlatex-sub-superscript)
+    (let (org-cdlatex-mode)
+      (call-interactively (key-binding (vector last-input-event))))))
+
+(defun org-cdlatex-math-modify (&optional arg)
+  "Execute `cdlatex-math-modify' in LaTeX fragments.
+Revert to the normal definition outside of these fragments."
+  (interactive "P")
+  (if (org-inside-LaTeX-fragment-p)
+      (call-interactively 'cdlatex-math-modify)
+    (let (org-cdlatex-mode)
+      (call-interactively (key-binding (vector last-input-event))))))
+
+
+
+;;;; LaTeX fragments
+
+(defvar org-latex-regexps
+  '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
+    ;; ("$" "\\([ 	(]\\|^\\)\\(\\(\\([$]\\)\\([^ 	\r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ 	\r\n,.$]\\)\\4\\)\\)\\([ 	.,?;:'\")]\\|$\\)" 2 nil)
+    ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
+    ("$1" "\\([^$]\\|^\\)\\(\\$[^ 	\r\n,;.$]\\$\\)\\([- 	.,?;:'\")\000]\\|$\\)" 2 nil)
+    ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ 	\r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ 	\r\n,.$]\\)\\$\\)\\)\\([- 	.,?;:'\")\000]\\|$\\)" 2 nil)
+    ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
+    ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
+    ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
+  "Regular expressions for matching embedded LaTeX.")
+
 (defun org-inside-LaTeX-fragment-p ()
 (defun org-inside-LaTeX-fragment-p ()
   "Test if point is inside a LaTeX fragment.
   "Test if point is inside a LaTeX fragment.
 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
@@ -17513,43 +17571,6 @@ looks only before point, not after."
     (org-in-regexp
     (org-in-regexp
      "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
      "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
 
 
-(defun org-try-cdlatex-tab ()
-  "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
-It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
-  - inside a LaTeX fragment, or
-  - after the first word in a line, where an abbreviation expansion could
-    insert a LaTeX environment."
-  (when org-cdlatex-mode
-    (cond
-     ;; Before any word on the line: No expansion possible.
-     ((save-excursion (skip-chars-backward " \t") (bolp)) nil)
-     ;; Just after first word on the line: Expand it.  Make sure it
-     ;; cannot happen on headlines, though.
-     ((save-excursion
-	(skip-chars-backward "a-zA-Z0-9*")
-	(skip-chars-backward " \t")
-	(and (bolp) (not (org-at-heading-p))))
-      (cdlatex-tab) t)
-     ((org-inside-LaTeX-fragment-p) (cdlatex-tab) t))))
-
-(defun org-cdlatex-underscore-caret (&optional arg)
-  "Execute `cdlatex-sub-superscript' in LaTeX fragments.
-Revert to the normal definition outside of these fragments."
-  (interactive "P")
-  (if (org-inside-LaTeX-fragment-p)
-      (call-interactively 'cdlatex-sub-superscript)
-    (let (org-cdlatex-mode)
-      (call-interactively (key-binding (vector last-input-event))))))
-
-(defun org-cdlatex-math-modify (&optional arg)
-  "Execute `cdlatex-math-modify' in LaTeX fragments.
-Revert to the normal definition outside of these fragments."
-  (interactive "P")
-  (if (org-inside-LaTeX-fragment-p)
-      (call-interactively 'cdlatex-math-modify)
-    (let (org-cdlatex-mode)
-      (call-interactively (key-binding (vector last-input-event))))))
-
 (defvar org-latex-fragment-image-overlays nil
 (defvar org-latex-fragment-image-overlays nil
   "List of overlays carrying the images of latex fragments.")
   "List of overlays carrying the images of latex fragments.")
 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
@@ -17604,18 +17625,6 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
 	 org-latex-create-formula-image-program)
 	 org-latex-create-formula-image-program)
 	(message msg "done.  Use `C-c C-c' to remove images.")))))
 	(message msg "done.  Use `C-c C-c' to remove images.")))))
 
 
-(defvar org-latex-regexps
-  '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
-    ;; ("$" "\\([ 	(]\\|^\\)\\(\\(\\([$]\\)\\([^ 	\r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ 	\r\n,.$]\\)\\4\\)\\)\\([ 	.,?;:'\")]\\|$\\)" 2 nil)
-    ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
-    ("$1" "\\([^$]\\|^\\)\\(\\$[^ 	\r\n,;.$]\\$\\)\\([- 	.,?;:'\")\000]\\|$\\)" 2 nil)
-    ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ 	\r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ 	\r\n,.$]\\)\\$\\)\\)\\([- 	.,?;:'\")\000]\\|$\\)" 2 nil)
-    ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
-    ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
-    ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
-  "Regular expressions for matching embedded LaTeX.")
-
-(defvar org-export-have-math nil) ;; dynamic scoping
 (defun org-format-latex (prefix &optional dir overlays msg at
 (defun org-format-latex (prefix &optional dir overlays msg at
 				forbuffer processing-type)
 				forbuffer processing-type)
   "Replace LaTeX fragments with links to an image, and produce images.
   "Replace LaTeX fragments with links to an image, and produce images.
@@ -17629,8 +17638,6 @@ Some of the options can be changed using the variable
 	 (optnew org-format-latex-options)
 	 (optnew org-format-latex-options)
 	 (matchers (plist-get opt :matchers))
 	 (matchers (plist-get opt :matchers))
 	 (re-list org-latex-regexps)
 	 (re-list org-latex-regexps)
-	 (org-format-latex-header-extra
-	  (plist-get (org-export-get-environment) :latex-header-extra))
 	 (cnt 0) txt hash link beg end re e checkdir
 	 (cnt 0) txt hash link beg end re e checkdir
 	 string
 	 string
 	 m n block-type block linkfile movefile ov)
 	 m n block-type block linkfile movefile ov)
@@ -17646,7 +17653,6 @@ Some of the options can be changed using the variable
 			 (not (eq (get-char-property (match-beginning n)
 			 (not (eq (get-char-property (match-beginning n)
 						     'org-overlay-type)
 						     'org-overlay-type)
 				  'org-latex-overlay))))
 				  'org-latex-overlay))))
-	    (setq org-export-have-math t)
 	    (cond
 	    (cond
 	     ((eq processing-type 'verbatim))
 	     ((eq processing-type 'verbatim))
 	     ((eq processing-type 'mathjax)
 	     ((eq processing-type 'mathjax)
@@ -17659,16 +17665,17 @@ Some of the options can be changed using the variable
 		  (insert (concat "\\(" (substring string 1 -1) "\\)")))))
 		  (insert (concat "\\(" (substring string 1 -1) "\\)")))))
 	     ((or (eq processing-type 'dvipng)
 	     ((or (eq processing-type 'dvipng)
 		  (eq processing-type 'imagemagick))
 		  (eq processing-type 'imagemagick))
-	      ;; Process to an image
+	      ;; Process to an image.
 	      (setq txt (match-string n)
 	      (setq txt (match-string n)
 		    beg (match-beginning n) end (match-end n)
 		    beg (match-beginning n) end (match-end n)
 		    cnt (1+ cnt))
 		    cnt (1+ cnt))
 	      (let ((face (face-at-point))
 	      (let ((face (face-at-point))
 		    (fg (plist-get opt :foreground))
 		    (fg (plist-get opt :foreground))
 		    (bg (plist-get opt :background))
 		    (bg (plist-get opt :background))
-		    print-length print-level)         ; make sure full list is printed
+		    ;; Ensure full list is printed.
+		    print-length print-level)
 		(when forbuffer
 		(when forbuffer
-	          ; Get the colors from the face at point
+		  ;; Get the colors from the face at point.
 		  (goto-char beg)
 		  (goto-char beg)
 		  (when (eq fg 'auto)
 		  (when (eq fg 'auto)
 		    (setq fg (face-attribute face :foreground nil 'default)))
 		    (setq fg (face-attribute face :foreground nil 'default)))
@@ -17679,9 +17686,8 @@ Some of the options can be changed using the variable
 		  (plist-put optnew :background bg))
 		  (plist-put optnew :background bg))
 		(setq hash (sha1 (prin1-to-string
 		(setq hash (sha1 (prin1-to-string
 				  (list org-format-latex-header
 				  (list org-format-latex-header
-					org-format-latex-header-extra
-					org-export-latex-default-packages-alist
-					org-export-latex-packages-alist
+					org-latex-default-packages-alist
+					org-latex-packages-alist
 					org-format-latex-options
 					org-format-latex-options
 					forbuffer txt fg bg)))
 					forbuffer txt fg bg)))
 		      linkfile (format "%s_%s.png" prefix hash)
 		      linkfile (format "%s_%s.png" prefix hash)
@@ -17689,7 +17695,7 @@ Some of the options can be changed using the variable
 	      (setq link (concat block "[[file:" linkfile "]]" block))
 	      (setq link (concat block "[[file:" linkfile "]]" block))
 	      (if msg (message msg cnt))
 	      (if msg (message msg cnt))
 	      (goto-char beg)
 	      (goto-char beg)
-	      (unless checkdir ; make sure the directory exists
+	      (unless checkdir	      ; Ensure the directory exists.
 		(setq checkdir t)
 		(setq checkdir t)
 		(or (file-directory-p todir) (make-directory todir t)))
 		(or (file-directory-p todir) (make-directory todir t)))
 	      (unless (file-exists-p movefile)
 	      (unless (file-exists-p movefile)
@@ -17876,12 +17882,11 @@ share a good deal of logic."
       (unless (string= bg "Transparent") (setq bg (org-dvipng-color-format bg))))
       (unless (string= bg "Transparent") (setq bg (org-dvipng-color-format bg))))
     (with-temp-file texfile
     (with-temp-file texfile
       (require 'ox-latex)
       (require 'ox-latex)
-      (insert (org-latex--guess-inputenc
+      (insert (org-latex-guess-inputenc
 	       (org-splice-latex-header
 	       (org-splice-latex-header
 		org-format-latex-header
 		org-format-latex-header
-		org-export-latex-default-packages-alist
-		org-export-latex-packages-alist t
-		org-format-latex-header-extra)))
+		org-latex-default-packages-alist
+		org-latex-packages-alist t)))
       (insert "\n\\begin{document}\n" string "\n\\end{document}\n"))
       (insert "\n\\begin{document}\n" string "\n\\end{document}\n"))
     (let ((dir default-directory))
     (let ((dir default-directory))
       (condition-case nil
       (condition-case nil
@@ -17919,7 +17924,7 @@ share a good deal of logic."
 		  (delete-file (concat texfilebase e))))
 		  (delete-file (concat texfilebase e))))
 	pngfile))))
 	pngfile))))
 
 
-(defvar org-latex-to-pdf-process) ;; Defined in org-latex.el
+(defvar org-latex-pdf-process)		; From ox-latex.el
 (defun org-create-formula-image-with-imagemagick (string tofile options buffer)
 (defun org-create-formula-image-with-imagemagick (string tofile options buffer)
   "This calls convert, which is included into imagemagick."
   "This calls convert, which is included into imagemagick."
   (let* ((tmpdir (if (featurep 'xemacs)
   (let* ((tmpdir (if (featurep 'xemacs)
@@ -17946,12 +17951,11 @@ share a good deal of logic."
 		(if (string= bg "Transparent") "white" bg))))
 		(if (string= bg "Transparent") "white" bg))))
     (with-temp-file texfile
     (with-temp-file texfile
       (require 'ox-latex)
       (require 'ox-latex)
-      (insert (org-latex--guess-inputenc
+      (insert (org-latex-guess-inputenc
 	       (org-splice-latex-header
 	       (org-splice-latex-header
 		org-format-latex-header
 		org-format-latex-header
-		org-export-latex-default-packages-alist
-		org-export-latex-packages-alist t
-		org-format-latex-header-extra)))
+		org-latex-default-packages-alist
+		org-latex-packages-alist t)))
       (insert "\n\\begin{document}\n"
       (insert "\n\\begin{document}\n"
 	      "\\definecolor{fg}{rgb}{" fg "}\n"
 	      "\\definecolor{fg}{rgb}{" fg "}\n"
 	      "\\definecolor{bg}{rgb}{" bg "}\n"
 	      "\\definecolor{bg}{rgb}{" bg "}\n"
@@ -17964,12 +17968,12 @@ share a good deal of logic."
       (condition-case nil
       (condition-case nil
 	  (progn
 	  (progn
 	    (cd tmpdir)
 	    (cd tmpdir)
-	    (setq cmds org-latex-to-pdf-process)
+	    (setq cmds org-latex-pdf-process)
 	    (while cmds
 	    (while cmds
 	      (setq latex-frags-cmds (pop cmds))
 	      (setq latex-frags-cmds (pop cmds))
 	      (if (listp latex-frags-cmds)
 	      (if (listp latex-frags-cmds)
 		  (setq cmds nil)
 		  (setq cmds nil)
-		(setq latex-frags-cmds (list (car org-latex-to-pdf-process)))))
+		(setq latex-frags-cmds (list (car org-latex-pdf-process)))))
 	    (while latex-frags-cmds
 	    (while latex-frags-cmds
 	      (setq cmd (pop latex-frags-cmds))
 	      (setq cmd (pop latex-frags-cmds))
 	      (while (string-match "%b" cmd)
 	      (while (string-match "%b" cmd)
@@ -17980,12 +17984,14 @@ share a good deal of logic."
 	      (while (string-match "%f" cmd)
 	      (while (string-match "%f" cmd)
 		(setq cmd (replace-match
 		(setq cmd (replace-match
 			   (save-match-data
 			   (save-match-data
-			     (shell-quote-argument (file-name-nondirectory texfile)))
+			     (shell-quote-argument
+			      (file-name-nondirectory texfile)))
 			   t t cmd)))
 			   t t cmd)))
 	      (while (string-match "%o" cmd)
 	      (while (string-match "%o" cmd)
 		(setq cmd (replace-match
 		(setq cmd (replace-match
 			   (save-match-data
 			   (save-match-data
-			     (shell-quote-argument (file-name-directory texfile)))
+			     (shell-quote-argument
+			      (file-name-directory texfile)))
 			   t t cmd)))
 			   t t cmd)))
 	      (setq cmd (split-string cmd))
 	      (setq cmd (split-string cmd))
 	      (eval (append (list 'call-process (pop cmd) nil nil nil) cmd))))
 	      (eval (append (list 'call-process (pop cmd) nil nil nil) cmd))))
@@ -18001,7 +18007,7 @@ share a good deal of logic."
 			    "-antialias"
 			    "-antialias"
 			    pdffile
 			    pdffile
 			    "-quality" "100"
 			    "-quality" "100"
-			    ;;			    "-sharpen" "0x1.0"
+			    ;; "-sharpen" "0x1.0"
 			    pngfile)
 			    pngfile)
 	    (call-process "convert" nil nil nil
 	    (call-process "convert" nil nil nil
 			  "-density" dpi
 			  "-density" dpi
@@ -18009,7 +18015,7 @@ share a good deal of logic."
 			  "-antialias"
 			  "-antialias"
 			  pdffile
 			  pdffile
 			  "-quality" "100"
 			  "-quality" "100"
-					;			  "-sharpen" "0x1.0"
+			  ;; "-sharpen" "0x1.0"
 			  pngfile))
 			  pngfile))
 	(error nil))
 	(error nil))
       (if (not (file-exists-p pngfile))
       (if (not (file-exists-p pngfile))
@@ -18121,8 +18127,9 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
   "Return string to be used as color value for an RGB component."
   "Return string to be used as color value for an RGB component."
   (format "%g" (/ value 65535.0)))
   (format "%g" (/ value 65535.0)))
 
 
-;; Image display
 
 
+
+;; Image display
 
 
 (defvar org-inline-image-overlays nil)
 (defvar org-inline-image-overlays nil)
 (make-variable-buffer-local 'org-inline-image-overlays)
 (make-variable-buffer-local 'org-inline-image-overlays)

+ 4 - 4
lisp/ox-beamer.el

@@ -829,12 +829,12 @@ holding export options."
 			"^[ \t]*\\\\documentclass\\(\\(\\[.*\\]\\)?\\)"
 			"^[ \t]*\\\\documentclass\\(\\(\\[.*\\]\\)?\\)"
 			class-options header t nil 1)))))
 			class-options header t nil 1)))))
 	  (when document-class-string
 	  (when document-class-string
-	    (org-latex--guess-babel-language
-	     (org-latex--guess-inputenc
+	    (org-latex-guess-babel-language
+	     (org-latex-guess-inputenc
 	      (org-splice-latex-header
 	      (org-splice-latex-header
 	       document-class-string
 	       document-class-string
-	       org-export-latex-default-packages-alist ; defined in org.el
-	       org-export-latex-packages-alist nil ; defined in org.el
+	       org-latex-default-packages-alist
+	       org-latex-packages-alist nil
 	       (plist-get info :latex-header-extra)))
 	       (plist-get info :latex-header-extra)))
 	     info)))))
 	     info)))))
      ;; 3. Insert themes.
      ;; 3. Insert themes.

+ 39 - 36
lisp/ox-latex.el

@@ -97,8 +97,8 @@
 (require 'ox)
 (require 'ox)
 (require 'ox-publish)
 (require 'ox-publish)
 
 
-(defvar org-export-latex-default-packages-alist)
-(defvar org-export-latex-packages-alist)
+(defvar org-latex-default-packages-alist)
+(defvar org-latex-packages-alist)
 (defvar orgtbl-exp-regexp)
 (defvar orgtbl-exp-regexp)
 
 
 
 
@@ -288,9 +288,9 @@ anything else that is needed for this setup.  To this header, the
 following commands will be added:
 following commands will be added:
 
 
 - Calls to \\usepackage for all packages mentioned in the
 - Calls to \\usepackage for all packages mentioned in the
-  variables `org-export-latex-default-packages-alist' and
-  `org-export-latex-packages-alist'.  Thus, your header
-  definitions should avoid to also request these packages.
+  variables `org-latex-default-packages-alist' and
+  `org-latex-packages-alist'.  Thus, your header definitions
+  should avoid to also request these packages.
 
 
 - Lines specified via \"#+LaTeX_HEADER:\"
 - Lines specified via \"#+LaTeX_HEADER:\"
 
 
@@ -317,15 +317,14 @@ So a header like
 will omit the default packages, and will include the
 will omit the default packages, and will include the
 #+LaTeX_HEADER lines, then have a call to \\providecommand, and
 #+LaTeX_HEADER lines, then have a call to \\providecommand, and
 then place \\usepackage commands based on the content of
 then place \\usepackage commands based on the content of
-`org-export-latex-packages-alist'.
+`org-latex-packages-alist'.
 
 
-If your header, `org-export-latex-default-packages-alist' or
-`org-export-latex-packages-alist' inserts
+If your header, `org-latex-default-packages-alist' or
+`org-latex-packages-alist' inserts
 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
 replaced with a coding system derived from
 replaced with a coding system derived from
 `buffer-file-coding-system'.  See also the variable
 `buffer-file-coding-system'.  See also the variable
-`org-latex-inputenc-alist' for a way to influence this
-mechanism.
+`org-latex-inputenc-alist' for a way to influence this mechanism.
 
 
 The sectioning structure
 The sectioning structure
 ------------------------
 ------------------------
@@ -673,12 +672,12 @@ in order to mimic default behaviour:
 This package will fontify source code, possibly even with color.
 This package will fontify source code, possibly even with color.
 If you want to use this, you also need to make LaTeX use the
 If you want to use this, you also need to make LaTeX use the
 listings package, and if you want to have color, the color
 listings package, and if you want to have color, the color
-package.  Just add these to `org-export-latex-packages-alist',
-for example using customize, or with something like:
+package.  Just add these to `org-latex-packages-alist', for
+example using customize, or with something like:
 
 
   \(require 'ox-latex)
   \(require 'ox-latex)
-  \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"listings\"))
-  \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"color\"))
+  \(add-to-list 'org-latex-packages-alist '\(\"\" \"listings\"))
+  \(add-to-list 'org-latex-packages-alist '\(\"\" \"color\"))
 
 
 Alternatively,
 Alternatively,
 
 
@@ -686,11 +685,11 @@ Alternatively,
 
 
 causes source code to be exported using the minted package as
 causes source code to be exported using the minted package as
 opposed to listings.  If you want to use minted, you need to add
 opposed to listings.  If you want to use minted, you need to add
-the minted package to `org-export-latex-packages-alist', for
-example using customize, or with
+the minted package to `org-latex-packages-alist', for example
+using customize, or with
 
 
   \(require 'ox-latex)
   \(require 'ox-latex)
-  \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"minted\"))
+  \(add-to-list 'org-latex-packages-alist '\(\"\" \"minted\"))
 
 
 In addition, it is necessary to install pygments
 In addition, it is necessary to install pygments
 \(http://pygments.org), and to configure the variable
 \(http://pygments.org), and to configure the variable
@@ -933,7 +932,25 @@ For non-floats, see `org-latex--wrap-label'."
      ;; Standard caption format.
      ;; Standard caption format.
      (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
      (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
 
 
-(defun org-latex--guess-babel-language (header info)
+(defun org-latex-guess-inputenc (header)
+  "Set the coding system in inputenc to what the buffer is.
+
+HEADER is the LaTeX header string.  This function only applies
+when specified inputenc option is \"AUTO\".
+
+Return the new header, as a string."
+  (let* ((cs (or (ignore-errors
+		   (latexenc-coding-system-to-inputenc
+		    buffer-file-coding-system))
+		 "utf8")))
+    (if (not cs) header
+      ;; First translate if that is requested.
+      (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
+      ;; Then find the \usepackage statement and replace the option.
+      (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
+				cs header t nil 1))))
+
+(defun org-latex-guess-babel-language (header info)
   "Set Babel's language according to LANGUAGE keyword.
   "Set Babel's language according to LANGUAGE keyword.
 
 
 HEADER is the LaTeX header string.  INFO is the plist used as
 HEADER is the LaTeX header string.  INFO is the plist used as
@@ -962,20 +979,6 @@ Return the new header."
 				    ",")
 				    ",")
 			 nil nil header 1))))))
 			 nil nil header 1))))))
 
 
-(defun org-latex--guess-inputenc (header)
-  "Set the coding system in inputenc to what the buffer is.
-HEADER is the LaTeX header string.  Return the new header."
-  (let* ((cs (or (ignore-errors
-		   (latexenc-coding-system-to-inputenc
-		    buffer-file-coding-system))
-		 "utf8")))
-    (if (not cs) header
-      ;; First translate if that is requested.
-      (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
-      ;; Then find the \usepackage statement and replace the option.
-      (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
-				cs header t nil 1))))
-
 (defun org-latex--find-verb-separator (s)
 (defun org-latex--find-verb-separator (s)
   "Return a character not used in string S.
   "Return a character not used in string S.
 This is used to choose a separator for constructs like \\verb."
 This is used to choose a separator for constructs like \\verb."
@@ -1106,12 +1109,12 @@ holding export options."
 			"^[ \t]*\\\\documentclass\\(\\(\\[.*\\]\\)?\\)"
 			"^[ \t]*\\\\documentclass\\(\\(\\[.*\\]\\)?\\)"
 			class-options header t nil 1)))))
 			class-options header t nil 1)))))
 	  (when document-class-string
 	  (when document-class-string
-	    (org-latex--guess-babel-language
-	     (org-latex--guess-inputenc
+	    (org-latex-guess-babel-language
+	     (org-latex-guess-inputenc
 	      (org-splice-latex-header
 	      (org-splice-latex-header
 	       document-class-string
 	       document-class-string
-	       org-export-latex-default-packages-alist ; defined in org.el
-	       org-export-latex-packages-alist nil ; defined in org.el
+	       org-latex-default-packages-alist
+	       org-latex-packages-alist nil
 	       (plist-get info :latex-header-extra)))
 	       (plist-get info :latex-header-extra)))
 	     info)))))
 	     info)))))
      ;; Possibly limit depth for headline numbering.
      ;; Possibly limit depth for headline numbering.