Ilya Zakharevich on Tue, 9 Nov 1999 00:09:14 -0500 (EST)


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

[PATCH 2.0.17] gphelp -to_pod


Conversion of .tex to .pod was almost completely broken.

This patch fixes this, and brings POD generation to "almost perfect" stage.

I did not fix any defects in .tex files.  [One I know is in Ch2
Generalities:

The special variable\idx{variable (special)} names known to GP are

- this should be \sidx].

Ilya

--- ./config/doc_Makefile.SH.orig	Fri Apr 16 11:45:10 1999
+++ ./config/doc_Makefile.SH	Mon Nov  8 23:27:04 1999
@@ -56,11 +56,16 @@ veryclean: clean
 	rm -f paricfg.tex gp.man
 
 .tex.pod:
-	perl $doc_dir/gphelp -to_pod \$*.tex > tmp_pod && mv tmp_pod \$*.pod
+	perl gphelp -to_pod \$*.tex > tmp_pod && mv tmp_pod \$*.pod
 
 .ipf.inf:
 	ipfc /INF \$*.ipf
 
-pari.ipf:  refcard.pod tutorial.pod usersch1.pod usersch1.pod usersch2.pod usersch3.pod usersch4.pod usersch5.pod appa.pod appb.pod appc.pod appd.pod
-	pod2ipf --title="PARI/GP Manual" --by-files --section-name="Getting started" --file=refcard.pod --file=tutorial.pod --section-name="User guide" --file=usersch1.pod --file=usersch1.pod --file=usersch2.pod --file=usersch3.pod --file=usersch4.pod --file=usersch5.pod --section-name=Appendices --file=appa.pod --file=appb.pod --file=appc.pod --file=appd.pod > tmp_ipf && mv tmp_ipf pari.ipf
+# This is for testing:
+
+.pod.ipf:
+	pod2ipf \$*.pod > tmp_ipf && mv tmp_ipf \$*.ipf
+
+pari.ipf:  refcard.pod tutorial.pod usersch1.pod usersch1.pod usersch2.pod usersch3.pod usersch4.pod usersch5.pod appa.pod appb.pod appc.pod
+	pod2ipf --title="PARI/GP Manual" --by-files --section-name="Getting started" --file=refcard.pod --file=tutorial.pod --section-name="User guide" --file=usersch1.pod --file=usersch1.pod --file=usersch2.pod --file=usersch3.pod --file=usersch4.pod --file=usersch5.pod --section-name=Appendices --file=appa.pod --file=appb.pod --file=appc.pod > tmp_ipf && mv tmp_ipf pari.ipf
 EOT
--- ./doc/gphelp.in.orig	Thu Sep 16 09:49:02 1999
+++ ./doc/gphelp.in	Mon Nov  8 23:28:26 1999
@@ -33,6 +35,7 @@ $xdvi = $ENV{GPXDVI} || "xdvi";
 $gzip = "gzip";
 $zcat = "$gzip -dc";
 
+$refcard = (@ARGV and $ARGV[-1] =~ /refcard/i);
 &to_pod() if @ARGV == 2 && $ARGV[0] eq '-to_pod'; 
 
 &options(); &init();
