--- loncom/xml/londefdef.pm 2003/09/02 14:30:31 1.158.4.5 +++ loncom/xml/londefdef.pm 2003/08/26 14:40:03 1.166 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.158.4.5 2003/09/02 14:30:31 albertel Exp $ +# $Id: londefdef.pm,v 1.166 2003/08/26 14:40:03 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -51,6 +51,8 @@ use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); +$Apache::londefdef::TD_redirection=0; + BEGIN { &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput')); @@ -162,9 +164,11 @@ sub start_html { \renewcommand{\deg}{$^{\circ}$} \usepackage{longtable} \usepackage{textcomp} + \usepackage{makeidx} \usepackage[dvips]{graphicx} \usepackage{epsfig}\usepackage{calc} -\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}}'; +\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}}'; } return $currentstring; } @@ -406,7 +410,7 @@ sub end_meta { my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); if ((not defined $content) && (not defined $name)) { - &Apache::lonxml::endredirection(); + &Apache::lonxml::startredirection(); } } return $currentstring; @@ -462,10 +466,6 @@ sub start_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { - if ($Apache::lonhomework::parsing_a_problem) { - &Apache::lonxml::warning(" tag found inside of tag this can cause problems."); - return ''; - } if (!$Apache::lonxml::registered) { $currentstring.=''. &Apache::lonmenu::registerurl(undef,$target).''; @@ -1407,14 +1407,21 @@ sub start_a { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1); - $a=~s/([^\\])%/$1\\\%/g; - $currentstring .= '\ref{'.$a.'}'; + 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; } sub end_a { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; @@ -1424,7 +1431,7 @@ sub end_a { #--
  • tag sub start_li { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; @@ -1769,9 +1776,11 @@ sub end_table { } } #continues trying estimate the width of raw data +# $currentstring.=' SSS '.$Apache::londefdef::table[-1]{'lengthrow'}[0].' FFF '; ####for test only my @length_raw_row = split(/,/,$Apache::londefdef::table[-1]{'lengthrow'}[0]); for (my $in=1;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) { my @length_row = split(/,/,$Apache::londefdef::table[-1]{'lengthrow'}[$in]); +# $currentstring.=' SSS '.$Apache::londefdef::table[-1]{'lengthrow'}[$in].' FFF '; ####for test only for (my $jn=0;$jn<=$#length_row;$jn++) { if ($length_raw_row[$jn]<$length_row[$jn]) {$length_raw_row[$jn]=$length_row[$jn];} } @@ -1788,7 +1797,7 @@ sub end_table { $needed=$#length_row_final-$needed+1; for (my $jn=0;$jn<=$#length_row_final;$jn++) { if ($length_row_final[$jn]==0) { - if ($length_raw_row[$jn]<$available_length) { + if ($length_raw_row[$jn]<$available_length/3) { $length_row_final[$jn]=$length_raw_row[$jn]; $available_length=$available_length-$length_raw_row[$jn]; $needed--; @@ -1847,11 +1856,14 @@ sub start_tr { } sub end_tr { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { + if ($Apache::londefdef::TD_redirection) { + &end_td_tex($parstack,$parser,$safeeval); + } push @{ $Apache::londefdef::table[-1]{'TeXlengthrow'} },$Apache::londefdef::table[-1]{'TeXlength'}; push @{ $Apache::londefdef::table[-1]{'lengthrow'} },$Apache::londefdef::table[-1]{'length'}; } @@ -1865,63 +1877,95 @@ sub start_td { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1); - if ($what_to_push eq '') { - $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);; - } - push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push; - $Apache::londefdef::table[-1]{'counter_columns'}++; - &Apache::lonxml::startredirection(); + $Apache::londefdef::TD_redirection = 1; + &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval); } return $currentstring; } - -sub end_td { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; - if ($target eq 'web') { - $currentstring = $token->[2]; - } elsif ($target eq 'tex') { - my $current_row = $Apache::londefdef::table[-1]{'row_number'}; - my $data=&Apache::lonxml::endredirection(); - my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); - if (defined $TeXwidth) { - my $current_length=&recalc($TeXwidth); - $current_length=~/(\d+)/; + +sub tag_check { + my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_; + my @ar=@$parstack; + for (my $i=$#ar-1;$i>=0;$i--) { + if (lc($$tagstack[$i]) eq $good_tag) { + &start_td_tex($parstack,$parser,$safeeval); + last; + } elsif (lc($$tagstack[$i]) eq $bad_tag) { + splice @ar, $i+1; + &end_td_tex(\@ar,$parser,$safeeval); + &start_td_tex($parstack,$parser,$safeeval); + last; + } + } + return ''; +} + +sub start_td_tex { + my ($parstack,$parser,$safeeval) = @_; + my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1); + if ($what_to_push eq '') { + $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);; + } + push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push; + $Apache::londefdef::table[-1]{'counter_columns'}++; + &Apache::lonxml::startredirection(); + return ''; +} + +sub end_td_tex { + my ($parstack,$parser,$safeeval) = @_; + my $current_row = $Apache::londefdef::table[-1]{'row_number'}; + my $data=&Apache::lonxml::endredirection(); + my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); + if (defined $TeXwidth) { + my $current_length=&recalc($TeXwidth); + $current_length=~/(\d+)/; + $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; + $Apache::londefdef::table[-1]{'length'} .= '0,'; + } else { + if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { + my $current_length=&recalc($1); + $current_length=~/(\d+\.?\d*)/; $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; $Apache::londefdef::table[-1]{'length'} .= '0,'; - } else { - if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { - my $current_length=&recalc($1); - $current_length=~/(\d+\.?\d*)/; - $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; - $Apache::londefdef::table[-1]{'length'} .= '0,'; - } else { - $data=~s/^\s+(\S.*)/$1/; + } else { + $data=~s/^\s+(\S.*)/$1/; $data=~s/(.*\S)\s+$/$1/; $data=~s/(\s)+/$1/; my $current_length=0; if ($data=~/\\vskip/) { - my $newdata=$data; - $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g; - my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata); - foreach my $elementdata (@newdata) { - $elementdata=~s/^\s+(\S.*)/$1/; - $elementdata=~s/(.*\S)\s+$/$1/; - $elementdata=~s/(\s)+/$1/; - my $lengthnewdata=1.8*length($elementdata); - if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;} - } - } else { - $current_length=1.8*length($data); - } - $Apache::londefdef::table[-1]{'length'} .= $current_length.','; - $Apache::londefdef::table[-1]{'TeXlength'} .= '0,'; - } + my $newdata=$data; + $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g; + my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata); + foreach my $elementdata (@newdata) { + $elementdata=~s/^\s+(\S.*)/$1/; + $elementdata=~s/(.*\S)\s+$/$1/; + $elementdata=~s/(\s)+/$1/; + my $lengthnewdata=1.8*length($elementdata); + if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;} + } + } else { + $current_length=1.8*length($data); + } + $Apache::londefdef::table[-1]{'length'} .= $current_length.','; + $Apache::londefdef::table[-1]{'TeXlength'} .= '0,'; + } + } for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) { $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/; } - @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; + @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; + return''; +} + +sub end_td { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my $currentstring = ''; + if ($target eq 'web') { + $currentstring = $token->[2]; + } elsif ($target eq 'tex') { + $Apache::londefdef::TD_redirection =0; + &end_td_tex($parstack,$parser,$safeeval); } return $currentstring; } @@ -2271,6 +2315,29 @@ sub end_frameset { return $currentstring; } +#-- +sub start_xmp { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my $currentstring = ''; + if ($target eq 'web') { + $currentstring .= $token->[4]; + } elsif ($target eq 'tex') { + $currentstring .= '\begin{verbatim}'; + } + return $currentstring; +} + +sub end_xmp { + my ($target,$token) = @_; + my $currentstring = ''; + if ($target eq 'web') { + $currentstring .= $token->[2]; + } elsif ($target eq 'tex') { + $currentstring .= '\end{verbatim}'; + } + return $currentstring; +} + #-- <pre> sub start_pre { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; @@ -2417,7 +2484,7 @@ sub start_base { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } return $currentstring; } @@ -3101,7 +3168,9 @@ sub start_var { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $currentstring = '\textit{'; + } return $currentstring; } @@ -3109,12 +3178,14 @@ sub end_var { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { - $currentstring = $token->[2]; + $currentstring = $token->[2]; + } elsif ($target eq 'tex') { + $currentstring = '}'; } return $currentstring; } -#-- <wbr> tag +#-- <wbr> tag (end tag forbidden) sub start_wbr { my ($target,$token) = @_; my $currentstring = ''; @@ -3133,7 +3204,6 @@ sub end_wbr { return $currentstring; } - #-- <hideweboutput> tag sub start_hideweboutput { my ($target,$token) = @_;