--- loncom/xml/londefdef.pm 2005/02/09 19:51:43 1.255 +++ loncom/xml/londefdef.pm 2007/03/13 13:35:39 1.358 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.255 2005/02/09 19:51:43 albertel Exp $ +# $Id: londefdef.pm,v 1.358 2007/03/13 13:35:39 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -39,7 +39,7 @@ package Apache::londefdef; -use Apache::lonnet(); +use Apache::lonnet; use strict; use Apache::lonxml; use Apache::File(); @@ -47,7 +47,9 @@ use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); use Apache::Constants qw(:common); - +use File::Basename; +use LONCAPA(); +# use Data::Dumper; BEGIN { @@ -55,6 +57,20 @@ BEGIN { } +# +# Dumps all elements of the table structure. +# Need this 'cause evidently when given an array, Data::Dumper only seems +# to dump element 0. +# +#sub debug_dump_table { +# my $lastrow = $#Apache::londefdef::table; +# &Apache::lonnet::logthis("Dumping table: Last row index: $lastrow"); +# my $row; +# for ($row =0; $row <= $lastrow; $row++ ) { +# my $text = Dumper($Apache::londefdef::table[$row]); +# &Apache::lonnet::logthis("table [ $row ]".$text); +# } +#} sub initialize_londefdef { $Apache::londefdef::TD_redirection=0; @Apache::londefdef::table = (); @@ -64,6 +80,8 @@ sub initialize_londefdef { @Apache::londefdef::DT=(0); @Apache::londefdef::seenDT=(0); $Apache::londefdef::list_index=0; + undef($Apache::londefdef::head); + undef($Apache::londefdef::title); } #======================= TAG SUBROUTINES ===================== @@ -84,17 +102,27 @@ sub start_m { my $currentstring = ''; my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); if ($target eq 'web' || $target eq 'analyze') { - $inside ='\\documentstyle{article}'.$inside; &Apache::lonxml::debug("M is starting with:$inside:"); my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); if ($eval eq 'on') { $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); #&Apache::lonxml::debug("M is evaulated to:$inside:"); } - $currentstring = &Apache::lontexconvert::converted(\$inside); + my $tex = $inside; + my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval); + $currentstring = &Apache::lontexconvert::converted(\$inside,$display); if ($Apache::lontexconvert::errorstring) { - &Apache::lonxml::warning("tth error: ". - $Apache::lontexconvert::errorstring); + my $errormsg='
'.&HTML::Entities::encode($Apache::lontexconvert::errorstring,'<>&"').'occured while attempting to convert this TeX:
'; + $tex = &HTML::Entities::encode($tex,'<>&"'); + my ($linenumber) = + ($Apache::lontexconvert::errorstring =~ /Line (\d+)/); + if (defined($linenumber)) { + my @tex=split("\n",$tex); + $tex[$linenumber]=''. + $tex[$linenumber].''; + $tex=join("\n",@tex); + } + &Apache::lonxml::warning($errormsg.$tex.''); $Apache::lontexconvert::errorstring=''; } #&Apache::lonxml::debug("M is ends with:$currentstring:"); @@ -106,6 +134,13 @@ sub start_m { $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]); } if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';} + # detect simple math mode entry exits, and convert them + # to use \ensuremath + if ($currentstring=~/^\s*\$[^\$].*[^\$]\$\s*$/) { + $currentstring=~s/^(\s*)\$/$1/; + $currentstring=~s/\$(\s*)$/$1/; + $currentstring='\ensuremath{'.$currentstring.'}'; + } $Apache::lonxml::post_evaluate=0; } return $currentstring; @@ -121,12 +156,13 @@ sub end_m { } sub start_tthoption { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $result; - if ($target eq 'web') { - my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser); + if ($target eq 'web' || $target eq 'webgrade') { + my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser, + $style); $inside=~s/^\s*//; - if ($ENV{'browser.mathml'}) { + if ($env{'browser.mathml'}) { &tth::ttmoptions($inside); } else { &tth::tthoptions($inside); @@ -145,21 +181,21 @@ sub end_tthoption { sub start_html { my ($target,$token) = @_; my $currentstring = ''; - my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'}; - &Apache::lontexconvert::init_tth(); - if ($target eq 'web' || $target eq 'edit') { - $currentstring = &Apache::lonxml::xmlbegin(); - } elsif ($target eq 'tex') { - @Apache::londefdef::table = (); - $currentstring .= '\documentclass[letterpaper]{article}'; - if (($ENV{'form.latex_type'}=~'batchmode') || - (!$ENV{'request.role.adv'})) {$currentstring .='\batchmode';} + if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) { + # start_body() takes care of emitting the + } elsif ($target eq 'tex') { + $currentstring .= + '\documentclass[letterpaper,twoside]{article}\raggedbottom'; + if (($env{'form.latex_type'}=~'batchmode') || + (!$env{'request.role.adv'})) {$currentstring .='\batchmode';} $currentstring .= '\newcommand{\keephidden}[1]{}'. '\renewcommand{\deg}{$^{\circ}$}'. + '\usepackage{multirow}'. '\usepackage{longtable}'. '\usepackage{textcomp}'. '\usepackage{makeidx}'. '\usepackage[dvips]{graphicx}'. + '\usepackage{wrapfig}'. '\usepackage{picins}'. '\usepackage{epsfig}'. '\usepackage{calc}'. @@ -177,8 +213,8 @@ sub start_html { sub end_html { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; - if ($target eq 'web') { - $currentstring = &Apache::lonxml::xmlend($target,$parser); + if ($target eq 'web' || $target eq 'webgrade') { + # end_body takes care of the } return $currentstring; } @@ -187,8 +223,8 @@ sub end_html { sub start_head { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { - $currentstring = $token->[4].&Apache::lonxml::fontsettings(); + if ($target eq 'web' || $target eq 'webgrade') { + &Apache::lonxml::startredirection(); } return $currentstring; } @@ -196,9 +232,12 @@ sub start_head { sub end_head { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web' && $ENV{'request.state'} eq 'published') { - $currentstring = &Apache::lonmenu::registerurl(undef,$target). - $token->[2]; + if (($target eq 'web' && $env{'request.state'} eq 'published') || + ($target eq 'webgrade' && $env{'request.state'} eq 'published')) { + # in case there is a but no + if ($Apache::lonxml::redirection) { + $Apache::londefdef::head = &Apache::lonxml::endredirection(); + } } return $currentstring; } @@ -207,7 +246,7 @@ sub end_head { sub start_map { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; } return $currentstring; @@ -216,7 +255,7 @@ sub start_map { sub end_map { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; } return $currentstring; @@ -226,7 +265,7 @@ sub end_map { sub start_select { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $Apache::londefdef::select=0; @@ -237,7 +276,7 @@ sub start_select { sub end_select { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; } return $currentstring; @@ -247,7 +286,7 @@ sub end_select { sub start_option { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $Apache::londefdef::select++; @@ -263,7 +302,7 @@ sub start_option { sub end_option { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring='}'; @@ -275,7 +314,7 @@ sub end_option { sub start_input { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; } return $currentstring; @@ -284,7 +323,7 @@ sub start_input { sub end_input { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; } return $currentstring; @@ -294,7 +333,7 @@ sub end_input { sub start_textarea { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; } return $currentstring; @@ -303,7 +342,7 @@ sub start_textarea { sub end_textarea { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; } return $currentstring; @@ -313,7 +352,7 @@ sub end_textarea { sub start_form { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; } return $currentstring; @@ -322,7 +361,7 @@ sub start_form { sub end_form { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; } return $currentstring; @@ -330,10 +369,11 @@ sub end_form { #--
+ if ($target eq 'web' || $target eq 'webgrade') { + $currentstring .= &Apache::loncommon::end_page({'discussion' => 1}); } elsif ($target eq 'tex') { - $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; + $currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; } return $currentstring; } +# \begin{center} causes a new paragprah spacing that looks odd inside +# of a table cell. Same at the end of a \center but with a slightly +# larger space .. hence center_correction and center_end_correction. +# +sub center_correction { return '\vspace*{-6 mm}'; } +sub center_end_correction { return '\vspace*{-7 mm}'; } + #--
sub start_b {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
- $currentstring = '\textbf{';
+ &disable_para();
+ $currentstring .= '\textbf{';
}
return $currentstring;
}
@@ -606,21 +614,24 @@ sub start_b {
sub end_b {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
- $currentstring = '}';
+ &enable_para();
+ $currentstring = '}';
}
return $currentstring;
}
#-- tag (end tag required)
+# NOTE: in TeX mode disables internal
sub start_strong {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
+ &disable_para();
$currentstring = '\textbf{';
}
return $currentstring;
@@ -629,9 +640,10 @@ sub start_strong {
sub end_strong {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
+ &enable_para();
$currentstring = '}';
}
return $currentstring;
@@ -640,8 +652,8 @@ sub end_strong {
#-- is a bit strange since it does not require a closing
+
+# Some tags are fragile meaning that inside of them
+# does not work within TeX mode. This is managed via the
+# counter below:
+#
+
+ my $para_disabled = 0;
+
+sub disable_para {
+ $para_disabled++;
+}
+sub enable_para {
+ $para_disabled--;
+}
+
+
#-- 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') {
+ if ($target eq 'web' || $target eq 'webgrade') {
+ $currentstring .= &end_p(); # close off prior para if in progress.
$currentstring .= $token->[4];
- } elsif ($target eq 'tex') {
+ if (! ($currentstring =~ /\//)) {
+ $closing_string = ' in tables.
+ } else {
+ $closing_string = '\strut\\\\\strut ';
+ }
}
- my $signal=1;# does not work inside ...
- foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
- if (!$signal) {$currentstring = '';}
- }
+
}
return $currentstring;
}
-
+#
+# End paragraph processing just requires that we output the
+# closing string that was saved and blank it.
sub end_p {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
- $currentstring .= $token->[2];
- } elsif ($target eq 'tex') {
- my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
- 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}';
- }
+ # Note only 'tex' mode uses disable_para and enable_para
+ # so we don't need to know the target in the check below:
+
+ if (!$para_disabled) {
+ my $current_string = $closing_string;
+ $closing_string = ''; # Not in a para anymore.
+ return $current_string;
+ } else {
+ return '';
}
- return $currentstring;
-}
+}
+}
#-- tag (end tag required)
sub start_h1 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
+ my $currentstring = &end_p(); # Close off any prior para.
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $pre;
@@ -655,9 +667,9 @@ sub start_h1 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
} elsif ($target eq 'meta') {
- $currentstring='
tag
sub start_h2 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
+ my $currentstring = &end_p(); # Close off any prior para.
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $pre;
@@ -704,7 +716,7 @@ sub start_h2 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -712,7 +724,7 @@ sub start_h2 {
sub end_h2 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
my $post='\vskip 0 mm ';
@@ -732,8 +744,8 @@ sub end_h2 {
#--
tag
sub start_h3 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
+ my $currentstring = &end_p(); # Close off any prior para.
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $pre;
@@ -747,7 +759,7 @@ sub start_h3 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -755,7 +767,7 @@ sub start_h3 {
sub end_h3 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
my $post='\vskip 0 mm ';
@@ -775,8 +787,8 @@ sub end_h3 {
#--
tag
sub start_h4 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
+ my $currentstring = &end_p(); # Close off any prior para.
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $pre;
@@ -790,7 +802,7 @@ sub start_h4 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -798,7 +810,7 @@ sub start_h4 {
sub end_h4 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
my $post='\vskip 0 mm ';
@@ -818,8 +830,8 @@ sub end_h4 {
#--
tag
sub start_h5 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
+ my $currentstring = &end_p(); # Close off any prior paras.
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $pre;
@@ -833,7 +845,7 @@ sub start_h5 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -841,7 +853,7 @@ sub start_h5 {
sub end_h5 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
my $post='\vskip 0 mm ';
@@ -861,8 +873,8 @@ sub end_h5 {
#--
tag
sub start_h6 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
+ my $currentstring = &end_p(); # Close off any prior paras.
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $pre;
@@ -876,7 +888,7 @@ sub start_h6 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -884,7 +896,7 @@ sub start_h6 {
sub end_h6 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
my $post='\vskip 0 mm ';
@@ -905,7 +917,7 @@ sub end_h6 {
sub start_cite {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\textit{';
@@ -916,7 +928,7 @@ sub start_cite {
sub end_cite {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -928,7 +940,7 @@ sub end_cite {
sub start_i {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\textit{';
@@ -939,7 +951,7 @@ sub start_i {
sub end_i {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -951,7 +963,7 @@ sub end_i {
sub start_address {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\textit{';
@@ -962,7 +974,7 @@ sub start_address {
sub end_address {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -974,7 +986,7 @@ sub end_address {
sub start_dfn {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\textit{';
@@ -985,7 +997,7 @@ sub start_dfn {
sub end_dfn {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -997,7 +1009,7 @@ sub end_dfn {
sub start_tt {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\texttt{';
@@ -1008,7 +1020,7 @@ sub start_tt {
sub end_tt {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -1020,7 +1032,7 @@ sub end_tt {
sub start_kbd {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\texttt{';
@@ -1031,7 +1043,7 @@ sub start_kbd {
sub end_kbd {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -1043,7 +1055,7 @@ sub end_kbd {
sub start_code {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\texttt{';
@@ -1054,7 +1066,7 @@ sub start_code {
sub end_code {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -1066,7 +1078,7 @@ sub end_code {
sub start_em {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\emph{';
@@ -1077,7 +1089,7 @@ sub start_em {
sub end_em {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -1089,7 +1101,7 @@ sub end_em {
sub start_q {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\emph{';
@@ -1100,7 +1112,7 @@ sub start_q {
sub end_q {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -1108,74 +1120,117 @@ sub end_q {
return $currentstring;
}
+#
tag (end tag forbidden)
sub start_br {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my @tempo=@$tagstack;
my $signal=0;
+ # Not going to factor this to is_inside_of since that would require
+ # multiple stack traversals.
+ #
for (my $i=$#tempo;$i>=0;$i--) {
if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
- ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||
- ($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
+ ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul')) {
$signal=1;
- last;
+ }
+ if (($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
+ $signal = 1;
}
}
- if ($signal) {
+ if ($signal eq 1) {
$currentstring .= ' \vskip 0 mm ';
- } elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
+ } else {
$currentstring .= '\strut \\\\ \strut ';
}
+
}
return $currentstring;
}
@@ -1183,7 +1238,7 @@ sub start_br {
sub end_br {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
}
return $currentstring;
@@ -1193,7 +1248,7 @@ sub end_br {
sub start_big {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '{\large ';
@@ -1204,7 +1259,7 @@ sub start_big {
sub end_big {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -1216,7 +1271,7 @@ sub end_big {
sub start_small {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '{\footnotesize ';
@@ -1227,7 +1282,7 @@ sub start_small {
sub end_small {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
@@ -1239,7 +1294,7 @@ sub end_small {
sub start_basefont {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
@@ -1253,7 +1308,7 @@ sub start_basefont {
sub end_basefont {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
@@ -1268,11 +1323,11 @@ sub end_basefont {
sub start_font {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
if ($face!~/symbol/i) {
- if (($ENV{'browser.fontenhance'} eq 'on') ||
- ($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
+ if (($env{'browser.fontenhance'} eq 'on') ||
+ ($env{'browser.blackwhite'} eq 'on')) { return ''; }
}
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
@@ -1287,7 +1342,7 @@ sub start_font {
sub end_font {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
@@ -1302,7 +1357,7 @@ sub end_font {
sub start_strike {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
&Apache::lonxml::startredirection();
@@ -1313,7 +1368,7 @@ sub start_strike {
sub end_strike {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring=&Apache::lonxml::endredirection();
@@ -1328,7 +1383,7 @@ sub end_strike {
sub start_s {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
&Apache::lonxml::startredirection();
@@ -1339,7 +1394,7 @@ sub start_s {
sub end_s {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring=&Apache::lonxml::endredirection();
@@ -1354,10 +1409,10 @@ sub end_s {
sub start_sub {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- $currentstring .= '\ensuremath{_{';
+ $currentstring .= '\raisebox{-\smallskipamount}{\scriptsize{';
}
return $currentstring;
}
@@ -1365,7 +1420,7 @@ sub start_sub {
sub end_sub {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}}';
@@ -1377,10 +1432,10 @@ sub end_sub {
sub start_sup {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- $currentstring .= '\ensuremath{^{';
+ $currentstring .= '\raisebox{\smallskipamount}{\scriptsize{';
}
return $currentstring;
}
@@ -1388,7 +1443,7 @@ sub start_sup {
sub end_sup {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}}';
@@ -1399,8 +1454,8 @@ sub end_sup {
#--
tag (end tag forbidden)
sub start_hr {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
+ my $currentstring = &end_p(); # End enclosing para.
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
@@ -1430,50 +1485,79 @@ sub start_hr {
sub end_hr {
my ($target,$token) = @_;
my $currentstring = '';
- if ($target eq 'web') {
+ if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[2];
}
return $currentstring;
}
#--