@@ -442,7 +445,7 @@ sub detex
 # We use the special char @ to transmit special sequences
 sub inittr {
   @ou = qw( dollar nbrk startbold endbold startcode endcode 
-	    startpodcode endpodcode
+	    startpodcode endpodcode startlink endlink
 	    startbcode endbcode startbi endbi startit endit
 	    startword endword startlword endlword pm empty gt lt podleader
 	  );
@@ -455,6 +458,8 @@ sub inittr {
 	  startbold => 'B<',
 	  endbold => '>',
 	  startcode => 'C<',
+	  startlink => 'L<',
+	  endlink => '>',
 	  endcode => '>',
 	  startpodcode => 'C<',
 	  endpodcode => '>',
@@ -476,10 +481,34 @@ sub inittr {
 	);
 }
 
+sub strip_code {
+  my $in = shift;
+  $in =~ s/\Q$tr{startcode}\E(.*?)\Q$tr{endcode}/$1/go;
+  $in;
+}
+
+sub strip_kbd {
+  my $in = shift;
+  $in =~ s/\\kbd\{((?:[^{}]|\{[^{}]*\})*)\}/$1/g;
+  $in =~ s/\$((?:[^{}]|\{[^{}]*\})*)\$/$1/g;
+  $in =~ s/~/ /g;
+  $in;
+}
+
 sub presubst
 {
   chop unless $to_pod;
+  s/([^\\])\\\{/$1`lBrAcE'/g;
+  s/([^\\])\\\}/$1`rBrAcE'/g;
+  s/\A\\q?quad\s+/$tr{nbrk}$tr{nbrk}/;
+  s|\\wwwsite|http://hasse.mathematik.tu-muenchen.de/ntsw/pari/|g;
+  s/^\\def\\.*\{\n.*\n\}//gm;
+  s/\\def\\.*//g;
+  s/(\{[\w\s]+)\{\}([\s\w]+\})/$1$2/g;	# {rnf{}llgram}
+
+
   s/\\\\(?=[a-zA-Z])/\\bs /g;
+  s/\\b{}\\b{}/\\bs\\bs /g;
   s/\\\\/\\bs/g;
   s/(\'\'|\`\`)/"/g unless $to_pod; # "
   # asymptotic or equivalent (~)
@@ -488,6 +517,8 @@ sub presubst
   s/(^|[^\\])~/$1$tr{nbrk}/g;
   s/\\(simeq|sim|approx|equiv)(?![a-zA-Z])/ ~ /g;
   s/(^|[^\\])%.*/$1/g;		# comments
+  # We do not strip %\n, thus:
+  s/\\kbd{\n\s*/\\kbd{/g;
   s/\$\\bf(\b|(?=[\d_]))\s*([^\$]+)\$/\$$tr{startbcode}$1$tr{endbcode}\$/g;
   s/\$/$tr{dollar}/g;		# math mode
   s/\t/ /g; s/\\,//g; s/\\[ ;]/ /g;# various spaces
@@ -495,7 +526,8 @@ sub presubst
   s/\\~/~/g;
   s/\\tilde/~/g;
   s/\\\///g;			# italic correction
-  s/([^\\])&+/$1/g;		# tab marks
+  s/^&+//g;			# tab marks
+  s/([^\\])&+/$1 /g;		# tab marks
   s/\\TeX\{\}/TeX/g;
   s/\\TeX(\W)/TeX$1/g;
   s/ *\\circ\b */ o /g;
@@ -539,13 +571,10 @@ sub presubst
   s/\\pm(?![a-zA-Z])/$tr{pm}/g;
   s/ *\\mid(?![a-zA-Z]) */ | /g;
 
-  s/^\\def\\.*\{\n.*\n\}//gm;
-  s/\\def\\.*//;
-  s/\\idxtyp\{[^\}]*\}//g;
+  s/\\idxtyp\{([^{}]*)\}/\\sidx{t_$1}/g;
   s/\\ref\{[^\}]*\}/$tr{startbold}??$tr{endbold}/g unless $to_pod;
   s/\\secref\{[^\}]*\}/Section ($tr{startbold}??$tr{endbold})/g unless $to_pod;
   s/\\label\{[^\}]*\}//g unless $to_pod;
-  s/\\(text|hbox)//g;
   s/\\rightarrow(?![a-zA-Z])/C<--E<gt>>/g;
   s/\\longleftrightarrow(?![a-zA-Z])/C<E<lt>-----E<gt>>/g;
 
@@ -553,19 +582,26 @@ sub presubst
   s/\\vfill *\\eject//g;
   s/\\(q|quad)(?![a-zA-Z])/  /g; 
   s/\\qquad(?![a-zA-Z])/    /g; 
-  s/\\centerline\b/    /g;
+  s/\\centerline\s*\{\s*(?:\\tt\b\s*)?(.*(\n[ \t].*)*)\}(?=\s*$)/    $1/g;
+  s/\\centerline\s*\{\s*(?:\\tt\b\s*)?((?:[^{}]|\{[^{}]*\})*)\}/    $1/g;
   s/\\big\b//g;
 
   s/\\settabs.*//; 
-  s/\\\+//g; 
+#  s/\\\+(.*)\\cr[ \t]*$/ strip_kbd($1) /ges;
+#  s/\\\+(.*)/ strip_kbd($1) /ge;
+  s/^\\\+/$tr{nbrk}/gm;
+  s/\\\+//g;
+#  s/\\\+/$tr{nbrk}/g;
   s/\\cr(?![a-zA-Z])//g;
+  s/\\B(?![a-zA-Z])/\\kbd{BIL}/g;
+  s/\\fun\s*\{([^{}]*)\}\s*\{((?:[^{}]|\{[^{}]*\})*)\}\s*\{([^{}]*)\}/\\kbd{$1 \\key{$2}($3)}\\sidx{$2}/g;
 
   s/ *\\leq?(?![a-zA-Z]) *([^ ])/<=$1/g;
   s/ *\\geq?(?![a-zA-Z]) *([^ ])/>=$1/g;
   s/ *([=><]) */ $1 /g;
   s/ *<  *([=<]) */ <$1 /g;
   s/ *>  *([=>]) */ >$1 /g;
-  s/ *=  *= */ == /g;
+  s/ *([*+-\/^&=|:]) += */ $1= /g;
 
   s/\\(vers|PARIversion)(?![a-zA-Z])/$tr{startbold}$version$tr{endbold}/;
   s/\\([QRCFZNapdf])(?![a-zA-Z])/$tr{startbi}$1$tr{endbi}$2/g;
@@ -585,12 +621,24 @@ sub presubst
   s/\\tet\{([^\}]*)\}/\\sidx{$1}$tr{startcode}$1$tr{endcode}/g;
   s/\\tec\{\s*([^{}]*)\}\{\s*([^{}]*)\}/\\sidx{$1}$1$tr{startcode}$2$tr{endcode}/g;
   s/\\kbd\{((?:[^{}]|\{[^{}]*\})*)\}/$tr{startcode}$1$tr{endcode}/g;
-  s/\\key\{([^\}]*)\}/$tr{startbold}$1$tr{endbold}/g;
+
+  s/\\key\{([^\}]*)\}/$tr{startbold}$1$tr{endbold}/g unless $refcard;
+
+#  s/\\(?:key|li)\s*{(.*)}\s*{(.+)}[ \t]*\n/\n\n=item C<$2>\n\n$1\n\n/msg;
+#  s/\\(?:key|li)\s*{(.*)}\s*{}[ \t]*\n/\n\n=back\n\n$1\n\n=over\n\n/mgs;
+#  s/\\(key|var)(?![a-zA-Z])\s*{(\w+)}/C<$2>/mg;
+  if ($refcard) {
+    s/\\(?:key|li)\{((?:[^{}]+(?=[{}])|\{[^{}]+\})*)\}\s*\{\}[ \t]*\n/\n\n=back\n\n$1\n\n=over\n\n/g if $refcard;
+    s/\\(?:key|li)\{((?:[^{}]+(?=[{}])|\{[^{}]+\})*)\}\s*\{(([^{}]+(?=[{}])|\{[^{}]+\})*)\}/\n=item C<$2>\n\n$1\n/g if $refcard;
+  }
+
   s/\\var\{([^\}]*)\}/$tr{startit}$1$tr{endit}/g;
   s/\\fl(?![a-zA-Z])/$tr{startit}flag$tr{endit}/g;
   s/\\b{([^}]*)}/$tr{startcode}\\$1$tr{endcode}/g;
   s/\\sidx\{[^\}]*\}//g unless $to_pod;
   s/\\[a-zA-Z]*idx\{([^\}]*)\}/$1/g unless $to_pod;
