--- loncom/xml/londefdef.pm 2006/11/06 23:45:00 1.343 +++ loncom/xml/londefdef.pm 2007/01/18 20:48:02 1.352 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.343 2006/11/06 23:45:00 foxr Exp $ +# $Id: londefdef.pm,v 1.352 2007/01/18 20:48:02 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -48,6 +48,7 @@ use Apache::lonmenu(); use Apache::lonmeta(); use Apache::Constants qw(:common); use File::Basename; +use LONCAPA(); # use Data::Dumper; BEGIN { @@ -1558,17 +1559,6 @@ sub start_a { my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval, undef,1); $currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href}); - } elsif ($target eq 'tex') { - my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1); - my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1); - if ($a=~/\S/) { - $a=~s/([^\\])%/$1\\\%/g; - $currentstring .= '\ref{URI: '.$a.'}'; - } elsif ($b=~/\S/) { - $currentstring .= '\ref{Anchor: '.$b.'}'; - } else { - $currentstring.=''; - } } return $currentstring; } @@ -1579,6 +1569,20 @@ sub end_a { if ($target eq 'web' || $target eq 'webgrade') { $currentstring .= $token->[2]; } + if ($target eq 'tex') { + my $href = + &Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1); + my $name = + &Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1); + if ($href =~ /\S/) { + $href =~ s/([^\\])%/$1\\\%/g; + $currentstring .= ' ({\tt URI:'.&Apache::lonxml::latex_special_symbols($href).'})'; + } elsif ($name =~ /\S/) { + $currentstring .= ' ({\tt Anchor:'.&Apache::lonxml::latex_special_symbols($name).'})'; + } else { + $currentstring.=''; + } + } return $currentstring; } @@ -1916,8 +1920,7 @@ sub start_table { if ($target eq 'web' || $target eq 'webgrade') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - my $aa = {}; - push @Apache::londefdef::table, $aa; + push(@Apache::londefdef::table, {}); $Apache::londefdef::table[-1]{'row_number'} = -1; #maximum table's width (default coincides with text line length) if ($#Apache::londefdef::table==0) { @@ -2251,6 +2254,12 @@ sub end_table { } $have_rowspan++; $output .= '\multirow{'.$rowspan.'}[0]{*}{'; + + $Apache::londefdef::table[-1]{'content'}[$in][$jn] =~ + s{^\s*\\par\s*}{}; + $Apache::londefdef::table[-1]{'content'}[$in][$jn] =~ + s{\s*\\vskip\s*0pt\s*$}{}; + # # If we did not throw in a multicolumn to align, then add # an extra { @@ -2859,8 +2868,6 @@ sub start_img { &Apache::lonxml::debug("$src exists"); my ($height_param,$width_param)= &image_size($origsrc,0.3,$parstack,$safeeval); - my $destpath = $path; - my $destfile = $file; my $size; if ($width_param) { $size.='width='.$width_param.' mm,'; } if ($height_param) { $size.='height='.$height_param.' mm]'; } @@ -2870,8 +2877,8 @@ sub start_img { $size='['.$size; $size=~s/,$/]/; - $currentstring .= '\graphicspath{{'.$destpath.'}}' - .'\includegraphics'.$size.'{'.$destfile.'} '; + $currentstring .= '\graphicspath{{'.$path.'}}' + .'\includegraphics'.$size.'{'.$file.'} '; # If there's an alignment specification we need to honor it here. # For the horizontal alignments, we will also honor the @@ -2889,17 +2896,26 @@ sub start_img { } elsif ($align eq "left") { if ($latex_rendering eq "parpic") { $currentstring = '\parpic[l]{'.$currentstring.'}'; - } else { # wrapfig render - $currentstring = '\begin{wrapfigure}{l}{'.$width_param.'mm}' + } elsif ($latex_rendering eq "parbox") { + $currentstring = '\begin{minipage}[l]{'.$width_param.'mm}' + .$currentstring.'\end{minipage}'; + } elsif ($latex_rendering eq "wrapfigure" + || $latex_rendering ne 'none') { # wrapfig render + $currentstring = + '\begin{wrapfigure}{l}{'.$width_param.'mm}' .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}'; } } elsif ($align eq "right") { if ($latex_rendering eq "parpic") { $currentstring = '\parpic[r]{'.$currentstring.'}'; - } else { # wrapfig rendering - $currentstring = '\begin{wrapfigure}{r}{'.$width_param.'mm}' + } elsif ($latex_rendering eq "parbox") { + $currentstring = '\begin{minipage}[r]{'.$width_param.'mm}' + .$currentstring.'\end{minipage}'; + } elsif ($latex_rendering eq "wrapfigure" + || $latex_rendering ne 'none') { # wrapfig render + $currentstring = + '\begin{wrapfigure}{r}{'.$width_param.'mm}' .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}'; - } } else { # Bottom is also default. # $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}'; @@ -2931,7 +2947,7 @@ sub start_img { $currentstring .=&Apache::edit::select_arg('Alignment:','align', ['','bottom','middle','top','left','right'],$token,5); $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap', - ['', 'parbox', 'parpic'], $token, 2); + ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2); $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl', ['no','yes'], $token, 2); $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); @@ -4238,7 +4254,7 @@ sub get_eps_image { &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal. } &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/\.(gif|png|jpg|jpeg)/i); $src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i; $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &Apache::lonxml::debug("Filelocation gives: $src"); @@ -4263,8 +4279,8 @@ sub get_eps_image { my $newsrc=$orig_src; $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|; &Apache::lonxml::debug("queueing $newsrc for dynamic eps production."); - print FILE "$newsrc\n"; - close FILE; + print FILE ("$newsrc\n"); + close(FILE); $src=~s|/home/httpd/html/res|/home/httpd/prtspool|; $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; if ($sext ne "") { # Put the ext. back in to uniquify. @@ -4288,6 +4304,7 @@ sub get_eps_image { $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; } my ($path,$file)=($src=~m|(.*)/([^/]*)$|); + $path =~ s/ /\_/g; $file =~ s/ /\_/g; &Apache::lonxml::debug("get_eps_image returning: $path / $file
"); return ($path.'/',$file); @@ -4300,15 +4317,15 @@ sub eps_generation { print $temp_file "$src\n"; my $newsrc = $src; $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i; - $newsrc=~s/\/home\/httpd\/html\/res//; - $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//; - $newsrc=~s/\/\.\//\//; - $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//; - if ($newsrc=~/\/home\/httpd\/lonUsers\//) { - $newsrc=~s/\/home\/httpd\/lonUsers//; - $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//; + $newsrc=~s{/home/httpd/html/res}{}; + $newsrc=~s{/home/($LONCAPA::username_re)/public_html/}{/$1/}; + $newsrc=~s{/\./}{/}; + $newsrc=~s{/([^/]+)\.(ps|eps)}{/}; + if ($newsrc=~m{/home/httpd/lonUsers/}) { + $newsrc=~s{/home/httpd/lonUsers}{}; + $newsrc=~s{/($LONCAPA::domain_re)/./././}{/$1/}; } - if ($newsrc=~/\/userfiles\//) { + if ($newsrc=~m{/userfiles/}) { return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; } else { return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';