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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7010 - (download) (as text) (annotate)
Thu Jul 28 23:26:30 2011 UTC (8 years, 5 months ago) by gage
File size: 40487 byte(s)
updated to courses.maa version


    1 loadMacros("Parser.pl");
    2 
    3 package Typeset;
    4 
    5 sub addVariables {
    6   my $context = shift; my @vars;
    7   foreach my $v ('a'..'z','A'..'Z') {push(@vars,$v=>'Real')}
    8   $context->variables->are(@vars);
    9   $context->variables->remove('U'); # used as operator below
   10 }
   11 
   12 ######################################################################
   13 
   14 package Typeset::Function;
   15 @ISA = qw(Parser::Function);
   16 
   17 sub _check {
   18   my $self = shift;
   19   $self->{type} = $Value::Type{number};
   20 }
   21 
   22 sub eval {
   23   my $self = shift;
   24   $self->Error("Can't evaluate '%s'",$self->{name});
   25 }
   26 
   27 sub perl {
   28   my $self = shift;
   29   $self->Error("No perl form for '%s'",$slef->{name});
   30 }
   31 
   32 ######################################################################
   33 
   34 package Typeset::Function::named;
   35 @ISA = qw(Typeset::Function);
   36 
   37 # just override the _check method
   38 
   39 ######################################################################
   40 
   41 package Typeset::Function::text;
   42 @ISA = qw(Typeset::Function);
   43 
   44 sub TeX {
   45   my $self = shift; my @params;
   46   foreach my $p (@{$self->{params}}) {push(@params,$p->{isQuoted}? $p->{value}: $p->string)};
   47   return '\hbox{'.join('',@params).'}';
   48 }
   49 
   50 ######################################################################
   51 
   52 package Typeset::Function::TeX;
   53 @ISA = qw(Typeset::Function);
   54 
   55 sub TeX {
   56   my $self = shift; my @params;
   57   foreach my $p (@{$self->{params}}) {push(@params,$p->{isQuoted}? $p->{value}: $p->string)};
   58   return join('',@params);
   59 }
   60 
   61 ######################################################################
   62 
   63 package Typeset::Function::bf;
   64 @ISA = qw(Typeset::Function);
   65 
   66 sub TeX {
   67   my $self = shift; my @params;
   68   foreach my $p (@{$self->{params}}) {push(@params,$p->TeX)};
   69   return '{\bf '.join('',@params).'}';
   70 }
   71 
   72 ######################################################################
   73 
   74 package Typeset::Function::cal;
   75 @ISA = qw(Typeset::Function);
   76 
   77 sub TeX {
   78   my $self = shift; my @params;
   79   foreach my $p (@{$self->{params}}) {push(@params,$p->TeX)};
   80   return '{\cal '.join('',@params).'}';
   81 }
   82 
   83 ######################################################################
   84 
   85 package Typeset::Function::det;
   86 @ISA = qw(Typeset::Function);
   87 
   88 sub TeX {
   89   my $self = shift;
   90   return $self->SUPER::TeX(@_) unless $self->{params}[0]->type eq 'Matrix';
   91   my $M = bless {%{$self->{params}[0]}, open => '|', close => '|'}, ref($self->{params}[0]);
   92   return '\det'.$M->TeX;
   93 }
   94 
   95 ######################################################################
   96 
   97 package Typeset::Function::accent;
   98 @ISA = qw(Typeset::Function);
   99 
  100 sub _check {
  101   my $self = shift;
  102   return if $self->checkArgCount(1);
  103   $self->{type} = $self->{params}[0]->typeRef;
  104 }
  105 
  106 sub TeX {
  107   my $self = shift;
  108   return '{'.$self->{def}{TeX}.'{'.$self->{params}[0]->TeX.'}}';
  109 }
  110 
  111 ######################################################################
  112 
  113 package Typeset::Function::overunder;
  114 @ISA = qw(Typeset::Function);
  115 
  116 sub _check {
  117   my $self = shift;
  118   return if $self->checkArgCount(1);
  119   $self->{type} = $self->{params}[0]->typeRef;
  120 }
  121 
  122 sub TeX {
  123   my $self = shift;
  124   return $self->{def}{TeX}.'{'.$self->{params}[0]->TeX.'}';
  125 }
  126 
  127 ######################################################################
  128 
  129 package Typeset::Function::Fence;
  130 @ISA = qw(Typeset::Function);
  131 
  132 sub _check {
  133   my $self = shift; my $n = scalar(@{$self->{params}});
  134   $self->Error("Fence requires an open parenthesis, a formula, and a close parenthesis") if $n < 3;
  135   if ($n > 3) {$self->{type} = Value::Type("List",$n,$Value::Type{unknown})}
  136     else {$self->{type} = $self->{params}[1]->typeRef}
  137 }
  138 
  139 sub TeX {
  140   my $self = shift; my @params = @{$self->{params}};
  141   my $open = shift(@params); my $close = pop(@params);
  142   $open = $open->{isQuoted}? $open->{value}: $open->string;
  143   $close = $close->{isQuoted}? $close->{value}: $close->string;
  144   $open = "." unless $open; $close = "." unless $close;
  145   $open = '\{' if $open eq '{'; $close = '\}' if $close eq '}';
  146   foreach my $p (@params) {$p = $p->TeX}
  147   return '\left'.$open." ".join(',',@params).'\right'.$close." ";
  148 }
  149 
  150 ######################################################################
  151 
  152 package Typeset::Function::Cases;
  153 @ISA = qw(Typeset::Function);
  154 
  155 sub _check {
  156   my $self = shift;
  157   $self->{formulas} = []; $self->{conditions} = [];
  158   $self->Error("There must be at least one argument for '%s'",$self->{name})
  159     unless scalar(@{$self->{params}}) > 0;
  160   foreach my $p (@{$self->{params}}) {
  161     if ($p->type eq 'List' && $p->length == 2) {
  162       push(@{$self->{formulas}},$p->{coords}[0]);
  163       push(@{$self->{conditions}},$p->{coords}[1]);
  164     } elsif ($p->class eq 'BOP' && $p->{bop} eq '->') {
  165       push(@{$self->{formulas}},$p->{rop});
  166       push(@{$self->{conditions}},$p->{lop});
  167     } elsif ($p->class eq 'BOP' && $p->{bop} eq 'if ') {
  168       push(@{$self->{formulas}},$p->{lop});
  169       my $if = $self->{equation}{context}{parser}{UOP}->new($self->{equation},'_if_',$p->{rop});
  170       push(@{$self->{conditions}},$if);
  171     } elsif ($p->class eq 'UOP' && $p->{uop} eq 'otherwise') {
  172       push(@{$self->{formulas}},$p->{op});
  173       my $otherwise = $self->{equation}{context}{parser}{String}->new($self->{equation},'"otherwise"');
  174       push(@{$self->{conditions}},$otherwise);
  175     } else {
  176       $self->Error("The arguments for '%s' must be function-condition pairs",$self->{name});
  177     }
  178   }
  179   my $type = $self->{formulas}[0]->typeRef;
  180   foreach my $f (@{$self->{formulas}}) {
  181     $self->Error("The formulas for '%s' must all be of the same type",$self->{name})
  182       unless Parser::Item::typeMatch($type,$f->typeRef);
  183   }
  184   $self->{type} = $type;
  185 }
  186 
  187 sub TeX {
  188   my $self = shift; my @rows = ();
  189   my @f = @{$self->{formulas}}; my @c = @{$self->{conditions}};
  190   foreach my $i (0..$#f) {push(@rows,$f[$i]->TeX.'&'.$c[$i]->TeX."\\\\ ")}
  191   return '\begin{cases}'.join('',@rows).'\end{cases}';
  192 }
  193 
  194 ######################################################################
  195 
  196 package Typeset::Function::Array;
  197 @ISA = qw(Typeset::Function);
  198 
  199 sub _check {
  200   my $self = shift;
  201   my $equation = $self->{equation}; my $context = $equation->{context};
  202   my $template; my $param = $self->{params}[0];
  203   $self->Error("Array requires a list of entries") unless defined $param;
  204   if ($param && $param->class eq 'QuotedString') {
  205     $template = shift(@{$self->{params}})->{value};
  206   }
  207   if (scalar(@{$self->{params}}) == 1 && $self->{params}[0]->type eq 'Matrix') {
  208     $self->{M} = $self->{params}[0];
  209   } else {
  210     my $null = $context->{parser}{Constant}->new($equation,"Null");
  211     my @rows = @{$self->{params}};
  212     @rows = @{$rows[0]->{coords}} if scalar(@rows) == 1 && $rows[0]->class eq 'List';
  213     my $c = 0; foreach my $r (@rows) {$c = $r->length if $r->length > $c}
  214     if ($c == 1 && scalar(@rows) > 1) {
  215       $c = scalar(@rows);
  216       @rows = ($context->{parser}{List}->new($equation,[@rows],0,$context->{parens}{start}));
  217     }
  218     foreach my $r (@rows) {
  219       $r = ($r->class eq 'List'? $r->{coords} : [$r]);
  220       while (scalar(@{$r}) < $c) {push(@{$r},$null)};
  221       $r = bless
  222         $context->{parser}{List}->new($equation,$r,0,$context->{parens}{start},$Value::Type{number},'[',']'),
  223         $context->{lists}{Matrix}{class};
  224     }
  225     $self->{M} = bless
  226         $context->{parser}{List}->new($equation,\@rows,0,$context->{parens}{start},$rows[0]->typeRef),
  227         $context->{lists}{Matrix}{class};
  228   }
  229   $self->{M}{open} = $self->{M}{close} = '';
  230   $self->{M}{array_template} = $template;
  231   $self->{type} = $self->{M}->typeRef;
  232 }
  233 
  234 sub TeX {my $self = shift; $self->{M}->TeX}
  235 
  236 ######################################################################
  237 
  238 package Typeset::Function::bigOp;
  239 @ISA = qw(Typeset::Function);
  240 
  241 sub _check {
  242   my $self = shift; my $name = $self->{name};
  243   my @params = @{$self->{params}}; my $allowMax = !$self->{def}{noMax};
  244   ## check for (x;fn),  (m,M; fn),  (x:m,M; fn),  (x,m,M; fn),  (x->m; fn)
  245   if (scalar(@params) == 2) {
  246     $self->{op} = $params[1]; my $lop = $params[0];
  247     if ($lop->type eq 'List') {
  248       if ($lop->length == 2 && $allowMax) {
  249   $self->{min} = $lop->{coords}[0];
  250   $self->{max} = $lop->{coords}[1];
  251       } elsif ($lop->length == 3 && $lop->{coords}[0]->class eq 'Variable' && $allowMax) {
  252   $self->{var} = $lop->{coords}[0];
  253   $self->{min} = $lop->{coords}[1];
  254   $self->{max} = $lop->{coords}[2];
  255       } else {
  256   $self->{min} = $lop;
  257       }
  258     } elsif ($lop->class eq 'Variable') {
  259       $self->{var} = $lop;
  260     } elsif ($lop->class eq 'BOP' && $lop->{bop} eq ':') {
  261       if ($lop->{lop}->class eq 'Variable') {
  262   $self->{var} = $lop->{lop};
  263   if ($lop->{rop}->class eq 'List' && $lop->{rop}->length == 2 && $allowMax) {
  264     $self->{min} = $lop->{rop}{coords}[0];
  265     $self->{max} = $lop->{rop}{coords}[1];
  266   } else {$self->{min} = $lop->{rop}}
  267       } else {$self->{min} = $lop}
  268     } elsif ($lop->class eq 'BOP' && $lop->{bop} eq '->') {
  269       if ($lop->{lop}->class eq 'Variable' && $self->{def}{allowArrow}) {
  270   $self->{var} = $lop->{lop};
  271   $self->{min} = $lop->{rop};
  272       } else {$self->{min} = $lop}
  273     } else {$self->{min} = $lop}
  274   } elsif (scalar(@params) == 1) {
  275     $self->{op} = $params[0];
  276   } else {
  277     $self->Error("Function '%s' has too many inputs",$name) if scalar(@params) > 2;
  278     $self->Error("Function '%s' requires a formula as input",$name) unless scalar(@params) < 1;
  279   }
  280   if (!$self->{var}) {
  281     my $variable = $self->{equation}{context}{parser}{Variable};
  282     my @vars = keys %{$self->{op}->getVariables};
  283     if (scalar(@vars) == 1) {
  284       $self->{var} = $variable->new($self->{equation},$vars[0]);
  285       $self->{implicitVar} = 1;
  286     }
  287   }
  288   $self->{type} = $self->{op}->typeRef;
  289 }
  290 
  291 sub TeX {
  292   my ($self,$precedence,$showparens,$position) = @_;
  293   my $fn = $self->{def}; my $x = $self->{var};
  294   my $min = $self->{min}; my $max = $self->{max};
  295   $min = $min->TeX if defined $min;
  296   $max = $max->TeX if defined $max;
  297   $min = (defined($min)? $x->TeX.($fn->{allowArrow} ? '\to ' : '=').$min : $x->TeX)
  298     if defined $x && !$fn->{dx};
  299   my $TeX = $fn->{TeX}.(defined($min)? "_{$min}": "").
  300                        (defined($max)? "^{$max}": "")." ".$self->{op}->TeX;
  301   $TeX .= '\,d'.$x->TeX if defined $x && $fn->{dx};
  302   if (defined($precedence) and $precedence > $fn->{precedence})
  303     {$TeX = '\left('.$TeX.'\right)'} else {$TeX = "{$TeX}"}
  304   return $TeX;
  305 }
  306 
  307 sub string {
  308   my ($self,$precedence,$showparens,$position,$outerRight,$power) = @_;
  309   my $fn = $self->{equation}{context}{operators}{'fn'};
  310   my $fn_precedence = $fn->{precedence};
  311   $fn_precedence = $fn->{parenPrecedence}
  312     if ($position && $position eq 'right' && $fn->{parenPrecedence});
  313   $fn = $self->{def}; my $x = $self->{var};
  314   my $min = $self->{min}; my $max = $self->{max};
  315   $min = $min->string if defined $min;
  316   $max = $max->string if defined $max;
  317   $min = (defined($min)? $x->string.($fn->{allowArrow}? "->": ":").$min : $x->string)
  318     if defined $x && !$self->{implicitVar};
  319   my $string = (defined($min)? $min: "").(defined($max)? ",$max": "");
  320   $string .= ";" if $string ne "";
  321   $string = $self->{name}.'('.$string.$self->{op}->string.')';
  322   $string = $self->addParens($string) if (defined($precedence) and $precedence > $fn_precedence);
  323   return $string;
  324 }
  325 
  326 ######################################################################
  327 
  328 package Typeset::BOP;
  329 @ISA = qw(Parser::BOP);
  330 
  331 ######################################################################
  332 
  333 package Typeset::BOP::TeX;
  334 @ISA = qw(Typeset::BOP);
  335 
  336 sub _check {
  337   my $self = shift;
  338   $self->{isConstant} = 0;
  339   $self->{type} = $Value::Type{number};
  340 }
  341 
  342 sub _eval {
  343   my $self = shift;
  344   my $name = $self->{def}{string} || $self->{bop};
  345   $self->Error("Can't evaluate '%s'",$name);
  346 }
  347 
  348 sub perl {
  349   my $self = shift;
  350   my $name = $self->{def}{string} || $self->{bop};
  351   $self->Error("No perl form for '%s'",$name);
  352 }
  353 
  354 ######################################################################
  355 
  356 package Typeset::BOP::subtract;
  357 @ISA = qw(Parser::BOP::subtract);
  358 
  359 sub matchError {
  360   my $self = shift; my ($ltype,$rtype) = @_;
  361   return $self->SUPER::matchError(@_)
  362     unless $ltype->{name} =~ m/Number|Set/ && $rtype->{name} =~ m/Number|Set/;
  363   $self->{type} = Value::Type('Set',1);
  364 }
  365 
  366 ######################################################################
  367 
  368 package Typeset::BOP::union;
  369 @ISA = qw(Parser::BOP::union);
  370 
  371 # handle _check to set type for numbers and sets
  372 
  373 ######################################################################
  374 
  375 package Typeset::BOP::divide;
  376 @ISA = qw(Parser::BOP::divide);
  377 
  378 sub TeX {
  379   my $self = shift;
  380   my ($precedence,$showparens,$position,$outerRight) = @_;
  381   my $TeX; my $bop = $self->{def};
  382   return $self->SUPER::TeX(@_) if $self->{def}{noFrac};
  383   $showparens = '' unless defined($showparens);
  384   my $addparens =
  385       defined($precedence) &&
  386       ($showparens eq 'all' || ($precedence > $bop->{precedence} && $showparens ne 'nofractions') ||
  387       ($precedence == $bop->{precedence} &&
  388         ($bop->{associativity} eq 'right' || $showparens eq 'same')));
  389 
  390   $self->{lop}{showParens} = $self->{rop}{showParens} = 0;
  391   $TeX = '\frac{'.($self->{lop}->TeX).'}{'.($self->{rop}->TeX).'}';
  392   $self->{lop}{showParens} = $self->{rop}{showParens} = 1;
  393 
  394   $TeX = '\left('.$TeX.'\right)' if $addparens;
  395   return $TeX;
  396 }
  397 
  398 
  399 ######################################################################
  400 
  401 package Typeset::BOP::power;
  402 @ISA = qw(Parser::BOP::power);
  403 
  404 sub TeX {
  405   my $self = shift; my $rop = $self->{rop};
  406   my ($open,$close,$parens) = ($rop->{open},$rop->{close});
  407   $rop->{open} = $rop->{close} = "" if $rop->{isSetType} || $rop->{isListType};
  408   my $tex = Parser::BOP::underscore::TeX($self,@_);
  409   $rop->{open} = $open; $rop->{close} = $close;
  410   return $tex;
  411 }
  412 
  413 ######################################################################
  414 
  415 package Typeset::BOP::underscore;
  416 @ISA = qw(Typeset::BOP::TeX);
  417 
  418 sub TeX {
  419   my $self = shift; my $rop = $self->{rop};
  420   my ($open,$close,$parens) = ($rop->{open},$op->{close});
  421   $rop->{open} = $rop->{close} = "" if $rop->{isSetType} || $rop->{isListType};
  422   my $tex = Parser::BOP::underscore::TeX($self,@_);
  423   $rop->{open} = $open; $rop->{close} = $close;
  424   return $tex;
  425 }
  426 
  427 ######################################################################
  428 
  429 package Typeset::BOP::colon;
  430 @ISA = qw(Typeset::BOP::TeX);
  431 
  432 sub string {
  433   my $self = shift;
  434   my ($lop,$rop) = ($self->{lop},$self->{rop});
  435   return $self->SUPER::string(@_) unless $lop->class eq 'Variable' &&
  436     $rop->class eq 'BOP' && $rop->{def}{isFnArrow};
  437   return $lop->string.': '.$rop->string;
  438 }
  439 
  440 sub TeX {
  441   my $self = shift;
  442   my ($lop,$rop) = ($self->{lop},$self->{rop});
  443   return $self->SUPER::TeX(@_) unless $lop->class eq 'Variable' &&
  444     $rop->class eq 'BOP' && $rop->{def}{isFnArrow};
  445   return $lop->TeX.'\colon '.$rop->TeX;
  446 }
  447 
  448 ######################################################################
  449 
  450 package Typeset::BOP::semicolon;
  451 @ISA = qw(Typeset::BOP);
  452 
  453 sub _check {
  454   my $self = shift;
  455   my ($ltype,$rtype) = ($self->{lop}->typeRef,$self->{rop}->typeRef);
  456   my $type = Value::Type('Comma',2,$Value::Type{unknown});
  457   if ($ltype->{name} eq 'Comma' && $self->{lop}{isSemicolon}) {
  458     $type->{length} += $self->{lop}->length - 1;
  459     $ltype = $self->{lop}->entryType;
  460   }
  461   $type->{entryType} = $ltype if (Parser::Item::typeMatch($ltype,$rtype));
  462   $self->{type} = $type;
  463   $self->{isSemicolon} = 1;
  464 }
  465 
  466 sub _eval {($_[1],$_[2])}
  467 
  468 sub makeList {
  469   my $self = shift;
  470   return $self unless $self->{isSemicolon};
  471   my ($lop,$rop) = ($self->{lop},$self->{rop});
  472   my $equation = $self->{equation}; my $context = $equation->{context};
  473   $lop = $context->{parser}{List}->
  474     new($equation,[$lop->makeList],$lop->{isConstant},$context->{parens}{start},$lop->entryType,'(',')')
  475       if $lop->{def}{isComma} && !$lop->{isSemicolon};
  476   $rop = $context->{parser}{List}->
  477     new($equation,[$rop->makeList],$dop->{isConstant},$context->{parens}{start},$rop->entryType,'(',')')
  478       if $rop->{def}{isComma};
  479   return (($self->{lop}{isSemicolon} ? $lop->makeList : $lop),
  480     ($self->{rop}{isSemicolon} ? $rop->makeList : $rop));
  481 }
  482 
  483 ######################################################################
  484 
  485 package Typeset::UOP;
  486 @ISA = qw(Parser::UOP);
  487 
  488 sub TeX {
  489   my ($self,$precedence,$showparens,$position,$outerRight) = @_;
  490   my $TeX; my $uop = $self->{def}; $position = '' unless defined($position);
  491   my $fracparens = ($uop->{nofractionparens}) ? "nofractions" : "";
  492   my $addparens = $outerRight;
  493   $TeX = (defined($uop->{TeX}) ? $uop->{TeX} : $uop->{string});
  494   if ($uop->{associativity} eq "right") {
  495     $TeX = $self->{op}->TeX($uop->{precedence},$fracparens) . $TeX;
  496   } else {
  497     $TeX = $TeX . $self->{op}->TeX($uop->{precedence},$fracparens);
  498   }
  499   $TeX = '\left('.$TeX.'\right)' if $addparens;
  500   return $TeX;
  501 }
  502 
  503 ######################################################################
  504 
  505 package Typeset::UOP::TeX;
  506 @ISA = qw(Typeset::UOP);
  507 
  508 sub _check {
  509   my $self = shift;
  510   $self->{isConstant} = 0;
  511   $self->{type} = $Value::Type{number};
  512 }
  513 
  514 sub _eval {
  515   my $self = shift;
  516   my $name = $self->{def}{string} || $self->{bop};
  517   $self->Error("Can't evaluate '%s'",$name);
  518 }
  519 
  520 sub TeX {
  521   my ($self,$precedence) = @_;
  522   my $TeX; my $uop = $self->{def};
  523   $TeX = (defined($uop->{TeX}) ? $uop->{TeX} : $uop->{string});
  524   if ($uop->{associativity} eq "right")
  525      {$TeX = $self->{op}->TeX($uop->{precedence}) . $TeX} else
  526      {$TeX = $TeX . $self->{op}->TeX($uop->{precedence})}
  527   return $TeX;
  528 }
  529 
  530 sub perl {
  531   my $self = shift;
  532   my $name = $self->{def}{string} || $self->{bop};
  533   $self->Error("No perl form for '%s'",$name);
  534 }
  535 
  536 ######################################################################
  537 
  538 package Typeset::UOP::_if_;
  539 @ISA = qw(Typeset::UOP::TeX);
  540 
  541 sub string {
  542   my $self = shift;
  543   return ' if '.$self->{op}->string;
  544 }
  545 
  546 sub TeX {
  547   my $self = shift;
  548   return '\hbox{if }'.$self->{op}->TeX;
  549 }
  550 
  551 ######################################################################
  552 
  553 package Typeset::UOP::prime;
  554 @ISA = qw(Typeset::UOP::TeX);
  555 
  556 sub string {
  557   my ($self,$precedence,$showparens,$position,$outerRight) = @_;
  558   my $uop = $self->{def}; $position = '' unless defined($position);
  559   my $addparens = defined($precedence) &&
  560     ($precedence > $uop->{precedence} || $position eq 'right' || $outerRight);
  561   my $string = $self->{op}->string($uop->{precedence},$fracparens) . "'";
  562   $string = '\left('.$string.'\right)' if $addparens;
  563   return $string;
  564 }
  565 
  566 sub TeX {
  567   my ($self,$precedence,$showparens,$position,$outerRight) = @_;
  568   my $uop = $self->{def}; $position = '' unless defined($position);
  569   my $addparens = defined($precedence) &&
  570     ($precedence > $uop->{precedence} || $position eq 'right' || $outerRight);
  571   my $TeX = $self->{op}->TeX($uop->{precedence},$fracparens) . "'";
  572   $TeX = '\left('.$TeX.'\right)' if $addparens;
  573   return $TeX;
  574 }
  575 
  576 ######################################################################
  577 
  578 package Typeset::UOP::root;
  579 @ISA = qw(Typeset::UOP::TeX);
  580 
  581 sub TeX {
  582   my $self = shift;
  583   return "\\root ".$self->{op}->TeX if $self->{op}->class eq 'BOP' && $self->{op}{bop} eq 'of ';
  584   return "\\root ".$self->{op}{coords}[0]->TeX." \\of {".$self->{op}{coords}[1]->TeX."}"
  585     if $self->{op}->class eq 'List' && scalar(@{$self->{op}{coords}}) == 2;
  586   return "\\sqrt{".$self->{op}->TeX."}";
  587 }
  588 
  589 package Typeset::BOP::of;
  590 @ISA = qw(Typeset::BOP::TeX);
  591 
  592 sub TeX {
  593   my $self = shift;
  594   return $self->{lop}->TeX . " \\of {" . $self->{rop}->TeX . "}";
  595 }
  596 
  597 ######################################################################
  598 
  599 package Typeset::List;
  600 @ISA = qw(Parser::List);
  601 
  602 sub _eval {
  603   my $self = shift;
  604   return $self->SUPER::_eval(@_) unless $self->type eq 'Number';
  605   $self->{coords}[0]->eval(@_);
  606 }
  607 
  608 sub new {
  609   my $self = shift;
  610   my $equation = shift; my $coords = shift;
  611   my $constant = shift; my $paren = shift;
  612   my $entryType = shift || $Value::Type{unknown};
  613   my $open = shift || ''; my $close = shift || '';
  614   my $context = $equation->{context};
  615   my $parens = $context->{parens};
  616 
  617   if ($paren && $close && $paren->{formInterval}) {
  618     $paren = $parens->{interval}
  619       if ($paren->{close} ne $close || (scalar(@{$coords}) == 2 &&
  620            ($coords->[0]->{isInfinite} || $coords->[1]->{isInfinite})));
  621   }
  622   my $type = Value::Type($paren->{type},scalar(@{$coords}),$entryType,
  623                                 list => 1, formMatrix => $paren->{formMatrix});
  624   if ($type->{name} ne 'Interval' && ($type->{name} ne 'Set' || $type->{length} != 0)) {
  625     if ($paren->{formMatrix} && $entryType->{formMatrix}) {$type->{name} = 'Matrix'}
  626     elsif ($entryType->{name} eq 'unknown') {
  627       if ($paren->{formList}) {$type->{name} = 'List'}
  628       elsif ($type->{name} eq 'Point') {
  629         $equation->Error("Entries in a Matrix must be of the same type and length")}
  630       elsif ($type->{name} ne 'Set') {
  631   $type->{name} = "Matrix" if $paren->{formMatrix};
  632   $equation->Error(["Entries in a %s must be of the same type",$type->{name}]);
  633       }
  634     }
  635   }
  636   $open = '' if $open eq 'start'; $close = '' if $close eq 'start';
  637   my $list = bless {
  638     coords => $coords, type => $type, open => $open, close => $close,
  639     paren => $paren, equation => $equation, isConstant => $constant
  640   }, $context->{lists}{$type->{name}}{class};
  641   $list->weaken;
  642 
  643   my $zero = 1;
  644   foreach my $x (@{$coords}) {$zero = 0, last unless $x->{isZero}}
  645   $list->{isZero} = 1 if $zero && scalar(@{$coords}) > 0;
  646 
  647   $list->_check;
  648 
  649 #  warn ">> $list->{type}{name} of $list->{type}{entryType}{name} of length $list->{type}{length}\n";
  650 
  651   if ($list->{isConstant} && $context->flag('reduceConstants')) {
  652     $type = $list->{type};
  653     $list = $list->Item("Value")->new($equation,[$list->eval]);
  654     $list->{type} = $type; $list->{open} = $open; $list->{close} = $close;
  655     $list->{value}->{open} = $open, $list->{value}->{close} = $close
  656       if ref($list->{value});
  657   }
  658   return $list;
  659 }
  660 
  661 ######################################################################
  662 
  663 package Typeset::List::List;
  664 @ISA = qw(Typeset::List Parser::List::List);
  665 
  666 sub _check {
  667   my $self = shift;
  668   $self->{isListType} = 1; $self->{showParens} = 1;
  669   return unless $self->length == 1;
  670   $self->{type} = {%{$self->{coords}[0]->typeRef}};
  671   $self->{type}{formMatrix} = 1 if $self->context->{parens}{$self->{open}}{formMatrix};
  672   $self->{isSingle} = 1;
  673   $self->entryType->{entryType} = $self->{coords}[0]->type if scalar(@{$self->{coords}}) == 1;
  674 }
  675 
  676 sub TeX {
  677   my $self = shift;
  678   return $self->SUPER::TeX(@_) if $self->{showParens} || $self->length != 1;
  679   return $self->{coords}[0]->TeX(@_);
  680 }
  681 
  682 ######################################################################
  683 
  684 package Typeset::List::Vector;
  685 @ISA = qw(Parser::List::List);
  686 
  687 sub TeX {
  688   my $self = shift; my $precedence = shift; my @coords = ();
  689   my $def = $self->context->{lists}{Vector};
  690   my ($open,$close) = ($def->{TeX_open},$def->{TeX_close});
  691   $open = '\{' if $open eq '{'; $close = '\}' if $close eq '}';
  692   $open  = '\left' .$open  if $open  ne '';
  693   $close = '\right'.$close if $close ne '';
  694   foreach my $x (@{$self->{coords}}) {push(@coords,$x->TeX)}
  695   return $open.join(',',@coords).$close unless $self->{ColumnVector};
  696   '\left[\begin{array}{c}'.join('\cr'."\n",@coords).'\cr\end{array}\right]';
  697 }
  698 
  699 ######################################################################
  700 
  701 package Typeset::List::Set;
  702 @ISA = qw(Typeset::List);
  703 
  704 sub _check {
  705   my $self = shift;
  706   $self->{isSetType} = 1; $self->{showParens} = 1;
  707   return unless $self->length == 1;
  708   my $x = $self->{coords}[0];
  709   if ($x->{isSetType}) {
  710     $x->{showParens} = 1;
  711     $self->{showParens} = 0;
  712   } else {
  713     if ($x->class =~ m/BOP|UOP/) {
  714       $self->{type} = $self->{coords}[0]->typeRef;
  715       $self->{showParens} = 0;
  716     }
  717   }
  718 }
  719 
  720 sub canBeInUnion {1};
  721 
  722 sub string {
  723   my $self = shift; my $precedence = shift;
  724   return $self->SUPER::string(@_) if $self->{showParens} || $self->length > 1;
  725   my $set = $self->{coords}[0];
  726   return '{ '.$set->string.' }' if $set->class eq 'BOP' && $set->{def}{formSet};
  727   return $self->{coords}[0]->string;
  728 }
  729 
  730 sub TeX {
  731   my $self = shift; my $precedence = shift;
  732   return $self->SUPER::TeX(@_) if $self->{showParens} || $self->length > 1;
  733   my $set = $self->{coords}[0];
  734   return '\left\{\,'.$set->TeX.'\,\right\}' if $set->class eq 'BOP' && $set->{def}{formSet};
  735   return $self->{coords}[0]->TeX;
  736 }
  737 
  738 ######################################################################
  739 
  740 package Typeset::List::AbsoluteValue;
  741 @ISA = qw(Parser::List::AbsoluteValue);
  742 
  743 sub TeX {
  744   my $self = shift;
  745   return $self->SUPER::TeX(@_) unless $self->{coords}[0]->type eq 'Matrix';
  746   my $M = bless {%{$self->{coords}[0]}, open => '|', close => '|'}, ref($self->{coords}[0]);
  747   $M->TeX;
  748 }
  749 
  750 ######################################################################
  751 
  752 package main;
  753 
  754 $context{Typeset} = $Parser::Context::Default::context{Full}->copy;
  755 $context{Typeset}->flags->set(
  756   reduceConstants => 0,
  757   reduceConstantFunctions => 0,
  758   allowMissingOperands => 1,          # turn off most error checking
  759   allowMissingFunctionInputs => 1,    #  by setting these four
  760   allowBadOperands => 1,              #  flags to 1
  761   allowBadFunctionInputs => 1,        #
  762   showExtraParens => 0,               # Try to keep the author's parens
  763 );
  764 $context{Typeset}->{_initialized} = 0;  # prevent updating of patterns until we're done
  765 
  766 sub TeXOp {
  767   my $type = shift; my $prec = shift; my $assoc = shift;
  768   my $op = shift; my $string = shift; my $tex = shift;
  769   $tex = "" unless defined $tex; $tex .= " " if substr($tex,0,1) eq "\\";
  770   my $class = 'Typeset::'.($type eq 'bin'? "BOP" : "UOP").'::TeX';
  771   return $op => {precedence => $prec, associativity => $assoc, type => $type,
  772     string => $string, TeX=>$tex, class=>$class, @_};
  773 }
  774 sub TeXUnary {my $op = shift; TeXOp("unary",1,"left",$op," $op ",@_)}
  775 sub TeXBin {my $op = shift; TeXOp("bin",.8,"left",$op," $op ",@_)}
  776 sub TeXRel {my $op = shift; TeXOp("bin",.7,"left",$op," $op ",@_)}
  777 sub TeXArrow {my $op = shift; TeXOp("bin",.7,"left",$op," $op ",@_)}
  778 
  779 $context{Typeset}->operators->add(
  780   ';' => {
  781     precedence => 0, associativity => 'left', type => 'bin', string => ';',
  782     class => 'Typeset::BOP::semicolon', isComma => 1
  783   },
  784   '_if_' => {
  785     precedence => .61, associativity => 'left', type => 'unary', string => ' if ',
  786     class => 'Typeset::UOP::_if_', hidden => 1
  787   },
  788   "'" => {
  789     precedence => 7.5, associativity => 'right', type => 'unary', string => "'",
  790     class => 'Typeset::UOP::prime'
  791   },
  792 );
  793 
  794 $context{Typeset}->operators->set(
  795   ',' => {precedence=>.5},
  796   '_' => {class=>'Typeset::BOP::underscore',associativity=>"right"},
  797   ' ' => {string => 'space'},
  798   'space' => {precedence => 3, associativity => 'left', type => 'bin',
  799         string => '', TeX => '', class => 'Parser::BOP::multiply', hidden => 1},
  800   '/'  => {class => 'Typeset::BOP::divide'},
  801   '/ ' => {class => 'Typeset::BOP::divide'},
  802   ' /' => {class => 'Typeset::BOP::divide'},
  803   '^'  => {class => 'Typeset::BOP::power'},
  804   '**' => {class => 'Typeset::BOP::power'},
  805   '-'  => {class => 'Typeset::BOP::subtract'},
  806   'U'  => {class => 'Typeset::BOP::union'},
  807 );
  808 
  809 $context{Typeset}->operators->redefine('&', using => ",", from=>$context{Typeset});
  810 $context{Typeset}->operators->redefine("\\\\", using => ";", from => $context{Typeset});
  811 $context{Typeset}->operators->redefine("cross", using => "><", from => $context{Typeset});
  812 
  813 $context{Typeset}->operators->add(
  814   TeXArrow('->','\to',isFnArrow=>1),
  815   TeXArrow('-->','\longrightarrow'),
  816   TeXArrow('<-','\leftarrow'),
  817   TeXArrow('<--','\longleftarrow'),
  818   TeXArrow('<->','\leftrightarrow'),
  819   TeXArrow('<-->','\longleftrightarrow'),
  820   TeXArrow('|->','\mapsto'),
  821   TeXArrow('|-->','\longmapsto'),
  822   TeXArrow('*->','\hookrightarrow'),
  823   TeXArrow('<-*','\hookleftarrow'),
  824   TeXArrow('=>','\Rightarrow'),
  825   TeXArrow('==>','\Longrightarrow'),
  826   TeXArrow('<=:','\Leftarrow'),
  827   TeXArrow('<==','\Longleftarrow'),
  828   TeXArrow('<=>','\Leftrightarrow'),
  829   TeXArrow('<==>','\Longleftrightarrow'),
  830   TeXArrow("up",'\uparrow'),
  831   TeXArrow('down','\downarrow'),
  832   TeXArrow('updown','\updownarrow'),
  833   TeXArrow('Up','\Uparrow'),
  834   TeXArrow('Down','\Downarrow'),
  835   TeXArrow('Updown','\Updownarrow'),
  836   TeXArrow('NW','\nwarrow'),
  837   TeXArrow('SE','\searrow'),
  838   TeXArrow('SW','\swarrow'),
  839   TeXArrow('NE','\nearrow'),
  840   TeXArrow('iff','\Leftrightarrow'),
  841 
  842   TeXRel('<','<'),                  TeXRel('lt','<'),
  843   TeXRel('>','>'),                  TeXRel('gt','>'),
  844   TeXRel('<=','\le'),               TeXRel('le'),
  845   TeXRel('>=','\ge'),               TeXRel('ge'),
  846   TeXRel('=','='),
  847   TeXRel('!=','\ne'),               TeXRel('ne','\ne'),
  848   TeXRel('<<','\ll'),
  849   TeXRel('>>','\gg'),
  850   TeXRel('sim','\sim'),             TeXRel('~','\sim'),
  851   TeXRel('simeq','\simeq'),         TeXRel('~-','\simeq'),
  852   TeXRel('cong','\cong'),           TeXRel('~=','\cong'),
  853   TeXRel('approx','\approx'),       TeXRel('~~','\approx'),
  854   TeXRel('equiv','\equiv'),         TeXRel('-=','\equiv'),
  855   TeXRel('vdash','\vdash'),         TeXRel('|--','\vdash'),
  856   TeXRel('dashv','\dashv'),         TeXRel('--|','\dashv'),
  857   TeXRel('perp','\perp'),           TeXRel('_|_','\perp'),
  858   TeXRel('parallel','\parallel'),   TeXRel('||','\parallel'),
  859   TeXRel('doteq','\doteq'),         TeXRel('=.=','\doteq'),
  860   TeXRel('models','\models'),       TeXRel('|==','\models'),
  861   TeXRel('in','\in'),
  862   TeXRel('subset','\subset'),
  863   TeXRel('subseteq','\subseteq'),
  864   TeXRel('sqsubseteq','\sqsubseteq'),
  865   TeXRel('supset','\supset'),
  866   TeXRel('supseteq','\supseteq'),
  867   TeXRel('sqsupseteq','\sqsupseteq'),
  868   TeXRel('prec','\prec'),           TeXRel('-<','\prec'),
  869   TeXRel('preceq','\preceq'),       TeXRel('-<=','\preceq'),
  870   TeXRel('succ','\succ'),           TeXRel('>-','\succ'),
  871   TeXRel('succeq','\succeq'),       TeXRel('>-=','\succeq'),
  872   TeXRel('propto','\propto'),
  873   TeXRel('mid','\mid', precedence=>.3,formSet=>1),
  874                                     TeXRel('s.t. ','\mid',string=>" s.t. ",precedence=>.3,formSet=>1),
  875   TeXRel('ni','\ni'),               TeXRel('gets','\gets'),
  876   TeXRel('smile','\smile'),
  877   TeXRel('frown','\frown'),
  878   TeXRel('asymp','\asymp'),
  879   TeXRel('bowtie','\bowtie'),
  880 
  881   TeXRel('!<','\not<'),                TeXRel('!lt','\not<'),
  882   TeXRel('!>','\not>'),                TeXRel('!gt','\not>'),
  883   TeXRel('!<=','\not\le'),             TeXRel('!ge','\not\le'),
  884   TeXRel('!>=','\not\ge'),             TeXRel('!le','\not\ge'),
  885   TeXRel('!sim','\not\sim'),           TeXRel('!~','\not\sim'),
  886   TeXRel('!simeq','\not\simeq'),       TeXRel('!~-','\not\simeq'),
  887   TeXRel('!cong','\not\cong'),         TeXRel('!~=','\not\cong'),
  888   TeXRel('!approx','\not\approx'),     TeXRel('!~~','\not\approx'),
  889   TeXRel('!perp',',\not\perp'),        TeXRel('!_|_','\not\perp'),
  890   TeXRel('!parallel','\not\parallel'), TeXRel('!||','\not\parallel'),
  891   TeXRel('!equiv','\not\equiv'),       TeXRel('!-=','\not\equiv'),
  892   TeXRel('!in','\notin'),
  893   TeXRel('!subset','\not\subset'),
  894   TeXRel('!subseteq','\not\subseteq'),
  895   TeXRel('!sqsubseteq','\not\sqsubseteq'),
  896   TeXRel('!supset','\not\supset'),
  897   TeXRel('!supseteq','\not\supseteq'),
  898   TeXRel('!sqsupseteq','\not\sqsupseteq'),
  899   TeXRel('!prec','\not\prec'),         TeXRel('!-<','\not\prec'),
  900   TeXRel('!preceq','\not\preceq'),     TeXRel('!-<=','\not\preceq'),
  901   TeXRel('!succ','\not\succ'),         TeXRel('!>-','\not\succ'),
  902   TeXRel('!succeq','\not\succeq'),     TeXRel('!>-=','\not\succeq'),
  903   TeXRel('!asymp','\not\asymp'),
  904 
  905   TeXBin(':',' :',class=>'Typeset::BOP::colon',precedence=>.3,isColon=>1,formSet=>1),
  906   TeXBin('::',' ::'),
  907   TeXUnary('pm','\pm'),
  908   TeXUnary('mp','\mp'),
  909   TeXBin('setminus','\setminus'),
  910   TeXBin('cdot','\cdot'),
  911   TeXBin('ast','\ast'),
  912   TeXBin('star','\star'),
  913   TeXBin('diamond','\diamond'),
  914   TeXBin('circ','\circ'),    TeXBin('o ','\circ'),
  915   TeXBin('bullet','\bullet'),
  916   TeXBin('div','\div'),      TeXBin('-:','\div'),
  917   TeXBin('cap','\cap'),
  918   TeXBin('cup','\cup'),
  919   TeXBin('uplus','\uplus'),  TeXBin('u+ ','\uplus'),
  920   TeXBin('sqcap','\sqcap'),
  921   TeXBin('sqcup','\sqcup'),
  922   TeXBin('triangleleft','\triangleleft'),
  923   TeXBin('triangleright','\triangleright'),
  924   TeXBin('wr','\wr'),
  925   TeXBin('bigcirc','\bigcirc'),
  926   TeXBin('bigtriangleup','\bigtriangleup'),
  927   TeXBin('bigtriangledown','\bigtriangledown'),
  928   TeXBin('vee','\vee'),       TeXBin("\\/",'\vee'),
  929   TeXBin('wedge','\wedge'),   TeXBin("/\\",'\wedge'),
  930   TeXBin('oplus','\oplus'),   TeXBin('o+ ','\oplus'),
  931   TeXBin('ominus','\ominus'), TeXBin('o- ','\ominus'),
  932   TeXBin('otimes','\otimes'), TeXBin('ox ','\otimes'),
  933   TeXBin('oslash','\oslash'), TeXBin('o/ ','\oslash'),
  934   TeXBin('odot','\odot'),     TeXBin('o. ','\odot'),
  935   TeXBin('amalg','\amalg'),
  936   TeXBin('times','\times'),
  937 
  938   TeXOp("bin",.63,"left",'and',' and ','\hbox{ and }'),
  939   TeXOp("bin",.62,"left",'or',' or ','\hbox{ or }'),
  940   TeXOp("unary",.64,"left",'not',' not ','\hbox{not }'),
  941   TeXOp("unary",.64,"left",'neg',' neg ','\neg'),
  942 
  943   TeXOp("bin",.61,"left",'if ',' if ','\hbox{ if }'),
  944   TeXOp("unary",.61,"right",'otherwise',' otherwise','\hbox{otherwise}'),
  945 
  946   TeXUnary('root', "\\root ", class=>'Typeset::UOP::root',precedence=>.65, string=>"root "),
  947   TeXBin('of ','\of',class=>'Typeset::BOP::of',precedence=>.66),
  948 
  949   TeXBin("quad",'\quad', precedence => .2),
  950   TeXBin("qquad",'\qquad', precedence => .2),
  951 );
  952 
  953 ######################################################################
  954 
  955 sub TeXGreek {
  956   my $greek = shift; my $uc = shift;
  957   push(@_,TeX=>"{\\rm $uc}") if $uc;
  958   return ($greek => {value => Real(1), TeX=>"\\$greek ", keepName=>1, @_});
  959 }
  960 
  961 sub TeXord {
  962   my $name = shift; my $tex = shift;
  963   $tex = "\\$name " unless defined $tex; $tex .= ' ' if $tex =~ m/\\[a-zA-Z]+$/;
  964   return ($name => {value => Real(1), TeX=>$tex, keepName=>1, @_});
  965 }
  966 
  967 sub TeXconst {
  968   my $name = shift; my $tex = shift; $tex .= " " unless $tex =~ m/}$/;
  969   my $string = shift; $string = $name unless defined $string;
  970   return ($name => {value => Real(1), TeX=>$tex, string=>$string, keepName=>1, @_});
  971 }
  972 
  973 $context{Typeset}->constants->{namePattern} = '.*';
  974 $context{Typeset}->constants->are(
  975   TeXGreek('alpha'),    TeXGreek('Alpha','A'),
  976   TeXGreek('beta'),     TeXGreek('Beta','B'),
  977   TeXGreek('gamma'),    TeXGreek('Gamma'),
  978   TeXGreek('delta'),    TeXGreek('Delta'),
  979   TeXGreek('epsilon'),  TeXGreek('Epsilon','E'),   TeXGreek('varepsilon'),
  980   TeXGreek('zeta'),     TeXGreek('Zeta','Z'),
  981   TeXGreek('eta'),      TeXGreek('Eta','H'),
  982   TeXGreek('theta'),    TeXGreek('Theta',),        TeXGreek('vartheta'),
  983   TeXGreek('iota'),     TeXGreek('Iota','I'),
  984   TeXGreek('kappa'),    TeXGreek('Kappa','K'),
  985   TeXGreek('lambda'),   TeXGreek('Lambda'),
  986   TeXGreek('mu'),       TeXGreek('Mu','M'),
  987   TeXGreek('nu'),       TeXGreek('Nu','N'),
  988   TeXGreek('xi'),       TeXGreek('Xi'),
  989   TeXGreek('omicron'),  TeXGreek('Omicron','O'),
  990   TeXGreek('pi'),       TeXGreek('Pi'),            TeXGreek('varpi'),
  991   TeXGreek('rho'),      TeXGreek('Rho','P'),       TeXGreek('varrho'),
  992   TeXGreek('sigma'),    TeXGreek('Sigma'),         TeXGreek('varsigma'),
  993   TeXGreek('tau'),      TeXGreek('Tau','T'),
  994   TeXGreek('upsilon'),  TeXGreek('Upsilon'),
  995   TeXGreek('phi'),      TeXGreek('Phi'),           TeXGreek('varphi'),
  996   TeXGreek('chi'),      TeXGreek('Chi','X'),
  997   TeXGreek('psi'),      TeXGreek('Psi'),
  998   TeXGreek('omega'),    TeXGreek('Omega'),
  999 
 1000   TeXconst('Null','',''),
 1001   TeXconst('RR','{\bf R}','R'),
 1002   TeXconst('QQ','{\bf Q}','Q'),
 1003   TeXconst('CC','{\bf C}','C'),
 1004   TeXconst('NN','{\bf N}','N'),
 1005   TeXconst('ZZ','{\bf Z}','Z'),
 1006 
 1007   TeXord('aleph'),
 1008   TeXord('hbar'),
 1009   TeXord('imath'),
 1010   TeXord('jmath'),
 1011   TeXord('ell'),
 1012   TeXord('wp'),
 1013   TeXord('emptyset'),
 1014   TeXord('nabla'),       TeXord('grad','\nabla'),
 1015   TeXord('top'),
 1016   TeXord('bot'),
 1017   TeXord('angle'),
 1018   TeXord('triangle'),
 1019   TeXord('backslash'),
 1020   TeXord('forall'),
 1021   TeXord('exists'),
 1022   TeXord('partial'),
 1023 
 1024   TeXord('ldots','\ldots'),  TeXord('..','\ldots'),
 1025   TeXord('cdots','\cdots'),  TeXord('...','\cdots'),
 1026   TeXord('vdots','\vdots'),
 1027   TeXord('ddots','\ddots'),
 1028 
 1029   TeXord('inf','\inf'),
 1030   TeXord('liminf','\liminf'),
 1031   TeXord('limsup','\limsup'),
 1032   TeXord('max','\max'),
 1033   TeXord('min','\min'),
 1034   TeXord('lim','\lim'),
 1035   TeXord('sum','\sum'),
 1036   TeXord('prod','\prod'),
 1037   TeXord('coprod','\coprod'),
 1038   TeXord('int','\int'),
 1039 # TeXord('iint','\iint'),
 1040 # TeXord('iiint','\iiint'),
 1041   TeXord('oint','\oint'),
 1042   TeXord('bigcup','\bigcup'),
 1043   TeXord('bigcap','\bigcap'),
 1044   TeXord('bigsqcup','\bigsqcup'),
 1045   TeXord('bigvee','\bigvee'),
 1046   TeXord('bigwedge','\bigwedge'),
 1047   TeXord('bigodot','\bigodot'),
 1048   TeXord('bigotimes','\bigotimes'),
 1049   TeXord('bigoplus','\bigoplus'),
 1050   TeXord('biguplus','\biguplus'),
 1051 );
 1052 $context{Typeset}->constants->add(_blank_ => {value => Real(0), hidden => 1, string => "", TeX => ""});
 1053 
 1054 ######################################################################
 1055 
 1056 sub TeXBigOp {
 1057   my $name = shift; my $tex = shift;
 1058   return ($name => {class => 'Typeset::Function::bigOp', precedence => .9, TeX => $tex, @_});
 1059 }
 1060 
 1061 sub TeXfn {
 1062   my $name = shift;
 1063   return ($name => {class => 'Typeset::Function::'.$name, @_});
 1064 }
 1065 
 1066 sub TeXnamedFn {
 1067   my $name = shift;
 1068   return ($name => {class => 'Typeset::Function::named', TeX=>"\\$name", @_});
 1069 }
 1070 
 1071 sub TeXaccent {
 1072   my $name = shift;
 1073   return ($name => {class => 'Typeset::Function::accent', TeX=>"\\$name", @_});
 1074 }
 1075 
 1076 sub TeXoverunder {
 1077   my $name = shift;
 1078   return ($name => {class => 'Typeset::Function::overunder', TeX=>"\\$name", @_});
 1079 }
 1080 
 1081 $context{Typeset}->functions->{namePattern} = qr/.*/;
 1082 $context{Typeset}->functions->add(
 1083   TeXBigOp('Lim','\lim', allowArrow => 1, noMax => 1),
 1084   TeXBigOp('Sum','\sum'),
 1085   TeXBigOp('Prod','\prod'),
 1086   TeXBigOp('Coprod','\coprod'),
 1087   TeXBigOp('Int','\int', dx => 1, precedence => 6.5),
 1088 # TeXBigOp('IInt','\iint', dx => 1, precedence => 6.5),
 1089 # TeXBigOp('IIInt','\iiint', dx => 1, precedence => 6.5),
 1090   TeXBigOp('Oint','\oint', dx => 1, precedence => 6.5),
 1091   TeXBigOp('Cup','\bigcup'),
 1092   TeXBigOp('Cap','\bigcap'),
 1093   TeXBigOp('Sqcup','\bigsqcup'),
 1094   TeXBigOp('Vee','\bigvee'),
 1095   TeXBigOp('Wedge','\bigwedge'),
 1096   TeXBigOp('Odot','\bigodot'),     TeXBigOp('O. ','\bigodot'),
 1097   TeXBigOp('Otimes','\bigotimes'), TeXBigOp('Ox ','\bigotimes'),
 1098   TeXBigOp('Oplus','\bigoplus'),   TeXBigOp('O+ ','\bigoplus'),
 1099   TeXBigOp('Uplus','\biguplus'),   TeXBigOp('U+ ','\biguplus'),
 1100 
 1101   TeXfn('text'),
 1102   TeXfn('bf'),
 1103   TeXfn('cal'),
 1104   TeXfn('Array'),
 1105   TeXfn('TeX'),
 1106   TeXfn('Fence'),
 1107   TeXfn('Cases'),
 1108 
 1109   TeXfn('det', TeX=>"\\det"),
 1110 
 1111   TeXnamedFn('deg'),
 1112   TeXnamedFn('dim'),
 1113   TeXnamedFn('gcd'),
 1114   TeXnamedFn('hom'),
 1115 #  TeXnamedFn('inf'),
 1116   TeXnamedFn('ker'),
 1117   TeXnamedFn('lg'),
 1118 #  TeXnamedFn('max'),
 1119 #  TeXnamedFn('min'),
 1120   TeXnamedFn('Pr'),
 1121 #  TeXnamedFn('sup'),
 1122 
 1123   TeXaccent('hat'),
 1124   TeXaccent('bar'),
 1125   TeXaccent('vec'),
 1126   TeXaccent('dot'),
 1127   TeXaccent('ddot'),
 1128 
 1129   TeXoverunder('underline'),
 1130   TeXoverunder('overline'),
 1131   TeXoverunder('underbrace'),
 1132   TeXoverunder('overbrace'),
 1133 );
 1134 
 1135 ######################################################################
 1136 
 1137 $context{Typeset}->parens->set(
 1138   '(' => {type => 'List', removable => 0, formMatrix => 0},
 1139   '[' => {type => 'List', removable => 0},
 1140   '{' => {type => "Set",  removable => 0, emptyOK=>1},
 1141 );
 1142 $context{Typeset}->parens->add(
 1143   '<[' => {type => "Vector", close => ']>'},
 1144 );
 1145 $context{Typeset}->parens->remove('<');
 1146 
 1147 $context{Typeset}->lists->set(
 1148   Set    => {class => 'Typeset::List::Set'},
 1149   List   => {class => 'Typeset::List::List'},
 1150   Vector => {class => 'Typeset::List::Vector', TeX_open => "<", TeX_close => ">"},
 1151   AbsoluteValue => {class => 'Typeset::List::AbsoluteValue'},
 1152 );
 1153 $context{Typeset}->{parser}{List} = 'Typeset::List';
 1154 
 1155 ######################################################################
 1156 
 1157 Typeset::addVariables($context{Typeset});
 1158 
 1159 ######################################################################
 1160 
 1161 $context{Typeset}->{_initialized} = 1; # now update the patterns
 1162 $context{Typeset}->update;
 1163 
 1164 ######################################################################
 1165 
 1166 $context{Typeset}->strings->clear();
 1167 $context{Typeset}->strings->redefine("infty", using=>"infinity");
 1168 $context{Typeset}->strings->set(infty => {string => "infty"});
 1169 $context{Typeset}->strings->redefine("infinity");
 1170 loadMacros("parserQuotedString.pl");
 1171 QuotedString::enable($context{Typeset});
 1172 
 1173 ######################################################################
 1174 
 1175 $context{"Typeset-Vector"} = $context{Typeset}->copy;
 1176 $context{"Typeset-Vector"}->operators->remove('<','>');
 1177 $context{"Typeset-Vector"}->parens->remove('<[');
 1178 $context{"Typeset-Vector"}->parens->redefine('<');
 1179 
 1180 ######################################################################
 1181 
 1182 Context("Typeset");
 1183 
 1184 ######################################################################
 1185 
 1186 1;
 1187 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9