#!/usr/bin/perl #FE Harrell 15Nov02 #Modified 29Jun09 to remove lines that contain doff() require 'getopts.pl'; #use strict; my ($program, $infile, $handle, $outfile); #================================================================= $program = "s2latx"; sub usage { die "Usage: $program [-v] [file [output-file]]\n"; } #================================================================= &Getopts("v") || &usage; $infile = shift(@ARGV); if ($infile) { open(INFILE, $infile) || die "$program: Cannot read from $infile\n"; $handle = "INFILE"; } else { $handle = "STDIN"; } $outfile = shift(@ARGV); if (!$outfile) { if($infile ne "") { # otherwise uses STDOUT by default $outfile = basename($infile, (".lst",".txt",".s",".r",".S",".R",".ssc",".SSC",".q")) . ".tex"; } } if ($outfile) { open(OUTFILE, ">$outfile") || die "$program: Cannot write to $outfile\n"; select(OUTFILE); } while(<$handle>) { s/\r//; # get rid of carriage returns if(/doff\(\)$/) {next;} s/\\ref{(.*)}/!ref!$1!/g; # keep \ref{} as is s/\\pageref{(.*)}/!pageref!$1!/g; # keep \pageref{} as is s/\\splus/!splus/g; # keep \splus as is s/\\/\\verb|\\|/g; s/{/\\verb|{|/g; # regular { and } are ignored by S.sty s/}/\\verb|}|/g; s/!ref!(.*)!/\\ref{$1}/g; # get \ref{} back s/!pageref!(.*)!/\\pageref{$1}/g; # get \pageref{} back # s/}/\\}/g; # s/{/\\}/g; s/\->/\\(\\rightarrow\\)/g; s/~/{\\Twiddle}/g; # translate ~ to {\Twiddle} s/\^/{\\Hat}/g; # translate ^ to {\Hat} s/\s*<-\s*/ \\Gets /g; # translate <- to \Gets s/##*\s*(.*)/\\scom{$1}/; # translate #xxx to \scom{xxx} s/\\scom{(.*)<=(.*)}/\\scom{$1\\(\\leq\\)$2}/g; s/\\scom{(.*)<(.*)}/\\scom{$1\\(<\\)$2}/g; s/\\scom{(.*)>=(.*)}/\\scom{$1\\(\\geq\\)$2}/g; s/\\scom{(.*)>(.*)}/\\scom{$1\\(>\\)$2}/g; print; }