|
From: Leo B. <Leo...@um...> - 2022-08-24 17:40:10
|
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
|