[comp.sources.x] v02i020: draw and edit diagrams, figures and pictures, Patch2

mikew@wyse.wyse.com (Mike Wexler) (11/24/88)

Submitted-by: Mark Moraes <moraes%csri.toronto.edu@RELAY.CS.NET>
Posting-number: Volume 2, Issue 20
Archive-name: xpic/patch2



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# If this archive is complete, you will see the following message at the end:
#		"End of shell archive."
#
# Contents:
#   x2tex.manX x2tex.script x2tpic.manX x2tpic.c xtp.c xtp.h
#   doc/tex doc/tex/Makefile doc/tex/funstuff.tex doc/tex/funstuff.x
#   doc/tex/funstuff.xpic doc/tex/node.x doc/tex/texwarning.x
#   doc/tex/xpic.aux doc/tex/xpic.tex fontdesc/x2tpic
#
# Wrapped by moraes@csri.toronto.edu on Wed Nov 16 04:36:58 1988
#
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f x2tex.manX -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"x2tex.manX\"
else
echo shar: Extracting \"x2tex.manX\" \(1265 characters\)
sed "s/^X//" >x2tex.manX <<'END_OF_x2tex.manX'
X.TH X2TEX 1  "30 October 1988"
X.SH NAME
Xx2tex \- convert an xpic file to TeX \\special format
X.SH SYNOPSIS
X.B x2tex
X[-s \fIscale\fP] [-f \fImaximum fonts\fP] [-d] [-n] [\fIfilename\fP] ....
X.SH DESCRIPTION
X.B x2tex
Xconverts the indicated files (output by the xpic picture-drawing program)
Xinto TeX format. The files will be given \fI.x\fP extensions if none
Xare provided.
XThe output is stored in file.tex. An intermediate file, file.pic, is
Xalso created. The picture is included into your LaTeX or TeX document with
Xthe sequence
X.br
X\\input{file}
X.br
X\\centerline{\\box\\graph}
X.br
X(Instead of \\centerline, any of the TeX primitives for manipulating
Xobjects may be used, if the picture is not to be centered).
X.PP
X.B Note: x2tex is a shell script which simply invokes x2tpic and tpic.
XTpic produces \\special codes which are passed through TeX to be translated
Xby the output driver. These codes are also interpreted by the
X.IR dvix " and " texx
XTeX previewers for the X Windows system. (Version 11)
X.PP
XThe -d (debugging) and -n (no scale) options are passed to
X.I tpic.
XAll the remaining options are passed to 
X.I x2tpic.
X.SH SEE ALSO
Xxpic(x), x2tpic(x), x2pic(x), tpic(x), dvix(x), texx(x).
X.br
XB. W. Kernighan,
X.I "PIC \(em A Graphics Language for Typesetting"
END_OF_x2tex.manX
if test 1265 -ne `wc -c <x2tex.manX`; then
    echo shar: \"x2tex.manX\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f x2tex.script -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"x2tex.script\"
else
echo shar: Extracting \"x2tex.script\" \(881 characters\)
sed "s/^X//" >x2tex.script <<'END_OF_x2tex.script'
X#!/bin/sh
X# Simple shell script to perform the two steps (x2tpic, tpic) to get from
X# file,.x or file.xpic to file.tex. Inspired by, and cannibalized from
X# an earlier version by Stephen Bellantoni.
Xif test $# -lt 1 ; then
X	echo "Usage: x2tex file ...    --- converts file.x to file.tex"
X	exit 1
Xfi
Xxoptions= 
Xtoptions= 
Xfiles= 
Xwhile test $# != 0
Xdo	case "$1" in
X	-s|-f) xoptions="$xoptions $1 $2"; shift ;;
X	-n|-d) toptions="$toptions $1" ;;
X	-*) xoptions="$xoptions $1" ;; # assume unknown options go to x2tpic
X	*) files="$files $1" ;;
X	esac
X	shift
Xdone
Xfor arg in $files
Xdo
X	xfile=`expr $arg : '\([^\.]*\)\.'`
X	if [ x"$xfile" = x ]; then
X		# No extension - add a .x
X		pfile=$arg
X		xfile=$arg.x
X	else
X		pfile=$xfile
X		xfile=$arg
X	fi
X	if [ -f "$xfile" ]; then
X		x2tpic $xoptions $xfile > $pfile.pic
X		tpic $toptions $pfile.pic
X	else
X		echo No file.x specified.
X		exit 1
X	fi
Xdone
END_OF_x2tex.script
if test 881 -ne `wc -c <x2tex.script`; then
    echo shar: \"x2tex.script\" unpacked with wrong size!
fi
chmod +x x2tex.script
# end of overwriting check
fi
if test -f x2tpic.manX -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"x2tpic.manX\"
else
echo shar: Extracting \"x2tpic.manX\" \(2049 characters\)
sed "s/^X//" >x2tpic.manX <<'END_OF_x2tpic.manX'
X.TH X2TPIC L
X.SH NAME
Xx2tpic - convert figures stored in \fIxpic\fP format to tpic (pic for TeX).
X.SH SYNOPSIS
X.B x2tpic
X[-s \fIscale\fP] [-f \fImaximum fonts\fP] [\fIfilename\fP] ....
X.SH DESCRIPTION
X.I X2tpic
Xtakes the given 
X.I xpic 
Xfile (default is the standard input) and
Xproduces corresponding tpic on the standard output. This can
Xthen be printed by passing it through 
Xthe 
X.I tpic
Xpreprocessor
Xand then through 
X.I TeX
Xand its postprocessing filters
Xto output devices like laser printers.
X.SH OPTIONS
X.IR -s " scale"
Xscales the picture by 
X.I scale, 
Xwhich is a floating point number. Text doesn't scale very well. (eg) 
X.I -s 0.5
Xwill scale the picture to half its size.
X.PP
X.IR -f " numfonts"
Xsets the maximum number of fonts that can be stored. The default is enough
Xunless the users 
X.I ~/.x2tpic 
Xhas a lot of font mappings.
X.SH "SEE ALSO"
X.IR xpic (L)
Xis what generates the files for 
X.I x2tpic
Xto convert.
X.br
X.IR x2ps (L)
Xis another filter for converting 
X.I xpic 
Xoutput to
X.I PostScript(tm)
Xformat.
X.br
X.IR tpic (L)
Xis a preprocessor for 
X.I TeX
Xto permit inclusion of pic in 
X.I TeX
Xdocuments. 
X.br
XThe 
X.I pic
Xlanguage is described in
X.I "PIC \(em A Graphics Language for Typesetting"
Xby B. W. Kernighan.
X.br
XSee the local guide for 
X.I LaTeX
Xand the examples in DOCDIR and DOCDIR/tex.
X.SH TRADEMARKS
XPostScript is a registered trademark of Adobe Systems, Inc.
X.SH FILES
X.I x2tpic
Xlooks at 
X.I XPICLIBDIR/fontdesc/x2tpic
Xand at 
X.I ~/.x2tpic 
Xto find font mappings.
X.SH CAVEATS
XMany versions of pic/tpic have a nasty bug in which the 
X.I scale
Xvariable is not reset between consecutive pictures. Since xpic uses
X.I scale 
Xin its pictures, (eg)
X.I scale = 80,
Xthe next picture will start off at this scale, and will therefore be
Xfurther shrunk if it is an xpic picture, or just shrunk if it is any
Xother picture, like a graph. Get someone to fix pic/tpic, or x2pic (which
Xhas a BROKENPIC ifdef to deal with this).
X.PP
XPic does NOT do patterned splines, ellipses or circles - xpic does.
XThis is a pic 'feature', not an xpic bug.
END_OF_x2tpic.manX
if test 2049 -ne `wc -c <x2tpic.manX`; then
    echo shar: \"x2tpic.manX\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f x2tpic.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"x2tpic.c\"
