--- loncom/xml/londefdef.pm 2003/05/21 14:57:31 1.134 +++ loncom/xml/londefdef.pm 2004/01/08 19:49:59 1.192 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.134 2003/05/21 14:57:31 sakharuk Exp $ +# $Id: londefdef.pm,v 1.192 2004/01/08 19:49:59 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -25,8 +25,7 @@ # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ -# -# Copyright for TtHfunc and TtMfunc by Ian Hutchinson. +## Copyright for TtHfunc and TtMfunc by Ian Hutchinson. # TtHfunc and TtMfunc (the "Code") may be compiled and linked into # binary executable programs or libraries distributed by the # Michigan State University (the "Licensee"), but any binaries so @@ -51,13 +50,24 @@ use Apache::File(); use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); +use Apache::Constants qw(:common); + 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')); + &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')); } +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; +} + #======================= TAG SUBROUTINES ===================== #-- <output> sub start_output { @@ -72,11 +82,12 @@ sub end_output { } #-- <m> tag sub start_m { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $currentstring = ''; - if ($target eq 'web') { + my $inside = &Apache::lonxml::get_all_text("/m",$parser,$style); + $inside=~s-<LONCAPA_INTERNAL_TURN_STYLE_ON />--g; + if ($target eq 'web' || $target eq 'analyze') { $Apache::lonxml::prevent_entity_encode++; - my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); $inside ='\\documentstyle{article}'.$inside; &Apache::lonxml::debug("M is starting with:$inside:"); my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); @@ -91,11 +102,15 @@ sub start_m { $Apache::lontexconvert::errorstring=''; } #&Apache::lonxml::debug("M is ends with:$currentstring:"); + $Apache::lonxml::post_evaluate=0; } elsif ($target eq 'tex') { - $currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); + $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 ';} - } else { - my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); + $Apache::lonxml::post_evaluate=0; } return $currentstring; } @@ -133,7 +148,7 @@ sub end_tthoption { return $result; } -#-- <html> tag +#-- <html> tag (end tag optional) sub start_html { my ($target,$token) = @_; my $currentstring = ''; @@ -152,18 +167,22 @@ sub start_html { &tth::tthoptions('-L -u0'); } } - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'edit') { $currentstring = &Apache::lonxml::xmlbegin(). &Apache::lonxml::fontsettings(); } elsif ($target eq 'tex') { @Apache::londefdef::table = (); - $currentstring .= '\documentclass[letterpaper]{article} - \newcommand{\keephidden}[1]{} + $currentstring .= '\documentclass[letterpaper]{article}'; + 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} -\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}}'; +\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}}'; } return $currentstring; } @@ -177,7 +196,7 @@ sub end_html { return $currentstring; } -#-- <head> tag +#-- <head> tag (end tag optional) sub start_head { my ($target,$token) = @_; my $currentstring = ''; @@ -190,14 +209,14 @@ sub start_head { sub end_head { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { + if ($target eq 'web' && $ENV{'request.state'} eq 'published') { $currentstring = &Apache::lonmenu::registerurl(undef,$target). $token->[2]; } return $currentstring; } -#-- <map> tag +#-- <map> tag (end tag required) sub start_map { my ($target,$token) = @_; my $currentstring = ''; @@ -216,13 +235,15 @@ sub end_map { return $currentstring; } -#-- <select> tag +#-- <select> tag (end tag required) sub start_select { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $Apache::londefdef::select=0; + } return $currentstring; } @@ -235,13 +256,20 @@ sub end_select { return $currentstring; } -#-- <option> tag +#-- <option> tag (end tag optional) sub start_option { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $Apache::londefdef::select++; + if ($Apache::londefdef::select == 1) { + $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{'; + } else { + $currentstring='\keephidden{'; + } + } return $currentstring; } @@ -250,11 +278,13 @@ sub end_option { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } + } elsif ($target eq 'tex') { + $currentstring='}'; + } return $currentstring; } -#-- <input> tag +#-- <input> tag (end tag forbidden) sub start_input { my ($target,$token) = @_; my $currentstring = ''; @@ -273,7 +303,7 @@ sub end_input { return $currentstring; } -#-- <textarea> tag +#-- <textarea> tag (end tag required) sub start_textarea { my ($target,$token) = @_; my $currentstring = ''; @@ -292,7 +322,7 @@ sub end_textarea { return $currentstring; } -#-- <form> tag +#-- <form> tag (end tag required) sub start_form { my ($target,$token) = @_; my $currentstring = ''; @@ -311,18 +341,18 @@ sub end_form { return $currentstring; } -#-- <title> tag +#-- <title> tag (end tag required) sub start_title { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\keephidden{' + $currentstring .= '\keephidden{Title of the document: ' } if ($target eq 'meta') { $currentstring='<title>'; - &start_output(); + &start_output($target); } return $currentstring; } @@ -336,13 +366,13 @@ sub end_title { $currentstring .= '}'; } if ($target eq 'meta') { - &end_output(); + &end_output($target); $currentstring='</title>'; } return $currentstring; } -#-- <meta> tag +#-- <meta> tag (end tag forbidden) sub start_meta { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -354,8 +384,7 @@ sub start_meta { } else { $currentstring = $token->[4]; } - } - if ($target eq 'meta') { + } elsif ($target eq 'meta') { unless (&Apache::lonxml::get_param ('http-equiv',$parstack,$safeeval,undef,1)) { my $name=$token->[2]->{'name'}; @@ -363,18 +392,38 @@ sub start_meta { $name=~s/\s/\_/gs; $name=~s/\W//gs; if ($name) { - $currentstring='<'.$name.'>'. + $currentstring='<'.$name; + my $display=&Apache::lonxml::get_param + ('display',$parstack,$safeeval,undef,1); + if ($display) { + $display=~s/\"/\'/g; + $currentstring.=' display="'.$display.'"'; + } + $currentstring.='>'. &Apache::lonxml::get_param ('content',$parstack,$safeeval,undef,1). - '</'.$name.'>'; + '</'.$name.'>'; } + my $display=&Apache::lonxml::get_param + ('display',$parstack,$safeeval,undef,1); + if ($display) { + $display=&HTML::Entities::encode($display); + $currentstring.='<'.$name.'.display>'.$display. + '</'.$name.'.display>'; + } + } + } elsif ($target eq 'tex') { + my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); + my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); + if ((not defined $content) && (not defined $name)) { + &Apache::lonxml::startredirection(); } } return $currentstring; } sub end_meta { - my ($target,$token,$tagstack,$parstack,$parser) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; @@ -382,7 +431,13 @@ sub end_meta { if ($args ne '') { $currentstring = $token->[4]; } - } + } elsif ($target eq 'tex') { + my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); + my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); + if ((not defined $content) && (not defined $name)) { + &Apache::lonxml::endredirection(); + } + } return $currentstring; } @@ -431,15 +486,43 @@ sub end_accessrule { return $currentstring; } -#-- <body> tag +#-- <body> tag (end tag required) sub start_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { - if (!$Apache::lonxml::registered) { + if ($Apache::lonhomework::parsing_a_problem) { + &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems."); + return ''; + } + if (!$Apache::lonxml::registered && + $ENV{'request.state'} eq 'published') { $currentstring.='<head>'. &Apache::lonmenu::registerurl(undef,$target).'</head>'; } +# Accessibility + if ($ENV{'browser.imagesuppress'} eq 'on') { + delete($token->[2]->{'background'}); + } + if ($ENV{'browser.fontenhance'} eq 'on') { + my $style=''; + foreach my $key (keys(%{$token->[2]})) { + if ($key =~ /^style$/i) { + $style.=$token->[2]->{$key}.';'; + delete($token->[2]->{$key}); + } + } + $token->[2]->{'style'}=$style.'; font-size: x-large;'; + } + if ($ENV{'browser.blackwhite'} eq 'on') { + delete($token->[2]->{'font'}); + delete($token->[2]->{'link'}); + delete($token->[2]->{'alink'}); + delete($token->[2]->{'vlink'}); + delete($token->[2]->{'bgcolor'}); + delete($token->[2]->{'background'}); + } +# Overload loads my $onLoad=''; foreach my $key (keys(%{$token->[2]})) { if ($key =~ /^onload$/i) { @@ -484,12 +567,12 @@ sub end_body { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = '\end{document}'; + $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; } return $currentstring; } -#-- <center> tag +#-- <center> tag (end tag required) sub start_center { my ($target,$token) = @_; my $currentstring = ''; @@ -497,9 +580,7 @@ sub start_center { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\begin{center}'; - } elsif ($target eq 'latexsource') { - $currentstring = '\begin{center}'; - } + } return $currentstring; } @@ -510,13 +591,11 @@ sub end_center { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '\end{center}'; - } elsif ($target eq 'latexsource') { - $currentstring = '\end{center}'; - } + } return $currentstring; } -#-- <b> tag +#-- <b> tag (end tag required) sub start_b { my ($target,$token) = @_; my $currentstring = ''; @@ -524,8 +603,6 @@ sub start_b { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\textbf{'; - } elsif ($target eq 'latexsource') { - $currentstring = '\textbf{'; } return $currentstring; } @@ -537,13 +614,11 @@ sub end_b { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '}'; - } elsif ($target eq 'latexsource') { - $currentstring = '}'; } return $currentstring; } -#-- <strong> tag +#-- <strong> tag (end tag required) sub start_strong { my ($target,$token) = @_; my $currentstring = ''; @@ -551,8 +626,6 @@ sub start_strong { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\textbf{'; - } elsif ($target eq 'latexsource') { - $currentstring = '\textbf{'; } return $currentstring; } @@ -560,18 +633,15 @@ sub start_strong { sub end_strong { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web') { - + if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '}'; - } elsif ($target eq 'latexsource') { - $currentstring = '}'; - } + } return $currentstring; } -#-- <h1> tag +#-- <h1> tag (end tag required) sub start_h1 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -592,7 +662,7 @@ sub start_h1 { $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; } elsif ($target eq 'meta') { $currentstring='<subject>'; - &start_output(); + &start_output($target); } return $currentstring; } @@ -614,7 +684,7 @@ sub end_h1 { } $currentstring .= '}}'.$post; } elsif ($target eq 'meta') { - &end_output(); + &end_output($target); $currentstring='</subject>'; } return $currentstring; @@ -835,17 +905,15 @@ sub end_h6 { return $currentstring; } -#--- <cite> tag +#--- <cite> tag (end tag required) sub start_cite { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; - } + $currentstring .= '\textit{'; + } return $currentstring; } @@ -855,14 +923,12 @@ sub end_cite { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + $currentstring .= '}'; + } return $currentstring; } -#-- <i> tag +#-- <i> tag (end tag required) sub start_i { my ($target,$token) = @_; my $currentstring = ''; @@ -870,9 +936,7 @@ sub start_i { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\textit{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\textit{'; - } + } return $currentstring; } @@ -883,23 +947,19 @@ sub end_i { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } -#-- <address> tag +#-- <address> tag (end tag required) sub start_address { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; - } + $currentstring .= '\textit{'; + } return $currentstring; } @@ -909,23 +969,19 @@ sub end_address { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; + $currentstring .= '}'; } return $currentstring; } -#-- <dfn> tag +#-- <dfn> tag (end tag required) sub start_dfn { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; + $currentstring .= '\textit{'; } return $currentstring; } @@ -936,14 +992,12 @@ sub end_dfn { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + $currentstring .= '}'; + } return $currentstring; } -#-- <tt> tag +#-- <tt> tag (end tag required) sub start_tt { my ($target,$token) = @_; my $currentstring = ''; @@ -951,9 +1005,7 @@ sub start_tt { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\texttt{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\texttt{'; - } + } return $currentstring; } @@ -964,23 +1016,19 @@ sub end_tt { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } -#-- <kbd> tag +#-- <kbd> tag (end tag required) sub start_kbd { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\texttt"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\texttt{"; - } + $currentstring .= '\texttt{'; + } return $currentstring; } @@ -990,14 +1038,12 @@ sub end_kbd { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + $currentstring .= '}'; + } return $currentstring; } -#-- <code> tag +#-- <code> tag (end tag required) sub start_code { my ($target,$token) = @_; my $currentstring = ''; @@ -1020,7 +1066,7 @@ sub end_code { return $currentstring; } -#-- <em> tag +#-- <em> tag (end tag required) sub start_em { my ($target,$token) = @_; my $currentstring = ''; @@ -1028,9 +1074,7 @@ sub start_em { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\emph{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\emph{'; - } + } return $currentstring; } @@ -1041,22 +1085,18 @@ sub end_em { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; - } + } return $currentstring; } -#-- <q> tag +#-- <q> tag (end tag required) sub start_q { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\\emph{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\emph{"; + $currentstring .= '\emph{'; } return $currentstring; } @@ -1067,24 +1107,22 @@ sub end_q { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + $currentstring .= '}'; + } return $currentstring; } -#-- <p> tag +#-- <p> tag (end tag optional) sub start_p { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '{\par '; - } elsif ($target eq 'latexsource') { - $currentstring .= '{\par '; - } + my $signal=1; + foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}} + if ($signal) {$currentstring .= '\par ';} + } return $currentstring; } @@ -1093,15 +1131,11 @@ sub end_p { my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; - } elsif ($target eq 'tex') { - $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } -#-- <br> tag +#-- <br> tag (end tag forbidden) sub start_br { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $currentstring = ''; @@ -1109,11 +1143,9 @@ sub start_br { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') { - $currentstring .= '\vskip 0.2 mm'; + $currentstring .= '\vskip 0.2 mm '; } - } elsif ($target eq 'latexsource') { - $currentstring .= '\\'; - } + } return $currentstring; } @@ -1126,17 +1158,15 @@ sub end_br { return $currentstring; } -#-- <big> tag +#-- <big> tag (end tag required) sub start_big { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\large{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '{\Large '; - } + $currentstring .= '{\large '; + } return $currentstring; } @@ -1147,13 +1177,11 @@ sub end_big { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } -#-- <small> tag +#-- <small> tag (end tag required) sub start_small { my ($target,$token) = @_; my $currentstring = ''; @@ -1161,9 +1189,7 @@ sub start_small { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '{\footnotesize '; - } elsif ($target eq 'latexsource') { - $currentstring .= '{\footnotesize '; - } + } return $currentstring; } @@ -1174,13 +1200,11 @@ sub end_small { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } -#-- <basefont> tag +#-- <basefont> tag (end tag forbidden) sub start_basefont { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $currentstring = ''; @@ -1209,13 +1233,18 @@ sub end_basefont { return $currentstring; } -#-- <font> tag +#-- <font> tag (end tag required) sub start_font { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $currentstring = ''; if ($target eq 'web') { my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval); - if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode++;} + if ($face=~/symbol/i) { + $Apache::lonxml::prevent_entity_encode++; + } else { + 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); @@ -1242,7 +1271,7 @@ sub end_font { return $currentstring; } -#-- <strike> tag +#-- <strike> tag (end tag required) sub start_strike { my ($target,$token) = @_; my $currentstring = ''; @@ -1268,7 +1297,7 @@ sub end_strike { return $currentstring; } -#-- <s> tag +#-- <s> tag (end tag required) sub start_s { my ($target,$token) = @_; my $currentstring = ''; @@ -1294,14 +1323,14 @@ sub end_s { return $currentstring; } -#-- <sub> tag +#-- <sub> tag (end tag required) sub start_sub { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\$_{ "; + $currentstring .= "\$_{"; } return $currentstring; } @@ -1312,19 +1341,19 @@ sub end_sub { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= " }\$"; + $currentstring .= "}\$"; } return $currentstring; } -#-- <sup> tag +#-- <sup> tag (end tag required) sub start_sup { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= "\$^{ "; + $currentstring .= "\$^{"; } return $currentstring; } @@ -1335,26 +1364,26 @@ sub end_sup { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= " }\$"; + $currentstring .= "}\$"; } return $currentstring; } -#-- <hr> tag +#-- <hr> tag (end tag forbidden) sub start_hr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,0); + my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); if (defined $LaTeXwidth) { if ($LaTeXwidth=~/^%/) { substr($LaTeXwidth,0,1)=''; $LaTeXwidth=($LaTeXwidth/100).'\textwidth'; } } else { - $LaTeXwidth ='0.95\textwidth'; + $LaTeXwidth ='0.9\textwidth'; } my ($pre,$post); my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); @@ -1365,7 +1394,7 @@ sub start_hr { } elsif ($align eq 'right') { $pre=' \hfill \llap{'; $post='}'; } - $currentstring .= ' \vskip 0 mm \noindent\makebox[\textwidth]{'.$pre.'\makebox['. + $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['. $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm '; } return $currentstring; @@ -1376,12 +1405,11 @@ sub end_hr { my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; - } elsif ($target eq 'tex') { - } + } return $currentstring; } -#-- <div> tag +#-- <div> tag (end tag required) sub start_div { my ($target,$token) = @_; my $currentstring = ''; @@ -1400,52 +1428,52 @@ sub end_div { return $currentstring; } -#-- <a> tag +#-- <a> tag (end tag required) sub start_a { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { + my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1); + my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1); + if ($a=~/\S/) { + $a=~s/([^\\])%/$1\\\%/g; + $currentstring .= '\ref{URI: '.$a.'}'; + } elsif ($b=~/\S/) { + $currentstring .= '\ref{Anchor: '.$b.'}'; + } else { + $currentstring.=''; + } } return $currentstring; } sub end_a { - my ($target,$token,$tagstack,$stackref) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; - } elsif ($target eq 'tex') { - my $tempor_var = $stackref->[$#$stackref]; - if (index($tempor_var,'name') != -1 ) { - $tempor_var =~ s/name=([^,]*),/$1/g; - } elsif (index($tempor_var,'href') != -1 ) { - $tempor_var =~ s/href=([^,]*),/$1/g; - $currentstring .= " \\ref{$tempor_var}"; - } } return $currentstring; } -#-- <li> tag +#-- <li> tag (end tag optional) sub start_li { - my ($target,$token,$tagstack,$stackref) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - my $tempor_var = $stackref->[$#$stackref]; - if (index($tempor_var,'circle') != -1 ) { - $currentstring .= " \\item[o] "; - } elsif (index($tempor_var,'square') != -1 ) { - $currentstring .= " \\item[$\Box$] "; - } elsif ($tempor_var ne '') { - $_ = $tempor_var; - m/my\s*([^=]*)=/; - $currentstring .= " \\item[$1] "; + my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1); + if ($type=~/circle/) { + $currentstring .= ' \item[o] '; + } elsif ($type=~/square/) { + $currentstring .= ' \item[$\Box$] '; + } elsif ($type ne '') { + $currentstring .= ' \item['.$type.'] '; } else { - $currentstring .= " \\item "; + $currentstring .= ' \item '; } } return $currentstring; @@ -1460,7 +1488,7 @@ sub end_li { return $currentstring; } -#-- <u> tag +#-- <u> tag (end tag required) sub start_u { my ($target,$token) = @_; my $currentstring = ''; @@ -1486,7 +1514,7 @@ sub end_u { return $currentstring; } -#-- <ul> tag +#-- <ul> tag (end tag required) sub start_ul { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1529,7 +1557,7 @@ sub end_ul { return $currentstring; } -#-- <menu> tag +#-- <menu> tag (end tag required) sub start_menu { my ($target,$token) = @_; my $currentstring = ''; @@ -1552,7 +1580,7 @@ sub end_menu { return $currentstring; } -#-- <dir> tag +#-- <dir> tag (end tag required) sub start_dir { my ($target,$token) = @_; my $currentstring = ''; @@ -1575,7 +1603,7 @@ sub end_dir { return $currentstring; } -#-- <ol> tag +#-- <ol> tag (end tag required) sub start_ol { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1628,79 +1656,122 @@ sub end_ol { return $currentstring; } -#-- <dl> tag +#-- <dl> tag (end tag required) sub start_dl { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\begin{description}'; + $currentstring = '\begin{description}'; + @Apache::londefdef::description=(); + $Apache::londefdef::DD_redirection=0; + $Apache::londefdef::DT_redirection=0; } return $currentstring; } sub end_dl { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = '\end{description}'; + if ($Apache::londefdef::DT_redirection) { + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; + } elsif ($Apache::londefdef::DD_redirection) { + $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); + } + foreach my $element (@Apache::londefdef::description) { + $currentstring.=' '.$element.' '; + } + @Apache::londefdef::description=(); + $currentstring.='\end{description}'; } return $currentstring; } -#-- <dt> tag +#-- <dt> tag (end tag optional) sub start_dt { - my ($target,$token) = @_; - my $currentstring = ''; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my $currentstring=''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\item['; + if ($Apache::londefdef::DT_redirection) { + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; + } elsif ($Apache::londefdef::DD_redirection) { + $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); + $Apache::londefdef::DD_redirection=0; + } + &Apache::lonxml::startredirection(); + $Apache::londefdef::DT_redirection=1; } return $currentstring; } sub end_dt { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = ']'; + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; } return $currentstring; } -#-- <dd> tag +sub item_cleanup { + my $item=&Apache::lonxml::endredirection(); + $item=~s/\\begin{center}//g; + $item=~s/\\end{center}//g; + return $item; +} + +#-- <dd> tag (end tag optional) sub start_dd { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; + } elsif ($target eq 'tex') { + if ($Apache::londefdef::DT_redirection) { + my $data=&item_cleanup; + push @Apache::londefdef::description,'\item['.$data.']'; + $Apache::londefdef::DT_redirection=0; + } + $Apache::londefdef::DD_redirection=1; + &Apache::lonxml::startredirection(); } return $currentstring; } sub end_dd { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } + } elsif ($target eq 'tex') { + $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); + $Apache::londefdef::DD_redirection=0; + } return $currentstring; } -#-- <table> tag +#-- <table> tag (end tag required) sub start_table { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $textwidth; + my $textwidth=''; if (not defined @Apache::londefdef::table) { $textwidth=&recalc($ENV{'form.textwidth'}); - $textwidth=~/(\d+)/; - $textwidth=$1; + $textwidth=~/(\d+\.?\d*)/; + $textwidth=0.95*$1; } else { $textwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); } @@ -1742,7 +1813,7 @@ sub start_table { $Apache::londefdef::table[-1]{'vvinc'} = ''; } $Apache::londefdef::table[-1]{'output'} = ' \noindent \begin{tabular} '; - $currentstring = '\keephidden{NEW TABLE ENTRY '.$textwidth.'}'; + $currentstring = '\keephidden{NEW TABLE ENTRY}'; } return $currentstring; } @@ -1790,7 +1861,7 @@ sub end_table { $needed=$#length_row_final-$needed+1; for (my $jn=0;$jn<=$#length_row_final;$jn++) { if ($length_row_final[$jn]==0) { - if ($length_raw_row[$jn]<$available_length/3) { + if ($length_raw_row[$jn]<$available_length) { $length_row_final[$jn]=$length_raw_row[$jn]; $available_length=$available_length-$length_raw_row[$jn]; $needed--; @@ -1820,12 +1891,13 @@ sub end_table { } else { $currentstring .= $Apache::londefdef::table[-1]{'output'}; pop @Apache::londefdef::table; + undef @Apache::londefdef::table; } } return $currentstring; } -#-- <tr> tag +#-- <tr> tag (end tag optional) sub start_tr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1848,74 +1920,118 @@ sub start_tr { } sub end_tr { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { + if ($Apache::londefdef::TD_redirection) { + &end_td_tex($parstack,$parser,$safeeval); + } push @{ $Apache::londefdef::table[-1]{'TeXlengthrow'} },$Apache::londefdef::table[-1]{'TeXlength'}; push @{ $Apache::londefdef::table[-1]{'lengthrow'} },$Apache::londefdef::table[-1]{'length'}; } return $currentstring; } -#-- <td> tag +#-- <td> tag (end tag optional) sub start_td { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1); - if ($what_to_push eq '') { - $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);; - } - push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push; - $Apache::londefdef::table[-1]{'counter_columns'}++; - &Apache::lonxml::startredirection(); + $Apache::londefdef::TD_redirection = 1; + &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval); } return $currentstring; } - + +sub tag_check { + my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_; + my @ar=@$parstack; + for (my $i=$#ar-1;$i>=0;$i--) { + if (lc($$tagstack[$i]) eq $good_tag) { + &start_td_tex($parstack,$parser,$safeeval); + last; + } elsif (lc($$tagstack[$i]) eq $bad_tag) { + splice @ar, $i+1; + &end_td_tex(\@ar,$parser,$safeeval); + &start_td_tex($parstack,$parser,$safeeval); + last; + } + } + return ''; +} + +sub start_td_tex { + my ($parstack,$parser,$safeeval) = @_; + my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1); + if ($what_to_push eq '') { + $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);; + } + push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push; + $Apache::londefdef::table[-1]{'counter_columns'}++; + &Apache::lonxml::startredirection(); + return ''; +} + +sub end_td_tex { + my ($parstack,$parser,$safeeval) = @_; + my $current_row = $Apache::londefdef::table[-1]{'row_number'}; + my $data=&Apache::lonxml::endredirection(); + my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); + if (defined $TeXwidth) { + my $current_length=&recalc($TeXwidth); + $current_length=~/(\d+)/; + $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; + $Apache::londefdef::table[-1]{'length'} .= '0,'; + } else { + if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { + my $current_length=&recalc($1); + $current_length=~/(\d+\.?\d*)/; + $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; + $Apache::londefdef::table[-1]{'length'} .= '0,'; + } else { + $data=~s/^\s+(\S.*)/$1/; + $data=~s/(.*\S)\s+$/$1/; + $data=~s/(\s)+/$1/; + my $current_length=0; + if ($data=~/\\vskip/) { + my $newdata=$data; + $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g; + my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata); + foreach my $elementdata (@newdata) { + my $lengthnewdata=1.8*LATEX_length($elementdata); + if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;} + } + } else { + $current_length=1.8*LATEX_length($data); + } + $Apache::londefdef::table[-1]{'length'} .= $current_length.','; + $Apache::londefdef::table[-1]{'TeXlength'} .= '0,'; + } + } + for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) { + $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/; + } + @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; + return''; +} + sub end_td { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - my $current_row = $Apache::londefdef::table[-1]{'row_number'}; - my $data=&Apache::lonxml::endredirection(); - my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); - if (defined $TeXwidth) { - my $current_length=&recalc($TeXwidth); - $current_length=~/(\d+)/; - $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; - $Apache::londefdef::table[-1]{'length'} .= '0,'; - } else { - if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { - my $current_length=&recalc($1); - $current_length=~/(\d+\.?\d*)/; - $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; - $Apache::londefdef::table[-1]{'length'} .= '0,'; - } else { - $data=~/^\s*(\S.*)/; - $data=$1; - $data=~/(.*\S)\s*$/; - $data=$1; - my $current_length=2*length($data); - $Apache::londefdef::table[-1]{'length'} .= $current_length.','; - $Apache::londefdef::table[-1]{'TeXlength'} .= '0,'; - } - } - for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) { - $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/; - } - @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; + $Apache::londefdef::TD_redirection =0; + &end_td_tex($parstack,$parser,$safeeval); } return $currentstring; } -#-- <th> tag +#-- <th> tag (end tag optional) sub start_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1971,20 +2087,24 @@ sub end_th { } return $currentstring; } -#-- <img> tag +#-- <img> tag (end tag forbidden) sub start_img { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval, undef,1); + if (not $src and ($target eq 'web' or $target eq 'tex')) { + my $inside = &Apache::lonxml::get_all_text("/img",$parser); + &Apache::lonnet::logthis("inside was $inside"); + return ''; + } $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; my $currentstring = ''; my $width_param = ''; my $height_param = ''; my $scaling = .3; - if ($target eq 'web') { if ($ENV{'browser.imagesuppress'} ne 'on') { - $currentstring = $token->[4]; + $currentstring.= $token->[4]; } else { my $alttag= &Apache::lonxml::get_param ('alt',$parstack,$safeeval,undef,1); @@ -1992,14 +2112,13 @@ sub start_img { $alttag=&Apache::lonmeta::alttag ($Apache::lonxml::pwd[-1],$src); } - $currentstring='[IMAGE: '.$alttag.']'; + $currentstring.='[IMAGE: '.$alttag.']'; } } elsif ($target eq 'tex') { $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &image_replication($src); - #if original gif/jpg/png file exist do following: - if (-e $src) { + if (-e $src) { #defines the default size of image my $image = Image::Magick->new; my $current_figure = $image->Read($src); @@ -2022,6 +2141,7 @@ sub start_img { } elsif ($width ne '') { $width_param = $width*$scaling; } + if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}} my $file; my $path; if ($src =~ m!(.*)/([^/]*)$!) { @@ -2052,7 +2172,11 @@ sub start_img { my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; $temp_file = Apache::File->new('>>'.$filename); print $temp_file "$src\n"; - $currentstring .= '\vskip 1 mm \graphicspath{{/home/httpd/prtspool/}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; + $newsrc=~s/\/home\/httpd\/html\/res//; + $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//; + $newsrc=~s/\/\.\//\//; + $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//; + $currentstring .= '\vskip 1 mm \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; } } } else { @@ -2069,6 +2193,45 @@ sub start_img { #<allow> tag will care about replication } } + } elsif ($target eq 'edit') { + $currentstring .=&Apache::edit::tag_start($target,$token); + $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70). + &Apache::edit::browse('src',undef,'alt').' '. + &Apache::edit::search('src',undef,'alt').'<br />'; + $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />'; + $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5); + $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />'; + $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5); + $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5); + $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval); + my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval); + my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval); + my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval); + $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" '; + if ($width) { $currentstring.=' width="'.$width.'" '; } + if ($height) { $currentstring.=' height="'.$height.'" '; } + $currentstring .= ' />'; + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'src','alt', + 'TeXwidth','TeXheight', + 'width','height'); + $src=$token->[2]{'src'}; + if (!$token->[2]{'width'} && !$token->[2]{'height'}) { + $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); + &image_replication($src); + if (-e $src) { + my $image = Image::Magick->new; + my ($width, $height, $size, $format) = $image->Ping($src); + if ($width && $height) { + $token->[2]{'width'} =$width; + $token->[2]{'height'}=$height; + $constructtag=1; + } + } + } + if ($constructtag) {$currentstring=&Apache::edit::rebuild_tag($token);} } return $currentstring; } @@ -2084,7 +2247,7 @@ sub end_img { return $currentstring; } -#-- <applet> tag +#-- <applet> tag (end tag required) sub start_applet { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; @@ -2109,7 +2272,16 @@ sub start_applet { $currentstring='[APPLET: '.$alttag.']'; } } elsif ($target eq 'tex') { - $currentstring = " \\begin{figure} "; + my $alttag= &Apache::lonxml::get_param('alt',$parstack, + $safeeval,undef,1); + unless ($alttag) { + my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval, + undef,1); + $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1], + $code); + } + $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag. + '.}\end{center}'; } return $currentstring; } @@ -2120,12 +2292,11 @@ sub end_applet { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = " \\end{figure}"; } return $currentstring; } -#-- <embed> tag +#-- <embed> tag (end tag optional/required) sub start_embed { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1); @@ -2143,7 +2314,6 @@ sub start_embed { $currentstring='[EMBED: '.$alttag.']'; } } elsif ($target eq 'tex') { - $currentstring = " \\begin{figure} "; } return $currentstring; } @@ -2153,13 +2323,12 @@ sub end_embed { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } elsif ($target eq 'tex') { - $currentstring = " \\end{figure}"; + } elsif ($target eq 'tex') { } return $currentstring; } -#-- <param> tag +#-- <param> tag (end tag forbidden) sub start_param { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; if (&Apache::lonxml::get_param @@ -2173,7 +2342,6 @@ sub start_param { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = " \\begin{figure} "; } return $currentstring; } @@ -2184,7 +2352,6 @@ sub end_param { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = " \\end{figure}"; } return $currentstring; } @@ -2194,7 +2361,8 @@ sub start_allow { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1); $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); - $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; + $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]= + &Apache::lonnet::clutter($src); &image_replication($src); my $result; if ($target eq 'edit') { @@ -2215,12 +2383,14 @@ sub end_allow { return ''; } -#-- Frames +#-- Frames (end tag required) +#-- <frameset> sub start_frameset { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { - if (!$Apache::lonxml::registered) { + if (!$Apache::lonxml::registered && + $ENV{'request.state'} eq 'published') { $currentstring.='<head>'. &Apache::lonmenu::registerurl(undef,$target).'</head>'; } @@ -2260,16 +2430,37 @@ sub end_frameset { return $currentstring; } -#-- <pre> +#-- <xmp> (end tag required) +sub start_xmp { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my $currentstring = ''; + if ($target eq 'web') { + $currentstring .= $token->[4]; + } elsif ($target eq 'tex') { + $currentstring .= '\begin{verbatim}'; + } + return $currentstring; +} + +sub end_xmp { + my ($target,$token) = @_; + my $currentstring = ''; + if ($target eq 'web') { + $currentstring .= $token->[2]; + } elsif ($target eq 'tex') { + $currentstring .= '\end{verbatim}'; + } + return $currentstring; +} + +#-- <pre> (end tag required) sub start_pre { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - my $width = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); - if (not defined $width) {$width ='\textwidth';} - $currentstring .= '\parbox['.$width.']{\begin{verbatim}'; + $currentstring .= '\begin{verbatim}'; } return $currentstring; } @@ -2280,7 +2471,7 @@ sub end_pre { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= '\end{verbatim}}'; + $currentstring .= '\end{verbatim}'; } return $currentstring; } @@ -2345,7 +2536,7 @@ sub end_blankspace { return $currentstring; } -#-- <abbr> tag +#-- <abbr> tag (end tag required) sub start_abbr { my ($target,$token) = @_; my $currentstring = ''; @@ -2364,7 +2555,7 @@ sub end_abbr { return $currentstring; } -#-- <acronym> tag +#-- <acronym> tag (end tag required) sub start_acronym { my ($target,$token) = @_; my $currentstring = ''; @@ -2383,7 +2574,7 @@ sub end_acronym { return $currentstring; } -#-- <area> tag +#-- <area> tag (end tag forbidden) sub start_area { my ($target,$token) = @_; my $currentstring = ''; @@ -2402,13 +2593,13 @@ sub end_area { return $currentstring; } -#-- <base> tag +#-- <base> tag (end tag forbidden) sub start_base { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } return $currentstring; } @@ -2421,7 +2612,7 @@ sub end_base { return $currentstring; } -#-- <bdo> tag +#-- <bdo> tag (end tag required) sub start_bdo { my ($target,$token) = @_; my $currentstring = ''; @@ -2440,7 +2631,7 @@ sub end_bdo { return $currentstring; } -#-- <bgsound> tag +#-- <bgsound> tag (end tag optional) sub start_bgsound { my ($target,$token) = @_; my $currentstring = ''; @@ -2459,7 +2650,7 @@ sub end_bgsound { return $currentstring; } -#-- <blink> tag +#-- <blink> tag (end tag required) sub start_blink { my ($target,$token) = @_; my $currentstring = ''; @@ -2478,7 +2669,7 @@ sub end_blink { return $currentstring; } -#-- <blockquote> tag +#-- <blockquote> tag (end tag required) sub start_blockquote { my ($target,$token) = @_; my $currentstring = ''; @@ -2497,7 +2688,7 @@ sub end_blockquote { return $currentstring; } -#-- <button> tag +#-- <button> tag (end tag required) sub start_button { my ($target,$token) = @_; my $currentstring = ''; @@ -2516,7 +2707,7 @@ sub end_button { return $currentstring; } -#-- <caption> tag +#-- <caption> tag (end tag required) sub start_caption { my ($target,$token) = @_; my $currentstring = ''; @@ -2535,7 +2726,7 @@ sub end_caption { return $currentstring; } -#-- <col> tag +#-- <col> tag (end tag forbdden) sub start_col { my ($target,$token) = @_; my $currentstring = ''; @@ -2554,7 +2745,7 @@ sub end_col { return $currentstring; } -#-- <colgroup> tag +#-- <colgroup> tag (end tag optional) sub start_colgroup { my ($target,$token) = @_; my $currentstring = ''; @@ -2573,7 +2764,7 @@ sub end_colgroup { return $currentstring; } -#-- <del> tag +#-- <del> tag (end tag required) sub start_del { my ($target,$token) = @_; my $currentstring = ''; @@ -2592,7 +2783,7 @@ sub end_del { return $currentstring; } -#-- <fieldset> tag +#-- <fieldset> tag (end tag required) sub start_fieldset { my ($target,$token) = @_; my $currentstring = ''; @@ -2611,7 +2802,7 @@ sub end_fieldset { return $currentstring; } -#-- <frame> tag +#-- <frame> tag (end tag forbidden) sub start_frame { my ($target,$token) = @_; my $currentstring = ''; @@ -2630,7 +2821,7 @@ sub end_frame { return $currentstring; } -#-- <iframe> tag +#-- <iframe> tag (end tag required) sub start_iframe { my ($target,$token) = @_; my $currentstring = ''; @@ -2649,7 +2840,7 @@ sub end_iframe { return $currentstring; } -#-- <ins> tag +#-- <ins> tag (end tag required) sub start_ins { my ($target,$token) = @_; my $currentstring = ''; @@ -2668,7 +2859,7 @@ sub end_ins { return $currentstring; } -#-- <isindex> tag +#-- <isindex> tag (end tag forbidden) sub start_isindex { my ($target,$token) = @_; my $currentstring = ''; @@ -2687,7 +2878,7 @@ sub end_isindex { return $currentstring; } -#-- <keygen> tag +#-- <keygen> tag (end tag forbidden) sub start_keygen { my ($target,$token) = @_; my $currentstring = ''; @@ -2725,7 +2916,7 @@ sub end_label { return $currentstring; } -#-- <layer> tag +#-- <layer> tag (end tag required) sub start_layer { my ($target,$token) = @_; my $currentstring = ''; @@ -2744,7 +2935,7 @@ sub end_layer { return $currentstring; } -#-- <legend> tag +#-- <legend> tag (end tag required) sub start_legend { my ($target,$token) = @_; my $currentstring = ''; @@ -2763,7 +2954,7 @@ sub end_legend { return $currentstring; } -#-- <link> tag +#-- <link> tag (end tag forbidden) sub start_link { my ($target,$token) = @_; my $currentstring = ''; @@ -2782,7 +2973,7 @@ sub end_link { return $currentstring; } -#-- <marquee> tag +#-- <marquee> tag (end tag optional) sub start_marquee { my ($target,$token) = @_; my $currentstring = ''; @@ -2801,8 +2992,8 @@ sub end_marquee { return $currentstring; } -#-- <malticol> tag -sub start_malticol { +#-- <multicol> tag (end tag required) +sub start_multicol { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { @@ -2811,7 +3002,7 @@ sub start_malticol { return $currentstring; } -sub end_malticol { +sub end_multicol { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { @@ -2820,13 +3011,15 @@ sub end_malticol { return $currentstring; } -#-- <nobr> tag +#-- <nobr> tag (end tag required) sub start_nobr { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $currentstring='\mbox{'; + } return $currentstring; } @@ -2835,11 +3028,13 @@ sub end_nobr { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } + } elsif ($target eq 'tex') { + $currentstring='}'; + } return $currentstring; } -#-- <noembed> tag +#-- <noembed> tag (end tag required) sub start_noembed { my ($target,$token) = @_; my $currentstring = ''; @@ -2858,7 +3053,7 @@ sub end_noembed { return $currentstring; } -#-- <noframes> tag +#-- <noframes> tag (end tag required) sub start_noframes { my ($target,$token) = @_; my $currentstring = ''; @@ -2877,7 +3072,7 @@ sub end_noframes { return $currentstring; } -#-- <nolayer> tag +#-- <nolayer> tag (end tag required) sub start_nolayer { my ($target,$token) = @_; my $currentstring = ''; @@ -2896,7 +3091,7 @@ sub end_nolayer { return $currentstring; } -#-- <noscript> tag +#-- <noscript> tag (end tag required) sub start_noscript { my ($target,$token) = @_; my $currentstring = ''; @@ -2915,7 +3110,7 @@ sub end_noscript { return $currentstring; } -#-- <object> tag +#-- <object> tag (end tag required) sub start_object { my ($target,$token) = @_; my $currentstring = ''; @@ -2934,7 +3129,7 @@ sub end_object { return $currentstring; } -#-- <optgroup> tag +#-- <optgroup> tag (end tag required) sub start_optgroup { my ($target,$token) = @_; my $currentstring = ''; @@ -2953,13 +3148,15 @@ sub end_optgroup { return $currentstring; } -#-- <samp> tag +#-- <samp> tag (end tag required) sub start_samp { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $currentstring='\texttt{'; + } return $currentstring; } @@ -2968,7 +3165,9 @@ sub end_samp { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; - } + } elsif ($target eq 'tex') { + $currentstring='}'; + } return $currentstring; } @@ -2991,7 +3190,7 @@ sub end_server { return $currentstring; } -#-- <spacer> tag +#-- <spacer> tag (end tag forbidden) sub start_spacer { my ($target,$token) = @_; my $currentstring = ''; @@ -3010,7 +3209,7 @@ sub end_spacer { return $currentstring; } -#-- <span> tag +#-- <span> tag (end tag required) sub start_span { my ($target,$token) = @_; my $currentstring = ''; @@ -3029,7 +3228,7 @@ sub end_span { return $currentstring; } -#-- <tbody> tag +#-- <tbody> tag (end tag optional) sub start_tbody { my ($target,$token) = @_; my $currentstring = ''; @@ -3048,7 +3247,7 @@ sub end_tbody { return $currentstring; } -#-- <tfoot> tag +#-- <tfoot> tag (end tag optional) sub start_tfoot { my ($target,$token) = @_; my $currentstring = ''; @@ -3067,7 +3266,7 @@ sub end_tfoot { return $currentstring; } -#-- <thead> tag +#-- <thead> tag (end tag optional) sub start_thead { my ($target,$token) = @_; my $currentstring = ''; @@ -3092,7 +3291,9 @@ sub start_var { my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; - } + } elsif ($target eq 'tex') { + $currentstring = '\textit{'; + } return $currentstring; } @@ -3100,12 +3301,14 @@ sub end_var { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { - $currentstring = $token->[2]; + $currentstring = $token->[2]; + } elsif ($target eq 'tex') { + $currentstring = '}'; } return $currentstring; } -#-- <wbr> tag +#-- <wbr> tag (end tag forbidden) sub start_wbr { my ($target,$token) = @_; my $currentstring = ''; @@ -3124,7 +3327,6 @@ sub end_wbr { return $currentstring; } - #-- <hideweboutput> tag sub start_hideweboutput { my ($target,$token) = @_; @@ -3146,18 +3348,14 @@ sub end_hideweboutput { sub image_replication { my $src = shift; - if (not -e $src) { - #replicates image itself - &Apache::lonnet::repcopy($src); - #replicates eps or ps - my $newsrc = $src; - $newsrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i; - if (not -e $newsrc) { - if (&Apache::lonnet::repcopy($newsrc) ne 'OK') { - $newsrc =~ s/\.eps$/\.ps/; - &Apache::lonnet::repcopy($newsrc); - } - } + if (not -e $src) { &Apache::lonnet::repcopy($src); } + #replicates eps or ps + my $epssrc = my $pssrc = $src; + $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i; + $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i; + if (not -e $epssrc && not -e $pssrc) { + my $result=&Apache::lonnet::repcopy($epssrc); + if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); } } return ''; } @@ -3180,5 +3378,26 @@ sub recalc { return $value.' mm'; } +sub LATEX_length { + my $garbage=shift; + $garbage=~s/^\s+(\S.*)/$1/; + $garbage=~s/(.*\S)\s+$/$1/; + $garbage=~s/(\s)+/$1/; + $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g; + $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$|\$)//g; + $garbage=~s/(\\alpha|\\beta|\\gamma|\\delta|\\epsilon|\\verepsilon|\\zeta|\\eta|\\theta|\\vartheta|\\iota|\\kappa|\\lambda|\\mu|\\nu|\\xi|\\pi|\\varpi|\\rho|\\varrho|\\sigma|\\varsigma|\\tau|\\upsilon|\\phi|\\varphi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)/1/g; + $garbage=~s/(\\pm|\\mp|\\times|\\div|\\cdot|\\ast|\\star|\\dagger|\\ddagger|\\amalg|\\cap|\\cup|\\uplus|\\sqcap|\\sqcup|\\vee|\\wedge|\\oplus|\\ominus|\\otimes|\\circ|\\bullet|\\diamond|\\lhd|\\rhd|\\unlhd|\\unrhd|\\oslash|\\odot|\\bigcirc|\\Box|\\Diamond|\\bigtriangleup|\\bigtriangledown|\\triangleleft|\\triangleright|\\setminus|\\wr)/1/g; + $garbage=~s/(\\le|\\ll|\\leq|\\ge|\\geq|\\gg|\\neq|\\doreq|\\sim|\\simeq|\\subset|\\subseteq|\\sqsubset|\\sqsubseteq|\\in|\\vdash|\\models|\\supset|\\supseteq|\\sqsupset|\\sqsupseteq|\\ni|\\dash|\\perp|\\approx|\\cong|\\equiv|\\propto|\\prec|\\preceq|\\parallel|\\asymp|\\smile|\\frown|\\bowtie|\\succ|\\succeq|\\mid)/1/g; + $garbage=~s/(\\not<|\\\\not\\le|\\not\\prec|\\not\\preceq|\\not\\subset|\\not\\subseteq|\\not\\sqsubseteq|\\not\\in|\\not>|\\not\\ge|\\not\\succ|\\notsucceq|\\not\\supset|\\notsupseteq|\\not\\sqsupseteq|\\notin|\\not=|\\not\\equiv|\\not\\sim|\\not\\simeq|\\not\\approx|\\not\\cong|\\not\\asymp)/1/g; + $garbage=~s/(\\leftarrow|\\gets|\\Leftarrow|\\rightarrow|\\to|\\Rightarrow|\\leftrightarrow|\\Leftrightarrow|\\mapsto|\\hookleftarrow|\\leftharpoonup|\\leftkarpoondown|\\rightleftharpoons|\\longleftarrow|\\Longleftarrow|\\longrightarrow|\\Longrightarrow|\\longleftrightarrow|\\Longleftrightarrow|\\longmapsto|\\hookrightarrow|\\rightharpoonup|\\rightharpoondown|\\uparrow|\\Uparrow|\\downarrow|\\Downarrow|\\updownarrow|\\Updownarrow|\\nearrow|\\searrow|\\swarrow|\\nwarrow)/1/g; + $garbage=~s/(\\aleph|\\hbar|\\imath|\\jmath|\\ell|\\wp|\\Re|\\Im|\\mho|\\prime|\\emptyset|\\nabla|\\surd|\\partial|\\top|\\bot|\\vdash|\\dashv|\\forall|\\exists|\\neg|\\flat|\\natural|\\sharp|\\\||\\angle|\\backslash|\\Box|\\Diamond|\\triangle|\\clubsuit|\\diamondsuit|\\heartsuit|\\spadesuit|\\Join|\\infty)/ /g; + $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g; + my $value=length($garbage); + return $value; +} + + + + 1; __END__