Ilya Zakharevich on Wed, 18 Oct 2000 17:57:01 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PATCH] better tex2mail


This patch

  a) adds a debugging subroutine (chunk 1);
  b) fixes the problem with interaction of colors and the
     prettyprinter (chunk 2);
  c) makes the output more compact in the case when there are long
     "unbreakable" "blocks" (chunk 3).

It is not absolutely clear that the change "c" is beneficial.  Please
judge by yourself.  Do this with and without the patch:

  \o3
  default(seriesprecision, 5)
  sin(x+y+z)

with the CVS version...  I will think whether one can somehow combine
advantages of both types of output...

Enjoy,
Ilya

--- ./misc/tex2mail~	Fri Sep 22 16:25:46 2000
+++ ./misc/tex2mail	Wed Oct 18 17:46:28 2000
@@ -41,6 +41,21 @@ $multitokenpattern="$usualtokenclass+|$a
 # height=0 denotes expandable string
 # Baseline=3 means the 4th row is the baseline
 
+sub debug_print_record {
+  local($h,$l,$b,$xs,$s) = split /,/, shift, 5;
+  local(@arr) = split /\n/, $s;
+  print STDERR "len=$l, h=$h, b=$b, exp_sp=$xs.\n";
+  local($i) = 0;
+  for (@arr) {
+    local($lead) = ($i++ == $b) ? 'b [' : '  [';
+    print STDERR "$lead$_]\n";
+  }
+  while ($i < $h) {		# Empty lines may skipped
+    local($lead) = ($i++ == $b) ? 'b' : '';
+    print STDERR "$lead\n";
+  }
+}
+
 # Takes length and a record, returns 2 records
 
 sub cut {
@@ -96,6 +111,10 @@ sub join {
   @str="" x $h;
   @str[$b-$b1 .. $b-$b1+$h1-1]=split(/\n/,$str1,$h1);
   @str2[0..$h2-1]=split(/\n/,$str2,$h2);
+  unless (length($str2[$b2])) {
+    $str2[$b2] = ' ' x $l2;	# Needed for length=0 "color" strings
+                                # in the baseline.
+  }
   if ($debug & $debug_record && (grep(/\n/,@str) || grep(/\n/,@str2))) {
     warn "\\n found in \@str or \@str2";
     warn "`$str1', need $h1 rows\n";
@@ -275,8 +297,21 @@ sub prepare_cut {
     }
     return $rec if $good;
   }
+  # If the added record is too long, there is no sense in cutting
+  # things we have already, since we will cut the added record anyway...
+  local($forcedcut);
+  if ($lenadd > $linelength && $lenrem) {
+      @p= &cut($lenrem,$rec);
+      warn "After forced cut: @p\n" if $debug & $debug_record;
+      push(@out,$p[0]);
+      $curlength+=$lenrem;
+      &print();
+      $rec=$p[1];
+      ($lenadd,$str)=(split(/,/,$rec,5))[1,4];
+      $lenrem=$linelength;
+  }
   # Now try to find a cut before the added record
-  if ($#out>=0) {
+  if ($#out>=0 && !$forcedcut) {
     for (0..$#out) {
       ($h,$str)=(split(/,/,$out[$#out-$_],5))[0,4];
       if ($h<2 && ($ind=rindex($str," "))>-1 && ($ind>0 || $_<$#out)) {
@@ -2173,3 +2228,7 @@ __END__
 	  things which cannot be broken between lines.
 # Sep 00: Add support for new macro for strings with screen escapes sequences:
 	  \LITERALnoLENGTH{escapeseq}.
+# Oct 00: \LITERALnoLENGTH can have a chance to work in the baseline only;
+	   in fact the previous version did not work even there...
+	  If the added record is longer than line length, do not try to
+	  break the line before it...