> TeXtable2:= > proc(f, rows, columns) > local i, j, str, optionalargs, corner, beginmath, endmath; > optionalargs := {args[4 .. nargs]}; > beginmath := `$$`; endmath := `$$`; > if nargs = 4 then corner := args[4] > else corner := `i\\backslash j` fi; > lprint(); > lprint(``.beginmath.`\\offinterlineskip\\vbox`); > lprint(`{\\halign{\\ \\hfil\\strut$#$\\hfil\\ \\vrule`. > `&&\\hfil\\ $#$\\ \\cr`); > str := ``; > for j from columns[1] to columns[2] do str := ``.str.`&`.j od; > lprint(``.corner.str.`\\cr`); > lprint(`\\noalign{\\hrule}`); > for i from rows[1] to rows[2] do > str := ``.i; > for j from columns[1] to columns[2] do str := ``.str.`&`.(f(i, > j)) od; > lprint(``.str.`\\cr`) > od; > lprint(`}}`.endmath) > end: > # Given a list, create a string of its elements separated by thin spaces > cpt:=proc(L) local s,x; s:=``; > for x in L do s:=``.s.`\\,`.(x) od; > s > end:# # Create TeX strings for Zeck, Lucas, and alpha representations > FTeX:=proc(A) > local st,i; > if nops(A)=0 then RETURN(0) fi; > st:=`F_{`.(A[1]).`}`; > for i from 2 to nops(A) do > st:=``.st.`+`.`F_{`.(A[i]).`}`; > od; > st; > end: > LTeX:=proc(A) > local st,i; > if nops(A)=0 then RETURN(0) fi; > st:=`L_{`.(A[1]).`}`; > for i from 2 to nops(A) do > st:=``.st.`+`.`L_{`.(A[i]).`}`; > od; > st; > end: > aTeX:=proc(A) > local st,i; > if nops(A)=0 then RETURN(0) fi; > st:=`\\alpha^{`.(A[1]).`}`; > for i from 2 to nops(A) do > st:=``.st.`+`.`\\alpha^{`.(A[i]).`}`; > od; > st; > end: # Examples: Create a table of u*(v^2) with u from 2 to 5 and v from 3 to # 7: # > myf:=proc(i,j) i*j^2 end: # # TeXtable2(myf,[2,5],[3,7], `u\\backslash v`); # A more useful example: Create a table of reduced Zeckendorf # representations of F(2mn)/L(m) > ZZ:=proc(m,n) cpt(rz(F(2*m*n)/L(m))) end: > TeXtable2(ZZ,[1,8],[1,5],`m\\backslash n`); $$\offinterlineskip\vbox {\halign{\ \hfil\strut$#$\hfil\ \vrule&&\hfil\quad $#$\quad\cr m\backslash n&1&2&3&4&5\cr \noalign{\hrule} 1&\,0&\,2&\,4&\,6&\,8\cr 2&\,0&\,0\,1&\,0\,3\,0&\,0\,4\,0\,1&\,0\,4\,0\,3\,0\cr 3&\,1&\,4\,1&\,4\,4\,1&\,4\,4\,4\,1&\,4\,4\,4\,4\,1\cr 4&\,2&\,0\,0\,0\,3&\,0\,0\,0\,7\,2&\,0\,0\,0\,8\,0\,0\,0\,3&\,0\,0\,0\ ,8\,0\,0\,0\,7\,2\cr 5&\,3&\,8\,3&\,8\,8\,3&\,8\,8\,8\,3&\,8\,8\,8\,8\,3\cr 6&\,4&\,0\,0\,0\,0\,0\,5&\,0\,0\,0\,0\,0\,11\,4&\,0\,0\,0\,0\,0\,12\,0 \,0\,0\,0\,0\,5&\,0\,0\,0\,0\,0\,12\,0\,0\,0\,0\,0\,11\,4\cr 7&\,5&\,12\,5&\,12\,12\,5&\,12\,12\,12\,5&\,12\,12\,12\,12\,5\cr 8&\,6&\,0\,0\,0\,0\,0\,0\,0\,7&\,0\,0\,0\,0\,0\,0\,0\,15\,6&\,0\,0\,0\ ,0\,0\,0\,0\,16\,0\,0\,0\,0\,0\,0\,0\,7&\,0\,0\,0\,0\,0\,0\,0\,16\,0\, 0\,0\,0\,0\,0\,0\,15\,6\cr }}$$ # Compute the TeX code for the alpha representation of 100 > Zecka(100); [9, 6, 3, 1, -4, -7, -10] > aTeX(%); \alpha^{9}+\alpha^{6}+\alpha^{3}+\alpha^{1}+\alpha^{-4}+\alpha^{\ -7}+\alpha^{-10} >