+  s/\\(?:text|hbox)\s*\{ *(?:\\it\b\s*)?(([^{}]+(?=[{}])|\{[^{}]+\})*)\}/$1/g;
+  s/\\(text|hbox)//g;
   s/\{ *\\(it|sl) *(([^{}]+(?=[{}])|\{[^{}]+\})*)\}/$tr{startit}$2$tr{endit}/g;
   s/\{ *\\bf *(([^{}]+(?=[{}])|\{[^{}]+\})*)\}/$tr{startbold}$1$tr{endbold}/g;
   s/\{ *\\tt *(([^{}]+(?=[{}])|\{[^{}]+\})*)\}/$tr{startpodcode}$1$tr{endpodcode}/g;
@@ -599,6 +647,18 @@ sub presubst
   s/\\(backslash|bs)\{(\w)\}/\\$2/g;
   s/\\(backslash|bs)(?![a-zA-Z]) */\\/g;
 
+  # Last resort:
+  s/\\kbd\{(.*?)\}/$tr{startcode}$1$tr{endcode}/g;
+  s/^([ \t]{3,})\Q$tr{startcode}\E(.*)\Q$tr{endcode}\E/$1$2/gmo if $to_pod;
+  # Last resort:
+  s/^([ \t]{3,})\Q$tr{startcode}\E(.*?)\Q$tr{endcode}\E/$1$2/gmso if $to_pod;
+  # Remove leading spaces unless have embedded wrapped code:
+  s/^[ \t]+//gm if $to_pod and /^\S/ and not /^[ \t]*\n[ \t]/m;
+  s/`lBrAcE'/\\{/g;
+  s/`rBrAcE'/\\}/g;
+
+  s{\Q$tr{startcode}\E(?=(ftp|http)://)}{$tr{startlink}}go if $to_pod;
+
   return if $to_pod;
 
   $in_prog = 0 if (s/\\eprog/$tr{endbold}/g);
@@ -618,7 +678,10 @@ sub wrap_code {
 #  } else {
     $in =~ s/^(.)/  $1/mg;
 #  }
-  $in
+  $in =~ s/\s*\Z//;
+  $in =~ s/\\kbd\{((?:[^{}]|\{[^{}]*\})*)\}/$1/g if $to_pod;
+  $in =~ s/\$([^\$\n]*)\$/$1/g if $to_pod;
+  "\n\n$in\n\n";
 }
 
 sub rewrap_code {	# This code got some escapes inside...
@@ -636,13 +699,22 @@ sub rewrap_lines {	# This code got some 
 sub indexify {
   my $in = shift;
   $in =~ s/(^|and\s+)(\w+)(\$?\()/$1\\idx{$2}$3/g;
+  $in =~ s/^(\\b\{\w+\})(?!\S)/\\idx{$1}/g;
+  $in;
+}
+
+sub for_index {
+  my $in = shift;
+  1 while $in =~ s/\Q$tr{startcode}\E(.*?)\Q$tr{endcode}\E/$1/go;
   $in;
 }
 
+
 sub TeXprint_topod {
   s/\A\s+//;
   s/^\\def\\.*\{\n.*\n\}//gm;
-  s/\\def\\.*//;		# Repeated in presubst
+  s/\\def\\.*//g;		# Repeated in presubst, as the next one
+  s/(\{[\w\s]+)\{\}([\s\w]+\})/$1$2/g;	# {rnf{}llgram}
 
   # \def\sectype#1#2{\subsec{Type \typ{#1} (#2s):}\sidx{#2}}
   # \def\sectypeindex#1#2#3{\subsec{Type \typ{#1} (#2):}\sidx{#3}}
@@ -655,21 +727,29 @@ sub TeXprint_topod {
   s/\\sectypes\{\s*((?:[^{}]|\{[^{}]*\})*)\}\{\s*((?:[^{}]|\{[^{}]*\})*)\}\{\s*((?:[^{}]|\{[^{}]*\})*)\}/\\subsec{Type \\typ{$1} and \\typ{$1} (${3}s)}\n\\sidx{$3}/g;
 
   # Try to guard \label/\sidx (removing possible '.')
+#  This somehow breaks index...
+#  s/(\\(?:section|subsec(?:ref|idx|op)?(unix)?)\s*{(?:(?:[^{}]+(?=[{}])|{[^{}]+})+)})\.?\s*\\(label|sidx)/$1\n\\$2/;
   s/(\\(?:section|subsec(?:ref|idx|op)?)\s*{(?:(?:[^{}]+(?=[{}])|{[^{}]+})+)})\.?\s*\\(label|sidx)/$1\n\\$2/;
 
   # last if /\\subsec[\\{}ref]*[\\\${]$help[}\\\$]/o;
   s/\\chapter\s*{((?:[^{}]|\{[^{}]*\})*)}/\n\n$tr{podleader}head1 NAME\n\nlibPARI - $1\n\n$tr{podleader}head1 DESCRIPTION\n\n/;
+  s/\\appendix\s*{((?:[^{}]|\{[^{}]*\})*)}/\n\n$tr{podleader}head1 NAME\n\nAppendix - $1\n\n$tr{podleader}head1 DESCRIPTION\n\n/;
   s/\\section\s*{((?:[^{}]|\{[^{}]*\})*)}/"\n\n$tr{podleader}head1 " . indexify($1) . "\n\n"/e;
 
   # Try to delimit by :
-  s/\\subsec(?:ref|idx|op)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}([^\n:]*):\s*/"\n\n$tr{podleader}head2 " . indexify("$1$3") . "\n\n"/e;
+  s/\\subsec(?:ref|idx|op)?(?:unix)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}((\W*default:)?[^\n:]*):\s*/"\n\n$tr{podleader}head2 " . indexify("$1$3") . "\n\n"/e;
+  s/\\subsec(?:ref|idx|op)?(?:unix)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}([^\n:]*):\s*/"\n\n$tr{podleader}head2 " . indexify("$1$3") . "\n\n"/e;
   s/\\subsubsec(?:ref|idx|op)?(?:unix)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}([^:]*):\s*/"\n\n$tr{podleader}item " . indexify("$1$3") . "\n\n"/e;
+#  s/\\subsubsec\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}\s*$/"\n\n$tr{podleader}item " . indexify("$1") . "\n\n"/e;
+  s/\\subsubsec\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}(.*)$/"\n\n$tr{podleader}item " . indexify("$1") . "$3\n\n"/me;
+#  s/\\subseckbd\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}:\s*/"\n\n$tr{podleader}head2 " . indexify("$1") . "\n\n"/e;
+  s/\\subseckbd\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}([^:]*):\s*/"\n\n$tr{podleader}head2 " . indexify("$1$3") . "\n\n"/e;
   # Try to delimit by ' '
-  s/\\subsec(?:ref|idx|op)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}(\S*)\s+/"\n\n$tr{podleader}head2 " . indexify("$1$3") . "\n\n"/e;
-  s/\\subsec(?:ref|title|idx|op)?\s*{(([^{}]+(?=[{}])|{[^{}]*})+)}:?\s*/"\n\n$tr{podleader}head2 " . indexify("$1") . "\n\n"/e;
+  s/\\subsec(?:ref|idx|op)?(?:unix)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}(\S*)\s+/"\n\n$tr{podleader}head2 " . indexify("$1$3") . "\n\n"/e;
+  s/\\subsec(?:ref|title|idx|op)?(?:unix)?\s*{(([^{}]+(?=[{}])|{[^{}]*})+)}:?\s*/"\n\n$tr{podleader}head2 " . indexify("$1") . "\n\n"/e;
 
   # This is to skip preface in refcard:
