Printing Files on CIT Printers ------------------------------------------- Anthony Thyssen -- anthony@cit.gu.edu.au For information on what printers are available and a summary of all the options to the `lpr' command here for the printers in CIT, please look at the file "Printer Options" in this directory. ------- The `type' of a file, or more correctly, its format can be discovered with the UNIX command `file' (try: man file). Note that this is only a summary of most common methods of viewing and printing files of various types. It is not the be all and end all. NOTE:- in this document {...} is to be provided by you while [...] is optional and may be left out. ------------------------------------------------------------------------------ Plain Text Files ------------------ Almost all the files and data in a UNIX operating system are written in a readable plain text file. This includes: mail, news, shell programs, output from most commands, etc, etc, etc. Printing:- lpr {textfile}... # Print text file to laser printer as is lpr -p {textfile}... # Print file formatted with headers/footers lpr -i1 {textfile}... # Bannered output on the text file lpr -i1 {textfile} -T {title} # set the banner title lpr -i2 {textfile}... # Two pages per page bannered output lpr -i3 {textfile}... # landscape (wide) bannered page lpr -i4 {textfile}... # Four pages per page mode Viewing (on screen):- cat {textfile}... # just print (no stops) on screen more {textfile}... # display one screen full at a time less {textfile}... # as more but can go backwards in file too! xmessage <{textfile} & # just display file in a X window (like MOTD) Convert (to postscript):- pstext <{textfile} >{postscript} # convert text file to postscript a2ps {textfile} >{postscript} # to postscript in 2up bannered Postscript ------------ This is mentioned early as it is this `type' of file that the printer understands. As such all other file types and formats are at some point converted to postscript before being sent to the printer. Postscript is a text file that starts with a line such as :- %!PS-Adobe-3.0 The first two characters `%!' is tells the "lpr" that the file it is reading is postscript and thus not a `plain text' to be converted to postscript before sending to the printer. Normal Text files thus should not start with these two characters (I have never encountered this problem). However some postscript files from a PC may be missing these start characters and thus will be printed as text! Please check PC postscript files before printing. Postscript is actually a program, which is executed by the printer and thus can do some pretty amazing things. A large number of UNIX commands exist to convert (filter) various file formats to postscript and indeed do other things to them (see multips program below) Printing:- lpr {postscript}... Print a postscript file to the printer (directly) Viewing:- gs {postscript}... [quit.ps] Low-level postscript display program for the X-window system. The return key is used in the xterm the program was launched in to progress to the next page. ghostview [{postscript}] & User friendly version of the above. This program also allows you to select specific pages to print and many other options. Conversion:- multips [-n 2|4|8|16] {postscript} >{postscript} This is a postscript filter which takes a postscript file and reorganizes it to `-n' pages per page. The number of pages on each page must be a power of 2, and the start postion for the first page can be set with the `-s' option. This command defaults to 4 pages/page starting at the 0th position (first position). As the program only filters postscript you must convert your file to postscript yourself before using this command. Troff, Cat4, Man Pages ------------------------ This format is the old method of document creation on UNIX system. It is however still in use today as the format of the Online manual system. A number of filters (conversion programs) are used to handle equations and tables in these doctuments. NOTE :- troff files are not usually printed directly but converted to a different format for printing. Two types of intermediate file formats are used CAT4 format (Cat Phototypesetter) which is available and a newer Ditroff (Device Independant troff) which is at the moment unavailable. To preview such files you either convert cat4 to text or postscript and use one of the other viewing programs provided above. Conversion:- ptroff -t {troff} >{postscript} # convert troff to postscript troff -t {troff} >{cat4} # format the troff file to tbl <{troff} >{troff} # format tables in troff eqn <{troff} >{troff} # format equations in a troff2ps <{troff} >{postscript} # convert cat4 to postscript /usr/lib/lp/postscript/dpost {troff} >{postscript} # `' on SOLARIS nroff -man {manual_file} >{textfile} # convert a manual to text troff -man {manual_file} >{cat4} # convert a manual to cat4 Printing:- lpr -t {cat4} # print a cat4 format file man -t {manual} # print a online manual troff -t {troff-file} | lpr -t # print troff tbl {troff} | troff -t | lpr -t # print troff with tables eqn {troff} | troff -t | lpr -t # print troff with equations eqn {troff} | tbl | troff -t | lpr -t # print troff with both Viewing:- eqn {troff} | tbl | nroff -t | less # view a troff file as text ptroff -t {troff} >{postscript} # convert to postscript ghostview {postscript} & # now display the postscipt xman & # display manual in windows man {manual} # display manual on screen as text Latex/Dvi ----------- Latex is the modern way of creating documents. Or even whole books. It is designed to make good use of laser printers and is able to incorperate graphics and diagrams directly into the output. As with troff documentation methods (see above) latex files are not normally printed directly to the printer. It uses a intermediate format "DVI" or Device Independant format. The dvi format file is then normally either converted to postscript (or even pdf) or printed with the lpr -d command. NOTE:- in the rare case that postscript files are to be included in the dvi file (via the use of the latex \special command) the dvi to postscript conversion will have to be done by the user. This is because the lpr command knows nothing of included files and thus will fail to find these files. In this case the `dvips' program will be required to be run by the user him/herself locally. The dvips option -f is used get dvips to output the postscript directly to standard output for use in a pipeline. Another common option is -t a4 which ensures that the output is appropriate for the A4 paper we use, and not the letter size used in the US. Printing:- lpr -d {dvifile} # print a dvi file. dvips -f {dvifile} | lpr # convert dvi file (filter) and print Viewing:- xdvi {dvifile} & # look at a dvi file directly dvips -o {postscript} {dvifile} # convert to postscript ghostscript {postscript} & # View as postscript (better than xdvi!) Conversion:- latex {latex} # produce a dvi file from a latex file dvips -o {postscript} {dvi-file}; # convert dvi to postscript Program source printing ------------------------- Although program source are usually text files. A program is provided to format these files to a better reading printing style. This program however outputs to the old printing format `cat4 photo-typesetter' and so must be printed using the `-t' option of lpr. Other methods are also available but not as good as this. The program "vgrind" is a Sun supplied command that takes a program source file and formats it depending on the programming language of the file. For example :- bold keywords, italicize comments, page number, index routine names The program calls troff directly and outputs a cat4 format. See `troff' for more info on this format. By default it will format `C' program source but the -l option can be used to change this. Some languages understood are :- C -lc MLisp -lml Bourne shell -lsh FORTRAN -lf C shell -lcsh Pascal -lp Conversion:- vgrind [-l{lang}] {file} >{Cat4} Printing:- vgrind [-l{lang}] {file} | lpr -t Example printing a C source file vgrind -lc main.c | lpr -t EXAMPLES ---------- lpr -i2 -T "My Project Report" report Print the file `report' with the title "My Project Report" to the printer using bannered pages and 2 pages per printed page. lpr -d mypaper.dvi Print a LaTeX document (dvi file) dvips -t a4 -o mypaper.ps mypaper.dvi Convert dvi file to postscript (paper type a4) multips -n2 mypaper.ps | lpr Print a postscript file two pages per page on laser printer gs mypaper.ps quit.ps Look at a dvi file on screen (return to go to next page) ghostview mypaper.ps & Look at a postscript document in a X window display program. tbl mypaper.t | troff -t -ms | lpr -t Print troff document with tables directly to the printer tbl mypaper.t | troff -t -ms | troff2ps > ps; ghostview ps & Preview a troff document (with tables) tbl mypaper.t | troff -t -ms | troff2ps | multips -n2 | lpr Print a troff document with two pages on each output page. vgrind -lp PascalsTriangle.p | troff2ps | multips -n2 | lpr format a pascal program source file and print with 2 pages per page.