--- loncom/xml/londefdef.pm 2005/07/07 10:09:50 1.277 +++ loncom/xml/londefdef.pm 2005/08/11 22:04:09 1.285 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.277 2005/07/07 10:09:50 foxr Exp $ +# $Id: londefdef.pm,v 1.285 2005/08/11 22:04:09 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -47,7 +47,7 @@ use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); use Apache::Constants qw(:common); - +use File::Basename; BEGIN { @@ -535,23 +535,25 @@ sub start_body { $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents(). ';'.$onUnload; - if ($env{'request.state'} ne 'construct') { - $currentstring .= '<'.$token->[1]; - } + $currentstring .= '<'.$token->[1]; foreach (keys %{$token->[2]}) { $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; } - if ($env{'request.state'} ne 'construct') { - $currentstring.='>'; + $currentstring.='>'; + &Apache::lontexconvert::jsMath_reset(); + if ($env{'environment.texengine'} eq 'jsMath') { + $currentstring.=&Apache::lontexconvert::jsMath_header(); } if ($env{'request.state'} ne 'published') { - my $remote=($env{'environment.remote'} ne 'off'); - $currentstring=&Apache::loncommon::bodytag(undef,undef, - $currentstring,$remote); + if ($env{'environment.remote'} eq 'off') { + $currentstring.= + &Apache::lonmenu::constspaceform(). + &Apache::lonmenu::menubuttons(1,'web',1); + } $currentstring.=(< - - +
+ +
EDITBUTTON } else { $currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1); @@ -565,7 +567,7 @@ EDITBUTTON sub end_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off unclosed

+ my $currentstring = &end_p(); # Close off unclosed

