                /**  Tabular output  **/
 
/*K: printing; tabulation; tabular data; boxes; ruled; columnar;
        report generation; formatting; matrices; Pr; Fmt */
 
/*A: J.Greif */
/*S: California Institute of Technology */
/*D: November 1981 */
/*U: November 1985 */
/* K McIsaac, Prmat has an off by one error in Flat (Is this a problem with 
	Flat?) causing matrices of lists to print incorrectly*/
 
/*: vline[$w]
        make a vertical line of length $w */
 
        vline[$w] :: vthing[$w,"|"]
 
/*: vblank[$w]
        make a vertical blank of length $w */
 
        vblank[$w] :: vthing[$w," "]
 
/*: vthing[$w,$x]
        make a column of vertical things $x of height $w */
 
        vthing[$w,$x]::Fmt[{[$xyzzy]: {0,$xyzzy}},Repl[ $x,$w]]
 
/*: hline[$w]
        make a horizontal line of length $w */
 
        hline[$w] :: hthing[$w,"-"]
 
/*: hthing[$w,$x]
        make a row of horizontal things $x of length $w */
 
        hthing[$w,$x]::Fmt[Null,Repl[ $x,$w]]
 
/*: box[$x]
        make a box around expression $x */
 
        box[$x] :: (Lcl[%h,%v,%f]; hv[%h,%v,$x]; \
        Fmt[{{1,0},{-1,0},{Inf,0},{1,-Inf},{1,Inf},{0,Inf},{0,-Inf}},\
        $x,vline[%v],vline[%v],\
        hline[%h],hline[%h],hline[1],hline[1]])
 
/*: vbar[$x]
        print a list $x horizontally with bars separating the elements */
 
        vbar[$x_=Listp[$x]] :: bar[$x,vline]
        bar[$x_=Listp[$x],$z] :: (Lcl[%v,%h,%s,%v1]; hv[%h,%v,$x]; \
        %s:S[Ar[Len[$x],If[$i=Len[$x],[Null,$x[$i],Null],\
        [Null,$x[$i],Null,$z[%v]]]],{$$u,$$v}-->[$$u,$$v],{0}])
 
/*: col[$x]
        print list $x horizontally inside box with bars separating the elts */
 
        col[$x_=Listp[$x]] :: box[Fmt[{[$s]:{$s,0}},vbar[$x]]]
 
/*: topbot[$x]
        print object $x with a horizontal bar above and below */
 
        topbot[$x] :: (Lcl[%f,%h]: %f:Prdsp[$x]; %h:%f[2]+%f[3]+2;\
        Fmt[{{1,0},{1,-Inf},{1,Inf},{0,Inf},{0,-Inf}},$x,\
        hline[%h],hline[%h],hline[1],hline[1]])
 
/*: hv[$h,$v,$x]
        find height $v and width $h of expression $x */
 
        hv[$h,$v,$x] :: (Lcl[%f]; %f:Prdsp[$x]; $h:%f[2]+%f[3]+2; \
        $v:%f[4]+%f[5]+1; )
 
/*: colmat[$x]
        print out columnated, and boxed matrix, i.e. a table */
 
        colmat[$x_=Fullp[$x,2]] :: (Lcl[%h,%l,%v,%t,%q]; %t:Trans[$x];\
        %l:Ar[Len[%t], Fmt[{[$s]:{0,-2$s}},S[%t[$i],{$$u,$$v}-->[$$u,$$v],\
                {0}]]]; col[%l])
 
/*: Prmat[$x]
        print out matrix $x in 2-D form */
 
        Prmat[$m_=Fullp[$m,2]] :: Ap[Fmt,\
                Cat[{Flat[Ar[{Dim[$m][1],Dim[$m][2]},{4*$2,-2*$1}],1]},\
                Flat[$m,1]]]/* Off by one in Flat ?*/
 
/*E:
#I[1]::  <XPrtable
 
#I[2]::  Ar[{3,3},Pow]
 
#O[2]:   {{1,1,1},{2,4,8},{3,9,27}}
 
#I[3]::  Prmat[%]
 
          1   1   1
 
#O[3]:    2   4   8
 
          3   9   27
 
#I[4]::  colmat[@2]
 
          --------------
         |  1 | 1 | 1   |
         |    |   |     |
#O[4]:   |  2 | 4 | 8   |
         |    |   |     |
         |  3 | 9 | 27  |
          --------------
 
*/
