summaryrefslogtreecommitdiff
path: root/support/purifyeps
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/purifyeps
Initial commit
Diffstat (limited to 'support/purifyeps')
-rw-r--r--support/purifyeps/README59
-rw-r--r--support/purifyeps/purifyeps529
-rw-r--r--support/purifyeps/purifyeps.1350
-rw-r--r--support/purifyeps/purifyeps.pdfbin0 -> 27761 bytes
4 files changed, 938 insertions, 0 deletions
diff --git a/support/purifyeps/README b/support/purifyeps/README
new file mode 100644
index 0000000000..7c0893da26
--- /dev/null
+++ b/support/purifyeps/README
@@ -0,0 +1,59 @@
+ +---------------------------------------------+
+ | PURIFYEPS |
+ | |
+ | Convert an ordinary Encapsulated PostScript |
+ | file (.eps) into one that works with both |
+ | LaTeX+dvips and pdfLaTeX. |
+ | |
+ | By Scott Pakin, scott+peps@pakin.org |
+ +---------------------------------------------+
+
+
+Description
+-----------
+
+While pdfLaTeX has a number of nice features, its primary shortcoming
+relative to standard LaTeX+dvips is that it is unable to read ordinary
+Encapsulated PostScript (EPS) files, the most common graphics format
+in the LaTeX world. purifyeps converts EPS files into a "purified"
+form that can be read by *both* LaTeX+dvips and pdfLaTeX. The trick
+is that the standard LaTeX2e graphics packages can parse
+MetaPost-produced EPS directly. Hence, purifyeps need only convert an
+arbitrary EPS file into the same stylized format that MetaPost
+outputs.
+
+Documentation is provided in Unix man-page format and in PDF
+(U.S. letter-sized). In addition, executing "purifyeps --help" gives
+basic command-line usage.
+
+
+Requirements
+------------
+
+To run purifyeps, you will need the following:
+
+ * Perl (http://www.cpan.org)
+
+ * pstoedit (http://www.pstoedit.net/pstoedit)
+
+ * a LaTeX distribution that includes MetaPost (mpost)
+
+purifyeps itself is a Perl script. On certain operating systems, you
+may need to rename purifyeps (e.g., to purifyeps.pl) to notify the
+system that purifyeps is, in fact, a Perl script.
+
+
+Copyright and license
+---------------------
+
+Copyright (C) 2010 by Scott Pakin
+
+This file may be distributed and/or modified under the conditions of
+the LaTeX Project Public License, either version 1.3c of this license
+or (at your option) any later version. The latest version of this
+license is in:
+
+ http://www.latex-project.org/lppl.txt
+
+and version 1.3c or later is part of all distributions of LaTeX
+version 2006/05/20 or later.
diff --git a/support/purifyeps/purifyeps b/support/purifyeps/purifyeps
new file mode 100644
index 0000000000..ff686227f0
--- /dev/null
+++ b/support/purifyeps/purifyeps
@@ -0,0 +1,529 @@
+#! /usr/bin/env perl
+
+################################################################
+# Convert an ordinary Encapsulated PostScript file (.eps) into #
+# one that works with both LaTeX+dvips and pdfLaTeX #
+# #
+# By Scott Pakin <scott+peps@pakin.org> #
+################################################################
+
+our $VERSION = "1.1";
+require 5.006_001;
+use English;
+use Getopt::Long;
+use FindBin qw($Script);
+use File::Basename;
+use File::Temp qw(tempfile);
+use File::Spec;
+use File::Which;
+use Pod::Usage;
+use Pod::Man;
+use Cwd qw(cwd chdir);
+use POSIX;
+use warnings;
+use strict;
+
+# Global variables
+my $fontmap = "mpost.fmp"; # pstoedit-style font map file
+my %TeX_to_PS; # Hash table representing the contents of the above
+my $infile = "-"; # Input file (default: stdin)
+my $outfile = "-"; # Output file (default: stdout)
+my $tempbase; # Base name of temporary files
+my @fontmappath = ( # Where to look for $fontmap
+ "/usr/share/pstoedit/",
+ "/usr/local/share/pstoedit/");
+
+########################################################################
+
+# At the end of the program's execution, delete all of our temporary files.
+END {
+ if (defined $tempbase) {
+ foreach my $tempfile ($tempbase, <$tempbase.*>) {
+ unlink $tempfile;
+ }
+ }
+}
+
+
+# Extract the first word from the given array. A word is either a
+# single token or a quoted set of space-separated tokens. Return the
+# first word followed by the remaining tokens.
+sub extractName (@)
+{
+ my @tokens = @_;
+ my $firstWord;
+
+ # Ensure we have a token to extract.
+ return (undef, @tokens) if $#tokens==-1;
+
+ # Extract the first word from the token list.
+ $firstWord = shift @tokens;
+ if (substr ($firstWord, 0, 1) eq '"') {
+ while (substr ($firstWord, length($firstWord)-1, 1) ne '"') {
+ return (undef, @tokens) if $#tokens==-1;
+ $firstWord .= " " . shift @tokens;
+ }
+ $firstWord = substr ($firstWord, 1, length($firstWord)-2);
+ }
+
+ # Return the word plus the remaining tokens.
+ return ($firstWord, @tokens);
+}
+
+
+# Execute a shell command, and die if it fails.
+sub executeCommand ($)
+{
+ my $command = $_[0];
+ if (system "$command 1>&2") {
+ die "${Script}: The following command failed with exit code @{[int($?/256)]}:\n $command\n";
+ }
+}
+
+
+# Generate -- and optionally clean up -- a man page.
+sub createManPage ($$$)
+{
+ my $manfile = $_[0]; # Name of file to produce
+ my $wantPS = $_[1]; # 1=produce PostScript, 0=produce troff
+ my $section = $_[2]; # Manual section that purifyeps belongs to
+
+ # Produce a (*roff) man page.
+ my $parser = Pod::Man->new (center => "",
+ release => "v$VERSION",
+ section => $section);
+ $parser->parse_from_file ($PROGRAM_NAME, $manfile);
+
+ # Touch up the man page, and use groff to write
+ # the result back to disk as a PostScript file.
+ return unless $wantPS;
+ open (MANFILE, "<$manfile") or die "${Script}: $! ($manfile)\n";
+ my @manlines = <MANFILE>;
+ close MANFILE;
+ open (MANFILE, "|groff -man > $manfile") or die "${Script}: $! ($manfile)\n";
+ foreach (@manlines) {
+ s/LaTeX/L\\h'-0.36m'\\v'-0.15'\\s-2A\\s+2\\v'0.15'\\h'-0.15m'TeX/g;
+ s/TeX/T\\h'-0.1667m'\\v'0.20'E\\v'-0.20'\\h'-0.125m'X/g;
+ s/\\\*\(--/--/g;
+ print MANFILE $_;
+ }
+ close MANFILE;
+}
+
+########################################################################
+
+# Initialize our base temporary filename.
+(undef, $tempbase) = tempfile ($Script . "-XXXXXXXX", DIR => File::Spec->tmpdir());
+
+# Try to determine the full filename of the font-map file.
+foreach my $dir (@fontmappath) {
+ my $newfontmap = File::Spec->catfile($dir, $fontmap);
+ if (-e $newfontmap) {
+ $fontmap = $newfontmap;
+ last;
+ }
+}
+
+# Process the command line.
+my ($wanthelp, $wantman, $wantps, $wantversion);
+my $versionmsg = "purifyeps version $VERSION
+
+Copyright (C) 2010 Scott Pakin
+
+This program may be distributed and/or modified under the conditions
+of the LaTeX Project Public License, either version 1.3c of this
+license or (at your option) any later version.
+
+The latest version of this license is in:
+
+ http://www.latex-project.org/lppl.txt
+
+and version 1.3c or later is part of all distributions of LaTeX
+version 2006/05/20 or later.
+";
+my $man_section = 1; # Section number of man page
+GetOptions ("fontmap=s" => \$fontmap,
+ "make-man:s" => \$wantman,
+ "make-ps-man:s" => \$wantps,
+ "section=s" => \$man_section,
+ "V|version" => \$wantversion,
+ "help" => \$wanthelp) || pod2usage(2);
+do {print $versionmsg; exit 1} if $wantversion;
+pod2usage(1) if $wanthelp;
+if (defined $wantman) {
+ # Create a troff manual page.
+ my $filename = ($wantman eq "" ?
+ basename ($PROGRAM_NAME, ".pl") . ".$man_section" :
+ $wantman);
+ createManPage ($filename, 0, $man_section);
+ print STDERR "Wrote $filename\n";
+ exit 0;
+}
+if (defined $wantps) {
+ # Create a PostScript manual page.
+ my $filename = ($wantps eq "" ?
+ basename ($PROGRAM_NAME, ".pl") . ".ps" :
+ $wantps);
+ createManPage ($filename, 1, $man_section);
+ print STDERR "Wrote $filename\n";
+ exit 0;
+}
+$infile = shift @ARGV if $#ARGV!=-1;
+$outfile = shift @ARGV if $#ARGV!=-1;
+pod2usage(2) if $#ARGV!=-1; # Too many arguments.
+
+# Ensure that pstoedit is installed. Give a helpful error message if it isn't.
+if (!defined which("pstoedit")) {
+ die "${Script}: pstoedit must be installed and must appear in the executable search path\n";
+}
+
+# Read the font map file into a hash table.
+open (FONTMAP, "<$fontmap") || die "${Script}: $! ($fontmap); specify an alternative with --fontmap\n";
+FONTMAP_LINE:
+ while (<FONTMAP>) {
+ # Clean up the line.
+ chomp;
+ s/\%.*//;
+ my $origLine = $_;
+ next if /^\s*$/;
+ my @tokens = split " ";
+
+ # Extract the PostScript name, which may be quoted and contain spaces.
+ my $PSname;
+ ($PSname, @tokens) = extractName @tokens;
+ if (!defined $PSname) {
+ warn "${fontmap}:$NR: warning: incorrect format -- ignoring line\n";
+ next FONTMAP_LINE;
+ }
+
+ # Extract the TeX name, which may also be quoted and contain spaces.
+ my $TeXname;
+ ($TeXname, @tokens) = extractName @tokens;
+ if (!defined $TeXname) {
+ warn "${fontmap}:$NR: warning: incorrect format -- ignoring line\n";
+ next FONTMAP_LINE;
+ }
+
+ # That should be the end of the line.
+ if ($#tokens != -1) {
+ warn "${fontmap}:$NR: warning: incorrect format -- ignoring line\n";
+ next FONTMAP_LINE;
+ }
+
+ # Store the mapping in a hash table.
+ # HEURISTIC: If the mapping is not unique, map the TeX
+ # name to the *shortest* PostScript name.
+ if (!defined $TeX_to_PS{$TeXname} ||
+ length $PSname < length $TeX_to_PS{$TeXname}) {
+ $TeX_to_PS{$TeXname} = $PSname;
+ }
+ }
+close FONTMAP;
+
+# Utilize pstoedit to convert from EPS to MetaPost.
+my $mpfile = $tempbase . ".mp";
+executeCommand "pstoedit -ssp -f mpost -fontmap \"$fontmap\" \"$infile\" \"$mpfile\"";
+
+# Utilize mpost to convert from MetaPost to MPS (stylized EPS).
+my $old_cwd = cwd();
+chdir (File::Spec->tmpdir()); # mpost always writes to the current directory.
+executeCommand "echo X | mpost $mpfile";
+chdir $old_cwd;
+
+# Post-process the MPS file into the output file.
+my $mpsfile = $tempbase . ".1";
+my @purified_eps;
+my $outfile_clean = ($outfile eq "-") ? "stdout" : $outfile;
+open (MPSFILE, "<$mpsfile") || die "${Script}: $! ($mpsfile)\n";
+while (<MPSFILE>) {
+ # Process blank lines.
+ chomp;
+ my @tokens = split " ";
+ if ($#tokens == -1) {
+ push @purified_eps, "$_\n";
+ next;
+ }
+
+ # Convert the list of document fonts.
+ if ($tokens[0] eq "%%DocumentFonts:") {
+ my $outputLine = shift @tokens;
+ foreach my $TeXname (@tokens) {
+ my $PSname = $TeX_to_PS{$TeXname};
+ if (!defined $PSname) {
+ warn "${outfile_clean}:$NR: warning: TeX font \"$TeXname\" does not appear in $fontmap\n";
+ $outputLine .= " $TeXname";
+ }
+ else {
+ $outputLine .= " $PSname";
+ }
+ }
+ push @purified_eps, "$outputLine\n";
+ next;
+ }
+
+ # Convert the font name definitions.
+ if ($#tokens == 2 &&
+ $tokens[0] eq $tokens[1] &&
+ $tokens[2] eq "def") {
+ push @purified_eps, sprintf " %s /%s def\n", $tokens[0], $TeX_to_PS{substr($tokens[1],1)};
+ next;
+ }
+
+ # By default, output the line as is.
+ push @purified_eps, "$_\n";
+}
+close MPSFILE;
+
+# Write the output file.
+open (OUTFILE, ">$outfile") || die "${Script}: $! ($outfile_clean)\n";
+print OUTFILE @purified_eps;
+close OUTFILE;
+
+# Finish up.
+print STDERR "\nFile seems to have been purified successfully.\n";
+exit 0;
+
+###########################################################################
+
+__END__
+
+
+=head1 NAME
+
+purifyeps - make an Encapsulated PostScript file work with both dvips and
+pdflatex
+
+
+=head1 SYNOPSIS
+
+purifyeps
+B<--help>
+
+purifyeps
+B<--version>
+
+purifyeps
+[B<--fontmap>=I<.fmp file>]
+[I<.eps input file> [I<.eps output file>]]
+
+purifyeps
+B<--make-man>[=I<filename>] [B<--section>=I<section>]
+
+purifyeps
+B<--make-ps-man>[=I<filename>] [B<--section>=I<section>]
+
+
+=head1 DESCRIPTION
+
+While B<pdflatex> has a number of nice features, its primary
+shortcoming relative to standard B<latex>+B<dvips> is that it is
+unable to read ordinary Encapsulated PostScript (EPS) files, the most
+common graphics format in the LaTeX world. B<pdflatex> can read only
+the following types of graphics files:
+
+=over 4
+
+=item PDF
+
+Most people who use B<pdflatex> convert their documents to PDF using a
+utility such as B<epstopdf>. This works well and preserves the vector
+nature of the original EPS. Unfortunately, B<dvips> does not read
+PDF, so two versions of the graphic must be maintained if the document
+is to be processed with both B<latex>+B<dvips> and B<pdflatex>.
+
+=item PNG
+
+PNG is a bitmap format and therefore scales poorly. Also, B<dvips>
+does not read PNG, so two versions of the graphic must be maintained
+if the document is to be processed with both B<latex>+B<dvips> and
+B<pdflatex>.
+
+=item JPEG
+
+JPEG is a bitmap format and therefore scales poorly. Also, B<dvips>
+does not read JPEG, so two versions of the graphic must be maintained
+if the document is to be processed with both B<latex>+B<dvips> and
+B<pdflatex>.
+
+=item MPS
+
+This is probably the least-used B<pdflatex>-compatible graphics
+format. MPS is actually a stylized version of EPS that MetaPost
+outputs. Like PDF, MPS is a vector format and remains as such when
+imported into a B<pdflatex> document. Also like PDF, B<dvips> does
+not read MPS, so two versions of the graphic must be maintained if the
+document is to be processed with both B<latex>+B<dvips> and
+B<pdflatex>.
+
+=back
+
+The insight behind B<purifyeps> is that there are only a few, small
+differences between MPS and EPS and that a file can be converted into
+a format that matches both the MPS and EPS specifications
+simultaneously. B<purifyeps> inputs an EPS file, uses B<pstoedit>'s
+C<mpost> filter to convert the file to MetaPost (F<.mp>), runs
+B<mpost> on the file to convert it to MPS, and finally performs some
+touchups on the result to convert the file back to EPS, while
+preserving its ability to be parsed by B<pdflatex>.
+
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--help>
+
+Display L<"Usage"> and L<"Options"> from the B<purifyeps> documentation.
+
+=item B<-V>, B<--version>
+
+Display the B<purifyeps> version number, copyright, and license.
+
+=item B<--fontmap>=I<.fmp file>
+
+Specify the name of a file that tells B<purifyeps> how to map from TeX
+font names to PostScript font names. [Default: F<mpost.fmp>]
+
+=item B<--make-man> [=I<filename>]] [B<--section>=I<section>]
+
+Automatically create a Unix man page for B<purifyeps>. I<section>
+specifies the section [default: C<1> (User Commands)]. I<filename>
+defaults to F<purifyeps.1> or an analogous filename if I<section> is
+specified.
+
+=item B<--make-ps-man> [=I<filename>]] [B<--section>=I<section>]
+
+Automatically create a PostScript version of the B<purifyeps>
+documentation. The documentation is formatted like a Unix man page.
+I<section> specifies the section [default: C<1> (User Commands)].
+I<filename> defaults to F<purifyeps.ps>.
+
+=back
+
+In normal operation (i.e., when not run with C<--help>, C<--make-man>,
+or C<--make-ps-man>), B<purifyeps> takes the name of an input file and
+output file. The same filename can safely be used for both files. If
+the output filename is omitted, output will go to the standard output
+device. If the input filename is omitted, B<purifyeps> will read from
+the standard input device.
+
+
+=head1 EXAMPLES
+
+Create a PostScript version of the B<purifyeps> documentation, but
+call it F<happydoc.ps> instead of the default, F<purifyeps.ps>:
+
+ purifyeps --make-ps-man=happydoc.ps
+
+Create a Unix man page for B<purifyeps> (in the usual roff format),
+but indicate that it belongs in section C<LOCAL> instead of the
+default of section C<1>:
+
+ purifyeps --make-man --section=LOCAL
+
+Purify F<sample.eps> (F<mpost.fmp> is in the current directory):
+
+ purifyeps sample.eps sample.eps
+
+Purify F<sample.eps> (F<mpost.fmp> is in a different location):
+
+ purifyeps --fontmap=/usr/share/pstoedit/mpost.fmp sample.eps sample.eps
+
+Rename the purified version while purifying:
+
+ purifyeps sample.eps sample-pure.eps
+
+Do the same, but in a Unix pipeline:
+
+ cat sample.eps | purifyeps > sample-pure.eps
+
+When you run B<purifyeps>, you should see the output from both
+B<pstoedit> and B<mpost>, followed by a success message from
+B<purifyeps>:
+
+ % cat sample.eps | purifyeps > sample-pure.eps
+ pstoedit: version 3.30 / DLL interface 107 (build Mar 14 2002) :
+ Copyright (C) 1993 - 2001 Wolfgang Glunz
+ Interpreter finished. Return status 0
+ This is MetaPost, Version 0.641 (Web2C 7.3.1)
+ (/tmp/purifyeps-jdeGPkh9.mp [1] )
+ 1 output file written: purifyeps-jdeGPkh9.1
+ Transcript written on purifyeps-jdeGPkh9.log.
+
+ File seems to have been purified successfully.
+
+
+=head1 FILES
+
+=over 4
+
+=item F<mpost.fmp>
+
+File containing mappings between TeX and PostScript font names. See
+L<"NOTES"> for a description of this file's contents.
+
+=back
+
+
+=head1 BUGS
+
+Error reporting could definitely stand to be improved. Error messages
+produced by B<pstoedit> and B<mpost> are sometimes silently ignored.
+Also, errors sometimes cause B<purifyeps> to leave temporary files
+(F<purifyeps->I<#####>) lying around.
+
+B<purifyeps> is subject to all of the limitations that affect
+B<pstoedit> and especially the C<mpost> backend to B<pstoedit>. As a
+result, B<purifyeps> ignores certain PostScript constructs, such as
+nonuniformly scaled text.
+
+
+=head1 NOTES
+
+B<purifyeps> needs a file that tells it how to map from TeX font names
+to PostScript font names. This file must contain two, space-separated
+columns. The first lists a PostScript font name, and the second lists
+the TeX equivalent. Blank lines and lines that start with C<%> are
+ignored. The following is a sample F<.fmp> file:
+
+ % This is a sample font map for purifyeps.
+ Times-Bold ptmb
+ Times-Italic ptmri
+ Times-Roman ptmr
+ Helvetica phvr
+ Helvetica-Bold phvb
+ Helvetica-Oblique phvro
+ Courier pcrr
+ Courier-Bold pcrb
+ Courier-Oblique pcrro
+
+Note that this is exactly the same format that B<pstoedit> uses. By
+default, B<purifyeps> looks in the current directory for a font map
+called F<mpost.fmp>. The C<--fontmap> command-line option tells
+B<purifyeps> to use a different font map, which will typically be the
+F<mpost.fmp> file that comes with B<pstoedit>.
+
+Once you create purified EPS files with B<purifyeps>, you need to
+instruct B<pdflatex> to use them. The pdfLaTeX configuration of the
+C<graphics> and C<graphicx> packages (F<pdftex.def>) normally ignores
+F<.eps> files. Putting the following LaTeX code in your document's
+preamble tells B<pdflatex> that all F<.eps> files are in MPS format:
+
+ % Tell pdfLaTeX that all .eps files were produced by MetaPost.
+ \usepackage{graphicx} % or graphics
+ \usepackage{ifpdf}
+ \ifpdf
+ \DeclareGraphicsRule{.eps}{mps}{*}{}
+ \makeatletter
+ \g@addto@macro\Gin@extensions{,.eps}
+ \makeatother
+ \fi
+
+=head1 SEE ALSO
+
+dvips(1), epstopdf(1), latex(1), mpost(1), pdflatex(1), pstoedit(1)
+
+
+=head1 AUTHOR
+
+Scott Pakin, I<scott+peps@pakin.org>
diff --git a/support/purifyeps/purifyeps.1 b/support/purifyeps/purifyeps.1
new file mode 100644
index 0000000000..0b3121ab24
--- /dev/null
+++ b/support/purifyeps/purifyeps.1
@@ -0,0 +1,350 @@
+.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07)
+.\"
+.\" Standard preamble:
+.\" ========================================================================
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+.\" Set up some character translations and predefined strings. \*(-- will
+.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
+.\" double quote, and \*(R" will give a right double quote. \*(C+ will
+.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
+.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
+.\" nothing in troff, for use with C<>.
+.tr \(*W-
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
+.ie n \{\
+. ds -- \(*W-
+. ds PI pi
+. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
+. ds L" ""
+. ds R" ""
+. ds C` ""
+. ds C' ""
+'br\}
+.el\{\
+. ds -- \|\(em\|
+. ds PI \(*p
+. ds L" ``
+. ds R" ''
+'br\}
+.\"
+.\" Escape single quotes in literal strings from groff's Unicode transform.
+.ie \n(.g .ds Aq \(aq
+.el .ds Aq '
+.\"
+.\" If the F register is turned on, we'll generate index entries on stderr for
+.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
+.\" entries marked with X<> in POD. Of course, you'll have to process the
+.\" output yourself in some meaningful fashion.
+.ie \nF \{\
+. de IX
+. tm Index:\\$1\t\\n%\t"\\$2"
+..
+. nr % 0
+. rr F
+.\}
+.el \{\
+. de IX
+..
+.\}
+.\"
+.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
+.\" Fear. Run. Save yourself. No user-serviceable parts.
+. \" fudge factors for nroff and troff
+.if n \{\
+. ds #H 0
+. ds #V .8m
+. ds #F .3m
+. ds #[ \f1
+. ds #] \fP
+.\}
+.if t \{\
+. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
+. ds #V .6m
+. ds #F 0
+. ds #[ \&
+. ds #] \&
+.\}
+. \" simple accents for nroff and troff
+.if n \{\
+. ds ' \&
+. ds ` \&
+. ds ^ \&
+. ds , \&
+. ds ~ ~
+. ds /
+.\}
+.if t \{\
+. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
+. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
+. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
+. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
+. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
+. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
+.\}
+. \" troff and (daisy-wheel) nroff accents
+.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
+.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
+.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
+.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
+.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
+.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
+.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
+.ds ae a\h'-(\w'a'u*4/10)'e
+.ds Ae A\h'-(\w'A'u*4/10)'E
+. \" corrections for vroff
+.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
+.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
+. \" for low resolution devices (crt and lpr)
+.if \n(.H>23 .if \n(.V>19 \
+\{\
+. ds : e
+. ds 8 ss
+. ds o a
+. ds d- d\h'-1'\(ga
+. ds D- D\h'-1'\(hy
+. ds th \o'bp'
+. ds Th \o'LP'
+. ds ae ae
+. ds Ae AE
+.\}
+.rm #[ #] #H #V #F C
+.\" ========================================================================
+.\"
+.IX Title "PURIFYEPS 1"
+.TH PURIFYEPS 1 "2010-11-28" "v1.1" ""
+.\" For nroff, turn off justification. Always turn off hyphenation; it makes
+.\" way too many mistakes in technical documents.
+.if n .ad l
+.nh
+.SH "NAME"
+purifyeps \- make an Encapsulated PostScript file work with both dvips and
+pdflatex
+.SH "SYNOPSIS"
+.IX Header "SYNOPSIS"
+purifyeps
+\&\fB\-\-help\fR
+.PP
+purifyeps
+\&\fB\-\-version\fR
+.PP
+purifyeps
+[\fB\-\-fontmap\fR=\fI.fmp file\fR]
+[\fI.eps input file\fR [\fI.eps output file\fR]]
+.PP
+purifyeps
+\&\fB\-\-make\-man\fR[=\fIfilename\fR] [\fB\-\-section\fR=\fIsection\fR]
+.PP
+purifyeps
+\&\fB\-\-make\-ps\-man\fR[=\fIfilename\fR] [\fB\-\-section\fR=\fIsection\fR]
+.SH "DESCRIPTION"
+.IX Header "DESCRIPTION"
+While \fBpdflatex\fR has a number of nice features, its primary
+shortcoming relative to standard \fBlatex\fR+\fBdvips\fR is that it is
+unable to read ordinary Encapsulated PostScript (\s-1EPS\s0) files, the most
+common graphics format in the LaTeX world. \fBpdflatex\fR can read only
+the following types of graphics files:
+.IP "\s-1PDF\s0" 4
+.IX Item "PDF"
+Most people who use \fBpdflatex\fR convert their documents to \s-1PDF\s0 using a
+utility such as \fBepstopdf\fR. This works well and preserves the vector
+nature of the original \s-1EPS\s0. Unfortunately, \fBdvips\fR does not read
+\&\s-1PDF\s0, so two versions of the graphic must be maintained if the document
+is to be processed with both \fBlatex\fR+\fBdvips\fR and \fBpdflatex\fR.
+.IP "\s-1PNG\s0" 4
+.IX Item "PNG"
+\&\s-1PNG\s0 is a bitmap format and therefore scales poorly. Also, \fBdvips\fR
+does not read \s-1PNG\s0, so two versions of the graphic must be maintained
+if the document is to be processed with both \fBlatex\fR+\fBdvips\fR and
+\&\fBpdflatex\fR.
+.IP "\s-1JPEG\s0" 4
+.IX Item "JPEG"
+\&\s-1JPEG\s0 is a bitmap format and therefore scales poorly. Also, \fBdvips\fR
+does not read \s-1JPEG\s0, so two versions of the graphic must be maintained
+if the document is to be processed with both \fBlatex\fR+\fBdvips\fR and
+\&\fBpdflatex\fR.
+.IP "\s-1MPS\s0" 4
+.IX Item "MPS"
+This is probably the least-used \fBpdflatex\fR\-compatible graphics
+format. \s-1MPS\s0 is actually a stylized version of \s-1EPS\s0 that MetaPost
+outputs. Like \s-1PDF\s0, \s-1MPS\s0 is a vector format and remains as such when
+imported into a \fBpdflatex\fR document. Also like \s-1PDF\s0, \fBdvips\fR does
+not read \s-1MPS\s0, so two versions of the graphic must be maintained if the
+document is to be processed with both \fBlatex\fR+\fBdvips\fR and
+\&\fBpdflatex\fR.
+.PP
+The insight behind \fBpurifyeps\fR is that there are only a few, small
+differences between \s-1MPS\s0 and \s-1EPS\s0 and that a file can be converted into
+a format that matches both the \s-1MPS\s0 and \s-1EPS\s0 specifications
+simultaneously. \fBpurifyeps\fR inputs an \s-1EPS\s0 file, uses \fBpstoedit\fR's
+\&\f(CW\*(C`mpost\*(C'\fR filter to convert the file to MetaPost (\fI.mp\fR), runs
+\&\fBmpost\fR on the file to convert it to \s-1MPS\s0, and finally performs some
+touchups on the result to convert the file back to \s-1EPS\s0, while
+preserving its ability to be parsed by \fBpdflatex\fR.
+.SH "OPTIONS"
+.IX Header "OPTIONS"
+.IP "\fB\-\-help\fR" 4
+.IX Item "--help"
+Display \*(L"Usage\*(R" and \*(L"Options\*(R" from the \fBpurifyeps\fR documentation.
+.IP "\fB\-V\fR, \fB\-\-version\fR" 4
+.IX Item "-V, --version"
+Display the \fBpurifyeps\fR version number, copyright, and license.
+.IP "\fB\-\-fontmap\fR=\fI.fmp file\fR" 4
+.IX Item "--fontmap=.fmp file"
+Specify the name of a file that tells \fBpurifyeps\fR how to map from TeX
+font names to PostScript font names. [Default: \fImpost.fmp\fR]
+.IP "\fB\-\-make\-man\fR [=\fIfilename\fR]] [\fB\-\-section\fR=\fIsection\fR]" 4
+.IX Item "--make-man [=filename]] [--section=section]"
+Automatically create a Unix man page for \fBpurifyeps\fR. \fIsection\fR
+specifies the section [default: \f(CW1\fR (User Commands)]. \fIfilename\fR
+defaults to \fIpurifyeps.1\fR or an analogous filename if \fIsection\fR is
+specified.
+.IP "\fB\-\-make\-ps\-man\fR [=\fIfilename\fR]] [\fB\-\-section\fR=\fIsection\fR]" 4
+.IX Item "--make-ps-man [=filename]] [--section=section]"
+Automatically create a PostScript version of the \fBpurifyeps\fR
+documentation. The documentation is formatted like a Unix man page.
+\&\fIsection\fR specifies the section [default: \f(CW1\fR (User Commands)].
+\&\fIfilename\fR defaults to \fIpurifyeps.ps\fR.
+.PP
+In normal operation (i.e., when not run with \f(CW\*(C`\-\-help\*(C'\fR, \f(CW\*(C`\-\-make\-man\*(C'\fR,
+or \f(CW\*(C`\-\-make\-ps\-man\*(C'\fR), \fBpurifyeps\fR takes the name of an input file and
+output file. The same filename can safely be used for both files. If
+the output filename is omitted, output will go to the standard output
+device. If the input filename is omitted, \fBpurifyeps\fR will read from
+the standard input device.
+.SH "EXAMPLES"
+.IX Header "EXAMPLES"
+Create a PostScript version of the \fBpurifyeps\fR documentation, but
+call it \fIhappydoc.ps\fR instead of the default, \fIpurifyeps.ps\fR:
+.PP
+.Vb 1
+\& purifyeps \-\-make\-ps\-man=happydoc.ps
+.Ve
+.PP
+Create a Unix man page for \fBpurifyeps\fR (in the usual roff format),
+but indicate that it belongs in section \f(CW\*(C`LOCAL\*(C'\fR instead of the
+default of section \f(CW1\fR:
+.PP
+.Vb 1
+\& purifyeps \-\-make\-man \-\-section=LOCAL
+.Ve
+.PP
+Purify \fIsample.eps\fR (\fImpost.fmp\fR is in the current directory):
+.PP
+.Vb 1
+\& purifyeps sample.eps sample.eps
+.Ve
+.PP
+Purify \fIsample.eps\fR (\fImpost.fmp\fR is in a different location):
+.PP
+.Vb 1
+\& purifyeps \-\-fontmap=/usr/share/pstoedit/mpost.fmp sample.eps sample.eps
+.Ve
+.PP
+Rename the purified version while purifying:
+.PP
+.Vb 1
+\& purifyeps sample.eps sample\-pure.eps
+.Ve
+.PP
+Do the same, but in a Unix pipeline:
+.PP
+.Vb 1
+\& cat sample.eps | purifyeps > sample\-pure.eps
+.Ve
+.PP
+When you run \fBpurifyeps\fR, you should see the output from both
+\&\fBpstoedit\fR and \fBmpost\fR, followed by a success message from
+\&\fBpurifyeps\fR:
+.PP
+.Vb 8
+\& % cat sample.eps | purifyeps > sample\-pure.eps
+\& pstoedit: version 3.30 / DLL interface 107 (build Mar 14 2002) :
+\& Copyright (C) 1993 \- 2001 Wolfgang Glunz
+\& Interpreter finished. Return status 0
+\& This is MetaPost, Version 0.641 (Web2C 7.3.1)
+\& (/tmp/purifyeps\-jdeGPkh9.mp [1] )
+\& 1 output file written: purifyeps\-jdeGPkh9.1
+\& Transcript written on purifyeps\-jdeGPkh9.log.
+\&
+\& File seems to have been purified successfully.
+.Ve
+.SH "FILES"
+.IX Header "FILES"
+.IP "\fImpost.fmp\fR" 4
+.IX Item "mpost.fmp"
+File containing mappings between TeX and PostScript font names. See
+\&\*(L"\s-1NOTES\s0\*(R" for a description of this file's contents.
+.SH "BUGS"
+.IX Header "BUGS"
+Error reporting could definitely stand to be improved. Error messages
+produced by \fBpstoedit\fR and \fBmpost\fR are sometimes silently ignored.
+Also, errors sometimes cause \fBpurifyeps\fR to leave temporary files
+(\fIpurifyeps\-\fR\fI#####\fR) lying around.
+.PP
+\&\fBpurifyeps\fR is subject to all of the limitations that affect
+\&\fBpstoedit\fR and especially the \f(CW\*(C`mpost\*(C'\fR backend to \fBpstoedit\fR. As a
+result, \fBpurifyeps\fR ignores certain PostScript constructs, such as
+nonuniformly scaled text.
+.SH "NOTES"
+.IX Header "NOTES"
+\&\fBpurifyeps\fR needs a file that tells it how to map from TeX font names
+to PostScript font names. This file must contain two, space-separated
+columns. The first lists a PostScript font name, and the second lists
+the TeX equivalent. Blank lines and lines that start with \f(CW\*(C`%\*(C'\fR are
+ignored. The following is a sample \fI.fmp\fR file:
+.PP
+.Vb 10
+\& % This is a sample font map for purifyeps.
+\& Times\-Bold ptmb
+\& Times\-Italic ptmri
+\& Times\-Roman ptmr
+\& Helvetica phvr
+\& Helvetica\-Bold phvb
+\& Helvetica\-Oblique phvro
+\& Courier pcrr
+\& Courier\-Bold pcrb
+\& Courier\-Oblique pcrro
+.Ve
+.PP
+Note that this is exactly the same format that \fBpstoedit\fR uses. By
+default, \fBpurifyeps\fR looks in the current directory for a font map
+called \fImpost.fmp\fR. The \f(CW\*(C`\-\-fontmap\*(C'\fR command-line option tells
+\&\fBpurifyeps\fR to use a different font map, which will typically be the
+\&\fImpost.fmp\fR file that comes with \fBpstoedit\fR.
+.PP
+Once you create purified \s-1EPS\s0 files with \fBpurifyeps\fR, you need to
+instruct \fBpdflatex\fR to use them. The pdfLaTeX configuration of the
+\&\f(CW\*(C`graphics\*(C'\fR and \f(CW\*(C`graphicx\*(C'\fR packages (\fIpdftex.def\fR) normally ignores
+\&\fI.eps\fR files. Putting the following LaTeX code in your document's
+preamble tells \fBpdflatex\fR that all \fI.eps\fR files are in \s-1MPS\s0 format:
+.PP
+.Vb 9
+\& % Tell pdfLaTeX that all .eps files were produced by MetaPost.
+\& \eusepackage{graphicx} % or graphics
+\& \eusepackage{ifpdf}
+\& \eifpdf
+\& \eDeclareGraphicsRule{.eps}{mps}{*}{}
+\& \emakeatletter
+\& \eg@addto@macro\eGin@extensions{,.eps}
+\& \emakeatother
+\& \efi
+.Ve
+.SH "SEE ALSO"
+.IX Header "SEE ALSO"
+\&\fIdvips\fR\|(1), \fIepstopdf\fR\|(1), \fIlatex\fR\|(1), \fImpost\fR\|(1), \fIpdflatex\fR\|(1), \fIpstoedit\fR\|(1)
+.SH "AUTHOR"
+.IX Header "AUTHOR"
+Scott Pakin, \fIscott+peps@pakin.org\fR
diff --git a/support/purifyeps/purifyeps.pdf b/support/purifyeps/purifyeps.pdf
new file mode 100644
index 0000000000..43827d1736
--- /dev/null
+++ b/support/purifyeps/purifyeps.pdf
Binary files differ