## TeXmacs plot interface

## Author: Matteo Bertini

function __tmplot__ (mode)
    if (strcmp (mode, "prepare_output"))
        if (length(getenv("TEXMACS_PATH"))>0)
        # we are inside TeXmacs
            gset output "/tmp/tmplot.eps";
        endif
    elseif (strcmp (mode, "output"))
        if ( length(getenv("TEXMACS_PATH"))>0)
        # we are inside TeXmacs
            #P= "\002ps:"
            P=[2;112;115;58];
            g=fopen("/tmp/tmplot.eps");
            while (g==-1)
                sleep(1);
                g=fopen("/tmp/tmplot.eps");
            endwhile
            while (!feof(g))
                f=fread(g,2048);
                if (length(f))
                    P=[P;f];
                endif
            endwhile
            fclose(g);
            P=[P;5];
            disp(sprintf("%cverbatim:\n",2));
            disp(setstr(P'));
            system("rm /tmp/tmplot.eps");
        endif
    else
        usage ("__tmplot__: pass \"output\" or \"prepare_output\"");
    endif
endfunction