I wasted some more time. try the following patch with
)se ou tex on
Many improvements necessary before committable:
* background of images doesn't fit
* temporary files are not deleted - I probably should create them at the
beginning and reuse them all the time, same for fricas-yank-file etc.
* error handling (if there is a LaTeX error, or dvipng not present etc.)
* should be possible to toggle between text and image
...
but it's a start.
Martin
Index: contrib/emacs/fricas.el
===================================================================
--- contrib/emacs/fricas.el (revision 410)
+++ contrib/emacs/fricas.el (working copy)
@@ -140,6 +140,11 @@
"(t (prin1 x)))"
"(princ #\\Newline))"))
(defvar fricas-annotate-regexp "\e\\([a-zA-Z\-]*\\)\n")
+(defvar fricas-TeX-preamble (concat "\\documentclass{article}"
+
"\\usepackage[active,dvips,tightpage,displaymath]{preview}"
+ "\\begin{document}"
+ "\\begin{preview}"))
+(defvar fricas-TeX-postamble "\\end{preview}\\end{document}")
(defvar fricas-mode-syntax-table
(let ((st (make-syntax-table)))
@@ -222,6 +227,8 @@
(setq fricas-cd nil) ;; are we changing the directory?
(make-local-variable 'fricas-yank-file?)
(setq fricas-yank-file? nil) ;; did we yank a file?
+ (make-local-variable 'fricas-TeX-buffer)
+ (setq fricas-TeX-buffer "") ;; buffer to put TeX code
(make-local-variable 'fricas-save-history?)
(setq fricas-save-history? nil) ;; did we just save the history
@@ -385,6 +392,16 @@
(defvar fricas-paint-face 'fricas-paint-lightblue)
+(defun fricas-clear-output ()
+ (interactive)
+ (when (fricas-paintable? (point))
+ (let ((inhibit-read-only t)
+ (pos (fricas-beginning-of-region-pos (point))))
+ (while (fricas-paintable? pos)
+ (put-text-property pos (1+ pos)
+ 'face (get-text-property pos 'type))
+ (setq pos (1+ pos))))))
+
(defun fricas-change-paint-face ()
(interactive)
(let ((newpaint (completing-read "New paint face: "
@@ -1013,9 +1030,9 @@
(cond ((null (car output-type)) ;; text to be inserted
(fricas-insert-output fricas-output-buffer
- output-index
- (cadr output-type)
- fricas-last-type))
+ output-index
+ (cadr output-type)
+ fricas-last-type))
((equal (car output-type) "\e|startReadLine|\n") ;; expect
input after prompt
(when (eq fricas-state 'starting) (set-buffer-modified-p nil))
@@ -1040,6 +1057,12 @@
((equal (car output-type) "\e|endOfAlgebraOutput|\n")
(setq fricas-last-type 'fricas-undefined))
+ ((equal (car output-type) "\e|startTeXOutput|\n")
+ (setq fricas-last-type 'fricas-TeX))
+ ((equal (car output-type) "\e|endOfTeXOutput|\n")
+ (fricas-insert-TeX)
+ (setq fricas-last-type 'fricas-undefined))
+
((equal (car output-type) "\e|startTypeTime|\n")
(setq fricas-last-type 'fricas-type-time))
((equal (car output-type) "\e|endOfTypeTime|\n")
@@ -1061,9 +1084,9 @@
(setq fricas-last-type 'fricas-undefined))
(t (fricas-insert-output fricas-output-buffer
- output-index
- (cadr output-type)
- fricas-last-type)))
+ output-index
+ (cadr output-type)
+ fricas-last-type)))
(setq output-index (cadr output-type))
(set-marker (process-mark proc) (point))))
@@ -1096,7 +1119,10 @@
(defun fricas-insert-output (str beg end type)
"inserts the substring of str into the buffer"
- (fricas-insert-ascii (substring str beg end) type))
+ (let ((new-text (substring str beg end)))
+ (if (eq type 'fricas-TeX)
+ (setq fricas-TeX-buffer (concat fricas-TeX-buffer new-text))
+ (fricas-insert-ascii new-text type))))
(defun fricas-insert-ascii (str type)
(let ((inhibit-read-only t)
@@ -1119,6 +1145,27 @@
(when (eq type 'fricas-prompt)
(put-text-property beg end 'field t)))
+(defun fricas-insert-TeX ()
+ (let* ((tmp (make-temp-file "fricas" nil ".tex"))
+ (bas (file-name-sans-extension tmp))
+ (dir (file-name-directory tmp))
+ (png (concat bas ".png"))
+ (dvi (concat bas ".dvi")))
+
+ (write-region (concat fricas-TeX-preamble
+ fricas-TeX-buffer
+ fricas-TeX-postamble)
+ nil tmp)
+ ;; TeX the file
+ (call-process "latex" nil nil nil (concat "-output-directory=" dir) tmp)
+ ;; png the output
+ (call-process "dvipng" nil nil nil "-bg" "transparent" "-o" png dvi)
+ ;; create and insert the image
+ (insert-image (create-image png 'png nil))
+ (fricas-insert-ascii "\n" 'fricas-undefined)
+ (setq fricas-TeX-buffer "")))
+
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; getting old input - taken and adapted from comint
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1269,8 +1316,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun fricas-save-history ()
- "If necessary, removes previous saved histories, since it seems that fricas
-does not store the %% facility correctly. Then issues )history )save."
+ "If necessary, removes previous saved histories, since it seems
+that fricas does not store the %% facility correctly. Then
+issues )history )save. Return nil, because it's hooked to
+write-contents-hooks for emacs versions before 22."
(if (fricas-can-receive-commands?)
(let ((dirname (concat (buffer-file-name) ".axh")))
(goto-char (process-mark fricas-process))
@@ -1278,7 +1327,9 @@
(delete-file (concat dirname "/index.KAF"))
(delete-directory dirname))
(setq fricas-save-history? t)
- (fricas-send-input (concat ")history )save " (buffer-file-name))))
+
+ (fricas-send-input (concat ")history )save " (buffer-file-name))
+ t))
(error "FriCAS is working"))
nil)
Index: src/interp/i-output.boot
===================================================================
--- src/interp/i-output.boot (revision 410)
+++ src/interp/i-output.boot (working copy)
@@ -156,7 +156,7 @@
-- the second - x - is the horizontal distance along the page
-- at which to start
-- the third - y - is some vertical hacking control
--- the foruth - d - is the "layout" so far
+-- the fourth - d - is the "layout" so far
-- these functions return an updated "layout so far" in general
appChar(string,x,y,d) ==
@@ -1260,6 +1260,7 @@
NIL
texFormat expr ==
+ ioHook("startTeXOutput")
tf := '(TexFormat)
formatFn :=
getFunctionFromDomain("convert",tf,[$OutputForm,$Integer])
@@ -1267,6 +1268,7 @@
SPADCALL(SPADCALL(expr,$IOindex,formatFn),displayFn)
TERPRI $texOutputStream
FORCE_-OUTPUT $texOutputStream
+ ioHook("endOfTeXOutput")
NIL
texFormat1 expr ==
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---