mailing-list for TeXmacs Users

Text archives Help


Re: [TeXmacs] maxima plugin: plot2d with automatic ps capture to document?


Chronological Thread 
  • From: Joris van der Hoeven <address@hidden>
  • To: Albrecht Gebhardt <address@hidden>
  • Cc: <address@hidden>, <address@hidden>
  • Subject: Re: [TeXmacs] maxima plugin: plot2d with automatic ps capture to document?
  • Date: Thu, 24 Feb 2005 14:25:20 +0100 (CET)


On Wed, 23 Feb 2005, Albrecht Gebhardt wrote:
> I was searching if there is already some
> capture-the-plot-into-the-texmacs-document function available for Maxima (as
> it is for R, octave, gnuplot). It seems to be not.
>
> So I decided to try some lisp coding:
>
> ;;
> ;; preliminary tmplot2d function, address@hidden
> ;;
> (defun $tmplot2d (&rest args)
> ($set_plot_option '((mlist) $gnuplot_term $ps))
> ($set_plot_option '((mlist) $gnuplot_out_file "/tmp/tmplot.eps"))
> (apply '$plot2d args)
> (write (concatenate 'string (vector (code-char 2)) "ps" ":")
> :escape nil :readably nil)
> ; TODO: something like this
> ;(setq plotfile (open "/tmp/tmplot.eps"))
> ;(format t "%s" (read plotfile))
> ;; ^^ should be a while loop until EOF.. don't know how to do
> ;(close plotfile)
> ; workaround:
> (system "cat /tmp/tmplot.eps")
> (write (concatenate 'string (vector(code-char 5)))
> :escape nil :readably nil)
> ($set_plot_option '((mlist) $gnuplot_term $default))
> ($set_plot_option '((mlist) $gnuplot_out_file nil))
> (print "plot done")))
>
>
> Put this into plugins/maxima/lisp/texmacs-maxima-5.9.1.lisp and then in a
> Maxima session call e.g.
>
> tmplot2d(sin(x), [x, -%Pi, %Pi]);
>
> instead of
>
> plot2d(sin(x), [x, -%Pi, %Pi]);
>
> It's not perfect, the plot is to large, the function should restore the plot
> options instead of resetting them to default afterwards, but maybe someone
> with more lisp, maxima and texmacs knowledge can inmprove it?
>
> I tested it with the Debian sarge packages of texmacs and maxima (that means
> maxima runs with GCL, don't know if my lisp code is GCL specific)
>
> I first tried a variant without redirecting output to file:
> (write (concatenate 'string (vector (code-char 2)) "ps" ":")
> (apply '$plot2d args)
> (write (concatenate 'string (vector(code-char 5)))
>
> it works too, but if you generate some syntax error in the $plot2d call
> (wrong
> range or so) then it hangs (because the error message gets captured between
> \0x02ps: .... \0x05.

Thanks a lot for the code. I hope that Andrey Grozin will take a look at
it soon and send me an improved version of the Maxima plug-in.

As to the size of the plot, you may try to find some standard postscript
utilities which transform the size of the generated output.
You may also try to hack the source code of the "ps:" format and
allow the user to specify width and height parameters before sending
the actual postscript file (and use 1par for the width, for instance).

Another interesting thing which you may try to do is take a look at
the Maxima graphical previewer code and see whether you may hack it
so as to return a postscript graphic on exit (instead of 0).

Thanks again for your contribution, Joris




Archive powered by MHonArc 2.6.19.

Top of page