--- loncom/xml/londefdef.pm 2004/11/13 08:56:53 1.244 +++ loncom/xml/londefdef.pm 2016/08/13 19:02:00 1.461 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.244 2004/11/13 08:56:53 albertel Exp $ +# $Id: londefdef.pm,v 1.461 2016/08/13 19:02:00 raeburn Exp $ # # # Copyright Michigan State University Board of Trustees @@ -36,29 +36,30 @@ # 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 = (); @@ -68,6 +69,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 ===================== @@ -88,28 +91,56 @@ 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:"); + if (!($inside =~ /^\s*\$.*\$\s*$/ || $inside =~ /^\s*\\[([].*\\[)\]]\s*$/)) { + # Non-math LaTeX will not be rendered correctly with MathJax + # and it should be avoided anyway. + # On top of that, MathJax will render math without $, but + # it will fail with tth. This is worth a warning. + # (even though some people might just use latex for printing) + &Apache::lonxml::warning(&mt("Missing \$ in <m>.")); + } 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; @@ -125,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); @@ -149,29 +181,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(); - } 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; } @@ -179,8 +193,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; } @@ -189,8 +203,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; } @@ -198,9 +212,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; } @@ -209,7 +226,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; @@ -218,7 +235,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; @@ -228,7 +245,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; @@ -239,7 +256,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; @@ -249,7 +266,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++; @@ -265,7 +282,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='}'; @@ -277,7 +294,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; @@ -286,7 +303,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; @@ -296,7 +313,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; @@ -305,7 +322,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; @@ -315,7 +332,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; @@ -324,7 +341,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; @@ -332,10 +349,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;
}
@@ -601,21 +758,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;
@@ -624,9 +784,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;
@@ -635,8 +796,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;
@@ -650,9 +811,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;
@@ -699,7 +860,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;
}
@@ -707,7 +868,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 ';
@@ -727,8 +888,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;
@@ -742,7 +903,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;
}
@@ -750,7 +911,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 ';
@@ -770,8 +931,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;
@@ -785,7 +946,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;
}
@@ -793,7 +954,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 ';
@@ -813,8 +974,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;
@@ -828,7 +989,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;
}
@@ -836,7 +997,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 ';
@@ -856,8 +1017,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;
@@ -871,7 +1032,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;
}
@@ -879,7 +1040,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 ';
@@ -900,7 +1061,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{';
@@ -911,7 +1072,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 .= '}';
@@ -923,7 +1084,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{';
@@ -934,7 +1095,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 .= '}';
@@ -946,7 +1107,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{';
@@ -957,7 +1118,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 .= '}';
@@ -969,7 +1130,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{';
@@ -980,7 +1141,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 .= '}';
@@ -992,7 +1153,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{';
@@ -1003,7 +1164,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 .= '}';
@@ -1015,7 +1176,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{';
@@ -1026,7 +1187,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 .= '}';
@@ -1038,7 +1199,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{';
@@ -1049,7 +1210,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 .= '}';
@@ -1061,7 +1222,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{';
@@ -1072,7 +1233,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 .= '}';
@@ -1084,7 +1245,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{';
@@ -1095,7 +1256,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 .= '}';
@@ -1103,74 +1264,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;
}
@@ -1178,7 +1380,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;
@@ -1188,7 +1390,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 ';
@@ -1199,7 +1401,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 .= '}';
@@ -1211,7 +1413,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 ';
@@ -1222,7 +1424,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 .= '}';
@@ -1234,7 +1436,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);
@@ -1248,7 +1450,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);
@@ -1263,12 +1465,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);
@@ -1282,7 +1480,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);
@@ -1297,7 +1495,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();
@@ -1308,7 +1506,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();
@@ -1323,7 +1521,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();
@@ -1334,7 +1532,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();
@@ -1349,10 +1547,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;
}
@@ -1360,7 +1558,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 .= '}}';
@@ -1372,10 +1570,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;
}
@@ -1383,7 +1581,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 .= '}}';
@@ -1394,10 +1592,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=~/^%/) {
@@ -1418,6 +1637,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;
}
@@ -1425,48 +1654,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;
}
#--