Wolfram ResearchProductsPurchasingServices & ResourcesAbout UsOur Sites
Services & Resources / Archive
-----
 /
Mathematica
*Mathematica
*Network Mathematica
*webMathematica
*gridMathematica
*Personal Grid Edition
*Wolfram Workbench
*Wolfram Education Group
*Application Packages
*Mathematica for Students
*Mathematica CalcCenter
*Publicon
*A New Kind of Science Explorer
*Mathematical Explorer
*Mathematica Teacher's Edition
*Calculus WIZ
*Mathematica Player
*Ask about this page
*Print this page
*Email this page
*Give us feedback
*
Sign up for our newsletter:

How do I prevent Mathematica from printing PostScript code instead of my notebook?

PostScript printers need to have a “%!” line at the beginning of the PostScript code, otherwise the printer will print the output as ASCII.

In certain situations, Mathematica® will put information ahead of its “%!PS-Adobe” line and the PostScript code will be printed verbatim. You may specify an arbitrary print command in the front end “print” dialog box or through X resources. The front end will pipe the PostScript that it generates to the command you specify. So, you can create a stream-based filter that discards every line until you encounter the “%!PS-Adobe” line.

Here is such a program written in C.


#include <stdio.h>
#include <string.h>

#define BUFSIZE         1024
#define KEEP            1
#define DISCARD         0
#define MAGIC           "%!PS-Adobe-2.0"

int main(){
        int state;
        char buf[BUFSIZE];

        state = DISCARD;
        while (fgets(buf, BUFSIZE, stdin) != NULL) {
                if (state == DISCARD)
                        if (!strncmp(buf, MAGIC, strlen(MAGIC) - 1)) 
                                state = KEEP;
                if (state == KEEP) {
                        fprintf(stdout, buf);
                }               
        }
        return 0;
}

You may then copy this snippet of code out and save it as a text file named fecleanps.c. The executable can be built using the shell command.

cc -o fecleanps fecleanps.c

The code adheres to the ISO/ANSI standard and should compile without any error on any compiler that supports the standard.

Once the fecleanps executable is built, it can be copied to a directory on a user's PATH shell environment variable.

You will need to edit the print command on the “Print to text” field of the “print” dialog box to read something similar to:

fecleanps | <shell command normally used for printing>

On BSD-style Unix (e.g., SunOS 4.1.x and Linux), the print command is lpr. On System V-based Unix (e.g., Solaris 2.5 and SGI IRIX), the command will be lp.

The print command can be set by default with the help of the Mathematica X resource XMathematica*printCommand. The value may be set globally using the XMathematica application default file in the Mathematica layout or by adding the following line in the user's .Xdefaults file:

XMathematica*printCommand: fecleanps | <print command goes here>

Download this FAQ as a Mathematica 5.2 Notebook






 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy