[system] / trunk / pg / macros / unionTables.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/unionTables.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6499 - (download) (as text) (annotate)
Thu Nov 11 13:03:14 2010 UTC (9 years, 3 months ago) by gage
File size: 8738 byte(s)
transferred some much used macro files to pg/macros for those not including the
NPL/macros/Union  directory in their macros search path

added PGanalyzeGraph to support graphical input

added POD documenta^tion to LiveGraphics3D.pl


    1 ######################################################################
    2 ##
    3 ##  Functions for creating tables of various kinds
    4 ##
    5 ##    ColumnTable()           Creates a two-column display in HTML,
    6 ##                            but only one column in TeX.
    7 ##
    8 ##    ColumnMatchTable()      Does a side-by-side match table
    9 ##
   10 ##    BeginTable()            Begin a borderless HTML table
   11 ##    Row()                   Create a row in the table
   12 ##    AlignedRow()            Create a row with alignment in each column
   13 ##    TableSpace()            Insert extra vertical space in the table
   14 ##    EndTable()              End the table
   15 ##
   16 
   17 sub _unionTables_init {}; # don't reload this file
   18 
   19 =head2 unionTables.pl
   20 
   21  ######################################################################
   22  #
   23  #  Make a two-column table in HTML and Latex2HTML modes
   24  #
   25  #  Usage:  ColumnTable(col1,col2,[options])
   26  #
   27  #  Options can be taken from:
   28  #
   29  #      indent => n           the width to indent the first column
   30  #                            (default is 0)
   31  #
   32  #      separation => n       the width of the separating gutter
   33  #                            (default is 50)
   34  #
   35  #      valign => type        set the vertical alignment
   36  #                            (default is "MIDDLE")
   37  #
   38 
   39 =cut
   40 
   41 sub ColumnTable {
   42   my $col1 = shift; my $col2 = shift;
   43   my %options = (indent => 0, separation => 50, valign => "MIDDLE", @_);
   44   my ($ind,$sep) = ($options{"indent"},$options{"separation"});
   45   my $valign = $options{"valign"};
   46 
   47   my ($bhtml,$ehtml) = ('\begin{rawhtml}','\end{rawhtml}');
   48   ($bhtml,$ehtml) = ('','') unless ($displayMode eq "Latex2HTML");
   49 
   50   my $HTMLtable = qq {
   51     $bhtml<TABLE BORDER="0"><TR VALIGN="$valign">
   52     <TD WIDTH="$ind">&nbsp;</TD><TD>$ehtml
   53     $col1
   54     $bhtml</TD><TD WIDTH="$sep">&nbsp;</TD><TD>$ehtml
   55     $col2
   56     $bhtml</TD></TR></TABLE>$ehtml
   57   };
   58 
   59   MODES(
   60     TeX => '\par\medskip\hbox{\qquad\vtop{'.
   61      '\advance\hsize by -3em '.$col1.'}}'.
   62            '\medskip\hbox{\qquad\vtop{'.
   63            '\advance\hsize by -3em '.$col2.'}}\medskip',
   64     Latex2HTML => $HTMLtable,
   65     HTML => $HTMLtable
   66   );
   67 }
   68 
   69 =pod
   70 
   71  #
   72  #  Use columns for a match-list output
   73  #
   74  #  Usage:  ColumnMatchTable($ml,options)
   75  #
   76  #  where $ml is a math list reference and options are those
   77  #  allowed for ColumnTable above.
   78  #
   79 =cut
   80 
   81 sub ColumnMatchTable {
   82   my $ml = shift;
   83 
   84   ColumnTable($ml->print_q,$ml->print_a,@_);
   85 }
   86 
   87 =pod
   88 
   89  #
   90  #  Command for tables with no borders.
   91  #
   92  #  Usage:  BeginTable(options);
   93  #
   94  #  Options are taken from:
   95  #
   96  #    border => n           value for BORDER attribute (default 0)
   97  #    spacing => n          value for CELLSPACING attribute (default 0)
   98  #    padding => n          value for CELLPADDING attribute (default 0)
   99  #    tex_spacing => dimen  value for spacing between columns in TeX
  100  #                          (e.g, tex_spacing => 2em) (default 1em)
  101  #    tex_border => dimen   value for left- and right border in TeX (0pt)
  102  #    center => 0 or 1      center table or not (default 1)
  103  #
  104 
  105 =cut
  106 
  107 sub BeginTable {
  108   my %options = (border => 0, padding => 0, spacing => 0, center => 1,
  109                  tex_spacing => "1em", tex_border => "0pt", @_);
  110   my ($bd,$pd,$sp) = ($options{border},$options{padding},$options{spacing});
  111   my ($tsp,$tbd) = ($options{tex_spacing},$options{tex_border});
  112   my ($center,$tcenter) = (' ALIGN="CENTER"','\centerline');
  113      ($center,$tcenter) = ('','') if (!$options{center});
  114   my $table =
  115     qq{<TABLE BORDER="$bd" CELLPADDING="$pd" CELLSPACING="$sp"$center>};
  116 
  117   MODES(
  118     TeX => '\par\medskip'.$tcenter.'{\kern '.$tbd.
  119            '\vbox{\halign{#\hfil&&\kern '.$tsp.' #\hfil',
  120     Latex2HTML => $bHTML.$table.$eHTML."\n",
  121     HTML => $table."\n"
  122   );
  123 }
  124 
  125 =pod
  126 
  127  #
  128  #  Usage:  EndTable(options)
  129  #
  130  #  where options are taken from:
  131  #
  132  #     tex_border => dimen     extra vertical space in TeX mode (default 0pt)
  133  #
  134 
  135 =cut
  136 
  137 sub EndTable {
  138   my %options = (tex_border => "0pt", @_);
  139   my $tbd = $options{tex_border};
  140   MODES(
  141     TeX => '\cr}}\kern '.$tbd.'}\medskip'."\n",
  142     Latex2HTML => $bHTML.'</TABLE>'.$eHTML."\n",
  143     HTML => '</TABLE>'."\n"
  144   );
  145 }
  146 
  147 =pod
  148 
  149  #
  150  #  Creates a row in the table
  151  #
  152  #  Usage:  Row([item1,item2,...],options);
  153  #
  154  #  Each item appears as a separate entry in the table.
  155  #
  156  #  Options control how the row is displayed:
  157  #
  158  #    indent => num           Specifies size of blank column on the left
  159  #                            (default:  indent => 0)
  160  #
  161  #    separation => num       Specifies separation of columns
  162  #                            (default:  spearation => 30)
  163  #
  164  #    tex_vspace => "dimen"   Specifies additional vertical spacing for TeX
  165  #
  166  #    align => "type"         Specifies alignment of initial column
  167  #                            (default:  align => "LEFT")
  168  #
  169  #    valign => "type"        Specified vertical alignment of row
  170  #                            (default:  valign => "MIDDLE")
  171  #
  172 
  173 =cut
  174 
  175 sub Row {
  176   my $rowref = shift; my @row = @{$rowref};
  177   my %options = (
  178      indent => 0, separation => 30,
  179      align => "LEFT", valign => "MIDDLE",
  180      @_
  181   );
  182   my ($cind,$csep) = ($options{indent},$options{separation});
  183   my ($align,$valign) = ($options{align},$options{valign});
  184   my $sep = '<TD WIDTH="'.$csep.'">&nbsp;</TD>'; $sep = '' if ($csep < 1);
  185   my $ind = '<TD WIDTH="'.$cind.'">&nbsp;</TD>'; $ind = '' if ($cind < 1);
  186   my $fill = '';
  187   $fill = '\hfil' if (uc($align) eq "CENTER");
  188   $fill = '\hfill' if (uc($align) eq "RIGHT");
  189   my $vspace = '';
  190   $vspace = '\noalign{\vskip '.$options{tex_vspace}.'}' if $options{tex_vspace};
  191 
  192   MODES(
  193     TeX => '\cr'.$vspace."\n". $fill . join('& ',@row),
  194     Latex2HTML =>
  195       $bHTML."<TR VALIGN=\"$valign\">$ind<TD ALIGN=\"$align\">".$eHTML .
  196       join($bHTML."</TD>$sep<TD>".$eHTML,@row) .
  197       $bHTML.'</TD></TR>'.$eHTML."\n",
  198     HTML => "<TR VALIGN=\"$valign\">$ind<TD ALIGN=\"$align\">" .
  199       join("</TD>$sep<TD>",@row) . '</TD></TR>'."\n"
  200   );
  201 }
  202 
  203 =pod
  204 
  205  #
  206  #  AlignedRow([item1,item2,...],options);
  207  #
  208  #  Options control how the row is displayed:
  209  #
  210  #    indent => num           Specifies size of blank column on the left
  211  #                            (default:  indent => 0)
  212  #
  213  #    separation => num       Specifies separation of columns
  214  #                            (default:  spearation => 30)
  215  #
  216  #    tex_vspace => "dimen"   Specifies additional vertical spacing for TeX
  217  #
  218  #    align => "type"         Specifies alignment of all columns
  219  #                            (default:  align => "CENTER")
  220  #
  221  #    valign => "type"        Specified vertical alignment of row
  222  #                            (default:  valign => "MIDDLE")
  223  #
  224 
  225 =cut
  226 
  227 sub AlignedRow {
  228   my $rowref = shift; my @row = @{$rowref};
  229   my %options = (
  230      indent => 0, separation => 30,
  231      align => "CENTER", valign => "MIDDLE",
  232      @_
  233   );
  234   my ($cind,$csep) = ($options{indent},$options{separation});
  235   my ($align,$valign) = ($options{align},$options{valign});
  236   my $sep = '<TD WIDTH="'.$csep.'">&nbsp;</TD>'; $sep = '' if ($csep < 1);
  237   my $ind = '<TD WIDTH="'.$cind.'">&nbsp;</TD>'; $ind = '' if ($cind < 1);
  238   my $fill = '';
  239   $fill = '\hfil ' if (uc($align) eq "CENTER");
  240   $fill = '\hfill ' if (uc($align) eq "RIGHT");
  241   my $vspace = '';
  242   $vspace = '\noalign{\vskip '.$options{tex_vspace}.'}' if $options{tex_vspace};
  243 
  244   MODES(
  245     TeX => '\cr'.$vspace."\n". $fill . join('&'.$fill,@row),
  246     Latex2HTML =>
  247       $bHTML."<TR VALIGN=\"$valign\">$ind<TD ALIGN=\"$align\">".$eHTML .
  248       join($bHTML."</TD>$sep<TD ALIGN=\"$align\">".$eHTML,@row) .
  249       $bHTML.'</TD></TR>'.$eHTML."\n",
  250     HTML => "<TR VALIGN=\"$valign\">$ind<TD ALIGN=\"$align\">" .
  251       join("</TD>$sep<TD ALIGN=\"$align\">",@row) . '</TD></TR>'."\n"
  252   );
  253 }
  254 
  255 =pod
  256 
  257  #
  258  #  Add extra space between rows of a table
  259  #
  260  #  Usage:  TableSpace(pixels,points)
  261  #
  262  #  where pixels is the number of pixels of space in HTML mode and
  263  #  points is the number of points to use in TeX mode.
  264  #
  265 
  266 =cut
  267 
  268 sub TableSpace {
  269   my $rsep = shift;
  270   my $tsep = shift;
  271   $rsep = $tsep if (defined($tsep) && $main::displayMode eq "TeX");
  272   return "" if ($rsep < 1);
  273   MODES(
  274     TeX => '\vadjust{\kern '.$rsep.'pt}' . "\n",
  275     Latex2HTML =>
  276       $bHTML.'<TR><TD HEIGHT="'.$rsep.'"><!></TD></TR>'.$eHTML."\n",
  277     HTML => '<TR><TD HEIGHT="'.$rsep.'"></TD></TR>'."\n",
  278   );
  279 }
  280 
  281 =pod
  282 
  283  #
  284  #  A horizontal rule within a table.  (Could have been a variable,
  285  #  but all the other table commands are subroutines, so kept it
  286  #  one to be consistent.)
  287  #
  288 
  289 =cut
  290 
  291 sub TableLine {
  292   MODES(
  293     TeX => '\vadjust{\kern2pt\hrule\kern2pt}',
  294     Latex2HTML => $bHTML.
  295       '<TR><TD COLSPAN="10"><HR NOSHADE SIZE="1"></TD></TR>'.
  296       $eHTML."\n",
  297     HTML =>'<TR><TD COLSPAN="10"><HR NOSHADE SIZE="1"></TD></TR>'."\n"
  298   );
  299 }
  300 
  301 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9