version 1.67, 2002/07/01 19:58:25
|
version 1.76, 2002/07/24 19:56:32
|
Line 1
|
Line 1
|
|
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# Tags Default Definition Module |
# Tags Default Definition Module |
# |
# |
Line 49 use Apache::lonnet;
|
Line 48 use Apache::lonnet;
|
use strict; |
use strict; |
use Apache::lonxml; |
use Apache::lonxml; |
use Apache::File(); |
use Apache::File(); |
|
use Image::Magick; |
|
|
BEGIN { |
BEGIN { |
|
|
Line 74 sub start_m {
|
Line 74 sub start_m {
|
my $currentstring = ''; |
my $currentstring = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
$Apache::lonxml::prevent_entity_encode++; |
$Apache::lonxml::prevent_entity_encode++; |
my $inside = &Apache::lonxml::get_all_text("/m",$$parser[-1]); |
my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); |
$inside ='\\documentstyle{article}'.$inside; |
$inside ='\\documentstyle{article}'.$inside; |
&Apache::lonxml::debug("M is starting with:$inside:"); |
&Apache::lonxml::debug("M is starting with:$inside:"); |
my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); |
my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); |
Line 90 sub start_m {
|
Line 90 sub start_m {
|
} |
} |
#&Apache::lonxml::debug("M is ends with:$currentstring:"); |
#&Apache::lonxml::debug("M is ends with:$currentstring:"); |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring = ""; |
$currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); |
|
if ($currentstring=~/\s*\\\\\s*/) {$currentstring = ' \vskip 0 mm ';} |
|
} else { |
|
my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 835 EDITBUTTON
|
Line 838 EDITBUTTON
|
} |
} |
#-- <br> tag |
#-- <br> tag |
sub start_br { |
sub start_br { |
my ($target,$token) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my $currentstring = ''; |
my $currentstring = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= '\vskip 0 mm'; |
if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') { |
|
$currentstring .= '\vskip 0 mm'; |
|
} |
} elsif ($target eq 'latexsource') { |
} elsif ($target eq 'latexsource') { |
$currentstring .= '\\'; |
$currentstring .= '\\'; |
} |
} |
Line 949 EDITBUTTON
|
Line 954 EDITBUTTON
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= "{\\underline "; |
$currentstring .= '\underline{'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 959 EDITBUTTON
|
Line 964 EDITBUTTON
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[2]; |
$currentstring .= $token->[2]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= " }"; |
$currentstring .= '}'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 970 EDITBUTTON
|
Line 975 EDITBUTTON
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= "{\\underline "; |
$currentstring .= '\underline{'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 980 EDITBUTTON
|
Line 985 EDITBUTTON
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[2]; |
$currentstring .= $token->[2]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= " }"; |
$currentstring .= '}'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1033 EDITBUTTON
|
Line 1038 EDITBUTTON
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= "\\hline "; |
$currentstring .= '\vskip 0 mm \noindent\makebox[\textwidth - 8 mm][b]{\hrulefill}'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1110 EDITBUTTON
|
Line 1115 EDITBUTTON
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= "{\\underline "; |
$currentstring .= '\underline{'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1120 EDITBUTTON
|
Line 1125 EDITBUTTON
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring .= $token->[2]; |
$currentstring .= $token->[2]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= " }"; |
$currentstring .= '}'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1286 EDITBUTTON
|
Line 1291 EDITBUTTON
|
$Apache::londefdef::table[-1]{'vvinc'} = '|'; |
$Apache::londefdef::table[-1]{'vvinc'} = '|'; |
} else { |
} else { |
$Apache::londefdef::table[-1]{'hinc'} = ''; |
$Apache::londefdef::table[-1]{'hinc'} = ''; |
$Apache::londefdef::table[-1]{'vinc'} = ''; |
$Apache::londefdef::table[-1]{'vinc'} = '&'; |
$Apache::londefdef::table[-1]{'vvinc'} = ''; |
$Apache::londefdef::table[-1]{'vvinc'} = ''; |
} |
} |
} |
} |
Line 1311 EDITBUTTON
|
Line 1316 EDITBUTTON
|
chop $output; |
chop $output; |
$output .= ' \\\\ '; |
$output .= ' \\\\ '; |
} |
} |
$Apache::londefdef::table[-1]{'output'} .= $header_of_table.$output.$Apache::londefdef::table[-1]{'hinc'}.'\end{tabular}'; |
my @length = split(/,/,$Apache::londefdef::table[-1]{'length'}); |
|
my $how_many_columns = $#length+1; |
|
my $parboxlength = '(\textwidth'; |
|
for (my $io=0; $io<=$#length;$io++) { |
|
if ($length[$io] ne '') { |
|
$parboxlength .= ' - '.$length[$io].' '; |
|
} |
|
} |
|
$parboxlength .= ')/'.$how_many_columns.' - 7 mm'; |
|
$output =~ s/\\parbox{}/\\parbox{$parboxlength}/g; |
|
$Apache::londefdef::table[-1]{'output'} .= $header_of_table.$output.$Apache::londefdef::table[-1]{'hinc'}.'\end{tabular}\vskip 0 mm '; |
if ($#Apache::londefdef::table > 0) { |
if ($#Apache::londefdef::table > 0) { |
$inmemory = $Apache::londefdef::table[-1]{'output'}; |
$inmemory = $Apache::londefdef::table[-1]{'output'}; |
pop @Apache::londefdef::table; |
pop @Apache::londefdef::table; |
Line 1336 EDITBUTTON
|
Line 1351 EDITBUTTON
|
if ($alignchar ne '') { |
if ($alignchar ne '') { |
push @ {$Apache::londefdef::table[-1]{'rows'} }, $alignchar; |
push @ {$Apache::londefdef::table[-1]{'rows'} }, $alignchar; |
} else { |
} else { |
push @ {$Apache::londefdef::table[-1]{'rows'} }, 'c'; |
push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l'; |
} |
} |
push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'}); |
push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'}); |
$Apache::londefdef::table[-1]{'counter_columns'} = -1; |
$Apache::londefdef::table[-1]{'counter_columns'} = -1; |
|
$Apache::londefdef::table[-1]{'length'} = ''; #just added |
|
|
} |
} |
return $currentstring; |
return $currentstring; |
Line 1380 EDITBUTTON
|
Line 1396 EDITBUTTON
|
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
my $current_row = $Apache::londefdef::table[-1]{'row_number'}; |
my $current_row = $Apache::londefdef::table[-1]{'row_number'}; |
my $data=&Apache::lonxml::endredirection(); |
my $data=&Apache::lonxml::endredirection(); |
@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= $data.' '.$Apache::londefdef::table[-1]{'vinc'}; |
if ($data=~m/width\s*=\s*(\d+\.*\d*\s*(mm|cm))/) { #just added |
|
$Apache::londefdef::table[-1]{'length'} .= $1.','; #just added |
|
} #just added |
|
@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{'.$1.'}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1410 EDITBUTTON
|
Line 1429 EDITBUTTON
|
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
my $current_row = $Apache::londefdef::table[-1]{'row_number'}; |
my $current_row = $Apache::londefdef::table[-1]{'row_number'}; |
my $data=&Apache::lonxml::endredirection(); |
my $data=&Apache::lonxml::endredirection(); |
@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\bf{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; |
if ($data=~m/width\s*=\s*(\d+\.*\d*\s*(mm|cm))/) { #just added |
|
$Apache::londefdef::table[-1]{'length'} .= $1.','; #just added |
|
} #just added |
|
@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{'.$1.'}{\textbf{'.$data.'}} '.$Apache::londefdef::table[-1]{'vinc'}; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1421 EDITBUTTON
|
Line 1443 EDITBUTTON
|
$token->[2]->{'src'}; |
$token->[2]->{'src'}; |
my $currentstring = ''; |
my $currentstring = ''; |
my $width_param = ''; |
my $width_param = ''; |
|
my $height_param = ''; |
|
my $scaling = .3; |
|
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$currentstring = $token->[4]; |
$currentstring = $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); |
|
my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); |
|
my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval); |
|
if ($TeXwidth ne '') { |
|
$width_param = $TeXwidth; |
|
} elsif ($TeXheight ne '') { |
|
$width_param = $TeXheight; |
|
} else { |
|
if ($width ne '') { |
|
$width_param = $width*.3; |
|
if ($width_param <= 900) { |
|
$width_param = '[width='.$width_param.'mm]'; |
|
} else { |
|
$width_param = '[width= 9.0 cm]'; |
|
} |
|
} |
|
} |
|
my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval); |
my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
|
my $image = Image::Magick->new; |
|
my $current_figure = $image->Read($src); |
|
$width_param = $image->Get('width') * $scaling;; |
|
$height_param = $image->Get('height') * $scaling;; |
|
undef $image; |
my $epssrc = $src; |
my $epssrc = $src; |
$epssrc =~ s/(\.gif|\.jpg|\.GIF|\.JPG)$/\.eps/; |
$epssrc =~ s/(\.gif|\.jpg)$/\.eps/i; |
if (not -e $epssrc) { |
if (not -e $epssrc) { |
my $localfile = $epssrc; |
my $localfile = $epssrc; |
$localfile =~ s/.*(\/res)/$1/; |
$localfile =~ s/.*(\/res)/$1/; |
Line 1470 EDITBUTTON
|
Line 1482 EDITBUTTON
|
} else { |
} else { |
$localfile = $src; |
$localfile = $src; |
$localfile =~ s/.*(\/res)/$1/; |
$localfile =~ s/.*(\/res)/$1/; |
my $as = &Apache::lonnet::getfile($src); |
my $as = &Apache::lonnet::getfile($src); |
|
|
} |
} |
} |
} |
my $file; |
my $file; |
Line 1482 EDITBUTTON
|
Line 1493 EDITBUTTON
|
} |
} |
my $newsrc = $src; |
my $newsrc = $src; |
$newsrc =~ s/(\.gif|\.jpg)$/\.eps/i; |
$newsrc =~ s/(\.gif|\.jpg)$/\.eps/i; |
$file=~s/(\.gif|\.jpg)$/\.eps/i; |
$file=~s/(\.gif|\.jpg)$/\.eps/i; |
|
#do we have any specified size of the picture? |
|
my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); |
|
my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); |
|
my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval); |
|
if ($TeXwidth ne '') { |
|
$width_param = $TeXwidth; |
|
} elsif ($TeXheight ne '') { |
|
$width_param = $TeXheight/$height_param*$width_param; |
|
} elsif ($width ne '') { |
|
$width_param = $width*$scaling; |
|
} |
|
#where can we find the picture? |
if (-e $newsrc) { |
if (-e $newsrc) { |
if ($path) { |
if ($path) { |
$currentstring .= '\noindent\graphicspath{{'.$path.'}}\fbox{\includegraphics'.$width_param.'{'.$file.'}}'; |
$currentstring .= '\noindent\graphicspath{{'.$path.'}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} '; |
} |
} |
} else { |
} else { |
my $temp_file; |
my $temp_file; |
my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; |
my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; |
$temp_file = Apache::File->new('>>'.$filename); |
$temp_file = Apache::File->new('>>'.$filename); |
print $temp_file "$src\n"; |
print $temp_file "$src\n"; |
$currentstring .= '\graphicspath{{/home/httpd/prtspool/}}\fbox{\includegraphics'.$width_param.'{'.$file.'}}'; |
$currentstring .= '\graphicspath{{/home/httpd/prtspool/}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} '; |
} |
} |
} |
} |
return $currentstring; |
return $currentstring; |