[comp.emacs] tek graphics in GNU Emacs front end

kitagawa@will.ntt.jp (Masahiro Kitagawa) (02/10/91)

In article <1517@aerodec.anu.edu.au> tridge@aerodec.anu.edu.au (Andrew Tridgell) writes:

 |I'm running NCSA Telnet on a PC and wish to use the GNU Emacs front end
 |for mathematica on a Sun4. I've found that in Tek mode the tek code get
 |mangled before reaching the PC, probably eigth bit stripping or

Emacs eats TEK escape sequences. I had the same problem with MS-Kermit
and here is my solution. We have been using this for months and
enjoying both great editing capabilities of GNU Emacs/math.el and TEK
graphics ability of Mathematica. Although you might need to modify it
to meet NCSA telnet, I hope it gives you some hints. Also I hope
someone hack and elaborate it as I am not qualified elisp hacker.
Be aware that this is very unofficial patch to math.el.

PRINCIPLE
=========

(1) Save Graphics as Mathematica style PostScript to temporary file,
    say, tmp.ps. [PSFile.m does it]

(2) Suspend Emacs
(3) Invoke tekps < tmp.ps
[C-c C-v (M-x math-view-graphics) does (2) and (3)]

(4) Echo something to bring MS-Kermit back into VT mode.
(5) Get Emacs to foreground 
[~/.cshrc should have a line saying:
	alias vt 'echo "^[^L^X" && fg'
so that just typing "vt" does (4) and (5). 
(^ is Control, not just a hat.)]

Example session
===============

Mathematica (sun4) 1.2 (June 13, 1990) [With pre-loaded data]
 -- Tektronix graphics initialized -- 

In[1]:= <<PSFile.m
        ^^^^^^^^^^
 -- PSFile graphics initialized -- 
 -- Graphics will be just saved as tmp.ps -- 

In[2]:= Plot[Sin[x]/x, {x, -8, 8}]

Out[2]= -Graphics-

In[3]:= C-c C-v (Emacs is suspended. tekps is invoked. MS-Kermit goes
        ^^^^^^^	 into TEK-mode. Graphics appears.)

vt	(MS-Kermit is back to VT-mode. Emacs comes back to forground.)
^^

In[3]:= 

FILES
=====

o Put PSFile.m in /usr/local/math/Init/
o Apply math.el.tek-patch to math.el
o Add directory where tekps resides to your PATH

============ /usr/local/math/Init/PSFile.m ========= CUT HERE ==============
(* Graphics output to PS File. 7-Nov-90 by M.Kitagawa kitagawa@wave.ntt.jp *)

(* These variables can be reset during a session to alter subsequently
   created graphics windows: *)

$Display := $PSFileDisplay
$PSTmpFile := StringJoin["tmp.ps"]
$PSFileDisplay := StringJoin["!cat > ", $PSTmpFile]

$DisplayFunction = Display[$Display, #]&

Print[" -- PSFile graphics initialized -- "]
Print[" -- Graphics will be just saved as ", $PSTmpFile, " -- "]


============ math.el.tek-patch ========= CUT HERE ==============
*** math.el.orig	Sat Feb  2 14:54:57 1991
--- math.el	Sat Feb  9 12:43:23 1991
***************
*** 45,50 ****
--- 45,52 ----
  ;;      Experimental version of April 10, 1990
  ;;      Assumes GNU Emacs version 18.54
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ;; 7-Nov-90 Tektro Graphics enhancement by M.Kitagawa, kitagawa@wave.ntt.jp
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (require 'shell)
  
  (defvar Mathematica-search-path 
***************
*** 119,124 ****
--- 121,128 ----
    (define-key math-mode-map "\C-c\C-y" 'math-copy-cell)
    (define-key math-mode-map "\C-c\C-e" 'find-math-error)
    (define-key math-mode-map "\C-c\C-r" 'math-isearch-backward))
+   ;; Tektro Graphics enhancement by M.Kitagawa
+   (define-key math-mode-map "\C-c\C-v" 'math-view-graphics)
  
  (defvar math-mode-syntax-table nil
    "Syntax table used while in math mode.")
***************
*** 894,897 ****
--- 898,919 ----
    ;; But if the buffer does not yet exist, it will still work.
    (setq math-process-buffer (or (get-buffer buffer) buffer)))
  
+ ;; Tektro Graphics enhancement by M.Kitagawa
+ ;; << PSFile.m will teach Mathematica where and how to send Graphics:
+ ;; i.e. saved as $PSTmpFile in Mathematica PostScript format.
+ ;; math-tmp-ps-file should be consistent with $PSTmpFile in PSFile.m.
+ (defvar math-tmp-ps-file "tmp.ps")
  
+ (defvar math-view-graphics-command (if (eq window-system 'x)
+ 				       "x11ps" "tekps")
+   "*Command to invoke previewer for Mathematica PostScript Graphics.")
+ 
+ (defun math-view-graphics ()
+   "View Mathematica Graphics after suspend Emacs."
+   (interactive)
+   (suspend-emacs (concat math-view-graphics-command " < " math-tmp-ps-file)))
+ 
+ ;; After you finish math-view-graphics, you can let MS-Kermit back
+ ;; into VT102 mode by % echo "^[^L^X" (Ctrl-[ Ctrl-L Ctrl-X). And then bring
+ ;; Emacs into foreground. It is wise to define alias in ~/.cshrc such as
+ ;; alias vt 'echo "^[^L^X" && fg'

*--- **** ***-- *--* *-* *-*
Masahiro Kitagawa			"Against all odds"
NTT Research Labs. Tokyo Japan
kitagawa@will.ntt.jp