if ($target eq 'web') { $currentstring .= &Apache::lonxml::xmlend($target,$parser); } elsif ($target eq 'tex') { @@ -577,7 +579,7 @@ sub end_body { #--

tag (end tag required) sub start_center { my ($target,$token) = @_; - my $currentstring = &end_p; # Close off any prior para. + my $currentstring = &end_p(); # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -598,13 +600,15 @@ sub end_center { } #-- tag (end tag required) +# NOTE: In TeX mode disables internal

sub start_b { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\textbf{'; + &disable_para(); + $currentstring .= '\textbf{'; } return $currentstring; } @@ -615,18 +619,21 @@ sub end_b { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = '}'; + &enable_para(); + $currentstring = '}'; } return $currentstring; } #-- tag (end tag required) +# NOTE: in TeX mode disables internal

sub start_strong { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { + &disable_para(); $currentstring = '\textbf{'; } return $currentstring; @@ -638,6 +645,7 @@ sub end_strong { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { + &enable_para(); $currentstring = '}'; } return $currentstring; @@ -646,7 +654,7 @@ sub end_strong { #--

tag (end tag required) sub start_h1 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off any prior para. + my $currentstring = &end_p(); # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -695,7 +703,7 @@ sub end_h1 { #--

tag sub start_h2 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off any prior para. + my $currentstring = &end_p(); # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -738,7 +746,7 @@ sub end_h2 { #--

tag sub start_h3 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off any prior para. + my $currentstring = &end_p(); # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -781,7 +789,7 @@ sub end_h3 { #--

tag sub start_h4 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off any prior para. + my $currentstring = &end_p(); # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -824,7 +832,7 @@ sub end_h4 { #--

tag sub start_h5 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off any prior paras. + my $currentstring = &end_p(); # Close off any prior paras. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -867,7 +875,7 @@ sub end_h5 { #--
tag sub start_h6 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off any prior paras. + my $currentstring = &end_p(); # Close off any prior paras. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1125,15 +1133,34 @@ sub end_q { my $closing_string = ''; # String required to close

+# Some tags are

fragile meaning that

inside of them +# does not work within TeX mode. This is managed via the +# counter below: +# + + my $para_disabled = 0; + +sub disable_para { + $para_disabled++; +} +sub enable_para { + $para_disabled--; +} + + #--

tag (end tag optional) #optional attribute - align="center|left|right" sub start_p { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # close off prior para if in progress. + my $currentstring = ''; if ($target eq 'web') { + $currentstring .= &end_p(); # close off prior para if in progress. $currentstring .= $token->[4]; - $closing_string = '

'; # Not sure this is correct. - } elsif ($target eq 'tex') { + if (! ($currentstring =~ /\//)) { + $closing_string = '

'; # Deal correctly with

e.g. + } + } elsif ($target eq 'tex' && !$para_disabled) { + $currentstring .= &end_p(); # close off prior para if in progress. my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); if ($align eq 'center') { $currentstring .='\begin{center}\par'; @@ -1146,18 +1173,8 @@ sub start_p { $closing_string = '}\hfill}'; } else { $currentstring.='\par '; - $closing_string = '\strut\\\\\strut'; + $closing_string = '\strut\\\\\strut '; } - my $signal=1;#

does not work inside ... - foreach my $tag (@$tagstack) { - if (lc($tag) eq 'b') { - $signal=0; - } - } - if (!$signal) { - $currentstring = &end_p; # Just close the prior? Not sure this is correct - $closing_string = ''; # Probably correct? - } } return $currentstring; @@ -1166,9 +1183,16 @@ sub start_p { # End paragraph processing just requires that we output the # closing string that was saved and blank it. sub end_p { - my $current_string = $closing_string; - $closing_string = ''; # Not in a para anymore. - return $current_string; + # Note only 'tex' mode uses disable_para and enable_para + # so we don't need to know the target in the check below: + + if (!$para_disabled) { + my $current_string = $closing_string; + $closing_string = ''; # Not in a para anymore. + return $current_string; + } else { + return ''; + } } } @@ -1417,7 +1441,7 @@ sub end_sup { #--


tag (end tag forbidden) sub start_hr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # End enclosing para. + my $currentstring = &end_p(); # End enclosing para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1455,12 +1479,44 @@ sub end_hr { } #--
tag (end tag required) +{ + +# Since div can be nested, the stack below is used +# in 'tex' mode to store the ending strings +# for the div stack. + + my @div_end_stack; + sub start_div { - my ($target,$token) = @_; - my $currentstring = &end_p; # Close enclosing para. + my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_; + my $currentstring = &end_p(); # Close enclosing para. if ($target eq 'web') { $currentstring .= $token->[4]; } + if ($target eq 'tex') { + # 4 possible alignments: left, right, center, and -missing-. + + my $endstring = ''; + + my $align = lc(&Apache::lonxml::get_param('align', $parstack, + $safeeval, undef, 1)); + if ($align eq 'center') { + $currentstring .= '\begin{center}'; + $endstring = '\end{center}'; + } + elsif ($align eq 'right') { + $currentstring .= '\begin{flushright}'; + $endstring .= '\end{flushright}'; + } elsif ($align eq 'left') { + $currentstring .= '\begin{flushleft}'; + $endstring = '\end{flushleft}'; + } else { + + } + $currentstring .= "\n"; # For human readability. + $endstring = "\n$endstring\n"; # For human readability + push(@div_end_stack, $endstring); + } return $currentstring; } @@ -1469,9 +1525,14 @@ sub end_div { my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; - } + } + if ($target eq 'tex') { + my $endstring = pop @div_end_stack; + $currentstring .= $endstring; + } return $currentstring; } +} #-- tag (end tag required) sub start_a { @@ -1539,7 +1600,7 @@ sub start_li { sub end_li { my ($target,$token) = @_; - my $currentstring = &end_p; # In case there's a

in the

  • + my $currentstring = &end_p(); # In case there's a

    in the

  • if ($target eq 'web') { $currentstring .= $token->[2]; } @@ -1575,7 +1636,7 @@ sub end_u { #--
      tag (end tag required) sub start_ul { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off enclosing list. + my $currentstring = &end_p(); # Close off enclosing list. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1642,7 +1703,7 @@ sub end_menu { #-- tag (end tag required) sub start_dir { my ($target,$token) = @_; - my $currentstring = &end_p; # In case there's a

      prior to the list. + my $currentstring = &end_p(); # In case there's a

      prior to the list. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1665,7 +1726,7 @@ sub end_dir { #--

        tag (end tag required) sub start_ol { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # In case there's a

        prior to the list. + my $currentstring = &end_p(); # In case there's a

        prior to the list. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1719,7 +1780,7 @@ sub end_ol { #--

        tag (end tag required) sub start_dl { my ($target,$token) = @_; - my $currentstring = &end_p; # In case there's a

        unclosed prior to the list. + my $currentstring = &end_p(); # In case there's a

        unclosed prior to the list. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1835,7 +1896,7 @@ sub end_dd { sub start_table { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $textwidth = ''; - my $currentstring = &end_p; + my $currentstring = &end_p(); if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1891,7 +1952,9 @@ sub start_table { $Apache::londefdef::table[-1]{'vvinc'} = ''; } if ($#Apache::londefdef::table==0) { - $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}'; + # 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'}=[]; @@ -2114,7 +2177,9 @@ sub end_table { } $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' '; } - $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut '; + # Note that \newline destroys alignment env's produced by e.g.

        + # $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut '; + $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut '; if ($#Apache::londefdef::table > 0) { my $inmemory = $Apache::londefdef::table[-1]{'output'}; pop @Apache::londefdef::table; @@ -2155,7 +2220,7 @@ sub start_tr { sub end_tr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close any pending

        in the row. + my $currentstring = &end_p(); # Close any pending

        in the row. if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { @@ -2432,7 +2497,7 @@ sub end_th_tex { sub end_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close any open

        in the row. + my $currentstring = &end_p(); # Close any open

        in the row. if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { @@ -2882,7 +2947,7 @@ sub end_xmp { #--

         (end tag required)
         sub start_pre {
             my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
        -    my $currentstring = &end_p;	# close off pending 

        + my $currentstring = &end_p(); # close off pending

        if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -2945,7 +3010,7 @@ sub end_externallink { #-- sub start_blankspace { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # closes off any unclosed

        + my $currentstring = &end_p(); # closes off any unclosed

        if ($target eq 'tex') { my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1); $currentstring .= '\vskip '.$howmuch.' '; @@ -3098,7 +3163,7 @@ sub end_blink { #--

        tag (end tag required) sub start_blockquote { my ($target,$token) = @_; - my $currentstring = &end_p; # Close any unclosed

        + my $currentstring = &end_p(); # Close any unclosed

        if ($target eq 'web') { $currentstring .= $token->[4]; } @@ -3421,7 +3486,7 @@ sub end_marquee { #-- tag (end tag required) sub start_multicol { my ($target,$token) = @_; - my $currentstring = &end_p; # Close any pending

        + my $currentstring = &end_p(); # Close any pending

        if ($target eq 'web') { $currentstring .= $token->[4]; } @@ -3619,7 +3684,7 @@ sub end_server { #-- tag (end tag forbidden) sub start_spacer { my ($target,$token) = @_; - my $currentstring = &end_p; # Close off any open

        tag. + my $currentstring = &end_p(); # Close off any open

        tag. if ($target eq 'web') { $currentstring .= $token->[4]; } @@ -3900,7 +3965,15 @@ sub image_height { sub get_eps_image { my ($src)=@_; my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src); + + # In order to prevent the substitution of the alt text, we need to + # be sure the orig_src file is on system now so: + + if (! -e $orig_src) { + &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal. + } &Apache::lonxml::debug("get_eps_image: Original image: $orig_src"); + my ($spath, $sname, $sext) = fileparse($src, qr/\.(gif|png|jpg|jpeg)/i); $src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i; $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &Apache::lonxml::debug("Filelocation gives: $src"); @@ -3929,6 +4002,9 @@ sub get_eps_image { close FILE; $src=~s|/home/httpd/html/res|/home/httpd/prtspool|; $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; + if ($sext ne "") { # Put the ext. back in to uniquify. + $src =~ s/\.eps$/$sext.eps/; + } } } }