--- loncom/xml/londefdef.pm 2012/03/05 14:41:15 1.415.4.6.2.1 +++ loncom/xml/londefdef.pm 2010/08/11 10:57:36 1.420 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.415.4.6.2.1 2012/03/05 14:41:15 raeburn Exp $ +# $Id: londefdef.pm,v 1.420 2010/08/11 10:57:36 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -48,7 +48,6 @@ 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(); @@ -56,7 +55,7 @@ use LONCAPA(); 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','style','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','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput')); } @@ -456,31 +455,6 @@ sub insert_meta { '; } -#-- tag -sub start_style { - my ($target, $token, $tagstack, $parstack, $parser, $safeeval, $style) = @_; - my $currentstring = ''; - - if ($target eq 'tex') { - Apache::lonxml::startredirection(); - } else { - $currentstring = $token->[4]; - } - return $currentstring; -} - -sub end_style { - my ($target, $token, $tagstack, $parstack, $parser, $safeeval) = @_; - my $currentstring = ''; - - if ($target eq 'tex') { - Apache::lonxml::endredirection(); - } else { - $currentstring = $token->[2]; - } - return $currentstring; -} - # accessrule sub start_accessrule { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; @@ -615,7 +589,7 @@ sub start_body { sub edit_controls { my ($nochgview) = @_; my $result .= ' -
+
'; unless ($nochgview) { $result .= ' @@ -627,12 +601,7 @@ sub edit_controls { $result .= '
'; if (($env{'request.course.id'}) && ($env{'form.forceedit'})) { - my $viewtext = &mt('Course View'); - if (&Apache::loncommon::course_type() eq 'Community') { - $viewtext = &mt('Community View'); - } - $result .= (' ' x 3).''; + $result .= (' ' x 3).''; } $result .= '
@@ -2070,41 +2039,36 @@ sub start_table { } elsif ($target eq 'tex') { &disable_para(); # Can't have paras in a table. + + # New table code: + # Get the parameters that we can do something about: my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0); my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0); my $theme = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0); my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0); - my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0); + my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0); # The only thing that needs any figuring out is the width.. and then only if it is # a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm # my $table = new Apache::lontable(); - if ((defined $border) && ($border > 0)) { - # &Apache::lonnet::logthis("Turning on table borders: $border"); - $table->table_border(1); - if (!defined $cell_border) { - $table->cell_border(1); # Default for rules is all if rules not defined. - } - } + if ((defined $border) && ($border > 0)) { + &Apache::lonnet::logthis("Turning on table borderes: $border"); + $table->table_border(1); + if ($cell_border ne 'none') { + $table->cell_border(1); # html specs that border turns on both...unless rules='none'. + } + } + # Only all or nothing for cell borders for now: - if ((defined $cell_border)) { - if ($cell_border eq 'all') { - $table->cell_border(1); - } elsif ($cell_border eq 'rows') { - $table->cell_border(2); - } elsif ($cell_border eq 'cols') { - $table->cell_border(3); - } elsif($cell_border eq 'groups') { - $table->cell_border(4); - } else { - $table->cell_border(0); - } - } - if (defined $theme) { + if ((defined $cell_border) && ($cell_border ne 'none')) { + &Apache::lonnet::logthis("Turning on cell borders: $cell_border"); + $table->cell_border(1); + } + if (defined $theme) { $table->theme($theme); } if (defined $align) { @@ -2116,7 +2080,7 @@ sub start_table { if (!(defined $width)) { $width = '70%'; } - + # If a percentage, need to calculate what this means in terms of # page width: @@ -2131,6 +2095,88 @@ sub start_table { push(@Apache::londefdef::table, $table); $currentstring.=' \keephidden{NEW TABLE ENTRY}'; + #-------------------------------------------------------- + # Old table code here. + #-------------------------------------------------------- + + + if (0) { + push(@Apache::londefdef::table, {}); + $Apache::londefdef::table[-1]{'row_number'} = -1; + #maximum table's width (default coincides with text line length) + if ($#Apache::londefdef::table==0) { + $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm + $textwidth=~/(\d+\.?\d*)/; + $textwidth=0.85*$1; #accounts "internal" LaTeX space for table frame + } else { + if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) { + #the maximum width of nested table is determined by LATeX width of parent cell + $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]; + } else { + #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly + $textwidth=$Apache::londefdef::table[-2]{'width'}; + for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) { + $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i]; + } + } + } + + # width either comes forced from the TeXwidth or the width parameters. + # in either case it can be a percentage or absolute width. + # in the width case we ignore absolute width + my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); + if (!defined($TeXwidth)) { + my $htmlwidth = &Apache::lonxml::get_param('width',$parstack, + $safeeval,undef,1); + if ($htmlwidth =~ /%/) { + $TeXwidth = $htmlwidth; + } else { + $TeXwidth = $textwidth; + } + } + # if the width is specified as a % it is converted to an absolute width. + # otherwise.. just plugged right in the hash + + if ($TeXwidth=~/%/) { + $TeXwidth=~/(\d+)/; + $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100; + } else { + $Apache::londefdef::table[-1]{'width'}=$TeXwidth; + } + # In the end, however the table width cannot be wider than $textwidth... + + if ($Apache::londefdef::table[-1]{'width'} > $textwidth) { + $Apache::londefdef::table[-1]{'width'} = $textwidth; + } + #table's border + my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval); + my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0); + unless (defined $border) { $border = 0; } + if ($border) { + $Apache::londefdef::table[-1]{'hinc'} = '\hline '; + $Apache::londefdef::table[-1]{'vinc'} = '&'; + $Apache::londefdef::table[-1]{'vvinc'} = '|'; + } else { + $Apache::londefdef::table[-1]{'hinc'} = ''; + $Apache::londefdef::table[-1]{'vinc'} = '&'; + $Apache::londefdef::table[-1]{'vvinc'} = ''; + } + if ($#Apache::londefdef::table==0) { + # Note that \newline seems to destroy the alignment envs. + # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}'; + $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}'; + } + $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} '; + $Apache::londefdef::table[-1]{'TeXlen'}=[]; + $Apache::londefdef::table[-1]{'objectlen'}=[]; + $Apache::londefdef::table[-1]{'objectsignal'}=[]; + $Apache::londefdef::table[-1]{'maxlen'}=[]; + $Apache::londefdef::table[-1]{'minlen'}=[]; + $Apache::londefdef::table[-1]{'content'}=[]; + $Apache::londefdef::table[-1]{'align'}=[]; + $currentstring.=' \keephidden{NEW TABLE ENTRY}'; + } + } return $currentstring; } @@ -2143,6 +2189,8 @@ sub end_table { } elsif ($target eq 'tex') { + # New table code: + my $table = pop(@Apache::londefdef::table); my $t = $table->generate(); $currentstring = $t->generate_string(); @@ -2684,26 +2732,17 @@ sub tag_check { # sub cell_config_hash { - my ($align, $rowspan, $colspan, $width) = @_; - if ($rowspan ne '') { - $rowspan =~ s/^\s+|\s+$//g; - } - if ($colspan ne '') { - $colspan =~ s/^\s+|\s+$//g; - } + my ($align, $rowspan, $colspan) = @_; my %config; if ($align ne '') { $config{'halign'} = $align; } - if (($colspan =~ /^\d+$/) && ($colspan > 0)) { + if ($colspan ne "") { $config{'colspan'} = $colspan; } - if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) { + if ($rowspan ne '') { $config{'rowspan'} = $rowspan; } - if ($width ne '') { - $config{'width'} = $width; - } return \%config; } @@ -2715,11 +2754,11 @@ sub start_td_tex { # attributes, but empty of text. end_td_tex will # fetch the contents from the recursive parse and # fill the cell with them: - my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval); - my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval); - my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval); - my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval); - my $config = &cell_config_hash($align, $rowspan, $colspan, $width); + my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1); + my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1); + my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1); + + my $config = &cell_config_hash($align, $rowspan, $colspan); my $table = $Apache::londefdef::table[-1]; $table->add_cell('', $config); @@ -3130,24 +3169,13 @@ sub start_img { # Render unto browsers that which are the browser's... if ($target eq 'web' || $target eq 'webgrade') { - if ($env{'browser.imagesuppress'} ne 'on') { - my $enc = ('yes' eq - lc(&Apache::lonxml::get_param('encrypturl',$parstack, - $safeeval))); - $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}, - $enc); - } else { - my $alttag = &Apache::lonxml::get_param('alt',$parstack,$safeeval, - undef,1); - if (!$alttag) { - $alttag = &Apache::lonmeta::alttag($Apache::lonxml::pwd[-1], - $src); - } - $currentstring.='[IMAGE: '.$alttag.']'; - } - - # and render unto TeX that which is LaTeX + my $enc = ('yes' eq + lc(&Apache::lonxml::get_param('encrypturl',$parstack, + $safeeval))); + $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}, + $enc); + # and render unto TeX that which is LaTeX } elsif ($target eq 'tex') { # # The alignment will require some superstructure to be put around @@ -3248,7 +3276,7 @@ sub start_img { ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2); my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval); my $enc= &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval); - + $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl', ['no','yes'], $token, 2); if (($alt=~/\S/) && (lc($enc) eq 'yes')) { @@ -3262,10 +3290,10 @@ sub start_img { if ($token->[2]{'src'}=~/\$/) { $currentstring.=&mt('Variable image source'); } elsif ($token->[2]{'src'}=~/\S/) { - $currentstring .= ''.$alt.'[4]; - } else { - my $alttag= &Apache::lonxml::get_param('alt',$parstack, - $safeeval,undef,1); - unless ($alttag) { - $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1], - $code); - } - $currentstring='[APPLET: '.$alttag.']'; - } + $currentstring = &Apache::lonenc::encrypt_ref($token, + {'code'=>$code, + 'archive'=>$archive} + ); } elsif ($target eq 'tex') { - # Turn off some stuff we can't be inside thank you LaTeX - + # Turn off some stuff we can't be inside thank you LaTeX my $restart_sub = 0; my $restart_sup = 0; @@ -3413,16 +3433,7 @@ sub start_embed { &Apache::lonxml::extlink($src); my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - if ($env{'browser.embedsuppress'} ne 'on') { - $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}); - } else { - my $alttag=&Apache::lonxml::get_param - ('alt',$parstack,$safeeval,undef,1); - unless ($alttag) { - $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src); - } - $currentstring='[EMBED: '.$alttag.']'; - } + $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}); } elsif ($target eq 'tex') { } return $currentstring; @@ -3432,9 +3443,10 @@ sub end_embed { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; - } elsif ($target eq 'tex') { - } + $currentstring = $token->[2]; + } elsif ($target eq 'tex') { + # ./. + } return $currentstring; } @@ -3855,32 +3867,11 @@ sub end_col { #-- tag (end tag optional) sub start_colgroup { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; + my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; - } - if ($target eq 'tex') { - # TODO: Ensure this tag is in a table: - - # Fetch the attributes and build the hash for the - # call to define_colgroup. - - my $span = &Apache::lonxml::get_param('span', $parstack, $safeeval); - my $halign = &Apache::lonxml::get_param('halign', $parstack, $safeeval); - - my %colgroup_params; - if ($span ne '') { - $colgroup_params{'span'} = $span; - } - if ($halign ne '') { - $colgroup_params{'halign'} = $halign; - } - - my $table = $Apache::londefdef::table[-1]; - $table->define_colgroup(\%colgroup_params); - - } + } return $currentstring; } @@ -3893,12 +3884,16 @@ sub end_colgroup { return $currentstring; } + #-- tag (end tag required) sub start_del { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; + } elsif ($target eq 'tex') { + &disable_para(); + $currentstring .= '\st{'; } return $currentstring; } @@ -3907,7 +3902,10 @@ sub end_del { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; + $currentstring = $token->[2]; + } elsif ($target eq 'tex') { + &enable_para(); + $currentstring = '}'; } return $currentstring; } @@ -4366,12 +4364,6 @@ sub start_tbody { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; - } - if ($target eq 'tex') { - # TODO: Ensure this tag is within a table: - - my $table = $Apache::londefdef::table[-1]; - $table->start_body(); } return $currentstring; } @@ -4381,12 +4373,6 @@ sub end_tbody { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; - } - if($target eq 'tex') { - # TODO: Ensure this tag is within a table: - - my $table = $Apache::londefdef::table[-1]; - $table->end_body(); } return $currentstring; } @@ -4397,11 +4383,6 @@ sub start_tfoot { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; - } - if ($target eq 'tex') { - # TODO: ensure this is within a table tag. - my $table = $Apache::londefdef::table[-1]; - $table->start_foot(); } return $currentstring; } @@ -4411,11 +4392,6 @@ sub end_tfoot { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; - } - if ($target eq 'tex') { - # TODO: Ensure this is in side a table - my $table = $Apache::londefdef::table[-1]; - $table->end_foot(); } return $currentstring; } @@ -4426,11 +4402,6 @@ sub start_thead { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; - } - if ($target eq 'tex') { - # Assume we're in a table... TODO: Verify that and ignore tag if not. - my $table = $Apache::londefdef::table[-1]; - $table->start_head(); } return $currentstring; } @@ -4440,12 +4411,6 @@ sub end_thead { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; - } - if ($target eq 'tex') { - # TODO: Verify we are in a table and ignore tag if not. - - my $table = $Apache::londefdef::table[-1]; - $table->end_head(); } return $currentstring; } @@ -4876,6 +4841,7 @@ sub latex_header { "\\usepackage{xcolor}\n". '\usepackage{calc}'. '\usepackage{amsmath}'. + '\usepackage{soul}', '\usepackage{amssymb}'. '\usepackage{amsfonts}'. '\usepackage{amsthm}'.