Question: For the Latex code for a Matrix

For the Latex code of matrix B, I used the following procedure. But the last column of B is not what we're looking for in the latex code. (There is no problem in the other columns)

Download_Latexcode.mw

restart:
interface(rtablesize=20):
f:=(x,t)->x*t;
g:=(x,t)->x^2*t;
  
B:=Matrix([[x,t,"f(x,t)","g(x,t)"],
         seq(seq([i,j,f(i,j),g(i,j)],
                 j=0.125..0.875, 0.25),
             i=0.125..0.875,0.25)]):
B[1,..]:=map(p->nprintf(`#mi(%a);`,p),B[1,..]):
B[2..,4]:=map(p->nprintf(`#mn(\"%1.2e\");`,p),B[2..,4]):
 
 

Lat:=proc(M::Matrix,
          {output::{NoUserValue,identical(string)}:=':-NoUserValue'})
  local m,n,S;
  (m,n):=op(1,M);
  S:=cat(" \\begin{tabular}",
         "{|",seq("c|",i=1..op([1,2],M)),"} ",
         "\\hline ",
         seq([seq(sprintf("$%s$ & ",latex(M[i,j],':-output'=string)),j=1..n-1),
         sprintf("$%s$ \\\\ \\hline ",latex(M[i,n],':-output'=string))][],i=1..m),
         "\\end{tabular} ");
  if output=':-string' then
    return S;
  else
    printf("%s",S);
    return NULL;
  end if;
end proc:
Lat(B);

 

Please Wait...