--- loncom/xml/londefdef.pm 2003/10/24 21:48:17 1.189 +++ loncom/xml/londefdef.pm 2004/03/09 20:37:58 1.201 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.189 2003/10/24 21:48:17 albertel Exp $ +# $Id: londefdef.pm,v 1.201 2004/03/09 20:37:58 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -82,11 +82,11 @@ sub end_output { } #-- tag sub start_m { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $currentstring = ''; - if ($target eq 'web') { + my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); + if ($target eq 'web' || $target eq 'analyze') { $Apache::lonxml::prevent_entity_encode++; - my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); $inside ='\\documentstyle{article}'.$inside; &Apache::lonxml::debug("M is starting with:$inside:"); my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); @@ -103,15 +103,13 @@ sub start_m { #&Apache::lonxml::debug("M is ends with:$currentstring:"); $Apache::lonxml::post_evaluate=0; } elsif ($target eq 'tex') { - $currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); + $currentstring = $inside; my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); if ($eval eq 'on') { $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]); } if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';} $Apache::lonxml::post_evaluate=0; - } else { - my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); } return $currentstring; } @@ -153,21 +151,8 @@ sub end_tthoption { sub start_html { my ($target,$token) = @_; my $currentstring = ''; - if ($ENV{'browser.mathml'}) { - &tth::ttminit(); - if ($ENV{'browser.unicode'}) { - &tth::ttmoptions('-L -u1'); - } else { - &tth::ttmoptions('-L -u0'); - } - } else { - &tth::tthinit(); - if ($ENV{'browser.unicode'}) { - &tth::tthoptions('-L -u1'); - } else { - &tth::tthoptions('-L -u0'); - } - } + my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'}; + &Apache::lontexconvert::init_tth(); if ($target eq 'web' || $target eq 'edit') { $currentstring = &Apache::lonxml::xmlbegin(). &Apache::lonxml::fontsettings(); @@ -550,12 +535,13 @@ sub start_body { if ($ENV{'request.state'} ne 'published') { $currentstring.=(< - + EDITBUTTON } else { $currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1); } + $currentstring.=&Apache::lonxml::message_location(); } elsif ($target eq 'tex') { $currentstring = '\begin{document}'; } @@ -650,7 +636,7 @@ sub start_h1 { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { my $pre; - my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); + my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1)); if (($align eq 'center') || (not defined $align)) { $pre='\begin{center}'; } elsif ($align eq 'left') { @@ -1114,24 +1100,45 @@ sub end_q { } #--

tag (end tag optional) +#optional attribute - align="center|left|right" sub start_p { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - my $signal=1; - foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}} - if ($signal) {$currentstring .= '\par ';} + my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); + if ($align eq 'center') { + $currentstring='\begin{center}\par'; + } elsif ($align eq 'right') { + $currentstring='\makebox['.$ENV{'form.textwidth'}.']{\hfill\llap{'; + } elsif ($align eq 'left') { + $currentstring='\noindent\makebox['.$ENV{'form.textwidth'}.']{\rlap{'; + } + my $signal=1;#

does not work inside ... + foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;} + if (!$signal) {$currentstring = '';} + } } return $currentstring; } sub end_p { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; + } elsif ($target eq 'tex') { + if ($$tagstack[-1] eq 'p') { + my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); + if ($align eq 'center') { + $currentstring .= '\end{center}'; + } elsif ($align eq 'right') { + $currentstring .= '}}'; + } elsif ($align eq 'left') { + $currentstring .= '}\hfill}'; + } + } } return $currentstring; } @@ -2100,8 +2107,6 @@ sub start_img { } $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; my $currentstring = ''; - my $width_param = ''; - my $height_param = ''; my $scaling = .3; if ($target eq 'web') { if ($ENV{'browser.imagesuppress'} ne 'on') { @@ -2117,38 +2122,11 @@ sub start_img { } } elsif ($target eq 'tex') { $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); - &image_replication($src); #if original gif/jpg/png file exist do following: - if (-e $src) { - #defines the default size of image - 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; - #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, - undef,1); - if ($TeXwidth ne '') { - if ($TeXwidth=~/(\d+)\s*\%/) { - $width_param = $1*$ENV{'form.textwidth'}/100; - } else { - $width_param = $TeXwidth; - } - } elsif ($TeXheight ne '') { - $width_param = $TeXheight/$height_param*$width_param; - } elsif ($width ne '') { - $width_param = $width*$scaling; - } - if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}} - my $file; - my $path; - if ($src =~ m!(.*)/([^/]*)$!) { - $file = $2; - $path = $1.'/'; - } + if (-e $src) { + #what is the image size? + my $width_param=&image_size($src,$scaling,$parstack,$safeeval); + my ($file,$path)=&file_path($src); my $newsrc = $src; $newsrc =~ s/\.(gif|jpg|png)$/.eps/i; $file=~s/\.(gif|jpg|png)$/.eps/i; @@ -2168,14 +2146,8 @@ sub start_img { $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; } } else { - #there aren't eps or ps - so create eps - my $temp_file; - my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; - $temp_file = Apache::File->new('>>'.$filename); - print $temp_file "$src\n"; - $newsrc=~s/\/home\/httpd\/html\/res//; - $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//; - $currentstring .= '\vskip 1 mm \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; + #care about eps dynamical generation + $currentstring.='\vskip 1 mm '.&eps_generation($src,$file,$width_param); } } } else { @@ -3359,6 +3331,59 @@ sub image_replication { return ''; } +sub image_size { + my ($src,$scaling,$parstack,$safeeval)=@_; + #size of image from gif/jpg/jpeg/png + my $image = Image::Magick->new; + my $current_figure = $image->Read($src); + my $width_param = $image->Get('width') * $scaling;; + my $height_param = $image->Get('height') * $scaling;; + undef $image; + #do we have any specified LaTeX size of the picture? + my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); + my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); + #do we have any specified web size of the picture? + my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval, + undef,1); + if ($TeXwidth ne '') { + if ($TeXwidth=~/(\d+)\s*\%/) { + $width_param = $1*$ENV{'form.textwidth'}/100; + } else { + $width_param = $TeXwidth; + } + } elsif ($TeXheight ne '') { + $width_param = $TeXheight/$height_param*$width_param; + } elsif ($width ne '') { + $width_param = $width*$scaling; + } + if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}} + return $width_param; +} + +sub eps_generation { + my ($src,$file,$width_param) = @_; + my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; + my $temp_file = Apache::File->new('>>'.$filename); + 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)/\//; + return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; +} + +sub file_path { + my $src=shift; + my ($file,$path); + if ($src =~ m!(.*)/([^/]*)$!) { + $file = $2; + $path = $1.'/'; + } + return $file,$path; +} + sub recalc { my $argument = shift; if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}