--- loncom/xml/londefdef.pm 2003/08/20 15:27:52 1.163 +++ loncom/xml/londefdef.pm 2003/10/10 19:05:31 1.179 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.163 2003/08/20 15:27:52 sakharuk Exp $ +# $Id: londefdef.pm,v 1.179 2003/10/10 19:05:31 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -92,9 +92,15 @@ sub start_m { $Apache::lontexconvert::errorstring=''; } #&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); + 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); } @@ -323,7 +329,7 @@ sub start_title { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\keephidden{' + $currentstring .= '\keephidden{Title of the document: ' } if ($target eq 'meta') { $currentstring=''; @@ -398,7 +404,7 @@ sub start_meta { } sub end_meta { - my ($target,$token,$tagstack,$parstack,$parser) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; @@ -407,8 +413,11 @@ sub end_meta { $currentstring = $token->[4]; } } elsif ($target eq 'tex') { - $currentstring=&Apache::lonxml::endredirection(); - $currentstring=''; + 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(); + } } return $currentstring; } @@ -463,6 +472,10 @@ 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("<body> tag found inside of <problem> tag this can cause problems."); + return ''; + } if (!$Apache::lonxml::registered) { $currentstring.='<head>'. &Apache::lonmenu::registerurl(undef,$target).'</head>'; @@ -534,7 +547,7 @@ sub end_body { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = '\end{document}'; + $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; } return $currentstring; } @@ -880,7 +893,7 @@ sub start_cite { if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\textit{"; + $currentstring .= '\textit{'; } return $currentstring; } @@ -891,7 +904,7 @@ sub end_cite { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; + $currentstring .= '}'; } return $currentstring; } @@ -926,7 +939,7 @@ sub start_address { if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\textit{"; + $currentstring .= '\textit{'; } return $currentstring; } @@ -937,7 +950,7 @@ sub end_address { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; + $currentstring .= '}'; } return $currentstring; } @@ -949,7 +962,7 @@ sub start_dfn { if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\textit{"; + $currentstring .= '\textit{'; } return $currentstring; } @@ -960,7 +973,7 @@ sub end_dfn { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; + $currentstring .= '}'; } return $currentstring; } @@ -995,7 +1008,7 @@ sub start_kbd { if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\texttt"; + $currentstring .= '\texttt{'; } return $currentstring; } @@ -1006,7 +1019,7 @@ sub end_kbd { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; + $currentstring .= '}'; } return $currentstring; } @@ -1064,7 +1077,7 @@ sub start_q { if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\emph{"; + $currentstring .= '\emph{'; } return $currentstring; } @@ -1075,7 +1088,7 @@ sub end_q { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; + $currentstring .= '}'; } return $currentstring; } @@ -1418,7 +1431,7 @@ sub start_a { } sub end_a { - my ($target,$token,$tagstack,$parstack,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; @@ -1428,7 +1441,7 @@ sub end_a { #-- <li> tag sub start_li { - my ($target,$token,$tagstack,$parstack,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; @@ -1631,45 +1644,77 @@ sub start_dl { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\begin{description}'; + $currentstring = '\begin{description}'; + @Apache::londefdef::description=(); + $Apache::londefdef::DD_redirection=0; + $Apache::londefdef::DT_redirection=0; } return $currentstring; } sub end_dl { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = '\end{description}'; + if ($Apache::londefdef::DT_redirection) { + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; + } elsif ($Apache::londefdef::DD_redirection) { + $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); + } + foreach my $element (@Apache::londefdef::description) { + $currentstring.=' '.$element.' '; + } + @Apache::londefdef::description=(); + $currentstring.='\end{description}'; } return $currentstring; } -#-- <dt> tag +#-- <dt> tag (end tag optional) sub start_dt { - my ($target,$token) = @_; - my $currentstring = ''; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my $currentstring=''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\item['; + if ($Apache::londefdef::DT_redirection) { + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; + } elsif ($Apache::londefdef::DD_redirection) { + $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); + $Apache::londefdef::DD_redirection=0; + } + &Apache::lonxml::startredirection(); + $Apache::londefdef::DT_redirection=1; } return $currentstring; } sub end_dt { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = ']'; + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; } return $currentstring; } +sub item_cleanup { + my $item=&Apache::lonxml::endredirection(); + $item=~s/\\begin{center}//g; + $item=~s/\\end{center}//g; + return $item; +} + #-- <dd> tag sub start_dd { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; @@ -1677,21 +1722,26 @@ sub start_dd { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - if ($$tagstack[-2] eq 'dl') { - $currentstring = ' \item [] '; - } elsif ($$tagstack[-2] eq 'dt') { - $currentstring = ']'; + if ($Apache::londefdef::DT_redirection) { + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; } + $Apache::londefdef::DD_redirection=1; + &Apache::lonxml::startredirection(); } return $currentstring; } sub end_dd { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } + } elsif ($target eq 'tex') { + $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); + $Apache::londefdef::DD_redirection=0; + } return $currentstring; } @@ -1792,7 +1842,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/3) { + if ($length_raw_row[$jn]<$available_length) { $length_row_final[$jn]=$length_raw_row[$jn]; $available_length=$available_length-$length_raw_row[$jn]; $needed--; @@ -1828,7 +1878,7 @@ sub end_table { return $currentstring; } -#-- <tr> tag +#-- <tr> tag (end tag optional) sub start_tr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1865,7 +1915,7 @@ sub end_tr { return $currentstring; } -#-- <td> tag +#-- <td> tag (end tag optional) sub start_td { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1924,9 +1974,24 @@ sub end_td_tex { $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; $Apache::londefdef::table[-1]{'length'} .= '0,'; } else { - $data=~s/^\s+(\S.*)/$1/; + $data=~s/^\s+(\S.*)/$1/; $data=~s/(.*\S)\s+$/$1/; - my $current_length=2*length($data); + $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,'; } @@ -1950,7 +2015,7 @@ sub end_td { return $currentstring; } -#-- <th> tag +#-- <th> tag (end tag optional) sub start_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -2143,7 +2208,16 @@ sub start_applet { $currentstring='[APPLET: '.$alttag.']'; } } elsif ($target eq 'tex') { - $currentstring = " \\begin{figure} "; + my $alttag= &Apache::lonxml::get_param('alt',$parstack, + $safeeval,undef,1); + unless ($alttag) { + my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval, + undef,1); + $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1], + $code); + } + $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag. + '.}\end{center}'; } return $currentstring; } @@ -2154,7 +2228,6 @@ sub end_applet { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = " \\end{figure}"; } return $currentstring; } @@ -2177,7 +2250,6 @@ sub start_embed { $currentstring='[EMBED: '.$alttag.']'; } } elsif ($target eq 'tex') { - $currentstring = " \\begin{figure} "; } return $currentstring; } @@ -2187,8 +2259,7 @@ sub end_embed { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } elsif ($target eq 'tex') { - $currentstring = " \\end{figure}"; + } elsif ($target eq 'tex') { } return $currentstring; } @@ -2207,7 +2278,6 @@ sub start_param { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = " \\begin{figure} "; } return $currentstring; } @@ -2218,7 +2288,6 @@ sub end_param { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = " \\end{figure}"; } return $currentstring; } @@ -2857,8 +2926,8 @@ sub end_marquee { return $currentstring; } -#-- <malticol> tag -sub start_malticol { +#-- <multicol> tag (end tag required) +sub start_multicol { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { @@ -2867,7 +2936,7 @@ sub start_malticol { return $currentstring; } -sub end_malticol { +sub end_multicol { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { @@ -2876,13 +2945,15 @@ sub end_malticol { return $currentstring; } -#-- <nobr> tag +#-- <nobr> tag (end tag required) sub start_nobr { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $currentstring='\mbox{'; + } return $currentstring; } @@ -2891,11 +2962,13 @@ sub end_nobr { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } + } elsif ($target eq 'tex') { + $currentstring='}'; + } return $currentstring; } -#-- <noembed> tag +#-- <noembed> tag (end tag required) sub start_noembed { my ($target,$token) = @_; my $currentstring = ''; @@ -2914,7 +2987,7 @@ sub end_noembed { return $currentstring; } -#-- <noframes> tag +#-- <noframes> tag (end tag required) sub start_noframes { my ($target,$token) = @_; my $currentstring = ''; @@ -2933,7 +3006,7 @@ sub end_noframes { return $currentstring; } -#-- <nolayer> tag +#-- <nolayer> tag (end tag required) sub start_nolayer { my ($target,$token) = @_; my $currentstring = ''; @@ -2952,7 +3025,7 @@ sub end_nolayer { return $currentstring; } -#-- <noscript> tag +#-- <noscript> tag (end tag required) sub start_noscript { my ($target,$token) = @_; my $currentstring = ''; @@ -2971,7 +3044,7 @@ sub end_noscript { return $currentstring; } -#-- <object> tag +#-- <object> tag (end tag required) sub start_object { my ($target,$token) = @_; my $currentstring = ''; @@ -2990,7 +3063,7 @@ sub end_object { return $currentstring; } -#-- <optgroup> tag +#-- <optgroup> tag (end tag required) sub start_optgroup { my ($target,$token) = @_; my $currentstring = ''; @@ -3009,13 +3082,15 @@ sub end_optgroup { return $currentstring; } -#-- <samp> tag +#-- <samp> tag (end tag required) sub start_samp { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $currentstring='\texttt{'; + } return $currentstring; } @@ -3024,7 +3099,9 @@ sub end_samp { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } + } elsif ($target eq 'tex') { + $currentstring='}'; + } return $currentstring; } @@ -3047,7 +3124,7 @@ sub end_server { return $currentstring; } -#-- <spacer> tag +#-- <spacer> tag (end tag forbidden) sub start_spacer { my ($target,$token) = @_; my $currentstring = ''; @@ -3066,7 +3143,7 @@ sub end_spacer { return $currentstring; } -#-- <span> tag +#-- <span> tag (end tag required) sub start_span { my ($target,$token) = @_; my $currentstring = ''; @@ -3085,7 +3162,7 @@ sub end_span { return $currentstring; } -#-- <tbody> tag +#-- <tbody> tag (end tag optional) sub start_tbody { my ($target,$token) = @_; my $currentstring = ''; @@ -3104,7 +3181,7 @@ sub end_tbody { return $currentstring; } -#-- <tfoot> tag +#-- <tfoot> tag (end tag optional) sub start_tfoot { my ($target,$token) = @_; my $currentstring = ''; @@ -3123,7 +3200,7 @@ sub end_tfoot { return $currentstring; } -#-- <thead> tag +#-- <thead> tag (end tag optional) sub start_thead { my ($target,$token) = @_; my $currentstring = '';