[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm
foxr
lon-capa-cvs@mail.lon-capa.org
Tue, 24 Oct 2006 10:37:58 -0000
foxr Tue Oct 24 06:37:58 2006 EDT
Modified files:
/loncom/interface lonprintout.pm
Log:
Think that this now does title substitution correctly in all cases..or
at least won't cause failures:
- Use format string chopping to do multiple substitutions since I'm not
smart enoug to get \G to work the way I want.
- deal with a nasty edge case.. where the substitution string was trimeed
in the middle of a LaTeX escaped character sequence (e.g. after \ in \%).
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.489 loncom/interface/lonprintout.pm:1.490
--- loncom/interface/lonprintout.pm:1.489 Mon Oct 23 06:40:09 2006
+++ loncom/interface/lonprintout.pm Tue Oct 24 06:37:58 2006
@@ -2,7 +2,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.489 2006/10/23 10:40:09 foxr Exp $
+# $Id: lonprintout.pm,v 1.490 2006/10/24 10:37:58 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -61,19 +61,38 @@
#
sub printf_style_subst {
my ($item, $format_string, $repl) = @_;
-
- while ($format_string =~m/%\d*\Q$item\E/) {
+ my $result = "";
+ while ($format_string =~ /(%)(\d*)\Q$item\E/g ) {
my $fmt = $1;
my $size = $2;
my $subst = $repl;
if ($size ne "") {
$subst = substr($subst, 0, $size);
+
+ # Here's a nice edge case.. supose the end of the
+ # substring is a \. In that case may have just
+ # chopped off a TeX escape... in that case, we append
+ # " " for the trailing character, and let the field
+ # spill over a bit (sigh).
+ # We don't just chop off the last character in order to deal
+ # with one last pathology, and that would be if substr had
+ # trimmed us to e.g. \\\
+
+
+ if ($subst =~ /\\$/) {
+ $subst .= " ";
+ }
}
- my $newpos = pos($format_string) + length($subst) - length($fmt);
- $format_string =~ s/\Q$fmt\E/$subst/;
- pos($format_string)=$newpos;
+ my $item_pos = pos($format_string);
+ $result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst;
+ $format_string = substr($format_string, pos($format_string));
}
- return $format_string;
+
+ # Put the residual format string into the result:
+
+ $result .= $format_string;
+
+ return $result;
}
@@ -133,7 +152,7 @@
# to \% else LaTeX will think they are comments and terminate
# the line.. which is bad!!!
- $format =~ s/%/\\%/g;
+
}
@@ -157,7 +176,7 @@
sub letters_to_num {
my ($letters) = @_;
my @letters = split('', uc($letters));
- my %substitution;
+ my %substitution;
my $digit = 0;
foreach my $letter ('A'..'J') {
$substitution{$letter} = $digit;