Bläddra i källkod

Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

Carsten Dominik 15 år sedan
förälder
incheckning
2aaad50393

+ 7 - 10
contrib/babel/lisp/langs/org-babel-latex.el

@@ -81,16 +81,13 @@ called by `org-babel-execute-src-block'."
 (defun org-babel-latex-body-to-tex-file (tex-file body &optional height width)
   "Extracted from `org-create-formula-image' in org.el."
   (with-temp-file tex-file
-    (insert org-format-latex-header
-            (if org-export-latex-packages-alist
-                (concat "\n"
-                        (mapconcat (lambda(p)
-                                     (if (equal "" (car p))
-                                         (format "\\usepackage{%s}" (cadr p))
-                                       (format "\\usepackage[%s]{%s}"
-                                               (car p) (cadr p))))
-                                   org-export-latex-packages-alist "\n"))
-              "")
+    (insert (org-splice-latex-header
+	       org-format-latex-header
+	       (remove-if
+                (lambda (el) (and (listp el) (string= "hyperref" (cadr el))))
+                org-export-latex-default-packages-alist)
+	       org-export-latex-packages-alist
+	       org-format-latex-header-extra)
             (if height (concat "\n" (format "\\pdfpageheight %s" height)) "")
             (if width (concat "\n" (format "\\pdfpagewidth %s" width)) "")
             (if org-format-latex-header-extra

+ 26 - 6
contrib/babel/lisp/langs/org-babel-octave.el

@@ -100,9 +100,16 @@ then create. Return the initialized session."
 	  (rename-buffer (if (bufferp session) (buffer-name session)
 			   (if (stringp session) session (buffer-name)))) (current-buffer))))))
 
- (defvar org-babel-octave-wrapper-method
+(defvar org-babel-octave-wrapper-method
    "%s
-save -ascii %s ans")
+if ischar(ans)
+   fid = fopen('%s', 'w')
+   fprintf(fid, ans)
+   fprintf(fid, '\\n')
+   fclose(fid)
+else
+   save -ascii %s ans
+end")
 
 (defvar org-babel-octave-eoe-indicator "\'org_babel_eoe\'")
 
@@ -130,12 +137,12 @@ value of the last statement in BODY, as elisp."
 	 (let* ((tmp-file (make-temp-file "org-babel-results-")) exit-code
 		(stderr
 		 (with-temp-buffer
-		   (insert (format org-babel-octave-wrapper-method body tmp-file))
+		   (insert (format org-babel-octave-wrapper-method body tmp-file tmp-file))
 		   (setq exit-code (org-babel-shell-command-on-region
 				    (point-min) (point-max) cmd nil 'replace (current-buffer)))
 		   (buffer-string))))
 	   (if (> exit-code 0) (org-babel-error-notify exit-code stderr))
-	   (org-babel-import-elisp-from-file (org-babel-maybe-remote-file tmp-file))))))))
+	   (org-babel-octave-import-elisp-from-file (org-babel-maybe-remote-file tmp-file))))))))
 
 (defun org-babel-octave-evaluate-session (session body result-type &optional matlabp)
   (let* ((tmp-file (make-temp-file "org-babel-results-"))
@@ -148,13 +155,13 @@ value of the last statement in BODY, as elisp."
 	    (value
 	     (mapconcat
 	      #'org-babel-chomp
-	      (list (format org-babel-octave-wrapper-method body tmp-file) org-babel-octave-eoe-indicator) "\n"))))
+	      (list (format org-babel-octave-wrapper-method body tmp-file tmp-file) org-babel-octave-eoe-indicator) "\n"))))
 	 (raw (org-babel-comint-with-output session
 		  (if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output) t
 		(insert full-body) (comint-send-input nil t))) results)
     (case result-type
       (value
-       (org-babel-import-elisp-from-file (org-babel-maybe-remote-file tmp-file)))
+       (org-babel-octave-import-elisp-from-file (org-babel-maybe-remote-file tmp-file)))
       (output
        (progn
 	 (setq results
@@ -166,6 +173,19 @@ value of the last statement in BODY, as elisp."
 					       (mapcar #'org-babel-trim raw)))))))
 	 (mapconcat #'identity (reverse results) "\n"))))))
 
+(defun org-babel-octave-import-elisp-from-file (file-name)
+  "Import data written to file by octave.
+This removes initial blank and comment lines and then calls
+`org-babel-import-elisp-from-file'."
+  (let ((temp-file (make-temp-file "org-babel-results-")) beg end)
+    (with-temp-file temp-file
+      (insert-file-contents file-name)
+      (re-search-forward "^[ \t]*[^# \t]" nil t)
+      (if (< (setq beg (point-min))
+	     (setq end (point-at-bol)))
+	  (delete-region beg end)))
+    (org-babel-import-elisp-from-file temp-file)))
+
 (defun org-babel-octave-read-string (string)
   "Strip \\\"s from around octave string"
   (if (string-match "^\"\\([^\000]+\\)\"$" string)