-  /\Q$tr{podleader}\Ehead1|\\title(?![a-zA-Z])\s*\{/ and $seen_start = 1
+  /\Q$tr{podleader}\Ehead1|\\title(?![a-zA-Z])\s*\{/o and $seen_start = 1
     or $seen_start or return;	# Skip now!
 
   s/\\title\s*\{([^{}\s]*)(\s+([^{}]*))?\}(\s*\\centerline\s*\{([^{}]*)\})?/$tr{podleader}head1 NAME\n\n$1 - $3.  $5\n\n/ and $seen_title++ 
@@ -682,12 +762,12 @@ sub TeXprint_topod {
 
   s/'(\W)'/{\\tt '$1'}/g;
   s/(\\\w+)(\\hbox)/$1 $2/g;
-  s/\\hbox\s*\{((?:\\[\{\}]|[^{}]|\{[^{}]*\})*)\}/$1/g;
+  s/\\hbox\s*\{(?:\\it\b\s*)?((?:\\[\{\}]|[^{}]|\{[^{}]*\})*)\}/$1/g;
   s/\\h\b/ /g;
 
   # XXXX ????
-  s/^{\\tt\s*\\obeylines\s*(([^{}]+(?=[{}])|{[^{}]*})+)}/\bprog $1 \eprog/g;
-  s/\\bprog(?:tabs[^\n]*)?(?![a-zA-Z])\s*(.*?)\\eprog/wrap_code($1)/ges;
+  s/^{(?:\\tt)?\s*\\obeylines\s*(([^{}]+(?=[{}])|{[^{}]*})+)}/\\bprog $1 \\eprog/g;
+  s/\s*\\bprog(?:tabs[^\n]*)?(?![a-zA-Z])\s*(.*?)\\eprog\s*/wrap_code($1)/ges;
 
   presubst();
 
@@ -711,8 +791,8 @@ sub TeXprint_topod {
 
   s/\\d?frac{\s*((?:[^{}]|\{[^{}]*\})*)}{\s*((?:[^{}]|\{[^{}]*\})*)}/($1)\/($2)/g;
 
-  s/\\s(?:ref|idx){\s*([^{}]*)}/X<$1>/g; # 
-  s/\\(?:ref|idx){\s*([^{}]*)}/X<$1>$1/g;
+  s/\\s(?:ref|idx){\s*([^{}]*)}/"X<" . for_index($1) . ">"/ge; # 
+  s/\\(?:ref|idx){\s*([^{}]*)}/"X<" . for_index($1) . ">$1"/ge;
 
 
 #  s/\\(backslash|bs)\s*(\b|(?=[\d_]|C\<))/\\Z<>/g;
@@ -721,12 +801,12 @@ sub TeXprint_topod {
   #s/\\pm(\b|(?=[\d_]))/F<+->/g;
   #s/\\noindent(\b|(?=[\d_]))/  /g;
 
-  # Conflict between different versions of PARI and refcard:
-  s/\\(?:key|li)(?![a-zA-Z])\s*{(.*)}\s*{(.+)}[ \t]*\n/\n\n=item C<$2>\n\n$1\n\n/mg;
-  s/\\(?:key|li)(?![a-zA-Z])\s*{(.*)}\s*{}[ \t]*\n/\n\n=back\n\n$1\n\n=over\n\n/mg;
-  s/\\(key|var)(?![a-zA-Z])\s*{(\w+)}/C<$2>/mg;
-  s/\\var(?![a-zA-Z])\s*{X<(\w+)>(\w+)}/X<$1>C<$2>/mg;
-  s/\\var(?![a-zA-Z])\s*{f{}lag}/C<flag>/mg;
+# Conflict between different versions of PARI and refcard:
+# s/\\(?:key|li)\s*{(.*)}\s*{(.+)}[ \t]*\n/\n\n=item C<$2>\n\n$1\n\n/msg;
+# s/\\(?:key|li)\s*{(.*)}\s*{}[ \t]*\n/\n\n=back\n\n$1\n\n=over\n\n/mgs;
+# s/\\(key|var)(?![a-zA-Z])\s*{(\w+)}/C<$2>/mg;
+  s/\\var\s*{X<(\w+)>(\w+)}/X<$1>C<$2>/mg;
+  s/\\var\s*{f{}lag}/C<flag>/mg;
 
   s/\\metax(?![a-zA-Z])\s*{(.*)}\s*{\s*(\w+)(?=C\<)(.*)}[ \t]*\n/\n\n=item C<L<$2>$3>\n\n$1\n\n/mg;
   s/\\metax(?![a-zA-Z])\s*{(.*)}\s*{(.*)}[ \t]*\n/\n\n=item C<$2>\n\n$1\n\n/mg;