--- loncom/xml/londefdef.pm	2006/11/06 23:06:19	1.342
+++ loncom/xml/londefdef.pm	2006/12/18 11:07:43	1.346
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.342 2006/11/06 23:06:19 foxr Exp $
+# $Id: londefdef.pm,v 1.346 2006/12/18 11:07:43 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -48,6 +48,7 @@ use Apache::lonmenu();
 use Apache::lonmeta();
 use Apache::Constants qw(:common);
 use File::Basename;
+use LONCAPA();
 # use Data::Dumper;
 
 BEGIN {
@@ -1916,8 +1917,7 @@ sub start_table {
     if ($target eq 'web' || $target eq 'webgrade') {
 	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
-	my $aa = {};
-	push @Apache::londefdef::table, $aa; 
+	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) {
@@ -2859,10 +2859,6 @@ sub start_img {
 	    &Apache::lonxml::debug("$src exists");
 	    my ($height_param,$width_param)=
 		&image_size($origsrc,0.3,$parstack,$safeeval);
-	    my $destpath = $path;
-	    $destpath    =~ s/ /\_/g; # Spaces in path cause LaTex to vomit.
-	    my $destfile = $file;
-	    $destfile    =~ s/ /\_/g;
 	    my $size;
 	    if ($width_param)  { $size.='width='.$width_param.' mm,'; }
 	    if ($height_param) { $size.='height='.$height_param.' mm]'; }
@@ -2872,8 +2868,8 @@ sub start_img {
 	    
 	    $size='['.$size;
 	    $size=~s/,$/]/; 
-	    $currentstring .= '\graphicspath{{'.$destpath.'}}'
-		.'\includegraphics'.$size.'{'.$destfile.'} ';
+	    $currentstring .= '\graphicspath{{'.$path.'}}'
+		.'\includegraphics'.$size.'{'.$file.'} ';
 
 	    #    If there's an alignment specification we need to honor it here.
 	    #    For the horizontal alignments, we will also honor the
@@ -2891,6 +2887,9 @@ sub start_img {
 	    } elsif ($align eq "left")   { 
 		if ($latex_rendering eq "parpic") { 
 		    $currentstring = '\parpic[l]{'.$currentstring.'}';
+		} elsif ($latex_rendering eq "parbox") {
+		    $currentstring = '\begin{minipage}[l]{'.$width_param.'mm}'
+			.$currentstring.'\end{minipage}';
 		} else {    	                                 # wrapfig render
 		    $currentstring = '\begin{wrapfigure}{l}{'.$width_param.'mm}'
 			.'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
@@ -2898,6 +2897,9 @@ sub start_img {
 	    } elsif ($align eq "right")  {   
 		if ($latex_rendering eq "parpic") {
 		    $currentstring = '\parpic[r]{'.$currentstring.'}';
+		} elsif ($latex_rendering eq "parbox") {
+		    $currentstring =  '\begin{minipage}[r]{'.$width_param.'mm}'
+			.$currentstring.'\end{minipage}';
 		} else {	                                 # wrapfig rendering
 		    $currentstring = '\begin{wrapfigure}{r}{'.$width_param.'mm}'
 			.'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
@@ -4240,12 +4242,11 @@ sub get_eps_image {
 	&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);
+    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");
     if (! -e $src) {
-	# &Apache::lonnet::logthis("$src does not exist...repcopying");
 	&Apache::lonxml::debug("$src does not exist");
 	if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
 	    &Apache::lonxml::debug("Repcopy of $src failed (1)");
@@ -4257,7 +4258,6 @@ sub get_eps_image {
 	    &Apache::lonxml::debug("repcopy of $src ... $didrepcopy");
 	    if ( (not -e $src) ||
 		($didrepcopy ne 'ok')) {
-		# &Apache::lonnet::logthis("queuing $orig_src for dynamic eps gen");
 		&Apache::lonxml::debug("Failed to find or replicate $src");
 
 		#if replication failed try to produce eps file dynamically
@@ -4267,8 +4267,8 @@ sub get_eps_image {
 		my $newsrc=$orig_src;
 		$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
 		&Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
-		print FILE "$newsrc\n";
-		close FILE;
+		print FILE ("$newsrc\n");
+		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.
@@ -4276,10 +4276,9 @@ sub get_eps_image {
 		}
 
 	    }
+
 	}
     } else {
-# 	&Apache::lonnet::logthis("$src exists. queueing for copy.");
-# 	&Apache::lonnet::logthis("Got eps already.. queue for copy");
 	# If the postscript file has spaces in its name,
 	# LaTeX will gratuitiously vomit.  Therefore
 	# queue such files for copy with " " replaced by "_".
@@ -4287,13 +4286,14 @@ sub get_eps_image {
 	my $newsrc = $orig_src;
 	$newsrc    =~  s|(.*)/res/|/home/httpd/html/res/|;
 	open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
-#	&Apache::lonnet::logthis("Queueing $newsrc for copy");
-	print FILE "$newsrc\n";
+	print FILE "$src\n";
 	close FILE;
 	$src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
 	$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
     }
     my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
+    $path =~ s/ /\_/g;
+    $file =~ s/ /\_/g;
     &Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />");
     return ($path.'/',$file);
 }
@@ -4305,15 +4305,15 @@ sub eps_generation {
     print $temp_file "$src\n";
     my $newsrc = $src;
     $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
-    $newsrc=~s/\/home\/httpd\/html\/res//;
-    $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
-    $newsrc=~s/\/\.\//\//;
-    $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
-    if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
-	$newsrc=~s/\/home\/httpd\/lonUsers//;
-	$newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
+    $newsrc=~s{/home/httpd/html/res}{};
+    $newsrc=~s{/home/($LONCAPA::username_re)/public_html/}{/$1/};
+    $newsrc=~s{/\./}{/};
+    $newsrc=~s{/([^/]+)\.(ps|eps)}{/};
+    if ($newsrc=~m{/home/httpd/lonUsers/}) {
+	$newsrc=~s{/home/httpd/lonUsers}{};
+	$newsrc=~s{/($LONCAPA::domain_re)/./././}{/$1/};
     }
-    if ($newsrc=~/\/userfiles\//) {
+    if ($newsrc=~m{/userfiles/}) {
 	return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
     } else {
 	return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';