--- loncom/homework/structuretags.pm 2002/08/23 21:17:16 1.105 +++ loncom/homework/structuretags.pm 2002/09/04 02:48:31 1.111 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.105 2002/08/23 21:17:16 albertel Exp $ +# $Id: structuretags.pm,v 1.111 2002/09/04 02:48:31 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -379,27 +379,43 @@ sub end_problem { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=''; my $status=$Apache::inputtags::status['-1']; - if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ) { + if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex') { if ( $target eq 'grade' && $Apache::inputtags::part eq '0') { # if part is zero, no s existed, so we need to the grading &Apache::inputtags::grade; - } elsif ( $target eq 'web' && $Apache::inputtags::part eq '0' && + } elsif ( ($target eq 'web' || $target eq 'tex') && $Apache::inputtags::part eq '0' && $status ne 'UNCHECKEDOUT') { # if part is zero, no s existed, so we need show the current # grading status - $result.= &Apache::inputtags::gradestatus($Apache::inputtags::part); + my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part); + #FIXME this is ugly we should just generate tex in inputtags + if ($target eq 'tex') { $gradestatus=&html_to_tex($gradestatus); } + $result.= $gradestatus; } if ( - ($target eq 'web' && ($ENV{'request.state'} ne 'construct')) || + (($target eq 'web' || $target eq 'tex') && ($ENV{'request.state'} ne 'construct')) || ($target eq 'answer') ) { if ($status eq 'CAN_ANSWER') { - $result.="\n"; + if ($target ne 'tex') { + $result.="\n"; + } } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' || $status eq 'UNCHECKEDOUT' ) { - $result.="\n"; + if ($target ne 'tex') { + $result.="\n"; + } + } + if ($target ne 'tex') { + $result.=&Apache::lonxml::xmlend(); + } else { + $result .= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}'; + if (not $ENV{'request.symb'} =~ m/\.page_/) { + $result .= '\end{document} '; + } else { + $result .= '} '; + } } - $result.=&Apache::lonxml::xmlend(); } if ($target eq 'grade') { &Apache::lonhomework::showhash(%Apache::lonhomework::results); @@ -412,22 +428,33 @@ sub end_problem { } elsif ($target eq 'edit') { &Apache::lonxml::debug("in end_problem with $target, edit"); $result = &problem_edit_footer(); - } elsif ($target eq 'tex') { - $result .= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}'; - if (not $ENV{'request.symb'} =~ m/\.page_/) { - $result .= '\end{document} '; - } else { - $result .= '} '; - } - } + } return $result; } +#FIXME I am ugly shoot me +sub html_to_tex { + my ($string)=@_; + $string =~ s///; + $string =~ s/<\/table>//; + $string =~ s/]*)>//g; + $string =~ s/<\/tr>//g; + $string =~ s/]*)>//g; + $string =~ s/<\/td>//g; + $string =~ s//\\textbf{/g; + $string =~ s/<\/b>/}/g; + $string =~ s/
/\\vskip 0 mm /g; + $string =~ s/]*)>//g; + return $string; +} + sub start_library { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my ($result,$head_tag_start,$body_tag_start,$form_tag_start)= - &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); + my ($result,$head_tag_start,$body_tag_start,$form_tag_start); + if ($target eq 'edit') { + ($result,$head_tag_start,$body_tag_start,$form_tag_start)= + &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); $result.=$head_tag_start."".$body_tag_start.$form_tag_start. &problem_edit_header(); my $temp=&Apache::edit::insertlist($target,$token); @@ -435,7 +462,10 @@ sub start_library { } elsif ($target eq 'modified') { $result=$token->[4]; $result.=&Apache::edit::handle_insert(); - } elsif ($target eq 'web' && $ENV{'request.state'} eq "construct" ) { + } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' && + $ENV{'request.state'} eq "construct" ) { + ($result,$head_tag_start,$body_tag_start,$form_tag_start)= + &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); my $name=&get_resource_name($parstack,$safeeval); my $rndseed=&setup_rndseed($safeeval); $result.="$head_tag_start$name @@ -507,7 +537,7 @@ sub end_while { return ""; } -# +# # .. # .. # .. @@ -516,7 +546,8 @@ sub end_while { sub start_randomlist { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result; - if ($target eq 'answer' || $target eq 'grade' || $target eq 'web') { + if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' || + $target eq 'tex') { my $body= &Apache::lonxml::get_all_text("/randomlist",$$parser[$#$parser]); my $b_parser= HTML::TokeParser->new(\$body); my $b_tok; @@ -626,8 +657,11 @@ sub end_part { if ( $target eq 'grade' && $status eq 'CAN_ANSWER') { return &Apache::inputtags::grade; } - if ($target eq 'web') { - return &Apache::inputtags::gradestatus($Apache::inputtags::part); + if ($target eq 'web' || $target eq 'tex' ) { + my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part); + #FIXME this is ugly we should just generate tex in inputtags + if ($target eq 'tex') { $gradestatus=&html_to_tex($gradestatus); } + return $gradestatus; } return ''; }