--- loncom/xml/londefdef.pm 2004/07/15 17:05:20 1.230 +++ loncom/xml/londefdef.pm 2004/08/30 18:25:55 1.239 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.230 2004/07/15 17:05:20 sakharuk Exp $ +# $Id: londefdef.pm,v 1.239 2004/08/30 18:25:55 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -66,6 +66,7 @@ sub initialize_londefdef { @Apache::londefdef::description=(); $Apache::londefdef::DD_redirection=0; $Apache::londefdef::DT_redirection=0; + $Apache::londefdef::list_index=0; } #======================= TAG SUBROUTINES ===================== @@ -154,7 +155,7 @@ sub start_html { &Apache::lonxml::fontsettings(); } elsif ($target eq 'tex') { @Apache::londefdef::table = (); - $currentstring .= '\documentclass[letterpaper]{article}'; + $currentstring .= '\documentclass[letterpaper]{book}'; if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';} $currentstring .= '\newcommand{\keephidden}[1]{}'. '\renewcommand{\deg}{$^{\circ}$}'. @@ -176,10 +177,10 @@ sub start_html { } sub end_html { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { - $currentstring = &Apache::lonxml::xmlend(); + $currentstring = &Apache::lonxml::xmlend($target,$parser); } return $currentstring; } @@ -1134,13 +1135,15 @@ sub end_p { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if ($align eq 'center') { + if (not defined $align) { + $currentstring.='\strut\\\\\strut '; + } elsif ($align eq 'center') { $currentstring .= '\end{center}'; } elsif ($align eq 'right') { $currentstring .= '}}'; } elsif ($align eq 'left') { $currentstring .= '}\hfill}'; - } + } } return $currentstring; } @@ -1483,17 +1486,28 @@ sub start_li { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1); - if ($type=~/circle/) { - $currentstring .= ' \item[o] '; + my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0); + my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0); + #FIXME need to support types i and I + if ($type=~/disc/) { + $currentstring .= ' \item[$\bullet$] '; + } elsif ($type=~/circle/) { + $currentstring .= ' \item[$\circ$] '; } elsif ($type=~/square/) { - $currentstring .= ' \item[$\Box$] '; - } elsif ($type ne '') { - $currentstring .= ' \item['.$type.'] '; + $currentstring .= ' \item[$\diamond$] '; + } elsif ($type eq '1') { + $currentstring .= ' \item['.($Apache::londefdef::list_index+1).'.]'; + } elsif ($type eq 'A') { + $currentstring .= ' \item['.('A'..'Z')[$Apache::londefdef::list_index].'.]'; + } elsif ($type eq 'a') { + $currentstring .= ' \item['.('a'..'z')[$Apache::londefdef::list_index].'.]'; + } elsif ($value ne '') { + $currentstring .= ' \item['.$value.'] '; } else { $currentstring .= ' \item '; } - } + $Apache::londefdef::list_index++; + } return $currentstring; } @@ -1540,6 +1554,7 @@ sub start_ul { $currentstring = $token->[4]; } elsif ($target eq 'tex') { my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0); + $Apache::londefdef::list_index=0; if ($TeXtype eq 'disc') { $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'. '\renewcommand{\labelitemii}{$\bullet$}'. @@ -1628,6 +1643,7 @@ sub start_ol { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { + $Apache::londefdef::list_index=0; my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0); if ($type eq '1') { $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'. @@ -2193,6 +2209,26 @@ sub end_td_tex { push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth; push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; + } elsif ($data=~/\\parbox\{\s*\d+\.?\d*\s*(mm|cm|in|pc|pt)*\s*\}/ or $data=~/\\epsfxsize\s*=\s*\d+\.?\d*\s*(mm|cm|in|pc|pt)*/) { + my $garbage_data=$data; + my $fwidth=0; + while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) { + my $current_length=&recalc($1); + $current_length=~/(\d+\.?\d*)/; + if ($fwidth<$1) {$fwidth=$1;} + $garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//; + } + while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { + my $current_length=&recalc($1); + $current_length=~/(\d+\.?\d*)/; + if ($fwidth<$1) {$fwidth=$1;} + $garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//; + } + push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; + push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth; + push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; + push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; + $data=~s/\\\\\s*$//; } else { $data=~s/^\s+(\S.*)/$1/; $data=~s/(.*\S)\s+$/$1/; @@ -2398,13 +2434,9 @@ sub start_img { $currentstring.='[IMAGE: '.$alttag.']'; } } elsif ($target eq 'tex') { + my $oldSRC=$src; + $oldSRC=~s/\.(gif|jpg|png)$/\.eps/; $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); - #if uploaded restore the path - if ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/simplepage\/([^\/]+)$/) { - $src=&Apache::loncommon::propath($1,$2).'/userfiles/simplepage/'.$3; - } elsif ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/aboutme\/([^\/]+)$/) { - $src=&Apache::loncommon::propath($1,$2).'/userfiles/aboutme/'.$3; - } #if original gif/jpg/png file exist do following: if (-e $src) { #what is the image size? @@ -2412,6 +2444,7 @@ sub start_img { my ($file,$path)=&file_path($src); my $newsrc = $src; $newsrc =~ s/\.(gif|jpg|png)$/.eps/i; + my $dummy_content=&Apache::lonnet::getfile($oldSRC); $file=~s/\.(gif|jpg|png)$/.eps/i; #where can we find the picture? if (-e $newsrc) { @@ -2457,6 +2490,8 @@ sub start_img { $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'
'; $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5); $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5); + $currentstring .=&Apache::edit::select_arg('Alignment:','align', + ['','bottom','middle','top','left','right'],$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); @@ -2470,7 +2505,7 @@ sub start_img { my ($osrc,$owidth,$oheight)= ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'}); my $ctag=&Apache::edit::get_new_args($token,$parstack, - $safeeval,'src','alt', + $safeeval,'src','alt','align', 'TeXwidth','TeXheight', 'width','height'); my ($nsrc,$nwidth,$nheight)= @@ -3678,7 +3713,11 @@ sub eps_generation { $newsrc=~s/\/home\/httpd\/lonUsers//; $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//; } - return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; + if ($newsrc=~/\/userfiles\//) { + return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; + } else { + return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; + } } sub file_path {