#!/usr/bin/perl -w use strict; use POSIX qw; use Getopt::Std; my %opts; getopts('a:h:p?', \%opts); if ($opts{'?'}) { print < !~ /^y/i; } open TEX, '>', "$f.tex" or print STDERR "Error writing to $f.tex: $!\n" and next; select TEX; print <<'EOC', headers($f), <<'EOT'; % The macros used here are taken from *TeX for the Impatient* by Paul W. % Abrahams, Kathryn A. Hargreaves, and Karl Berry, which can be found at % . EOC \tt \def\deactivate{% \catcode`\\=12 \catcode`\{=12 \catcode`\}=12 \catcode`\$=12 \catcode`\&=12 \catcode`\#=12 \catcode`\~=12 \catcode`\^=12 \catcode`\_=12 } \def\makeactive#1{\catcode`#1=\active\ignorespaces} {\makeactive\^^M \gdef\obeywhitespace{% \makeactive\^^M \let^^M=\newline\aftergroup\removebox\obeyspaces\frenchspacing }} \def\~{\char126}\def\newline{\par\indent}\def\removebox{\setbox0=\lastbox} \def\verbatim{\begingroup\deactivate\obeywhitespace\catcode`\~=0} \verbatim% EOT while () { chomp; if ($_ eq '') {print "\n"; next; } 1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e; while ((my $sub = substr $_, 0, 80, '') ne '') { $sub =~ s/~( ?)/'~~' . ($1 ? '~ ' : '')/ge; $sub =~ s/%/~%/g; print $sub, "\n"; } } print "~endgroup\n\\bye\n"; select STDOUT; system "pdftex $f.tex"; unlink "$f.log"; unless ($opts{p}) { system "lpr $f.pdf"; print "Delete TeX & PDF files for $f now? (y/n) "; unlink "$f.tex", "$f.pdf" if =~ /^y/i; } }