--- loncom/xml/londefdef.pm 2003/05/07 16:59:01 1.131 +++ loncom/xml/londefdef.pm 2003/06/30 19:26:36 1.150 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.131 2003/05/07 16:59:01 sakharuk Exp $ +# $Id: londefdef.pm,v 1.150 2003/06/30 19:26:36 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -54,7 +54,7 @@ use Apache::lonmeta(); 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')); } @@ -157,9 +157,11 @@ sub start_html { &Apache::lonxml::fontsettings(); } elsif ($target eq 'tex') { @Apache::londefdef::table = (); - $currentstring .= '\documentclass[letterpaper]{article} - \newcommand{\keephidden}[1]{} + $currentstring .= '\documentclass[letterpaper]{article}'. + #'\batchmode'. + '\newcommand{\keephidden}[1]{} \renewcommand{\deg}{$^{\circ}$} + \usepackage{longtable} \usepackage{textcomp} \usepackage[dvips]{graphicx} \usepackage{epsfig}\usepackage{calc} @@ -354,8 +356,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'}; @@ -366,9 +367,11 @@ sub start_meta { $currentstring='<'.$name.'>'. &Apache::lonxml::get_param ('content',$parstack,$safeeval,undef,1). - ''; + ''; } } + } elsif ($target eq 'tex') { + &Apache::lonxml::startredirection(); } return $currentstring; } @@ -382,7 +385,10 @@ sub end_meta { if ($args ne '') { $currentstring = $token->[4]; } - } + } elsif ($target eq 'tex') { + $currentstring=&Apache::lonxml::endredirection(); + $currentstring=''; + } return $currentstring; } @@ -497,9 +503,7 @@ sub start_center { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\begin{center}'; - } elsif ($target eq 'latexsource') { - $currentstring = '\begin{center}'; - } + } return $currentstring; } @@ -510,9 +514,7 @@ sub end_center { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '\end{center}'; - } elsif ($target eq 'latexsource') { - $currentstring = '\end{center}'; - } + } return $currentstring; } @@ -524,8 +526,6 @@ sub start_b { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\textbf{'; - } elsif ($target eq 'latexsource') { - $currentstring = '\textbf{'; } return $currentstring; } @@ -537,8 +537,6 @@ sub end_b { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '}'; - } elsif ($target eq 'latexsource') { - $currentstring = '}'; } return $currentstring; } @@ -551,8 +549,6 @@ sub start_strong { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\textbf{'; - } elsif ($target eq 'latexsource') { - $currentstring = '\textbf{'; } return $currentstring; } @@ -565,9 +561,7 @@ sub end_strong { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '}'; - } elsif ($target eq 'latexsource') { - $currentstring = '}'; - } + } return $currentstring; } @@ -843,9 +837,7 @@ sub start_cite { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; - } + } return $currentstring; } @@ -856,9 +848,7 @@ sub end_cite { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } @@ -870,9 +860,7 @@ sub start_i { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\textit{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\textit{'; - } + } return $currentstring; } @@ -883,8 +871,6 @@ sub end_i { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } @@ -897,9 +883,7 @@ sub start_address { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; - } + } return $currentstring; } @@ -910,8 +894,6 @@ sub end_address { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; } return $currentstring; } @@ -924,8 +906,6 @@ sub start_dfn { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; } return $currentstring; } @@ -937,9 +917,7 @@ sub end_dfn { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } @@ -951,9 +929,7 @@ sub start_tt { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\texttt{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\texttt{'; - } + } return $currentstring; } @@ -964,8 +940,6 @@ sub end_tt { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } @@ -978,9 +952,7 @@ sub start_kbd { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\texttt"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\texttt{"; - } + } return $currentstring; } @@ -991,9 +963,7 @@ sub end_kbd { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } @@ -1028,9 +998,7 @@ sub start_em { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\emph{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\emph{'; - } + } return $currentstring; } @@ -1041,9 +1009,7 @@ sub end_em { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; - } + } return $currentstring; } @@ -1055,8 +1021,6 @@ sub start_q { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\emph{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\emph{"; } return $currentstring; } @@ -1068,9 +1032,7 @@ sub end_q { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } @@ -1081,10 +1043,8 @@ sub start_p { if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '{\par '; - } elsif ($target eq 'latexsource') { - $currentstring .= '{\par '; - } + $currentstring .= '\par '; + } return $currentstring; } @@ -1093,10 +1053,6 @@ sub end_p { my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; - } elsif ($target eq 'tex') { - $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } @@ -1109,11 +1065,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; } @@ -1133,10 +1087,8 @@ sub start_big { if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\large{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '{\Large '; - } + $currentstring .= '{\large '; + } return $currentstring; } @@ -1147,8 +1099,6 @@ sub end_big { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } @@ -1161,9 +1111,7 @@ sub start_small { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '{\footnotesize '; - } elsif ($target eq 'latexsource') { - $currentstring .= '{\footnotesize '; - } + } return $currentstring; } @@ -1174,8 +1122,6 @@ sub end_small { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } @@ -1347,14 +1293,14 @@ sub start_hr { 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 +1311,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,8 +1322,7 @@ sub end_hr { my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; - } elsif ($target eq 'tex') { - } + } return $currentstring; } @@ -1402,50 +1347,43 @@ sub end_div { #-- tag 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); + $a=~s/([^\\])%/$1\\\%/g; + $currentstring .= '\ref{'.$a.'}'; } return $currentstring; } sub end_a { - my ($target,$token,$tagstack,$stackref) = @_; + my ($target,$token,$tagstack,$parstack,$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; } #--
  • tag sub start_li { - my ($target,$token,$tagstack,$stackref) = @_; + my ($target,$token,$tagstack,$parstack,$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; @@ -1676,10 +1614,14 @@ sub end_dt { #--
    tag 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 ($$tagstack[-2] eq 'dl') { + $currentstring = ' \item [] '; + } } return $currentstring; } @@ -1696,11 +1638,11 @@ sub end_dd { #-- tag 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 +1684,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; } @@ -1820,6 +1762,7 @@ sub end_table { } else { $currentstring .= $Apache::londefdef::table[-1]{'output'}; pop @Apache::londefdef::table; + undef @Apache::londefdef::table; } } return $currentstring; @@ -1894,20 +1837,18 @@ sub end_td { } else { if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { my $current_length=&recalc($1); - $current_length=~/(\d+)/; + $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; + } else { + $data=~s/^\s+(\S.*)/$1/; + $data=~s/(.*\S)\s+$/$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++) { + 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'}; @@ -2194,7 +2135,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') { @@ -2224,7 +2166,29 @@ sub start_frameset { $currentstring.=''. &Apache::lonmenu::registerurl(undef,$target).''; } - $currentstring .= $token->[4]; + my $onLoad=''; + foreach my $key (keys(%{$token->[2]})) { + if ($key =~ /^onload$/i) { + $onLoad.=$token->[2]->{$key}.';'; + delete($token->[2]->{$key}); + } + } + $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad; + my $onUnload=''; + foreach my $key (keys(%{$token->[2]})) { + if ($key =~ /^onunload$/i) { + $onUnload.=$token->[2]->{$key}.';'; + delete($token->[2]->{$key}); + } + } + $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents(). + ';'.$onUnload; + + $currentstring .= '<'.$token->[1]; + foreach (keys %{$token->[2]}) { + $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; + } + $currentstring.='>'; } return $currentstring; } @@ -2245,9 +2209,7 @@ sub start_pre { 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; } @@ -2258,7 +2220,7 @@ sub end_pre { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - $currentstring .= '\end{verbatim}}'; + $currentstring .= '\end{verbatim}'; } return $currentstring; } @@ -3102,6 +3064,26 @@ sub end_wbr { return $currentstring; } + +#-- tag +sub start_hideweboutput { + my ($target,$token) = @_; + if ($target eq 'web') { + &Apache::lonxml::startredirection(); + } + return ''; +} + +sub end_hideweboutput { + my ($target,$token) = @_; + my $currentstring = ''; + if ($target eq 'web') { + $currentstring = &Apache::lonxml::endredirection(); + } + return ''; +} + + sub image_replication { my $src = shift; if (not -e $src) { @@ -3123,7 +3105,7 @@ sub image_replication { sub recalc { my $argument = shift; if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';} - $argument=~/\s*(\d+)\s*(mm|cm|in|pc|pt)/; + $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/; my $value=$1; my $units=$2; if ($units eq 'cm') {