Diff for /loncom/xml/londefdef.pm between versions 1.379 and 1.396

version 1.379, 2007/10/15 19:40:53 version 1.396, 2008/11/10 11:17:50
Line 46  use Apache::File(); Line 46  use Apache::File();
 use Image::Magick;  use Image::Magick;
 use Apache::lonmenu();  use Apache::lonmenu();
 use Apache::lonmeta();  use Apache::lonmeta();
   use Apache::lonlocal;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use File::Basename;  use File::Basename;
 use LONCAPA();  use LONCAPA();
Line 106  sub start_m { Line 107  sub start_m {
  my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);   my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
  if ($eval eq 'on') {   if ($eval eq 'on') {
     $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);      $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
     #&Apache::lonxml::debug("M is evaulated to:$inside:");      #&Apache::lonxml::debug("M is evaluated to:$inside:");
  }   }
  my $tex = $inside;   my $tex = $inside;
  my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);   my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
  $currentstring = &Apache::lontexconvert::converted(\$inside,$display);   $currentstring = &Apache::lontexconvert::converted(\$inside,$display);
  if ($Apache::lontexconvert::errorstring) {   if ($Apache::lontexconvert::errorstring) {
     my $errormsg='<pre>'.&HTML::Entities::encode($Apache::lontexconvert::errorstring,'<>&"').'</pre> occured while attempting to convert this TeX: <pre>';      my $errormsg='<pre>'.&HTML::Entities::encode($Apache::lontexconvert::errorstring,'<>&"').'</pre> occurred while attempting to convert this TeX: <pre>';
     $tex = &HTML::Entities::encode($tex,'<>&"');      $tex = &HTML::Entities::encode($tex,'<>&"');
     my ($linenumber) =      my ($linenumber) =
  ($Apache::lontexconvert::errorstring =~ /Line (\d+)/);   ($Apache::lontexconvert::errorstring =~ /Line (\d+)/);
Line 138  sub start_m { Line 139  sub start_m {
  # detect simple math mode entry exits, and convert them   # detect simple math mode entry exits, and convert them
         # to use \ensuremath ... unless there's a \verb inside.          # to use \ensuremath ... unless there's a \verb inside.
  if (! ($currentstring=~/\\verb/)) {   if (! ($currentstring=~/\\verb/)) {
     if ($currentstring=~/^\s*\$[^\$].*[^\$]\$\s*$/) {      if ($currentstring=~/^\s*\$[^\$].*\$\s*$/) {
  $currentstring=~s/^(\s*)\$/$1/;   $currentstring=~s/^(\s*)\$/$1/;
  $currentstring=~s/\$(\s*)$/$1/;   $currentstring=~s/\$(\s*)$/$1/;
  $currentstring='\ensuremath{'.$currentstring.'}';   $currentstring='\ensuremath{'.$currentstring.'}';
Line 200  sub start_html { Line 201  sub start_html {
                           '\usepackage[dvips]{graphicx}'.                            '\usepackage[dvips]{graphicx}'.
   '\usepackage{wrapfig}'.    '\usepackage{wrapfig}'.
   '\usepackage{picins}'.    '\usepackage{picins}'.
     '\usepackage[T1]{fontenc}'."\n".
                             '\usepackage{lmodern}'."\n".
     '\usepackage[postscript]{ucs}'."\n".
     '\usepackage[utf8x]{inputenc}'."\n".
     '\usepackage{pifont}' ."\n".
     '\usepackage{latexsym}'."\n".
                           '\usepackage{epsfig}'.                            '\usepackage{epsfig}'.
                           '\usepackage{calc}'.                            '\usepackage{calc}'.
                           '\usepackage{amsmath}'.                            '\usepackage{amsmath}'.
                           '\usepackage{amssymb}'.                            '\usepackage{amssymb}'.
                           '\usepackage{amsfonts}'.                            '\usepackage{amsfonts}'.
                           '\usepackage{amsthm}'.                            '\usepackage{amsthm}'.
                           '\usepackage{amscd}'.                            '\usepackage{amscd}';
                           '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'.  
           if($env{'form.pdfFormFields'} eq 'yes') {
               $currentstring .= '\usepackage{hyperref}'.
                                 '\usepackage{eforms}'.
                                 '\usepackage{tabularx}';
           } 
   
           $currentstring .= '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'.
                           '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large\textbf{Index}} \newline \setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}';                            '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large\textbf{Index}} \newline \setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}';
     }      }
     return $currentstring;      return $currentstring;
Line 589  sub start_body { Line 603  sub start_body {
 }  }
   
 sub edit_controls {  sub edit_controls {
     my $result .= (<<EDITBUTTON);      my $result .= '
 <form method="post">  <form method="post">
 <input type="submit" name="editmode" accesskey="e" value="Edit" />  <div class="LC_edit_problem_header">
   <div class="LC_edit_problem_header_row1">'.
   &Apache::lonxml::renderingoptions().'
   <input type="submit" name="changeproblemmode" value="'.&mt('Change View').'" />
   </div>
   <div class="LC_edit_problem_header_edit_row"><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" /></div></div>
 </form>  </form>
 <br />  <br />';
 EDITBUTTON  
     return $result;      return $result;
 }  }
   
Line 1585  sub start_div { Line 1603  sub start_div {
     }       } 
     if ($target eq 'tex') {      if ($target eq 'tex') {
  # 4 possible alignments: left, right, center, and -missing-.   # 4 possible alignments: left, right, center, and -missing-.
           # If inside a table row, we must let the table logic
    # do the alignment, however.
    # 
   
  my $endstring = '';   my $endstring = '';
   
Line 1595  sub start_div { Line 1616  sub start_div {
     $endstring      = '\end{center}';      $endstring      = '\end{center}';
     if (&is_inside_of($tagstack, "table")) {      if (&is_inside_of($tagstack, "table")) {
  $currentstring = &center_correction().$currentstring;   $currentstring = &center_correction().$currentstring;
    $endstring    .= &center_end_correction(); 
     }      }
  }   }
  elsif ($align eq 'right') {   elsif ($align eq 'right') {
Line 1650  sub end_a { Line 1672  sub end_a {
     &Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);      &Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
  my $name =   my $name =
     &Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);      &Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
  if ($href =~ /\S/) {          my $uriprint =
               &Apache::lonxml::get_param('uriprint',$parstack,$safeeval,undef,1);
           my $anchorprint =
               &Apache::lonxml::get_param('anchorprint',$parstack,$safeeval,undef,1);
    if (($href =~ /\S/) && ($uriprint=~/^on|uriprint|yes|1$/i)) {
     $href =~ s/([^\\])%/$1\\\%/g;      $href =~ s/([^\\])%/$1\\\%/g;
     # Substitute special symbols... and allow line breaks at each /      # Substitute special symbols... and allow line breaks at each /
     #      #
     $href = &Apache::lonxml::latex_special_symbols($href);      $href = &Apache::lonxml::latex_special_symbols($href);
     $href =~ s/\//\/\\-/g;              # Map / to /\- to allow hyphenation.      $href =~ s/\//\/\\-/g;              # Map / to /\- to allow hyphenation.
     $currentstring .= ' ({\tt URI:'.$href.'})';      $currentstring .= ' ({\tt URI:'.$href.'})';
  } elsif ($name =~ /\S/) {   } elsif (($name =~ /\S/) && ($anchorprint=~/^on|anchorprint|yes|1$/i)) {
     $currentstring .= ' ({\tt Anchor:'.&Apache::lonxml::latex_special_symbols($name).'})';      $currentstring .= ' ({\tt Anchor:'.&Apache::lonxml::latex_special_symbols($name).'})';
  } else {   } else {
     $currentstring.='';      $currentstring.='';
Line 2000  sub start_table { Line 2026  sub start_table {
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring .= $token->[4];        $currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
    &disable_para(); # Can't have paras in a table.
  push(@Apache::londefdef::table, {});    push(@Apache::londefdef::table, {}); 
  $Apache::londefdef::table[-1]{'row_number'} = -1;   $Apache::londefdef::table[-1]{'row_number'} = -1;
         #maximum table's width (default coincides with text line length)          #maximum table's width (default coincides with text line length)
Line 2092  sub end_table { Line 2119  sub end_table {
  my $WARNING='';   my $WARNING='';
         #width of columns from TeXwidth attributes          #width of columns from TeXwidth attributes
   
    # Protect against unbalanced </table> tag.
   
    if (scalar(@Apache::londefdef::table) > 0) {
   
  for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {   for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
     for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {      for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
  if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {   if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
Line 2494  sub end_table { Line 2525  sub end_table {
     pop @Apache::londefdef::table;      pop @Apache::londefdef::table;
     undef @Apache::londefdef::table;      undef @Apache::londefdef::table;
  }   }
    }
    &enable_para();
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 2993  sub start_img { Line 3026  sub start_img {
   
  # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");   # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
   
  #if original gif/jpg/png file exist do following:   #if original bmp/gif/jpg/png file exist do following:
  my $origsrc=$src;   my $origsrc=$src;
  my ($path,$file) = &get_eps_image($src);   my ($path,$file) = &get_eps_image($src);
  # &Apache::lonnet::logthis("Image source: $src result: $path $file");   # &Apache::lonnet::logthis("Image source: $src result: $path $file");
Line 3059  sub start_img { Line 3092  sub start_img {
  my $width=  &Apache::lonxml::get_param('width',$parstack,$safeeval);   my $width=  &Apache::lonxml::get_param('width',$parstack,$safeeval);
  my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);   my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
   
           if ($token->[2]{'src'}=~/\$/) {
  $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';             $currentstring.='Variable image source';
  if ($width) { $currentstring.=' width="'.$width.'" '; }          } else {
  if ($height) { $currentstring.=' height="'.$height.'" '; }     $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
  $currentstring .= ' />';     if ($width) { $currentstring.=' width="'.$width.'" '; }
      if ($height) { $currentstring.=' height="'.$height.'" '; }
      $currentstring .= ' />';
           }
     } elsif ($target eq 'modified') {      } elsif ($target eq 'modified') {
  my ($osrc,$owidth,$oheight)=   my ($osrc,$owidth,$oheight)=
     ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});      ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
Line 4391  sub get_eps_image { Line 4427  sub get_eps_image {
  &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.   &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
     }      }
     &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");      &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
     my ($spath, $sname, $sext) = &fileparse($src, qr/\.(gif|png|jpg|jpeg)/i);      my ($spath, $sname, $sext) = &fileparse($src, qr/\.(bmp|gif|png|jpg|jpeg)/i);
     $src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i;      $src=~s/\.(bmp|gif|png|jpg|jpeg)$/\.eps/i;
     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);      $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
     &Apache::lonxml::debug("Filelocation gives: $src");      &Apache::lonxml::debug("Filelocation gives: $src");
     if (! -e $src) {      if (! -e $src) {
Line 4453  sub eps_generation { Line 4489  sub eps_generation {
     my $temp_file = Apache::File->new('>>'.$filename);       my $temp_file = Apache::File->new('>>'.$filename); 
     print $temp_file "$src\n";      print $temp_file "$src\n";
     my $newsrc = $src;      my $newsrc = $src;
     $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;      $newsrc =~ s/(\.bmp|\.gif|\.jpg|\.jpeg)$/\.eps/i;
     $newsrc=~s{/home/httpd/html/res}{};      $newsrc=~s{/home/httpd/html/res}{};
     $newsrc=~s{/home/($LONCAPA::username_re)/public_html/}{/$1/};      $newsrc=~s{/home/($LONCAPA::username_re)/public_html/}{/$1/};
     $newsrc=~s{/\./}{/};      $newsrc=~s{/\./}{/};

Removed from v.1.379  
changed lines
  Added in v.1.396


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