Discussion:
[Texmacs-dev] Maxima inline plots
Marduk Bolaños
2017-09-05 02:16:47 UTC
Permalink
Dear all,

I implemented in Lisp what Python and Gnuplot do in order to display a
plot inline in TeXmacs:

(defun tm_out (str)
(let ((beg (string (code-char 2)))
(end (string (code-char 5))))

(concatenate 'string beg "ps: " str end)))


(defmfun $ps_out (filename)
(with-open-file (stream filename)
(let ((contents (make-string (file-length stream))))

(read-sequence contents stream)
;; princ does not enclose the string in quotes
(princ (tm_out contents))
(princ "")
)))


This works great inside a Maxima session, but I would also like to use
it in an executable Maxima fold (script).

I have tried a million things and the script output is always
empty. How can I get it done?

Thanks in advance!

Cheers,
Marduk
Marduk Bolaños
2017-09-05 18:45:00 UTC
Permalink
Dear all,

I am happy to tell you that I solved it. Now we can have LabView-style
plots in the sense that one can switch between the plot and the code
behind it. This also enables one to have reproducible plots.

So here is the code:

In maxima-menus.scm change this function (actually this was the culprit)

(tm-define (plugin-output-simplify name t)
(:require (== name "maxima"))
;;(display* "Simplify output " t "\n")
(if (func? t 'document)
(with u (list-find (cdr t) maxima-contains-prompt?)
;; Changed "" to (maxima-output-simplify t)
(if u (maxima-output-simplify u) (maxima-output-simplify t)))
(maxima-output-simplify t)))


In texmacs-maxima.lisp add:

(defun tm_out (raw_data)
(let ((beg (string (code-char 2)))
(end (string (code-char 5))))
(concatenate 'string beg "ps:" raw_data end)))


(defmfun $ps_out (filename)
(with-open-file (stream (concatenate 'string $maxima_tempdir "/" filename))
(let ((contents (make-string (file-length stream))))
(read-sequence contents stream)
;; princ does not enclose the string in quotes
(princ (tm_out contents))
(princ ""))))


(defmfun $ps_plot2d (&rest args)
#$set_plot_option([gnuplot_term, ps])$
#$set_plot_option([gnuplot_out_file, "plot.ps"])$
(apply '$plot2d args))


In my-init-texmacs.scm:

(kbd-map
("A-." (make-session "maxima" "default"))

("A-f" (begin (insert-go-to `(script-input "maxima" "default" "ps_out(\"plot.ps\")" "") '(2 0))
(set-pretty-preference "automatic quotes" "Disabled")))
)


I use it like this:

+ Insert a big figure
+ A-f A-.
+ Plot something in Maxima
+ Toggle the script to show the plot/show the Maxima code

Of course, this procedure also works with other languages and even with
equations. So no more "after a long calculation that I will not show you
and maybe the result is wrong".

Let's bring scientific authoring to the 21st century!

P.S.

This solves Bill Eaton's enquiry from 2013
https://lists.gnu.org/archive/html/texmacs-dev/2013-05/msg00024.html
ederag
2018-02-13 13:27:46 UTC
Permalink
Dear Marduk,

Thanks a lot for the ps_plot2d function:
http://lists.gnu.org/archive/html/texmacs-dev/2017-09/msg00002.html

Here is a pull request based on part of your code, slightly modified.
https://github.com/texmacs/texmacs/pull/30
That should make the reviewing process easier.

The changes to maxima-menus.scm and my-init-texmacs.scm
were not obvious to me, so left aside.
Someone else with a better understanding of texmacs,
and a similar workflow as yours,
will have to review it.

Ederag
Darcy Shen
2018-06-02 12:13:51 UTC
Permalink
I have merged these changes into the svn repo.Thanks for your PR---- On Tue, 13 Feb 2018 21:27:46 +0800 ederag<***@gmx.fr> wrote ----Dear Marduk, Thanks a lot for the ps_plot2d function: http://lists.gnu.org/archive/html/texmacs-dev/2017-09/msg00002.html Here is a pull request based on part of your code, slightly modified. https://github.com/texmacs/texmacs/pull/30 That should make the reviewing process easier. The changes to maxima-menus.scm and my-init-texmacs.scm were not obvious to me, so left aside. Someone else with a better understanding of texmacs, and a similar workflow as yours, will have to review it. Ederag _______________________________________________ Texmacs-dev mailing list Texmacs-***@gnu.org https://lists.gnu.org/mailman/listinfo/texmacs-dev
Loading...