Math-Pari

 view release on metacpan or  search on metacpan

utils/chap3_to_pod  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Please correct the above line to the actual location of perl on your
# system, and the line below to the location of PARI manual, ch. 3.
#
# The manual file can compressed. Sometimes you need to change the
# name of the compression program in the %compress = ... statement below.
#

# How to show a chunk of docs:
# pod2man --lax a.pod  | nroff -man |
# perl -p00e "s/\s*$/\n/;if (/^\S/) {$_=''} else {print qq'\n' if $next++}"|
# less -s -+C

$version = $1, shift @ARGV if @ARGV and $ARGV[0] =~ /^-v=(.*)$/;

$parifile = shift || "f:/pari/doc/usersch3.tex.gz";
# $parifile="/opt/src/pari-1.39/doc/usersch3.tex.gz";

die "Usage: $0 [-v=version-of-pari] pari-chapter-filename\n"
  unless -f $parifile;

#%transl=(
#	 '\\', '\backslash',
#	 '^',  '\hat{}',
#	 '!',  'fact',
#	 '~',  'trans',
#	 '_',  'conj',
#	 '-',  '\+',
#	 '%',  '\%',
#	 'min',  'max',
#	 'log',  'ln',
#);
%compress = ('.gz', 'gzip -cd',
	   '.z', 'gzip -cd',
	   '.Z', 'zcat',
	  );

#print $help;
foreach $suffix (keys %compress) {
  ($patt = $suffix) =~ s/(\W)/\\$1/;
  if ($parifile =~ /$patt$/) {
    $pipe = $compress{$suffix};
    last;
  }
}
if ($pipe) {
  open(DOC,"$pipe $parifile |") || 
    die "Cannot open pipe $pipe from $parifile: $!, stopped";
} else {
  open(DOC,$parifile) || die "Cannot find file $parifile: $!, stopped";
}
$/='';				# Paragraph mode
# %table = qw(`a ? "a ? "u ? "o ? 'e ?);

sub indexify ($) {
  my $in = shift;
  $in =~ s/(^|and\s+)(\w+)(\$?\()/$1\\ref{$2}$3/g;
  $in;
}

while (<DOC>) {
  # last if /\\subsec[\\{}ref]*[\\\${]$help[}\\\$]/o;
  s/\\chapter\s*{(.*)}/\n\n=head1 NAME\n\nlibPARI - $1\n\n=head1 DESCRIPTION\n\n/;
  s/\\section\s*{(.*)}/"\n\n=head1 " . indexify($1) . "\n\n"/e;
  # Try to delimit by :
  s/\\subsec(?:ref|idx|op)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}([^\n:]*):\s*/"\n\n=head2 " . indexify("$1$3") . "\n\n"/e;
  s/\\subsubsec(?:ref|idx|op)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}([^\n:]*):\s*/"\n\n=item " . indexify("$1$3") . "\n\n"/e;
  # Try to delimit by ' '
  s/\\subsec(?:ref|idx|op)?\s*{(([^{}]+(?=[{}])|{[^{}]+})+)}(\S*)\s+/"\n\n=head2 " . indexify("$1$3") . "\n\n"/e;
  s/\\subsec(?:ref|title|idx|op)?\s*{(([^{}]+(?=[{}])|{[^{}]*})+)}:?\s*/"\n\n=head2 " . indexify("$1") . "\n\n"/e;
  &TeXprint;
}
if ($pipe) {
  if ($^O eq 'os2') {
    # Would get 'illegal seek' otherwise?
    1 while <DOC>;
  }
  close(DOC) || die "Cannot close pipe `$pipe $parifile': $!, stopped";
} else {
  close(DOC) || die "Cannot close file $parifile: $!, stopped";
}

sub wrap_code {
  my $in = shift;
  $in =~ s/^(.)/  $1/mg;
  $in
}

# sref is invisible reference
# tec(a,b) is ref(a)tt(b)
sub TeXprint_old {
  # d?frac{}{} ???  bullet ???
  s/\\\///g;
  s/\\([% &|\#])/$1/g;
  s/\\c?dots\b/.../g;
  s/\\cdot\b/ . /g;
  s/\\mid\b/ | /g;
  s/(\\string)?\\_/_/g;
  s/\\(hat\b|\^)({\\?\s*})?/^/g;
  s/(^|[^\\])~/$1 /g;
  s/\\,/ /g;
  s/\\enspace(\b|(?=[\d_]))/ /g;
  s/\\~(\{(\\\s*)?\})?/~/g;
  s/\\tilde(\{\\\s+\})?/~/g;
  s/\\hbox{}/ /g;
  s/\\parskip.*/\n/g;		# Up to end of the line
  s/\\(equiv|approx|simeq)(\b|(?=[\d_]))/ ~ /g;
  s/\\neq(\b|(?=[\d_]))/!=/g;
  s/([A-Z])\</$1 < /g;
  s/\>/E<gt>/g;
  s/\\leq?(\b|(?=[\d_]))/E<lt>=/g;
  s/\\geq?(\b|(?=[\d_]))/E<gt>=/g;



( run in 0.725 second using v1.01-cache-2.11-cpan-364913b4093 )