From: peg@cs.washington.edu (Peter Granger)
Newsgroups: comp.text.tex,comp.text.frame
Subject: Solution: Figures from FrameMaker to LaTeX
Summary: includes source code, ftp pointers
Date: 8 Oct 92 08:46:36 GMT
Article-I.D.: beaver.1992Oct8.084636.14413
Organization: Computer Science & Engineering, U. of Washington, Seattle

This file describes a method to take figures drawn in FrameMaker (and
probably other drawing packages that output non-encapsulated
PostScript) and incorporate them into LaTeX documents. I have run into
this problem several times, and have never gotten a workable solution
from anyone, although several people managed to give me the various
pieces that I needed.

Note: The following is not written from the point of view of an expert
in FrameMaker, LaTeX, or PostScript. I am just a guy who had a problem
and found a workable solution to it. I don't claim that this is the
best solution to these problems, or even that they will work at other
sites under other conditions. This is just what worked for me. I'm
posting it because I think other people may find it useful at some
point.

If you have problems with any of these programs, don't write to me
about it, please. They all have author's names attached to them, so
you can get real help if you need it.

         - Pete Granger

	   -----------------------------------------------

In a nutshell, here's how to do the conversions so FrameMaker figures
can go in LaTex documents:

1. Generate figure in Frame.
2. Save to a PostScript file with the Print command.

This generates regular PostScript, and not encapsulated. I don't know
why. But LaTex will choke and puke on non-encapsulated PostScript, so
you nave to convert it to encapsulated.

3. Run pstoepsi on the .ps file, generating a .epsi file.

You will probably have to get pstoepsi, and the utility it uses,
pbmplus, via ftp. You will also have to build them. This is a
nuisance, but I managed it, so you probably can, too. You can get
pstoepsi at:

Host: cs.tut.fi (130.230.4.2)
Directory: /pub/src/commands.1/framemaker-filters

That includes a README document that tells you about pbmplus, which is at:

Host: export.lcs.mit.edu
Directory: contrib/pbmplus.tar.Z

After running pstoepsi, you have your figure in encapsulated
PostScript format. However, you may find (as I did) that you can view
it in GhostScript, but can't get the figures to come out when you
print it. If so, then you need to...

4. Use fmfix, or manually edit, to comment out these four
   lines of the .epsi file:

% 	setpapername 
% 	manualfeed {true} {papersize} ifelse 
% 	{manualpapersize} {false} ifelse 
% 	{desperatepapersize} if

As close as I can tell, and I know *nothing* about PostScript, it
looks like this only influences things that go onto actual physical
paper. That would explain why ghostscript worked, but printing didn't.
No paper, no problem.

The source for fmfix was sent to me by Arthur Castonguay
(arthurc@doe.carleton.ca). I don't know whether he supports this in
any way, but considering that the program only has one function, it
should be near 100% robust. Here is what he gave me. (I include it
here because I don't think it's available by ftp anywhere; maybe it
should be.)

----- 8< ----- Cut Here --- fmfix.c --- Cut Here ----- 8< -----
/*
 * This is a filter to comment four lines out of FrameMaker
 * generated PostScript files so that they can be imported
 * in to TeX/LaTeX correctly and view with Ghostscript.
 *
 * The lines in question are:
 *
 *       setpapername
 *       manualfeed {true} {papersize} ifelse
 *       {manualpapersize} {false} ifelse
 *       {desperatepapersize} if
 */

#define BUFSIZ 1024
#define EQUAL  0

#include <stdio.h>

char aline[BUFSIZ+1];

char *search_string[] =
{
    "setpapername",
    "manualfeed {true} {papersize} ifelse",
    "{manualpapersize} {false} ifelse",
    "{desperatepapersize} if"
};

int num_strings = sizeof( search_string ) / sizeof( char * );

int read_a_line()
{
    int i, c;
    
    for (i = 0; i < BUFSIZ; i++)
    {
	c = fgetc( stdin );
	
	if (c == EOF)
	{
	    aline[i] = '\0'; /* Terminate the string */
	    return EOF;
	}
	else
	{
	    aline[i] = c;
	    
	    /* Check for EOL */
	    if (c == '\n')
	    {
		break;
	    }
	}
    }
    
    aline[i+1] = '\0'; /* Terminate the string */
    return 0;
}	    
		
	     
/* main(argc) */   /* For older C compilers */
/* int argc;  */
main( int argc )
{
    int   i, c, done;
    char *s;

    if (argc != 1)
    {
	fprintf( stderr, "Usage: fmfix < fmfile.ps > fixedfile.ps\n" );
	exit( 1 );
    }

    done = 0;
    do
    {
	if (read_a_line() == EOF)
	{
	    done = 1;
	}

	/* Find the place in the string where the first non-blank character starts */
	s = aline;
	while (((*s == ' ') || (*s == '\t')) && (*s != '\0')) s++;

	/* Search for strings to match */
	for (i = 0; i < num_strings; i++)
	{
	    if (strncmp( s, search_string[i], strlen( search_string[i] ) ) == EQUAL)
	    {
		fputs( "% ", stdout );
		break;
	    }
	}
	
	fputs( aline, stdout );
    }
    while (!done);

    exit( 0 );
}
----- 8< ----- Cut Here --- fmfix.c --- Cut Here ----- 8< -----

You now have an encapsulated PostScript file with the trouble-causing
lines removed. Now you can use psfig, or augpsfig, or probably
whatever else you like to pull the .epsi file into your LaTex
document. You can see the result equally well in both GhostScript and
actual printed pages.

Hope this saves somebody some trouble. If anyone has easier ways of
doing this, like an all-in-one program that makes the conversion, I'd
be glad to hear about it.
-- 
--------
 Pete Granger                     "I'm having an old friend for dinner."
 peg@cs.washington.edu                 - Dr. Hannibal Lecter
                                         "The Silence of the Lambs"
Newsgroups: comp.text.tex