--- loncom/interface/lonprintout.pm 2006/10/16 10:32:46 1.486 +++ loncom/interface/lonprintout.pm 2006/10/23 10:40:09 1.489 @@ -2,7 +2,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.486 2006/10/16 10:32:46 foxr Exp $ +# $Id: lonprintout.pm,v 1.489 2006/10/23 10:40:09 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -62,24 +62,17 @@ my $resources_printed; sub printf_style_subst { my ($item, $format_string, $repl) = @_; - while ($format_string =~ /%\d*$item/) { - my $start = $-[0]; - my $end = $+[0]; - my $len = $end - $start; - - # see if we need to truncate: - + while ($format_string =~m/%\d*\Q$item\E/) { + my $fmt = $1; + my $size = $2; my $subst = $repl; - my $fmt = substr($format_string, $start, $len); - my $size = $fmt; - $size =~ s/%(\d*)$item/$1/; if ($size ne "") { $subst = substr($subst, 0, $size); } - $format_string =~ s/%(\d*)$item/$subst/; - + my $newpos = pos($format_string) + length($subst) - length($fmt); + $format_string =~ s/\Q$fmt\E/$subst/; + pos($format_string)=$newpos; } - return $format_string; } @@ -135,6 +128,12 @@ sub format_page_header { $format = &printf_style_subst("a", $format, $assignment); $format = &printf_style_subst("c", $format, $course); $format = &printf_style_subst("n", $format, $student); + + # If the user put %'s in the format string, they must be escaped + # to \% else LaTeX will think they are comments and terminate + # the line.. which is bad!!! + + $format =~ s/%/\\%/g; }