Maxima: How to preserve prompt message to user (e.g. asksign()) when customizing output display?

Viewed 84

I'm developing an interface to Maxima (from R), that changes the output display of maxima on startup via an init-file:

load("mactex-utilities")$
load("alt-display.mac")$
set_prompt('prefix, "prompt;>>")$
set_prompt('suffix, "<<prompt;")$
my_display(x):=(?princ("out;>>"), ?princ("(%o"), ?princ(linenum), ?princ(") "), tex(?caddr(x)), ?princ("<<out;"))$
set_alt_display(2, my_display)$

Now I'm trying to handle cases were Maxima prompts the user to declare assumptions about variables like in this example:

(%i1) L: sqrt(1 - 1/(R^2));
                                          1
(%o1)                            sqrt(1 - --)
                                           2
                                          R
(%i2) integrate(x, x, 0, L);
Is R positive or negative?

positive;
                                     2
                                    R  - 1
(%o2)                               ------
                                        2
                                     2 R
(%i3) 

So the default display shows a prompt message "Is R positive or negative?". However, when I use the initialization file above, this message does not get printed. However, the console waits for the user input. So my question is, if there is a way, so I can include it in my customized output. Preferably, I think it should be possible to also wrap it in pre-/suffix strings for my interface to properly catch it, but I'm not too versed with maxima internals.

Just for the record, my interface's repo is https://www.github.com/rcst/rmaxima

1 Answers

This topic has been resolved on the maxima mailing list (here)

In essence this seems to be a bug in the alt-display.lisp code

Thanks to Leo Butler, here is a re-written version of the initialization script that in addition customizes user prompt messages that circumvents the problem.

(load("mactex-utilities"), load("alt-display.mac"));
(set_prompt('prefix, "prompt;>>",'suffix, "<<prompt;"),
my_display(x):=block([type], type:?caar(x),
if type=?mtext then printf(true,"~%TEXT;>>~%~a~%<<TEXT;~%",?cadr(x))
else if type=?mlabel then printf(true,"~%out;>>~%(~a) ~a~a~a~%<<out;~%",?cadr(x),"$$",tex1(?caddr(x)),"$$")
else block([alt_display1d:false, alt_display2d:false], displa(x))),
set_alt_display(2,my_display)) $

When using this to initialize maxima, the output for the above example is

prompt;>>(%i1) <<prompt;L: sqrt(1 - 1/(R^2));

out;>>
(%o1) $$\sqrt{1-\frac{1}{R^2}}$$
<<out;
prompt;>>(%i2) <<prompt;integrate(x, x, 0, L);
prompt;>>
TEXT;>>Is R positive or negative?<<TEXT;
<<prompt;
p;

out;>>
(%o2) $$\frac{R^2-1}{2\,R^2}$$
<<out;
prompt;>>(%i3) <<prompt;
Related