--- loncom/xml/londefdef.pm 2004/08/17 14:18:04 1.233 +++ loncom/xml/londefdef.pm 2016/08/13 20:01:52 1.456.2.2 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.233 2004/08/17 14:18:04 sakharuk Exp $ +# $Id: londefdef.pm,v 1.456.2.2 2016/08/13 20:01:52 raeburn Exp $ # # # Copyright Michigan State University Board of Trustees @@ -36,36 +36,41 @@ # The C source of the Code may not be distributed by the Licensee # to any other parties under any circumstances. # -# -# last modified 06/26/00 by Alexander Sakharuk -# 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer -# 01/18 Alex Sakharuk package Apache::londefdef; -use Apache::lonnet(); +use Apache::lonnet; use strict; use Apache::lonxml; -use Apache::File(); +use Apache::lontable; use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); +use Apache::lonlocal; +use Apache::loncommon(); use Apache::Constants qw(:common); - +use File::Basename; +use LONCAPA(); +# use Data::Dumper; 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')); + &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','style','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput')); } + sub initialize_londefdef { $Apache::londefdef::TD_redirection=0; @Apache::londefdef::table = (); $Apache::londefdef::select=0; - @Apache::londefdef::description=(); - $Apache::londefdef::DD_redirection=0; - $Apache::londefdef::DT_redirection=0; + undef(@Apache::londefdef::description); + @Apache::londefdef::DD=(0); + @Apache::londefdef::DT=(0); + @Apache::londefdef::seenDT=(0); + $Apache::londefdef::list_index=0; + undef($Apache::londefdef::head); + undef($Apache::londefdef::title); } #======================= TAG SUBROUTINES ===================== @@ -86,28 +91,48 @@ 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:"); + #&Apache::lonxml::debug("M is evaluated 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,'<>&"').'occurred 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:"); $Apache::lonxml::post_evaluate=0; } elsif ($target eq 'tex') { + $currentstring = $inside; 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 ';} + # detect simple math mode entry exits, and convert them + # to use \ensuremath ... unless there's a \verb inside. + if (! ($currentstring=~/\\verb/)) { + if ($currentstring=~/^\s*\$[^\$].*\$\s*$/) { + $currentstring=~s/^(\s*)\$/$1/; + $currentstring=~s/\$(\s*)$/$1/; + $currentstring='\ensuremath{'.$currentstring.'}'; + } + } $Apache::lonxml::post_evaluate=0; } return $currentstring; @@ -123,12 +148,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); @@ -147,30 +173,11 @@ 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(). - &Apache::lonxml::fontsettings(); - } elsif ($target eq 'tex') { - @Apache::londefdef::table = (); - $currentstring .= '\documentclass[letterpaper]{book}'; - if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';} - $currentstring .= '\newcommand{\keephidden}[1]{}'. - '\renewcommand{\deg}{$^{\circ}$}'. - '\usepackage{longtable}'. - '\usepackage{textcomp}'. - '\usepackage{makeidx}'. - '\usepackage[dvips]{graphicx}'. - '\usepackage{epsfig}'. - '\usepackage{calc}'. - '\usepackage{amsmath}'. - '\usepackage{amssymb}'. - '\usepackage{amsfonts}'. - '\usepackage{amsthm}'. - '\usepackage{amscd}'. - '\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}}'; + if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) { + # start_body() takes care of emitting the + } elsif ($target eq 'tex') { + + $currentstring .= &latex_header(); } return $currentstring; } @@ -178,8 +185,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; } @@ -188,8 +195,8 @@ sub end_html { sub start_head { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { - $currentstring = $token->[4]; + if ($target eq 'web' || $target eq 'webgrade') { + &Apache::lonxml::startredirection(); } return $currentstring; } @@ -197,9 +204,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; } @@ -208,7 +218,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; @@ -217,7 +227,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; @@ -227,7 +237,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; @@ -238,7 +248,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; @@ -248,7 +258,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++; @@ -264,7 +274,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='}'; @@ -276,7 +286,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; @@ -285,7 +295,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; @@ -295,7 +305,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; @@ -304,7 +314,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; @@ -314,7 +324,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; @@ -323,7 +333,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; @@ -331,10 +341,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;
}
@@ -599,21 +744,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;
@@ -622,9 +770,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;
@@ -633,8 +782,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;
@@ -648,9 +797,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;
@@ -697,7 +846,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;
}
@@ -705,7 +854,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 ';
@@ -725,8 +874,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;
@@ -740,7 +889,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;
}
@@ -748,7 +897,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 ';
@@ -768,8 +917,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;
@@ -783,7 +932,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;
}
@@ -791,7 +940,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 ';
@@ -811,8 +960,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;
@@ -826,7 +975,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;
}
@@ -834,7 +983,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 ';
@@ -854,8 +1003,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;
@@ -869,7 +1018,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;
}
@@ -877,7 +1026,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 ';
@@ -898,7 +1047,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{';
@@ -909,7 +1058,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 .= '}';
@@ -921,7 +1070,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{';
@@ -932,7 +1081,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 .= '}';
@@ -944,7 +1093,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{';
@@ -955,7 +1104,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 .= '}';
@@ -967,7 +1116,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{';
@@ -978,7 +1127,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 .= '}';
@@ -990,7 +1139,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{';
@@ -1001,7 +1150,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 .= '}';
@@ -1013,7 +1162,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{';
@@ -1024,7 +1173,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 .= '}';
@@ -1036,7 +1185,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{';
@@ -1047,7 +1196,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 .= '}';
@@ -1059,7 +1208,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{';
@@ -1070,7 +1219,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 .= '}';
@@ -1082,7 +1231,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{';
@@ -1093,7 +1242,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 .= '}';
@@ -1101,74 +1250,115 @@ 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) {
- $currentstring .= ' \vskip 0 mm ';
- } elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
+ if ($signal != 1) {
$currentstring .= '\strut \\\\ \strut ';
}
+
}
return $currentstring;
}
@@ -1176,7 +1366,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;
@@ -1186,7 +1376,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 ';
@@ -1197,7 +1387,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 .= '}';
@@ -1209,7 +1399,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 ';
@@ -1220,7 +1410,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 .= '}';
@@ -1232,7 +1422,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);
@@ -1246,7 +1436,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);
@@ -1261,12 +1451,8 @@ 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 ''; }
- }
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
@@ -1280,7 +1466,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);
@@ -1295,7 +1481,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();
@@ -1306,7 +1492,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();
@@ -1321,7 +1507,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();
@@ -1332,7 +1518,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();
@@ -1347,10 +1533,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;
}
@@ -1358,7 +1544,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 .= '}}';
@@ -1370,10 +1556,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;
}
@@ -1381,7 +1567,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 .= '}}';
@@ -1392,10 +1578,31 @@ 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') {
+
+ #
can't be inside of thank you LaTeX.
+ #
+ my $restart_sub = 0;
+ my $restart_sup = 0;
+
+ # Since and are simple tags it's ok to turn off/on
+ # using the start_ stop_ functions.. those tags only care about
+ # $target.
+
+ if (&is_inside_of($tagstack, "sub")) {
+ $restart_sub = 1;
+ $currentstring .= &end_sub($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+ if (&is_inside_of($tagstack, "sup")) {
+ $restart_sup = 1;
+ $currentstring .= &end_sup($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+
my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
if (defined $LaTeXwidth) {
if ($LaTeXwidth=~/^%/) {
@@ -1416,6 +1623,16 @@ sub start_hr {
}
$currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
$LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
+ # Turn stuff back on that we can't be inside of.
+
+ if ($restart_sub) {
+ $currentstring .= &start_sub($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+ if ($restart_sup) {
+ $currentstring .= &start_sup($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
}
return $currentstring;
}
@@ -1423,48 +1640,112 @@ 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;
}
#--