|
From: Leo B. <Leo...@um...> - 2022-08-25 16:18:22
|
On Wed, Aug 24 2022, Eduardo Ochs <edu...@gm...> wrote:
> On Wed, 24 Aug 2022 at 14:25, Leo Butler <Leo...@um...> wrote:
>
>> On Tue, Aug 23 2022, Eduardo Ochs <edu...@gm...> wrote:
>>
>> > Hi list,
>> >
>> > I am trying to learn how to define new operators that have "nice"
>> > representations in LaTeX and in display2d. Here is the example on
>> > which I am working. I want
>> >
>> > Eq5(aa, bb, cc, dd, ee)
>> >
>> > to be displayed as:
>> >
>> > aa = bb
>> > = cc
>> > = dd
>> > = ee
>> >
>> > To configure its LaTeX output I simply adapted the example in the
>> > section about "texput" here,
>> >
>> > (info "(maxima)Functions and Variables for TeX Output")
>> >
>> > and I wrote this:
>> >
>> > texEq5(ex) :=
>> > block([a,b,c,d,e], [a,b,c,d,e] : args (ex),
>> > concat("\\begin{array}{rcl}",
>> > tex1(a), "&=&", tex1(b), "\\\\",
>> > "&=&", tex1(c), "\\\\",
>> > "&=&", tex1(d), "\\\\",
>> > "&=&", tex1(e), "\\\\",
>> > "\\end{array}"));
>> > texput(Eq5, texEq5);
>> > tex(Eq5(aa, bb, cc, dd, ee));
>> >
>> > Here's the output of the last line above, indented by hand:
>> >
>> > $$\begin{array}{rcl}
>> > {\it aa} &=& {\it bb} \\
>> > &=& {\it cc} \\
>> > &=& {\it dd} \\
>> > &=& {\it ee} \\
>> > \end{array}
>> > $$
>> >
>> > This was easy to do, and works great. But I couldn't find much
>> > documentation on how to configure how display2d displays "Eq5"
>> > objects. I was only able to write this prototype for the first step:
>> >
>> > MatrixEq5(ex) :=
>> > block([a,b,c,d,e], [a,b,c,d,e] : args (ex),
>> > matrix([a,"=",b],["","=",c],["","=",d],["","=",e]))$
>> >
>> > If I run this
>> >
>> > MatrixEq5(Eq5(aa, bb, cc, dd, ee));
>> >
>> > the output is:
>> >
>> > [ aa = bb ]
>> > [ ]
>> > [ = cc ]
>> > [ ]
>> > [ = dd ]
>> > [ ]
>> > [ = ee ]
>> >
>> > So, questions:
>> >
>> > 1) How can I get rid of the outer "[]"s?
>> > 2) How can I get rid of the blank lines?
>> > 3) How can I make Eq5 objects be displayed with MatrixEq5?
>> > 4) Where can I find docs and examples about this?
>> >
>> > Thanks in advance! =)
>> > Eduardo Ochs
>> > http://angg.twu.net/eev-maxima.html
>>
>> It depends on how ambitious your goals are, but the alt-display package
>> is probably what you want.
>>
>> To elaborate: suppose that you want to print Eq5(...) using some
>> function printEq5; other things should just be printed as is. You can
>> define a custom printer that checks an expression to see if its op has a
>> custom printer; if so, dispatch that; otherwise, use the default.
>>
>> Here is a working POC:
>>
>> (%i1)
>> define_alt_display(ochs_display(form),
>>
>> block([alt_display1d:false,alt_display2d:false,x:second(form),p],
>> if mapatom(x) then displa(form) else if
>> (p:get(op(x),display2d_printer))#false then
>> p(form) else twod_display(form))) $
>>
>> (%i2) printEq5(x) := block([a:args(second(x))], printf(true,"BANG!~%~a ~{=
>> ~a ~}~%!GNAB",first(a), rest(a))) $
>>
>> (%i3) put(Eq5,printEq5,display2d_printer) $
>>
>> (%i4) Eq5(aa,bb);
>> BANG!
>> aa = bb
>> !GNAB
>>
>> (%i5) Eq5(aa,bb,cc,dd,ee);
>> BANG!
>> aa = bb = cc = dd = ee
>> !GNAB
>>
>> (%i6) 1/2+x;
>> 1
>> (%o6) x + -
>> 2
>>
>>
>> Leo
>
>
> Hi Leo,
>
> your code looks like the right way to go, but it doesn't work here...
> does it need something that is in your init file?
>
> First attempt:
>
> (%i1) define_alt_display(ochs_display(form),
> block([alt_display1d:false,alt_display2d:false,x:second(form),p],
> if mapatom(x) then displa(form) else if
> (p:get(op(x),display2d_printer))#false then
> p(form) else twod_display(form)))$
>
> second: argument must be a non-atomic expression; found form
> -- an error. To debug this try: debugmode(true);
> (%i2)
>
> Second attempt:
>
> (%i1) load("alt-display.mac")$
>
> (%i2) define_alt_display(ochs_display(form),
> block([alt_display1d:false,alt_display2d:false,x:second(form),p],
> if mapatom(x) then displa(form) else if
> (p:get(op(x),display2d_printer))#false then
> p(form) else twod_display(form)))$
>
> (%i3) printEq5(x) := block([a:args(second(x))],
> printf(true,"BANG!~%~a ~{= ~a ~}~%!GNAB",first(a), rest(a)))$
>
> (%i4) put(Eq5,printEq5,display2d_printer)$
>
Apologies, before %i5 you need to also enter:
display2d : true $ /* set default */
set_alt_display(2,ochs_display);
Leo
> (%i5) Eq5(aa,bb);
> (%o5) Eq5(aa, bb)
> (%i6) Eq5(aa,bb,cc,dd,ee);
> (%o6) Eq5(aa, bb, cc, dd, ee)
> (%i7) 1/2+x;
> 1
> (%o7) x + -
> 2
> (%i8)
>
> Thanks in advance =/,
> Eduardo
|