else
echo shar: Extracting \"x2tpic.c\" \(13035 characters\)
sed "s/^X//" >x2tpic.c <<'END_OF_x2tpic.c'
X/* $Header: x2tpic.c,v 1.1 88/11/04 23:30:12 moraes Exp $ */
X#include <stdio.h>
X#include <ctype.h>
X#include "xpic.h"
X#include "tune.h"
X#include "xtp.h"
X
X/*
X* This program reads in a file in xpic formats and outputs a file
X* which, when given as input to tpic, will produce a TeX format
X* file with the xpic picture.
X* The difference from x2pic is that strings are written in
X* the form "{\twelverm datastring}" instead of "\fR\s12datastring\fP".
X* Furthermore, when a font is encountered, a string of the form
X* "\font\eighteenrm cmr10 scaled1800" is written after the ".PE";
X* this will pass through tpic and initialize the font when it gets to
X* TeX.
X*/
X
X/*
X *  Define this is your pic does not reset the scale between consecutive
X *  pictures, resulting in successive xpic pictures in a document
X *  shrinking more and more - or apply pic.fix to your pic source, if
X *  you have it - or complain to your pic vendor.
X */
X/* define BROKENPIC */
X
X/* To do:
X	2. Allow some sort of scaling and positioning arguments.
X */
X
X#define MAXFONTS 127
X#define FONTDESCFILE "x2tpic"
X
X#define STRNEQ(s1, s2, n)	((*s1)==(*s2) && strncmp(s1, s2, n) == 0)
X
Xextern char *malloc();
Xextern char *calloc();
X
X#define xtransform(x)	((double) ((x) - orgX))
X#define ytransform(y)	((double) (picHeight - (y)))
X
Xstatic int orgX, orgY, picWidth, picHeight, delX, delY;
X
Xstatic double width, height;
Xstatic double x, y;
Xstatic char *style_words[NSTYLES] = {
X	"", "dotted", "dashed", "dashed 0.1 * scale", "dashed 0.15 * scale"
X};
Xstatic int style;
Xstatic int linewidth = 0;
X
Xstatic char *halign_words[] = {
X	"", "ljust", "rjust"
X};
Xstatic int halign;
Xstatic int valign;
X
Xstatic char *arrows[] = {
X	"", "<-", "->", "<->"
X};
Xstatic int arrow_type;
Xstatic char *name;
Xstatic double picScale = 1.0;
X
Xstatic int nfonts = MAXFONTS;
Xstruct fontinfo *availfonts;
Xint navailfonts;
X
Xextern int optind;
Xextern char *optarg;
X
X
Xstatic void ChangeThickness(t)
X{
X	if (linewidth != t) {
X		linewidth = t;
X		if (linewidth == 0)
X			fprintf(outFile, ".ps 10\n");
X		else
X			fprintf(outFile, ".ps %d\n", linewidth * 20);
X	}
X}
X
Xstatic void MakeBox(x1, y1, x2, y2, attr)
X{
X	style = getlinestyle(attr);
X	if ((style < 0) || (style >= NSTYLES)) {
X		fprintf(stderr, "Unknown style - %d\n", style);
X		style = 0;
X	}
X	width = x2 - x1;
X	height = y2 - y1;
X	x = xtransform(((double) (x1 + x2)) / 2.0);
X	y = ytransform(((double) (y1 + y2)) / 2.0);
X	fprintf(outFile, "box %s wid %g ht %g at %g, %g\n", 
X	 style_words[style], width, height, x, y);
X}
X
X
X/* Ellipses and circles have no attributes in pic - not yet, anyway. */
X/*ARGSUSED*/
Xstatic void MakeEllipse(xc, yc, xr, yr, attr, x1, y1, x2, y2)
X{
X	if (attr != 0) {
X		fprintf(stderr, "warning: ellipses have no attributes in pic\n");
X	}
X	width = 2.0 * xr;
X	height = 2.0 * yr;
X	x = xtransform((double) xc);
X	y = ytransform((double) yc);
X	fprintf(outFile, "ellipse wid %g ht %g at %g, %g\n", 
X	 width, height, x, y);
X}
X
X/*ARGSUSED*/
Xstatic void MakeCircle(xc, yc, r, attr, x1, y1, x2, y2)
X{
X	if (attr != 0) {
X		fprintf(stderr, "warning: circles have no attributes in pic\n");
X	}
X	x = xtransform((double) xc);
X	y = ytransform((double) yc);
X	fprintf(outFile, "circle radius %d at %g, %g\n", 
X	 r, x, y);
X}
X
X
X/*
X *  print out a string, escaping '"' with a \ - we don't escape \, to
X *  give people a mechanism for sending strange numbers to the lw
X */
Xstatic void PrintText(s)
Xchar *s;
X{
X	register char *cp = s;
X
X	for(; *cp != 0; cp++) {
X		if (isascii(*cp) && isprint(*cp)) {
X 			if (*cp != '"')
X		 		(void) fputc(*cp, outFile);
X			else
X				(void) fprintf(outFile, "\\%c", *cp);
X		} else {
X			/* We don't want to print these! */
X			(void) fprintf(stderr, "Ignoring weird character \\%o in \"%s\"", 
X				*cp & 0xff, s);
X		} 
X	}
X}
X			
X
X/*ARGSUSED*/
Xstatic void MakeText(s, len, font, size, attr, xc, yc, x1, y1, x2, y2)
Xchar *s;
Xchar *font;
X{
X	if (size < 0) {
X		fprintf(stderr, "Incorrect font size %d\n", size);
X		size = 10;
X	}
X	valign = gettext_valign(attr);
X	if ((valign < 0) || (valign >= 3)) {
X		fprintf(stderr, "Incorrect vert alignment %d\n", valign);
X		valign = 0;
X	}
X	halign = gettext_halign(attr);
X	if ((halign < 0) || (halign >= 3)) {
X		fprintf(stderr, "Incorrect horiz. alignment %d\n", halign);
X		halign = 0;
X	}
X	size = (int) (picScale * size);
X	x = xtransform(xc);
X	switch (valign) {
X	case 0: /* MIDLINE */
X		y = ytransform( yc );
X		break;
X	case 1: /* TOPLINE */
X		y = ytransform( yc + ((double) (y2 - y1)) / 2.0 );
X		break;
X	case 2: /* BOTLINE */
X		y = ytransform( yc - ((double) (y2 - y1)) / 2.0 );
X		break;
X	}
X	/* FIX FOR TeX */
X	fprintf(outFile, "\"{%s ", ChangeFont( font, size) );
X	PrintText(s);
X	fprintf(outFile, " }\" %s at %g, %g\n", halign_words[halign], x, y);
X}
X	
X
X/*ARGSUSED*/
Xstatic void StartLine(xc, yc, n, attr, type)
X{
X	arrow_type = getlinearrow(attr);
X	if ((arrow_type < 0) || (arrow_type >= 4)) {
X		fprintf(stderr, "Unknown arrow type %d\n", arrow_type);
X		arrow_type = 0;
X	}
X	style = getlinestyle(attr);
X	if ((style < 0) || (style >= NSTYLES)) {
X		fprintf(stderr, "Unknown style - %d\n", style);
X		style = 0;
X	}
X	x = xtransform(xc);
X	y = ytransform(yc);
X	name = "line";
X	if (type != LINE) {
X		name = "spline";
X		if (style != 0) {
X			fprintf(stderr, "warning: splines have no attributes in pic\n");
X			style = 0;
X		}
X	}
X	fprintf(outFile, "%s %s %s from %g, %g ",
X	 name, arrows[arrow_type], style_words[style], x, y);
X}
X
X
Xstatic void NextAt(xc, yc)
X{
X	x = xtransform(xc);
X	y = ytransform(yc);
X	fprintf(outFile, "\\\n\tto %g, %g ", x, y);
X}
X
X
Xstatic void EndLine()
X{
X	fprintf(outFile, "\n");
X}
X
X/*
X *  Read in a file output by xpic, and emit the appropriate pic text
X */
Xstatic void convert()
X{
X	int type;
X	int xc, yc, xr, yr, len, attr;
X	int size;
X	int x1, y1, x2, y2;
X	char *s;
X	int c, i, n;
X	int err, nf, gs;
X	double width, height;
X	double x, y;
X	int num, thickness;
X	char font[MAXSTR];
X
X
X#define INPERR 2
X#define INPEOF 3
X
X	err = 0;
X#ifdef MAGIC
X	/* Check for the magic header that the new xpic puts out */
X	if ((c = fgetc(inFile)) == EOF) {
X		fprintf(stderr, "Incorrect input format");
X		return;
X	}
X	ungetc(c, inFile);
X	if (c == '#') {
X		/* Magic header - ignore */
X		fscanf(inFile, "%*[^\n]");
X	}
X#endif MAGIC
X	/* Read in (and ignore) the gel bounding box */
X	(void) fscanf(inFile, " %d %d %d %d %d", &x1, &y1, &x2, &y2, &gs);
X	/* Set up constants for scaling, translation etc. */
X	orgX = x1;
X	orgY = y1;
X	delX = x2 - x1;
X	delY = y2 - y1;
X	picWidth = x2;
X	picHeight = y2;
X	fprintf(outFile, ".PS\nscale = %lg\n", (double) (gs * 10 / picScale));
X	/* Read in the actual picture */
X	do {
X		if ((nf = fscanf(inFile, " %d", &type)) != 1) {
X			err = INPEOF;
X			break;
X		}
X		nf = fscanf(inFile, " %d %d %d %d %d %x %d", &num, &x1, &y1, 
X		 &x2, &y2, &attr, &thickness);
X		if (nf != 7) {
X			err = INPERR;
X			break;
X		}
X		ChangeThickness(thickness);
X		switch (type) {
X		case BOX:
X			MakeBox(x1, y1,x2, y2, attr);
X			break;
X		case ELLIPSE:
X			nf = fscanf(inFile, " %d %d %d %d", &xc, &yc, &xr, &yr) ;
X			if (nf != 4) {
X				err = INPERR;
X				break;
X			}
X			MakeEllipse(xc, yc, xr, yr, attr, x1, y1, x2, y2);
X			break;
X		case CIRCLE:
X			nf = fscanf(inFile, " %d %d %d", &xc, &yc, &xr);
X			if (nf != 3) {
X				err = INPERR;
X				break;
X			}
X			MakeCircle(xc, yc, xr, attr, x1, y1, x2, y2);
X			break;
X		case TEXT:
X			nf = fscanf(inFile, " %d %d %d %s %d", &xc, &yc, &len, font, 
X			 &size);
X			if (nf != 5) {
X				err = INPERR;
X				break;
X			}
X			/*
X			 *  For backward compatibility with the bad old days. The
X			 *  old convention of storing font information was really
X			 *  ugly - a font number from 0-3, (corresponding to Roman,
X			 *  Bolld, Italic, Special) and a size from 0-9
X			 *  (corresponding to point sizes 6 - 24)
X			 */
X			if (font[1] == '\0') {
X				int oldfontconvention = TRUE;
X				
X				switch (font[0]) {
X				case '0':
X					strcpy(font, "Roman");
X					break;
X				case '1':
X					strcpy(font, "Bold");
X					break;
X				case '2':
X					strcpy(font, "Italic");
X					break;
X				case '3':
X					strcpy(font, "Special");
X					break;
X				default:
X					/* Must a new font with a one letter name. Eeep! */
X					oldfontconvention = FALSE;
X				}
X				if (oldfontconvention)
X					/* Convert to pointsize */
X					size = size * 2 + 6;
X			}
X			/* Go to the next line */
X			while ((c = fgetc(inFile)) != '\n' && c != EOF)
X				;
X			if (c == EOF) {
X				err = INPERR;
X				break;
X			}
X			if (( s = malloc(len + 2)) == NULL) {
X				fprintf("No more memory for text string");
X				break;
X			}
X			if (fgets(s, len + 1, inFile) == NULL) {
X				free(s);
X				err = INPERR;
X				break;
X			}
X			s[len] = '\0';
X			MakeText(s, len, font, size, attr, xc, yc, x1, y1, x2, y2);
X			free(s);
X			break;
X		case LINE:
X		case SPLINE:
X			if (fscanf(inFile, " %d %d %d", &n, &xc, &yc) != 3) {
X				err = INPERR;
X				break;
X			}
X			StartLine(xc, yc, n, attr, type);
X			for (i = 1; i < n; i++) {
X				if (fscanf(inFile, " %d %d", &xc, &yc) != 2) {
X					err = INPERR;
X					break;
X				}
X				NextAt(xc, yc);
X			}
X			if (err != INPERR)
X				EndLine();
X			break;
X		}
X	} while (err == 0);
X	fprintf(outFile, ".PE\n");
X#ifdef BROKENPIC
X	fprintf(outFile, ".PS\nscale = 0\n.PE\n");
X#endif
X	if (err == INPERR)
X		fprintf(stderr, "Incorrect input format");
X
X	/* FIX FOR TeX */
X	fflush(outFile);
X	rewind(outFile);
X	PutTexFontPostScript(stdout);
X	copystuff(outFile, stdout);
X	rewind(outFile);
X
X	return;
X
X#undef INPEOF
X#undef INPERR
X}
X
Xcopystuff(from, to)
XFILE *from;
XFILE *to;
X{
X	char s[BUFSIZ];
X	
X	while(fgets(s, sizeof(s), outFile) != NULL)
X		fputs(s, stdout);
X
X}
X
Xusage(s)
Xchar *s;
X{
X	fprintf(stderr, "Usage: %s [-s scale] [-f maxfonts] [filename]\n", s);
X	exit(-1);
X}
X
Xchar *
Xgetword(cpp)
Xchar **cpp;
X{
X	register char *cp = *cpp;
X	char *s;
X
X	while(*cp != '\0' && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
X		cp++;
X	if (*cp == '\0')
X		return(NULL);
X	s = cp;
X	while(*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
X		cp++;
X	*cp++ = '\0';
X	*cpp = cp;
X	return(s);
X}
X
X
X/* Font tables are of the form
X        xpic-font-name point-size tex-font-string real-tex-font how-to-scale
X   (eg)
X        Roman 12 twelverm cmr10 magstep1
X        Helvetica 24 twfourhelv PS-Helvetica pointsize24
X */
X
Xstatic char *pointsize = "pointsize";
Xstatic char *curparse;
X
Xreadfonttable(file)
Xchar *file;
X{
X	FILE *fp;
X	int size, texsize;
X	char *s1, *s2, *s3, *s4, *s5, *s;
X	extern char *strsave();
X	char buf[MAXSTR*4];
X	char fbuf[MAXSTR];
X	int nlines = 0;
X	struct fontinfo *font = availfonts;
X	
X	if ((fp = fopen(file, "r")) == NULL)
X		return;
X	while(fgets(buf, sizeof(buf), fp) != NULL) {
X		nlines++;
X		if ((curparse = index(buf, '#')) != NULL)
X			*curparse = '\0';
X		curparse = buf;
X		if ((s1 = getword(&curparse)) == NULL)
X			continue;
X		if ((s2 = getword(&curparse)) == NULL || (size = atoi(s2)) <= 0)
X			goto complain;
X		if ((s3 = getword(&curparse)) == NULL || *s3 != '\\')
X			goto complain;
X		if ((s4 = getword(&curparse)) == NULL)
X			goto complain;
X		s5 = getword(&curparse);
X		if (navailfonts == nfonts) {
X			fprintf(stderr, "Too many fonts - max %d. Use -f to raise it\n",
X			 nfonts);
X			exit(-1);
X		}
X		if (s5 == NULL) {
X			s = strsave(s4);
X		} else if (STRNEQ(s5, pointsize, 9)) {
X			s5 += 9;
X			if ((texsize = atoi(s5)) == 0)
X				goto complain;
X			sprintf(fbuf, "%s at %dpt", s4, texsize);
X			s = strsave(fbuf);
X		} else {
X			sprintf(fbuf, "%s scaled %s", s4, s5);
X			s = strsave(fbuf);
X		}
X#ifdef DEBUG
X		fprintf(stderr, "Adding mapping %s, %d, %s, %s\n", s1, size, s3, s);
X#endif
X		font->style = strsave(s1);
X		font->size = size;
X		font->texname = strsave(s3);
X		font->texfontinit = s;
X		font->refcnt = 0;
X		font++;
X		navailfonts++;
X		continue;
Xcomplain:
X		fprintf(stderr, "Bad syntax on line %d, file %s somewhere at \"%s\"\n",
X		 nlines, file, curparse);
X	}
X	fclose(fp);
X}
X
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X	double atof();
X	int c;
X	char fontfile[MAXSTR];
X	char *hdir;
X	char *getenv();
X	char tempfilename[MAXSTR];
X	
X	progname = argv[0];
X	inFile = stdin;
X	(void) sprintf(tempfilename, "%s/x2tpic%d", DUMPDIR, getpid());
X	if ((outFile = fopen(tempfilename, "w+")) == NULL) {
X		fprintf(stderr, "Can't open %s for update\n", tempfilename);
X		exit(-1);
X	}
X#ifndef DEBUG
X	unlink(tempfilename);	/* So the file goes away when the program dies */
X#endif
X	while((c = getopt(argc, argv, "s:f:")) != EOF) {
X		switch (c) {
X		case 's':
X			picScale = atof(optarg);
X			break;
X		case 'f':
X			nfonts = atoi(optarg);
X			break;
X		case '?':
X			usage(progname);
X			break;
X		}
X	}
X
X	HashInit(nfonts);
X	availfonts = (struct fontinfo *) calloc(nfonts, sizeof(struct fontinfo));
X	if (availfonts == NULL) {
X		fprintf(stderr, "Can't allocate font table of %d elements.\n", nfonts);
X		exit(-1);
X	}
X	navailfonts = 0;
X	sprintf(fontfile, "%s/fontdesc/%s", LIBDIR, FONTDESCFILE);
X	readfonttable(fontfile);
X	if (hdir = getenv("HOME")) {
X		sprintf(fontfile, "%s/.%s", hdir, FONTDESCFILE);
X		readfonttable(fontfile);
X	}
X	/* Must have some files */
X	if (optind >= argc) {
X		convert();
X	} else {
X		while (optind < argc) {
X			if ((inFile = fopen(argv[optind], "r")) == NULL) {
X				fprintf(stderr, "Can't open %s for reading\n", 
X				 argv[optind]);
X				break;
X			}
X			convert();
X			optind++;
X		}
X	}
X	exit(0);
X}
END_OF_x2tpic.c
if test 13035 -ne `wc -c <x2tpic.c`; then
    echo shar: \"x2tpic.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f xtp.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"xtp.c\"
else
echo shar: Extracting \"xtp.c\" \(2128 characters\)
sed "s/^X//" >xtp.c <<'END_OF_xtp.c'
X#ifndef lint
Xstatic char *rcsid = "$Header: xtp.c,v 1.1 88/11/04 23:31:10 moraes Exp $";
X#endif
X
X#include <stdio.h>
X#include "xpic.h"	/* Just for ABS and STREQ - Yechh */
X#include "xtp.h"
X
Xchar *def_font = "Roman";
X
Xchar *
XChangeFont(style, size)
Xchar *style;
Xint size;
X{
X	extern char *HashSearch();
X	extern char *strsave();
X	extern char *sprintf();
X	struct fontinfo *fp;
X	struct fontinfo *FindClosestFont();
X	char buf[64];
X
X	(void) sprintf(buf, "%s.%d", style, size);
X	fp = (struct fontinfo *) HashSearch(buf);
X
X	if (fp != NULL) {
X		/* We used it before, so it is cached in the hash table */
X#ifdef DEBUG
X		fprintf(stderr, "%s cached as %s\n", buf, fp->texname);
X#endif
X		return(fp->texname);
X	}
X		
X	/* 
X	 *  We haven't cached the font, so we search for it in the list,
X	 *  cache the nearest font we find under it's name. Also increase
X	 *  the reference count so we know that it's been used
X	 */
X	fp = FindClosestFont(style, size);
X	HashInsert(strsave(buf), (char *) fp);
X	fp->refcnt++;
X#ifdef DEBUG
X	fprintf(stderr, "%s maps to %s\n", buf, fp->texname);
X#endif
X	return(fp->texname);
X}
X
X
Xstruct fontinfo *
XFindClosestFont(style, size)
Xchar *style;
Xint size;
X{
X	register struct fontinfo *fp = availfonts;
X	struct fontinfo *closest = NULL;
X	register int n = navailfonts;
X	register int bestdelta = 99999;
X	register int delta;
X
X	while(n-- > 0) {
X		delta = ABS(fp->size - size);
X		if (delta <= bestdelta &&
X		 (STREQ(style, fp->style) || STREQ(def_font, fp->style))) {
X		 	closest = fp;
X			bestdelta = delta;
X		 }
X		fp++;
X	}
X	if (bestdelta == 0 && STREQ(closest->style, style)) {
X		return(closest);
X	} else if (closest != NULL) {
X		(void) fprintf(stderr,
X		 "Couldn't find font \"%s\" in size %d - using \"%s\" in %d instead\n",
X		 style, size, closest->style, closest->size);
X	} else {
X		(void) fprintf(stderr, "Help - couldn't find any fonts.\n");
X		exit(-1);
X	}
X	return(closest);
X}
X
Xvoid
XPutTexFontPostScript( fd)
XFILE *fd;
X{
X	register struct fontinfo *fp = availfonts;
X	register int n = navailfonts;
X	
X	while(n-- > 0) {
X		if (fp->refcnt > 0)
X			(void)fprintf(fd, "\\font%s = %s\n", fp->texname, fp->texfontinit);
X		fp++;
X	}
X}
END_OF_xtp.c
if test 2128 -ne `wc -c <xtp.c`; then
    echo shar: \"xtp.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f xtp.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"xtp.h\"
else
echo shar: Extracting \"xtp.h\" \(460 characters\)
sed "s/^X//" >xtp.h <<'END_OF_xtp.h'
X/* Find closest TeX font we know about. */
Xextern char *ChangeFont( /* style, size */);
X
X/* Write "\font\twelverm cmr10 scaled \magstep1" etc for each font used. */
Xextern void PutTexFontPostScript( /* fd */);
X
X/* structure for mapping xpic fonts to TeX initialization commands */
Xstruct fontinfo {
X	char *style;
X	int size;
X	char *texname;
X	char *texfontinit;
X	int refcnt;
X};
X
Xextern struct fontinfo *availfonts;
Xextern int navailfonts;
Xextern char *def_font;
END_OF_xtp.h
if test 460 -ne `wc -c <xtp.h`; then
    echo shar: \"xtp.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test ! -d doc/tex ; then
    echo shar: Creating directory \"doc/tex\"
    mkdir doc/tex
fi
if test -f doc/tex/Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/Makefile\"
else
echo shar: Extracting \"doc/tex/Makefile\" \(745 characters\)
sed "s/^X//" >doc/tex/Makefile <<'END_OF_doc/tex/Makefile'
X#DVI2PS = /local/src/tex/drivers/dvi2ps.3.13/driver/src/dvi2ps
XDVI2PS=dvi2ps
XX2PS=x2ps
XX2TPIC=x2tpic
X
Xfirst: xpic.ps
X
Xclean:
X	rm -f *.dvi *.log *.o x2tpic *.ps *.pic node.tex shrunknode.tex *~. \#*
X
Xxpic.ps: xpic.dvi 
X	rm -f xpic.ps
X	dvi2ps xpic > xpic.ps
X
Xtexwarning.ps: texwarning.x
X	rm -f texwarning.ps
X	x2ps texwarning.x > texwarning.ps
X
Xfunstuff.ps: funstuff.x
X	rm -f funstuff.ps
X	x2ps funstuff.x > funstuff.ps
X
Xnode.tex: node.pic
X	tpic node.pic
X
Xnode.pic: node.x
X	rm -f node.pic
X	x2tpic node.x > node.pic
X
Xshrunknode.tex: shrunknode.pic
X	tpic shrunknode.pic
X
Xshrunknode.pic: node.x
X	rm -f shrunknode.pic
X	x2tpic -s 0.6 node.x > shrunknode.pic
X
Xxpic.dvi: xpic.tex node.tex shrunknode.tex texwarning.ps funstuff.ps 
X	rm -f xpic.dvi
X	lt xpic
END_OF_doc/tex/Makefile
if test 745 -ne `wc -c <doc/tex/Makefile`; then
    echo shar: \"doc/tex/Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/tex/funstuff.tex -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/funstuff.tex\"
else
echo shar: Extracting \"doc/tex/funstuff.tex\" \(1899 characters\)
sed "s/^X//" >doc/tex/funstuff.tex <<'END_OF_doc/tex/funstuff.tex'
X\font\Xtenrm = cmr10
X\catcode`@=11
X\expandafter\ifx\csname graph\endcsname\relax \alloc@4\box\chardef\insc@unt\graph\fi
X\catcode`@=12
X\setbox\graph=\vtop{%
X  \baselineskip=0pt \lineskip=0pt \lineskiplimit=0pt
X  \vbox to0pt{\hbox{%
X    \special{pn 8}%
X    \rlap{\kern  2.462in\lower 1.078in\hbox to 0pt{\hss {\Xtenrm A }\hss}}%
X    \rlap{\kern  2.374in\lower 0.316in\hbox to 0pt{\hss {\Xtenrm B }\hss}}%
X    \rlap{\kern  1.762in\lower 0.716in\hbox to 0pt{\hss {\Xtenrm c }\hss}}%
X    \rlap{\kern  1.262in\lower 0.716in\hbox to 0pt{\hss {\Xtenrm c }\hss}}%
X    \rlap{\kern  0.700in\lower 0.366in\hbox to 0pt{\hss {\Xtenrm B }\hss}}%
X    \rlap{\kern  0.600in\lower 1.078in\hbox to 0pt{\hss {\Xtenrm A }\hss}}%
X    \special{pa 37 12}%
X    \special{pa 1549 12}%
X    \special{pa 1549 2999}%
X    \special{pa 3024 3011}%
X    \special{pa 3036 1487}%
X    \special{pa 25 1499}%
X    \special{pa 14 13}%
X    \special{pa 1563 13}%
X    \special{pa 1552 3012}%
X    \special{pa 16 3024}%
X    \special{pa 5 1513}%
X    \special{pa 3054 1489}%
X    \special{pa 3043 3}%
X    \special{pa 1582 15}%
X    \special{pa 1533 1502}%
X    \special{pa 1533 1502}%
X    \special{sp}%
X    \special{ar 575 1512 550 799  0.000  6.283}%
X    \special{ar 2474 1512 550 799  0.000  6.283}%
X    \special{pn 40}%
X    \special{ar 1512 2374 612 612  0.000  6.283}%
X    \special{ar 1525 625 612 612  0.000  6.283}%
X    \special{pn 10}%
X    \special{pa 25 12}%
X    \special{pa 3024 3012}%
X    \special{da  0.150}%
X    \special{pa 25 3012}%
X    \special{pa 3024 12}%
X    \special{da  0.150}%
X    \special{pa 25 3012}%
X    \special{pa 3024 3012}%
X    \special{da  0.001}%
X    \special{pa 3024 3012}%
X    \special{pa 3024 12}%
X    \special{da  0.001}%
X    \special{pa 3024 12}%
X    \special{pa 25 12}%
X    \special{da  0.001}%
X    \special{pa 25 12}%
X    \special{pa 25 3012}%
X    \special{da  0.001}%
X    \kern  3.055in
X  }\vss}%
X  \kern  3.025in
X}
END_OF_doc/tex/funstuff.tex
if test 1899 -ne `wc -c <doc/tex/funstuff.tex`; then
    echo shar: \"doc/tex/funstuff.tex\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/tex/funstuff.x -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/funstuff.x\"
else
echo shar: Extracting \"doc/tex/funstuff.x\" \(737 characters\)
sed "s/^X//" >doc/tex/funstuff.x <<'END_OF_doc/tex/funstuff.x'
X#! /local/bin/X11/xpic
X198 119 442 361 8
X6 23 391 192 399 204 0 0
X395 202 1 Roman 10
XA
X6 22 384 131 392 143 0 0
X388 141 1 Roman 10
XB
X6 20 336 163 343 175 0 0
X339 173 1 Roman 10
Xc
X6 19 296 163 303 175 0 0
X299 173 1 Roman 10
Xc
X6 18 250 135 258 147 0 0
X254 145 1 Roman 10
XB
X6 17 242 192 250 204 0 0
X246 202 1 Roman 10
XA
X2 16 198 119 442 361 0 0
X16
X 201 120 322 120 322 359 440 360
X 441 238 200 239 199 120 323 120
X 322 360 199 361 198 240 442 238
X 441 119 324 120 320 239 320 239
X5 15 200 176 288 304 0 0
X244 240 44 64
X5 14 352 176 440 304 0 0
X396 240 44 64
X4 13 270 260 368 358 1 2
X319 309 49
X4 12 271 120 369 218 1 2
X320 169 49
X1 3 200 120 440 360 4 0
X2
X 200 120 440 360
X1 2 200 120 440 360 4 0
X2
X 200 360 440 120
X3 1 200 120 440 360 2 0
END_OF_doc/tex/funstuff.x
if test 737 -ne `wc -c <doc/tex/funstuff.x`; then
    echo shar: \"doc/tex/funstuff.x\" unpacked with wrong size!
fi
chmod +x doc/tex/funstuff.x
# end of overwriting check
fi
if test -f doc/tex/funstuff.xpic -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/funstuff.xpic\"
else
echo shar: Extracting \"doc/tex/funstuff.xpic\" \(737 characters\)
sed "s/^X//" >doc/tex/funstuff.xpic <<'END_OF_doc/tex/funstuff.xpic'
X#! /local/bin/X11/xpic
X198 119 442 361 8
X6 23 391 192 399 204 0 0
X395 202 1 Roman 10
XA
X6 22 384 131 392 143 0 0
X388 141 1 Roman 10
XB
X6 20 336 163 343 175 0 0
X339 173 1 Roman 10
Xc
X6 19 296 163 303 175 0 0
X299 173 1 Roman 10
Xc
X6 18 250 135 258 147 0 0
X254 145 1 Roman 10
XB
X6 17 242 192 250 204 0 0
X246 202 1 Roman 10
XA
X2 16 198 119 442 361 0 0
X16
X 201 120 322 120 322 359 440 360
X 441 238 200 239 199 120 323 120
X 322 360 199 361 198 240 442 238
X 441 119 324 120 320 239 320 239
X5 15 200 176 288 304 0 0
X244 240 44 64
X5 14 352 176 440 304 0 0
X396 240 44 64
X4 13 270 260 368 358 1 2
X319 309 49
X4 12 271 120 369 218 1 2
X320 169 49
X1 3 200 120 440 360 4 0
X2
X 200 120 440 360
X1 2 200 120 440 360 4 0
X2
X 200 360 440 120
X3 1 200 120 440 360 2 0
END_OF_doc/tex/funstuff.xpic
if test 737 -ne `wc -c <doc/tex/funstuff.xpic`; then
    echo shar: \"doc/tex/funstuff.xpic\" unpacked with wrong size!
fi
chmod +x doc/tex/funstuff.xpic
# end of overwriting check
fi
if test -f doc/tex/node.x -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/node.x\"
else
echo shar: Extracting \"doc/tex/node.x\" \(952 characters\)
sed "s/^X//" >doc/tex/node.x <<'END_OF_doc/tex/node.x'
X#! /local/bin/X11/xpic
X-21 92 600 288 8
X6 20 375 180 441 194 0 0
X408 192 8 Roman 12
X\nodeeqn
X3 1 296 144 520 248 0 0
X6 9 184 124 248 138 0 0
X216 136 9 Roman 12
X$ w_{1} $
X6 2 552 164 584 178 0 0
X568 176 5 Roman 12
X$ y $
X1 3 520 192 600 192 20 0
X2
X 520 192 600 192
X6 18 -21 268 56 282 2000 0
X56 280 11 Roman 12
X$ x_{n-1} $
X1 17 80 120 296 160 20 0
X3
X 80 120 240 120 296 160
X1 16 80 144 296 168 20 0
X3
X 80 144 240 144 296 168
X1 15 80 240 296 280 20 0
X3
X 80 280 240 280 296 240
X6 14 84 164 157 178 0 0
X120 176 11 Roman 12
X$ \bullet $
X6 13 84 188 157 202 0 0
X120 200 11 Roman 12
X$ \bullet $
X6 12 84 220 157 234 0 0
X120 232 11 Roman 12
X$ \bullet $
X6 11 175 260 258 274 0 0
X216 272 12 Roman 12
X$  w_{n-1} $
X6 10 184 92 248 106 0 0
X216 104 9 Roman 12
X$ w_{0} $
X6 8 -6 108 56 122 2000 0
X56 120 9 Roman 12
X$ x_{0} $
X6 7 -6 132 56 146 2000 0
X56 144 9 Roman 12
X$ x_{1} $
X4 6 64 112 80 128 0 0
X72 120 8
X4 5 64 136 80 152 0 0
X72 144 8
X4 4 64 272 80 288 0 0
X72 280 8
END_OF_doc/tex/node.x
if test 952 -ne `wc -c <doc/tex/node.x`; then
    echo shar: \"doc/tex/node.x\" unpacked with wrong size!
fi
chmod +x doc/tex/node.x
# end of overwriting check
fi
if test -f doc/tex/texwarning.x -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/texwarning.x\"
else
echo shar: Extracting \"doc/tex/texwarning.x\" \(389 characters\)
sed "s/^X//" >doc/tex/texwarning.x <<'END_OF_doc/tex/texwarning.x'
X#! /local/bin/X11/xpic
X184 120 360 360 8
X2 9 184 164 352 236 0 5
X4
X 248 164 352 180 184 216 312 236
X2 5 200 120 360 280 0 0
X9
X 240 160 200 200 240 240 280 280
X 320 240 360 200 320 160 280 120
X 240 160
X1 3 272 268 272 360 0 0
X2
X 272 360 272 268
X1 2 288 268 288 360 0 0
X2
X 288 268 288 360
X1 1 240 360 320 360 0 0
X2
X 320 360 240 360
X1 0 272 120 288 132 0 0
X4
X 272 132 272 120 288 120 288 132
END_OF_doc/tex/texwarning.x
if test 389 -ne `wc -c <doc/tex/texwarning.x`; then
    echo shar: \"doc/tex/texwarning.x\" unpacked with wrong size!
fi
chmod +x doc/tex/texwarning.x
# end of overwriting check
fi
if test -f doc/tex/xpic.aux -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/xpic.aux\"
else
echo shar: Extracting \"doc/tex/xpic.aux\" \(1325 characters\)
sed "s/^X//" >doc/tex/xpic.aux <<'END_OF_doc/tex/xpic.aux'
X\relax 
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {1}Introduction}{1}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {1}{\ignorespaces A simple example. Don't take the warning seriously!}}{1}}
X\newlabel{fig:texwarning}{{1}{1}}
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {2}Psfig/T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX\ }{1}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {2}{\ignorespaces Abstract art. Untitled}}{2}}
X\newlabel{fig:funstuff}{{2}{2}}
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {3}\string\ptt\space Tpic}{3}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {3}{\ignorespaces Computational element or node which forms a weighting sum of $ n $ inputs}}{3}}
X\newlabel{fig:node}{{3}{3}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {4}{\ignorespaces Computational element or node which forms a weighting sum of $ n $ inputs}}{4}}
X\newlabel{fig:shrunknode}{{4}{4}}
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {4}Further Reading}{4}}
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {5}Availability}{5}}
END_OF_doc/tex/xpic.aux
if test 1325 -ne `wc -c <doc/tex/xpic.aux`; then
    echo shar: \"doc/tex/xpic.aux\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/tex/xpic.tex -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/tex/xpic.tex\"
