Diff for /loncom/xml/londefdef.pm between versions 1.183 and 1.189

version 1.183, 2003/10/20 19:47:23 version 1.189, 2003/10/24 21:48:17
Line 50  use Apache::File(); Line 50  use Apache::File();
 use Image::Magick;  use Image::Magick;
 use Apache::lonmenu();  use Apache::lonmenu();
 use Apache::lonmeta();  use Apache::lonmeta();
   use Apache::Constants qw(:common);
   
 $Apache::londefdef::TD_redirection=0;  
   
 BEGIN {  BEGIN {
   
Line 59  BEGIN { Line 59  BEGIN {
   
 }  }
   
   sub initialize_londefdef {
       $Apache::londefdef::TD_redirection=0;
       @Apache::londefdef::table = ();
       $Apache::londefdef::select=0;
       @Apache::londefdef::description=();
       $Apache::londefdef::DD_redirection=0;
       $Apache::londefdef::DT_redirection=0;
   }
   
 #======================= TAG SUBROUTINES =====================  #======================= TAG SUBROUTINES =====================
 #-- <output>  #-- <output>
 sub start_output {  sub start_output {
Line 159  sub start_html { Line 168  sub start_html {
     &tth::tthoptions('-L -u0');      &tth::tthoptions('-L -u0');
  }   }
     }      }
     if ($target eq 'web') {      if ($target eq 'web' || $target eq 'edit') {
  $currentstring = &Apache::lonxml::xmlbegin().   $currentstring = &Apache::lonxml::xmlbegin().
     &Apache::lonxml::fontsettings();           &Apache::lonxml::fontsettings();     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
Line 344  sub start_title { Line 353  sub start_title {
     }      }
     if ($target eq 'meta') {      if ($target eq 'meta') {
  $currentstring='<title>';   $currentstring='<title>';
  &start_output();   &start_output($target);
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 358  sub end_title { Line 367  sub end_title {
  $currentstring .= '}';   $currentstring .= '}';
     }        }  
     if ($target eq 'meta') {      if ($target eq 'meta') {
  &end_output();   &end_output($target);
  $currentstring='</title>';   $currentstring='</title>';
     }       } 
     return $currentstring;      return $currentstring;
Line 654  sub start_h1 { Line 663  sub start_h1 {
  $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';    $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } elsif ($target eq 'meta') {      } elsif ($target eq 'meta') {
  $currentstring='<subject>';   $currentstring='<subject>';
  &start_output();   &start_output($target);
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 676  sub end_h1 { Line 685  sub end_h1 {
  }   }
  $currentstring .= '}}'.$post;   $currentstring .= '}}'.$post;
     } elsif ($target eq 'meta') {      } elsif ($target eq 'meta') {
  &end_output();   &end_output($target);
  $currentstring='</subject>';   $currentstring='</subject>';
     }       } 
     return $currentstring;      return $currentstring;
Line 1994  sub end_td_tex { Line 2003  sub end_td_tex {
  $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;   $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
  my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);   my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
  foreach my $elementdata (@newdata) {   foreach my $elementdata (@newdata) {
     $elementdata=~s/^\s+(\S.*)/$1/;       my $lengthnewdata=1.8*LATEX_length($elementdata);
     $elementdata=~s/(.*\S)\s+$/$1/;  
     $elementdata=~s/(\s)+/$1/;  
   
     my $lengthnewdata=1.8*length($elementdata);  
     if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}      if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
  }   }
     } else {      } else {
  my $working_data=$data;   $current_length=1.8*LATEX_length($data);
  $working_data=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$|\$)//g;  
  $working_data=~s/\\cdot/ /;  
  $current_length=1.8*length($working_data);  
     }      }
     $Apache::londefdef::table[-1]{'length'} .= $current_length.',';      $Apache::londefdef::table[-1]{'length'} .= $current_length.',';
     $Apache::londefdef::table[-1]{'TeXlength'} .= '0,';      $Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
Line 2091  sub start_img { Line 2093  sub start_img {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,      my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
  undef,1);   undef,1);
       if (not $src and ($target eq 'web' or $target eq 'tex')) { 
    my $inside = &Apache::lonxml::get_all_text("/img",$parser);
    &Apache::lonnet::logthis("inside was $inside");
    return '';
       }
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;      $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
     my $currentstring = '';      my $currentstring = '';
     my $width_param = '';      my $width_param = '';
Line 2185  sub start_img { Line 2192  sub start_img {
  #<allow> tag will care about replication    #<allow> tag will care about replication 
     }      }
  }   }
       } elsif ($target eq 'edit') {
    $currentstring .=&Apache::edit::tag_start($target,$token);
    $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
       &Apache::edit::browse('src',undef,'alt').' '.
       &Apache::edit::search('src',undef,'alt').'<br />';
    $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
    $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
    $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
    $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
    $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
    $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
    my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval);
    my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval);
    my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
    my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
    $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
    if ($width) { $currentstring.=' width="'.$width.'" '; }
    if ($height) { $currentstring.=' height="'.$height.'" '; }
    $currentstring .= ' />';
       } elsif ($target eq 'modified') {
    my $constructtag=&Apache::edit::get_new_args($token,$parstack,
        $safeeval,'src','alt',
        'TeXwidth','TeXheight',
        'width','height');
    $src=$token->[2]{'src'};
    if (!$token->[2]{'width'} && !$token->[2]{'height'}) {
       $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
       &image_replication($src);
       if (-e $src) {
    my $image = Image::Magick->new;
    my ($width, $height, $size, $format) = $image->Ping($src);
    if ($width && $height) {
       $token->[2]{'width'} =$width;
       $token->[2]{'height'}=$height;
       $constructtag=1;
    }
       }
    }
    if ($constructtag) {$currentstring=&Apache::edit::rebuild_tag($token);}
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 3301  sub end_hideweboutput { Line 3347  sub end_hideweboutput {
   
 sub image_replication {  sub image_replication {
     my $src = shift;      my $src = shift;
     if (not -e $src) {      if (not -e $src) { &Apache::lonnet::repcopy($src); }
  #replicates image itself      #replicates eps or ps 
  &Apache::lonnet::repcopy($src);      my $epssrc = my $pssrc = $src;
  #replicates eps or ps       $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
  my $newsrc = $src;      $pssrc  =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
  $newsrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;      if (not -e $epssrc && not -e $pssrc) {
  if (not -e $newsrc) {   my $result=&Apache::lonnet::repcopy($epssrc);
     if (&Apache::lonnet::repcopy($newsrc) ne 'OK') {   if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); }
  $newsrc =~ s/\.eps$/\.ps/;  
  &Apache::lonnet::repcopy($newsrc);  
     }  
  }  
     }      }
     return '';      return '';
 }  }
Line 3335  sub recalc { Line 3377  sub recalc {
     return $value.' mm';      return $value.' mm';
 }  }
   
   sub LATEX_length {
       my $garbage=shift;
       $garbage=~s/^\s+(\S.*)/$1/; 
       $garbage=~s/(.*\S)\s+$/$1/;
       $garbage=~s/(\s)+/$1/;
       $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;
       $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$|\$)//g;
       $garbage=~s/(\\alpha|\\beta|\\gamma|\\delta|\\epsilon|\\verepsilon|\\zeta|\\eta|\\theta|\\vartheta|\\iota|\\kappa|\\lambda|\\mu|\\nu|\\xi|\\pi|\\varpi|\\rho|\\varrho|\\sigma|\\varsigma|\\tau|\\upsilon|\\phi|\\varphi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)/1/g;
       $garbage=~s/(\\pm|\\mp|\\times|\\div|\\cdot|\\ast|\\star|\\dagger|\\ddagger|\\amalg|\\cap|\\cup|\\uplus|\\sqcap|\\sqcup|\\vee|\\wedge|\\oplus|\\ominus|\\otimes|\\circ|\\bullet|\\diamond|\\lhd|\\rhd|\\unlhd|\\unrhd|\\oslash|\\odot|\\bigcirc|\\Box|\\Diamond|\\bigtriangleup|\\bigtriangledown|\\triangleleft|\\triangleright|\\setminus|\\wr)/1/g;
       $garbage=~s/(\\le|\\ll|\\leq|\\ge|\\geq|\\gg|\\neq|\\doreq|\\sim|\\simeq|\\subset|\\subseteq|\\sqsubset|\\sqsubseteq|\\in|\\vdash|\\models|\\supset|\\supseteq|\\sqsupset|\\sqsupseteq|\\ni|\\dash|\\perp|\\approx|\\cong|\\equiv|\\propto|\\prec|\\preceq|\\parallel|\\asymp|\\smile|\\frown|\\bowtie|\\succ|\\succeq|\\mid)/1/g;
       $garbage=~s/(\\not<|\\\\not\\le|\\not\\prec|\\not\\preceq|\\not\\subset|\\not\\subseteq|\\not\\sqsubseteq|\\not\\in|\\not>|\\not\\ge|\\not\\succ|\\notsucceq|\\not\\supset|\\notsupseteq|\\not\\sqsupseteq|\\notin|\\not=|\\not\\equiv|\\not\\sim|\\not\\simeq|\\not\\approx|\\not\\cong|\\not\\asymp)/1/g;
       $garbage=~s/(\\leftarrow|\\gets|\\Leftarrow|\\rightarrow|\\to|\\Rightarrow|\\leftrightarrow|\\Leftrightarrow|\\mapsto|\\hookleftarrow|\\leftharpoonup|\\leftkarpoondown|\\rightleftharpoons|\\longleftarrow|\\Longleftarrow|\\longrightarrow|\\Longrightarrow|\\longleftrightarrow|\\Longleftrightarrow|\\longmapsto|\\hookrightarrow|\\rightharpoonup|\\rightharpoondown|\\uparrow|\\Uparrow|\\downarrow|\\Downarrow|\\updownarrow|\\Updownarrow|\\nearrow|\\searrow|\\swarrow|\\nwarrow)/1/g;
       $garbage=~s/(\\aleph|\\hbar|\\imath|\\jmath|\\ell|\\wp|\\Re|\\Im|\\mho|\\prime|\\emptyset|\\nabla|\\surd|\\partial|\\top|\\bot|\\vdash|\\dashv|\\forall|\\exists|\\neg|\\flat|\\natural|\\sharp|\\\||\\angle|\\backslash|\\Box|\\Diamond|\\triangle|\\clubsuit|\\diamondsuit|\\heartsuit|\\spadesuit|\\Join|\\infty)/ /g;
       $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g; 
       my  $value=length($garbage);
       return $value;
   }
   
   
   
   
 1;  1;
 __END__  __END__

Removed from v.1.183  
changed lines
  Added in v.1.189


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>