Index: doc/doc2tex.pl
===================================================================
--- doc/doc2tex.pl	(revision 9282f3e4f8e984faff4761ae454243093af7ee0c)
+++ doc/doc2tex.pl	(revision 460c1e191b2029d71d3c85f849b12944b8be0afa)
@@ -1,4 +1,4 @@
 #!/usr/local/bin/perl
-# $Id: doc2tex.pl,v 1.8 1999-07-17 14:49:10 obachman Exp $
+# $Id: doc2tex.pl,v 1.9 1999-07-19 12:06:13 obachman Exp $
 ###################################################################
 #  Computer Algebra System SINGULAR
@@ -319,4 +319,5 @@
 {
   s/^\@c\s*include\s+([^\s]+)\s/$1/;
+  s/\s*$//;
   unless (&Open(*INC, "<$_"))
   {
@@ -407,5 +408,5 @@
 sub HandleLib
 {
-  local($lib, $lib_name, $ltex_file, $l_ex, $l_fun);
+  local($lib, $lib_name, $ltex_file, $l_ex, $l_fun, $no_node, $section);
   my ($func);
 
@@ -426,5 +427,12 @@
   $l_fun = 1 if (($lib_fun || (/lib_fun/)) && !/no_fun/);
   $l_ex = 1 if (($lib_ex || /lib_ex/) && !/no_ex/ && $l_fun);
-
+  if (/(\w+)section/)
+  {
+    $section = $1. 'section';
+  }
+  else
+  {
+    $section = "subsection";
+  }
   $ltex_file = "$doc_subdir/$lib"."_lib";
   unless ($l_ex)
@@ -555,15 +563,22 @@
 	print LDOC " ".$procs[$i-1] if ($i > 0);
 	print LDOC ", " . $lib ."_lib\n";
-	print LDOC "\@subsection " . $procs[$i] . "\n";
+	print LDOC "\@$section " . $procs[$i] . "\n";
 	print LDOC "\@cindex ". $procs[$i] . "\n";
 
 	print LDOC "\@c ---content $procs[$i]---\n";
 	print LDOC "Procedure from library \@code{$lib.lib} (\@pxref{${lib}_lib}).\n\n";
-	print LDOC "\@table \@asis\n";
-	$table_is_open = 1;
-	# print help
-	$ref = OutInfo(\*LDOC, $help{$procs[$i]});
-	print LDOC "\@end table\n";
-	$table_is_open = 0;
+	if ($help{$procs[$i]} =~ /^\@/)
+	{
+	  print LDOC $help{$procs[$i]};
+	  $ref = '';
+	}
+	else
+	{
+	  print LDOC "\@table \@asis\n";
+	  $table_is_open = 1;
+	  # print help
+	  $ref = OutInfo(\*LDOC, $help{$procs[$i]});
+	  print LDOC "\@end table\n";
+	}
 	# print example 
 	if ($example = &CleanUpExample($lib, $example{$procs[$i]}))
@@ -600,4 +615,9 @@
   my ($FH, $info, $l_fun) = @_;
   print $FH "\@c ---content LibInfo---\n";
+    if ($info =~ /^\@/)
+  {
+    print $FH $info;
+    return;
+  }
   print $FH "\@table \@asis\n";
   $table_is_open = 1;
@@ -614,4 +634,9 @@
 {
   my ($FH, $info, $l_fun) = @_;
+  if ($info =~ /^\@/)
+  {
+    print $FH $info;
+    return;
+  }
   $info =~ s/^\s*//;
   $info =~ s/\s*$//;
@@ -654,7 +679,17 @@
     {
       $line = $1;
+      # break line if
       $text .= '@*' 
-	if ($line =~ /\w/ && $pline =~ /\w/ && 
-	    ((length($pline) < 60) || $line =~ /^\s*\w*\(.*?\)/));
+	if ($line =~ /\w/ && $pline =~ /\w/ # line and prev line are not empty
+	    && $line !~ /^\s*\@\*/  # line does not start with @*
+	    && $pline !~ /\@\*\s*/  # prev line does not end with @*
+	    &&
+	    ((length($pline) < 60  && # prev line is shorter than 60 chars
+	      $pline !~ /\@code{.*?}/ # and does not contain @code, @math
+	      && $pline !~ /\@math{.*?}/) 
+	     ||
+	     $line =~ /^\s*\w*\(.*?\)/ # $line starts with \w*(..)
+	     ||
+	     $pline =~ /^\s*\w*\(.*?\)[\s;:]*$/)); # prev line is only \w(..)
       $line =~ s/\s*$//;
       $text .= "$line\n";
@@ -667,8 +702,12 @@
   s/\s*$//g;
   s/ +/ /g;  # replace double whitespaces by one
+  s/(\w+\(.*?\))/\@code{$1}/g;
   s/\@\*\s*/\@\*/g;
   s/(\@[^\*])/\@$1/g; # escape @ signs, except @*
-  s/{/\@{/g;
+  s/{/\@{/g; # escape {}
   s/}/\@}/g;
+  # unprotect @@math@{@}, @code@{@}
+  s/\@\@math\@{(.*?)\@}/\@math{$1}/g;
+  s/\@\@code\@{(.*?)\@}/\@code{$1}/g;
 }
 
@@ -753,8 +792,4 @@
     # just print the text
     FormatInfoText(length($item) + 1);
-    # if functions are in text, then make it in code
-    s/(\w+\(.*?\))/\@code{$1}/g
-      if ($item =~ /usage/i || $item =~ /Return/i);
-
     print $FH "$_\n";
   }
@@ -787,5 +822,6 @@
   $refs =~ s/^\s*//;
   $refs =~ s/\s*$//;
-  my @refs = split (/[\s,]+/, $refs);
+  $refs =~ s/\n/,/g;
+  my @refs = split (/[,;\.]+/, $refs);
   my $ref;
 
@@ -795,5 +831,7 @@
   for $ref (@refs)
   {
-    print $FH ", \@ref{$ref}";
+    $ref =~ s/^\s*//;
+    $ref =~ s/\s*$//;
+    print $FH ", \@ref{$ref}"  if ($ref =~ /\w/);
   }
   print $FH "\n\@c ref\n";