else
echo shar: Extracting \"doc/tex/xpic.tex\" \(10668 characters\)
sed "s/^X//" >doc/tex/xpic.tex <<'END_OF_doc/tex/xpic.tex'
X% Document type: LaTeX
X%
X% $Header: xpic.tex,v 1.2 88/11/04 23:01:46 moraes Exp $
X%
X%  Copyright 1988, Mark Moraes
X%  May be freely used for non-commercial purposes provided acknowledgement
X%  to the source is given.
X%
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X% Specifies the document style.
X\documentstyle[twoside,fullpage,notes]{article}
X
X\def\Ps{Post\-Script}
X\newcommand{\postscript}{Post\-Script\ }
X\newcommand{\psfigtex}{Psfig/\TeX\ }
X\newcommand{\tex}{\TeX\ }
X\newcommand{\nodeeqn}{$ {\displaystyle y = f \left( \sum_{i=1}^{n-1}
Xw_{i} x_{i} - \theta \right)} $}
X
X% From the TeXbook, Appendix E, pg 419
X\def\dbend{{\manual\char127}} % "dangerous bend" sign
X\def\d@nger{\medbreak\begingroup\clubpenalty=10000
X  \def\par{\endgraf\endgroup\mdebreak} \noindent\hang\hangafter=-1
X  \hbox to0pt{\hskip-\hangindent\dbend\hfill}\ninepoint}
X\outer\def\danger{\d@nger}
X
X\input{psfig}
X\title{Including {\tt xpic} figures in \LaTeX}
X\author{Mark Moraes\\
Xmoraes@csri.toronto.edu}
X\date{November 5, 1988}    % Deleting this command produces today's date.
X
X\begin{document}           % End of preamble and beginning of text.
X\maketitle                 % Produces the title.
X
X\section{Introduction}
X
X{\tt Xpic} is a program for drawing figures under {\em the X Window
Xsystem}. It produces a file in a special format. Various programs
Xexist to translate from this format to formats which may be included
Xin \tex documents to eliminate the pains of manual paste-up.
XThis document describes two ways to do just that.
X\begin{figure}[h]
X\centerline{\psfig{figure=texwarning.ps,height=1.5in}}
X\caption{A simple example. Don't take the warning seriously!}
X\label{fig:texwarning}
X\end{figure}
X\section{\psfigtex} The first method is to convert the {\tt xpic}
Xfigure to \postscript and include the \postscript in the document.
XThe conversion is done with the {\tt x2ps} program, which can be run
Xas follows
X\begin{quote}
X\tt
Xx2ps file.x > file.ps
X\end{quote}
Xwhere {\tt file.x} is the {\tt xpic} figure and {\tt file.ps} is the
Xresulting \postscript figure.
X
X\psfigtex is a macro package for \tex that facilitates the inclusion of
Xarbitrary \postscript figures into \tex documents. Figures are
Xautomatically scaled and positioned on the page, and the proper amount
Xof space is reserved. The only restriction is that the \postscript
Xfigures must be {\em well behaved} and
Xmust adhere to the bounding box comment convention.\footnote[1]{
XSee `Appendix J: \Ps\ File Structuring Conventions' in
X{\it The \Ps\ Language Reference Manual}}
X{\tt xpic} follows
Xthis convention, so inclusion of such figures in \psfigtex is easy.
X
XTo include a \Ps\ figure with {\tt psfig}, first load the {\tt psfig}
Xmacros at the beginning of your document with
X\begin{quote}
X{\tt\verb+\input{psfig}+}
X\end{quote}
X\postscript files may then be included in the document using the commands
X\begin{quote}
X\tt
X{\tt\verb+\+psfig\{figure={\it file.ps}\}}
X\end{quote}
XPsfig will automatically position the figure at the current point on the page, 
Xand reserve the proper amount of space in \TeX\ so that it doesn't conflict
Xwith any other objects on the page.
X
XFor example, we included the {\tt xpic} figure in the file {\tt
Xtexwarning.x} as figure \ref{fig:texwarning} by first converting it to the
X\postscript file {\tt texwarning.ps} using the {\tt x2ps} command as
Xfollows ---
X\begin{quote}
X\begin{verbatim}
Xx2ps texwarning.x > texwarning.ps
X\end{verbatim}
X\end{quote}
XWe could then use the commands
X\begin{quote}
X\tt
X\begin{verbatim}
X\begin{figure}[h]
X\centerline{\psfig{figure=texwarning.ps}}
X\caption{A simple example. Don't take the warning seriously!}
X\label{fig:texwarning}
X\end{figure}
X\end{verbatim}
X\end{quote} 
Xto include it as a centered paragraph.  Since no mention
Xof size was made in the above example, \psfigtex draws the figure at
Xits natural size (as if it was printed directly on a \Ps\ printer.) The
Xfigure's natural size is several inches high, which is a little large;
XFigure \ref{fig:texwarning} in the introduction was produced with the actual
X{\tt psfig} invocation changed to:
X\begin{quote}
X\tt\verb+\+centerline\{\verb+\+psfig\{figure=texwarning.ps,height=1.5in\}\}
X\end{quote} 
XThe {\tt height} option specifies how tall the figure
Xshould be on the page. Since no {\tt width} was specified, the figure
Xwas scaled equally in both dimensions. By listing both a {\tt height}
Xand a {\tt width}, figures can be scaled disproportionately, with
Xinteresting results.  For example:
X
X\begin{figure}[h]
X\centerline{\hbox{
X\psfig{figure=funstuff.ps,height=.8in,width=.15in}
X\psfig{figure=funstuff.ps,height=.8in,width=.35in}
X\psfig{figure=funstuff.ps,height=.8in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.2in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.5in}
X}}
X\caption{Abstract art. Untitled}
X\label{fig:funstuff}
X\end{figure}
X
Xwas produced with:
X
X\begin{quote}
X\tt
X\begin{verbatim}
X\begin{figure}[h]
X\centerline{\hbox{
X\psfig{figure=funstuff.ps,height=.8in,width=.15in}
X\psfig{figure=funstuff.ps,height=.8in,width=.35in}
X\psfig{figure=funstuff.ps,height=.8in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.2in}
X\psfig{figure=funstuff.ps,height=.8in,width=1.5in}
X}}
X\caption{Abstract art. Untitled}
X\label{fig:funstuff}
X\end{figure}
X\end{verbatim}
X\end{quote}
X
X\section{\tt Tpic}
X
XEven though \psfigtex is a powerful and easy-to-use method of
Xincluding \postscript figures in a document, it has two drawbacks. The
Xfirst is that all output devices used for \tex do not have
X\Ps. The other problem is that strings put in a
X\postscript figure are not processed by \TeX, so if you want to put
Xequations in, you have to overlay them on top of the picture.
X(You can measure distances with a ruler and use the {\tt\verb+\picture+} 
Xenvironment to do this, using {\tt \verb+\put+} commands to place the 
Xequations.)
X
XA way of getting around this is to use a picture drawing preprocessor that
Xpasses the text through \TeX. One such preprocessor is {\tt tpic}.\footnote{
X{\tt Tpic} is a port of {\tt troff} 's {\tt pic} preprocessor.}
X
XTo convert {\tt xpic} output to {\tt tpic} format, use the {\tt x2tpic}
Xcommand, then run {\tt tpic} to convert this to \TeX. You can then include
Xthis \tex file produced in a document. For instance we include the
Xfigure
X{\tt node.x}, with the following commands:\footnote{
XThe command {\tt x2tex} does the same thing as running the following two
Xcommands. It is sometimes more flexible to use the two commands separately.}
X\begin{quote}
X\tt
Xx2tpic node.x > node.pic \\
Xtpic node.pic 
X\end{quote}
XWe now have a file called {\tt node.tex} with a picture called
X{\tt\verb+\graph+} in it --- the following \LaTeX\
Xcommands are used to include it:
X\begin{quote}
X\tt
X\begin{verbatim}
X\begin{figure} [h]
X\input{node}		% This reads in the picture definition
X\centerline{\box\graph}		% This positions the picture and draws it
X\caption{Computational element or node which forms a weighting 
Xsum of $ n $ inputs}
X\label{fig:node}
X\end{figure}
X\end{verbatim}
X\end{quote}
XThis produces the picture in figure \ref{fig:node}.
X\begin{figure} [h]
X\input{node}
X\centerline{\box\graph}
X\caption{Computational element or node which forms a weighting 
Xsum of $ n $ inputs}
X\label{fig:node}
X\end{figure}
XThe figure is little large, so we generate a smaller version asking
X{\tt x2tpic} to scale it down for us with:
X\begin{quote}
X\tt
Xx2tpic -s 0.6 node.x > shrunknode.pic \\
Xtpic shrunknode.pic 
X\end{quote}
Xand include it as figure \ref{fig:shrunknode}.
X\begin{figure}[h]
X\input{shrunknode}
X\centerline{\box\graph}
X\caption{Computational element or node which forms a weighting 
Xsum of $ n $ inputs}
X\label{fig:shrunknode}
X\end{figure}
X\par
X{\small {\em Hint} --- The text for the equation
Xin the box above is 
X\begin{verbatim}
X$ {\displaystyle y = f \left( \sum_{i=1}^{n-1} w_{i} x_{i} - \theta \right)} $
X\end{verbatim}
Xwhich is quite long, and appears literally in the {\tt xpic} figure
Xsince {\tt xpic} does not process equations on the screen.  This looks
Xslightly messy onscreen and overflows the edges of the picture --- a
Xbetter way to do it is to define a command to generate the equation,
Xand use that in the figure. Then in the document, you could say
Xsomething like
X\begin{verbatim}
X\newcommand{\nodeeqn}{ $ {\displaystyle y = f \left( \sum_{i=1}^{n-1} 
Xw_{i} x_{i} - \theta \right)} $ }
X\end{verbatim}
Xand put \verb+\+nodeeqn in the picture instead of the long equation.}
X\par
X{\small {\em Hint} --- {\tt xpic}'s text alignment options are
Ximportant if you want to get good results. For instance, in the figure
Xabove, most text, including the equation in the box uses the default {\tt
XCentered, Middle} attributes, which mean that the single {\em control
Xpoint} whose location is guaranteed is the centre of the text. For the
Xlabels $ x_{0}, x_{1}, x_{n-1} $ along the left edge, we use the {\tt
XRight Justified, Middle} attributes so that we ensure that they are all
Xaligned along the same right edge. Remember that {\tt xpic} screen
Xfonts are only approximations of the actual fonts used by \TeX, and
Xaren't too accurate.}
X\section{Further Reading}
XFor more information on \psfigtex --- see the {\em
X\psfigtex 1.2 Users Guide} by Trevor Darrell ({\em
Xtrevor@grasp.cis.upenn.edu}). Some of
Xthe examples used in this note are based on that document.
X
X{\tt Pic} is a powerful language for describing pictures --- {\tt xpic}
Xuses only a small subset. For more information on the {\tt pic}language, see {\em PIC --- A Graphics Language for Typesetting} by
XBrian W. Kernighan. {\tt Pic} is really a preprocessor for the {\tt
Xtroff} typesetting program, but the language is quite independent of
Xthe underlying typesetter. A few differences are listed in the {\tt
Xtpic} manual page.
X
X{\tt Xpic, x2ps} and {\tt x2tpic} are described in {\em Using xpic} by
XMark Moraes. {\em moraes@csri.toronto.edu}. These programs also have
Xmanual pages.
X
X\section{Availability}
X\psfigtex is available by anonymous ftp from {\em linc.cis.upenn.edu}
X(Internet host number 128.91.2.8), in the tar file
X{\tt ~ftp/dist/psfig/tex.tar.Z}. There exists a corresponding {\tt troff}
Xversion.
X
X{\tt Pic} is part of the {\em Documenter's Workbench} sold by AT\&T
X(and many vendors of Unix.\footnote{Unix is a trademark of AT\&T}). It
Xis also supplied with research editions of Unix. (eg) Eighth Edition.
X
X{\tt Tpic} is a port of {\tt pic}. Therefore, you need a Unix source
Xlicense to get it. Contact Tim Morgan {\em morgan@rome.ics.uci.edu}
Xfor more details.
X
X{\tt Xpic, x2ps} and {\tt x2pic} are part of the user-contributed
Xsoftware for the X Windows System Version 11 Release 3.  This document
Xis part of the source.
X
X\end{document}             % End of document.
END_OF_doc/tex/xpic.tex
if test 10668 -ne `wc -c <doc/tex/xpic.tex`; then
    echo shar: \"doc/tex/xpic.tex\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f fontdesc/x2tpic -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"fontdesc/x2tpic\"
else
echo shar: Extracting \"fontdesc/x2tpic\" \(2268 characters\)
sed "s/^X//" >fontdesc/x2tpic <<'END_OF_fontdesc/x2tpic'
X# Font description file for mapping xpic font names to TeX fonts.
X# Almost all these fonts are magstep values and should therefore be available
X# on most machines. The Special font is mapped to the PostScript(tm)
X# Symbol font - we store the tfm file as PS-Symbol. Other sites may
X# call it other names.
X# The algorithm to find the closest font will try to find the closest size in
X# the same font style or Roman.
X# Add or remove fonts from this list depending on availability - the LaTeX
X# lfonts.tex file is a good place to check.
XRoman 	5		\Xfiverm	cmr5
XRoman 	6		\Xsixrm		cmr6
XRoman 	7		\Xsevenrm	cmr7
XRoman 	8		\Xeightrm	cmr8
XRoman 	9		\Xninerm	cmr9
XRoman 	10		\Xtenrm		cmr10
XRoman 	11		\Xelevenrm	cmr10  \magstephalf
XRoman 	12		\Xtwelverm	cmr10  \magstep1
XRoman 	14		\Xfourteenrm	cmr10  \magstep2
XRoman 	17		\Xseventeenrm	cmr10  \magstep3
XRoman 	20		\Xtwentyrm	cmr10  \magstep4
XRoman 	25		\Xtwentyfiverm	cmr10  \magstep5
X#Italic 	5		\Xfiveit	cmti7  714
X#Italic 	6		\Xsixit		cmti7  857
XItalic 	7		\Xsevenit	cmti7
XItalic 	8	\Xeightit	cmti8
XItalic 	9	\Xnineit	cmti9
XItalic 	10	\Xtenit		cmti10
XItalic 	11	\Xelevenit	cmti10 \magstephalf
XItalic 	12	\Xtwelveit	cmti10 \magstep1
XItalic 	14	\Xfourteenit	cmti10 \magstep2
XItalic 	17	\Xseventeenit	cmti10 \magstep3
XItalic 	20	\Xtwentyit	cmti10 \magstep4
XItalic 	25	\Xtwentyfiveit	cmti10 \magstep5
X#Bold 	5	\Xfivebf	cmbx7  714
X#Bold 	6	\Xsixbf		cmbx7  857
XBold 	7	\Xsevenbf	cmbx7
XBold 	8	\Xeightbf	cmbx8
XBold 	9	\Xninebf	cmbx9
XBold 	10	\Xtenbf		cmbx10
XBold 	11	\Xelevenbf	cmbx10 \magstephalf
XBold 	12	\Xtwelvebf	cmbx10 \magstep1
XBold 	14	\Xfourteenbf	cmbx10 \magstep2
XBold 	17	\Xseventeenbf	cmbx10 \magstep3
XBold 	20	\Xtwentybf	cmbx10 \magstep4
XBold 	25	\Xtwentyfivebf	cmbx10 \magstep5
XSpecial 5	\Xfivesp	PS-Symbol pointsize5	# No \ in pointsize!
XSpecial 6	\Xsixsp		PS-Symbol pointsize6
XSpecial 7	\Xsevensp	PS-Symbol pointsize7
XSpecial 8	\Xeightsp	PS-Symbol pointsize8
XSpecial 9	\Xninesp	PS-Symbol pointsize9
XSpecial 10	\Xtensp		PS-Symbol pointsize10
XSpecial 11	\Xelevensp	PS-Symbol pointsize11
XSpecial 12	\Xtwelvesp	PS-Symbol pointsize12
XSpecial 14	\Xfourteensp	PS-Symbol pointsize14
XSpecial 17	\Xseventeensp	PS-Symbol pointsize17
XSpecial 20	\Xtwentysp	PS-Symbol pointsize20
XSpecial 25	\Xtwentyfivesp	PS-Symbol pointsize25
END_OF_fontdesc/x2tpic
if test 2268 -ne `wc -c <fontdesc/x2tpic`; then
    echo shar: \"fontdesc/x2tpic\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x