Public feed #893413

Anonymous

public text v1 · immutable
Raw Edit
·published 2008-02-06 02:49 UTC
rendered paste body
(require 'color-theme)
(color-theme-standard)
(setq ring-bell-function
      (lambda ()
	(if (= (random 5) 1)
	    (call-process-shell-command 
	     "aplay -Dpulse ~/trap.wav" 
	     nil 
	     0 
	     nil ))))
(setq TeX-PDF-mode t)
(setq
 TeX-output-view-style (quote (("^dvi$" ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$") "%(o?)dvips -t landscape %d -o && gv %f") ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "%(o?)dvips %d -o && gv %f") ("^dvi$" ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$") "%(o?)xdvi %dS -paper a4r -s 0 %d") ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "%(o?)xdvi %dS -paper a4 %d") ("^dvi$" ("^a5\\(?:comb\\|paper\\)$" "^landscape$") "%(o?)xdvi %dS -paper a5r -s 0 %d") ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d") ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d") ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d") ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d") ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d") ("^dvi$" "." "%(o?)xdvi %dS %d") ("^pdf$" "." "gnome-open %o") ("^html?$" "." "netscape %o"))))

(defvar mathematica-command-line "math")
(defun start-mathematica ()
  (setq math-buffer
	(make-comint "mathematica" mathematica-command-line)))
(start-mathematica)
(defun restart-mathematica (&optional arg)
  (interactive "*p")
  (kill-buffer math-buffer)
  (start-mathematica))

(defun insert-math-graphic (expression)
  (let ((randfix (random 10000))
	(file-prefix (car
		      (split-string
		       (buffer-name)
		       "\\."))))
    (progn
      (save-current-buffer
	(progn
	  (set-buffer math-buffer)
	  (progn
	    (insert (concat
		     "Export[\"/tmp/"
		     file-prefix
		     (number-to-string randfix)
		     ".pdf\","
		     expression
		     "];\n\n"))
	    (comint-send-input))))
      (insert (concat
	       "\\includegraphics[width=4cm]{/tmp/"
	       file-prefix
	       (number-to-string randfix)
	       "}")))
    (while 
	(not (file-exists-p
	      (concat "/tmp/"
		      file-prefix
		      (number-to-string randfix)
		      ".pdf")))
      (sleep-for 1))
    (preview-at-point)))


(defun insert-graphic-minibuffer (&optional arg)
  (interactive "*p")
  (insert-math-graphic 
   (read-string "Mathematica expression: ")))

(global-unset-key "\M-m")
(global-unset-key "\M-n")
(global-set-key "\M-m" 'insert-graphic-minibuffer)
(global-set-key "\M-n" 'line-to-mathematica)