--- loncom/xml/londefdef.pm 2007/01/22 11:28:08 1.353 +++ loncom/xml/londefdef.pm 2007/02/01 10:49:27 1.354 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.353 2007/01/22 11:28:08 foxr Exp $ +# $Id: londefdef.pm,v 1.354 2007/02/01 10:49:27 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -2879,9 +2879,13 @@ sub start_img { $size=~s/,$/]/; $currentstring .= '\graphicspath{{'.$path.'}}' .'\includegraphics'.$size.'{'.$file.'} '; - $currentstring = &align_latex_image($align, $latex_rendering, - $currentstring, - $width_param, $height_param); + my $closure; + ($currentstring, $closure) = &align_latex_image($align, + $latex_rendering, + $currentstring, + $width_param, + $height_param); + $currentstring .= $closure; } else { &Apache::lonxml::debug("$src does not exist"); @@ -4360,11 +4364,15 @@ sub LATEX_length { # latex_rendering - rendering hint for latex. # image - The LaTeX needed to insert the image itsef. # width,height - dimensions of the image. +# Returns: +# The 1/2 wrapped image and the stuff required to close the +# wrappage. This allows e.g. randomlabel to insert more stuff +# into the closure. # sub align_latex_image { my ($align, $latex_rendering, $image, $width, $height) = @_; - my $currentstring; # The result. - + my $currentstring; # The 1/2 wrapped image. + my $closure; # The closure of the wrappage. # If there's an alignment specification we need to honor it here. # For the horizontal alignments, we will also honor the # value of the latex specfication. The default is parbox, @@ -4373,40 +4381,52 @@ sub align_latex_image { # Even though we set a default alignment value, the user # could have given us an illegal value. In that case we # just use the default alignment of bottom.. + $currentstring = "\n% figurewrapping \n"; if ($align eq "top") { - $currentstring = '\raisebox{-'.$height.'mm}{'.$image.'}'; + $currentstring .= '\raisebox{-'.$height.'mm}{'.$image; + $closure = '}'; } elsif (($align eq "center") || ($align eq "middle")) { # Being kind my $offset = $height/2; - $currentstring = '\raisebox{-'.$offset.'mm}{'.$image.'}'; + $currentstring .= '\raisebox{-'.$offset.'mm}{'.$image; + $closure = '}'; } elsif ($align eq "left") { if ($latex_rendering eq "parpic") { - $currentstring = '\parpic[l]{'.$image.'}'; + $currentstring .= '\parpic[l]{'.$image; + $closure = '}'; } elsif ($latex_rendering eq "parbox") { - $currentstring = '\begin{minipage}[l]{'.$width.'mm}' - .$image.'\end{minipage}'; + $currentstring .= '\begin{minipage}[l]{'.$width.'mm}' + .$image; + $closure = '\end{minipage}'; } elsif ($latex_rendering eq "wrapfigure" || $latex_rendering ne 'none') { # wrapfig render - $currentstring = + $currentstring .= '\begin{wrapfigure}{l}{'.$width.'mm}' - .'\scalebox{1.0}{'.$image.'}\end{wrapfigure}'; + .'\scalebox{1.0}{'.$image; + $closure = '}\end{wrapfigure}'; } } elsif ($align eq "right") { if ($latex_rendering eq "parpic") { - $currentstring = '\parpic[r]{'.$image.'}'; + $currentstring .= '\parpic[r]{'.$image; + $closure = '}'; } elsif ($latex_rendering eq "parbox") { - $currentstring = '\begin{minipage}[r]{'.$width.'mm}' - .$image.'\end{minipage}'; + $currentstring .= '\begin{minipage}[r]{'.$width.'mm}' + .$image; + $closure = '\end{minipage}'; } elsif ($latex_rendering eq "wrapfigure" || $latex_rendering ne 'none') { # wrapfig render - $currentstring = + $currentstring .= '\begin{wrapfigure}{r}{'.$width.'mm}' - .'\scalebox{1.0}{'.$image.'}\end{wrapfigure}'; + .'\scalebox{1.0}{'.$image; + $closure = '}\end{wrapfigure}'; } } else { # Bottom is also default. # $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}'; - $currentstring = $image; + $currentstring .= "{$image"; + $closure = '}'; } - return $currentstring; + $currentstring .= "\n% end wrappage\n"; + $closure = "\n% Begin closure\n".$closure."\n% End closure\n"; + return ($currentstring, $closure); } # is_inside_of $tagstack $tag