📄 ch43_15.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 43] 43.15 From a Source File to the Printer </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:51:57Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch43_01.htm"TITLE="43. Printing"><LINKREL="prev"HREF="ch43_14.htm"TITLE="43.14 nroff/troff and Macro Packages "><LINKREL="next"HREF="ch43_16.htm"TITLE="43.16 groff "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_14.htm"TITLE="43.14 nroff/troff and Macro Packages "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.14 nroff/troff and Macro Packages "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 43<BR>Printing</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_16.htm"TITLE="43.16 groff "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.16 groff "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-2480">43.15 From a Source File to the Printer </A></H2><PCLASS="para">The path from a TeX or <EMCLASS="emphasis">troff</EM> source file to your printer issurprisingly complex.It's often useful to know exactly what ishappening.It isn't knowledge that will help you "do anything" (i.e.,you won't be able to make fancier documents), but it will come inhandy - particularly when something goes wrong.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48363"></A>For TeX and <EMCLASS="emphasis">troff</EM>, the processing is surprisingly similar, asshown in<ACLASS="xref"HREF="ch43_15.htm#UPT-ART-2480-FIG-0"TITLE="Processing Path for TeX or troff Source File">Figure 43.1</A>.</P><H4CLASS="figure"><ACLASS="title"NAME="UPT-ART-2480-FIG-0">Figure 43.1: Processing Path for TeX or troff Source File</A></H4><IMGCLASS="graphic"SRC="figs/2480.gif"ALT="Figure 43.1"><PCLASS="para">You start with a source file, containing your text and markup.First,it's processed by one or more <EMCLASS="emphasis">preprocessors</EM> to handle figures,tables, and so on.Preprocessors are essential to <EMCLASS="emphasis">troff</EM>; theyaren't used that often with TeX, but they do exist.What a preprocessor does is provide a simpler language for formattingcomplex elements like tables, equations, or figures; the preprocessorinterprets this language, and outputs the low-level <EMCLASS="emphasis">troff</EM> requestsneeded to implement the desired result.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48376"></A>The most commonlyused preprocessors are listed in<ACLASS="xref"HREF="ch43_15.htm#UPT-ART-2480-TAB-0"TITLE="Common troff and TeX Preprocessors">Table 43.1</A></P><TABLECLASS="table"><CAPTIONCLASS="table"><ACLASS="title"NAME="UPT-ART-2480-TAB-0">Table 43.1: Common troff and TeX Preprocessors</A></CAPTION><THEADCLASS="thead"><TRCLASS="row"VALIGN="TOP"><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Name</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Used with</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Function</TH></TR></THEAD><TBODYCLASS="tbody"><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">pic</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">troff</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Illustrations</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">grap</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">troff</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Graphs; not frequently used</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">tbl</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">troff</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Tables</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">eqn</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">troff</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Equations</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">tpic</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">TeX</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Illustrations; equivalent to <EMCLASS="emphasis">pic</EM></TD></TR></TBODY></TABLE><PCLASS="para">After going through the preprocessors, you're left with a "pure"document that consists of basic commands and macros.This is fed intothe TeX or <EMCLASS="emphasis">troff</EM> processor, which starts by adding a "macrodefinition file" to the beginning of your text.The processor thenproduces a device independent file; this is a generic representation ofyour document in terms of low-level commands.You can't do much withdevice-independent output except (possibly) inspect it for bugs.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48413"></A>Before going on, a word about macro files.A macro file is nothingmore than a file of <EMCLASS="emphasis">troff</EM> or TeX commands that defines macros,sets up page borders, headers, footers, and so on.Basically, a macrofile defines the look of your document, together with any"high-level" (e.g., paragraph or heading) commands that you use.For <EMCLASS="emphasis">troff</EM>, these files are kept in the directory <EMCLASS="emphasis">/usr/lib/tmac</EM>and have filenames like <EMCLASS="emphasis">tmac.name</EM>; when you invoke <EMCLASS="emphasis">troff</EM>,you give the option <CODECLASS="literal">-m</CODE><CODECLASS="replaceable"><I>name</I></CODE> to select a macro package.</P><PCLASS="para">Since the macro file is nothing more than another file of <EMCLASS="emphasis">troff</EM>commands, there's no reason you can't just stick it onto the front ofyour source file.That is, the command:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch08_05.htm"TITLE="8.5 Command-Line Evaluation ">;</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat /usr/lib/tmac/tmac.s myfile.ms > foo.ms; troff foo.ms</B></CODE></PRE></TD></TR></TABLE></P><PCLASS="para">is completely equivalent to <CODECLASS="literal">troff -ms foo.ms</CODE>.</P><PCLASS="para">Why would you want to insert the macro file "by hand"?You usuallydon't; but if you're debugging a new macro file, or ifyou're defining one or two special macros for your own purposes,adding the macros by hand can be a useful trick.</P><PCLASS="para">After <EMCLASS="emphasis">troff</EM> or TeX has finished grinding your file intodust, you're left with a device independent (or DVI) file. I'm reallystretching terminology here, but (conceptually) this is the right wayto think. The problem is that there are two versions of<EMCLASS="emphasis">troff</EM>: device independent <EMCLASS="emphasis">troff</EM>, or <EMCLASS="emphasis">ditroff</EM>, and"old" <EMCLASS="emphasis">troff</EM>. <EMCLASS="emphasis">ditroff</EM> is the only one that reallygenerates device independent output: generic output that caneasily be translated into a file for any printer. The old <EMCLASS="emphasis">troff</EM>generates output for a C/A/T phototypesetter, an archaic beast thatprobably exists only in museums. C/A/T output is not deviceindependent at all: it reflects lots of C/A/T idiosyncraciesthat are a pain to deal with. However, conceptually, you can think ofC/A/T output as device independent output with a botcheddesign; it's certainly independent of any device you're likely to see!<CODECLASS="literal">:-)</CODE></P><PCLASS="para">The concept of device independent output really originated with TeX;TeX's DVI files are very well defined and quite elegant.Unfortunately, they're completely different from <EMCLASS="emphasis">ditroff</EM> 's DVIfiles. And if you're using some "third-party" version of <EMCLASS="emphasis">troff</EM>, likeSoftQuad's <EMCLASS="emphasis">sqtroff</EM> or the FSF's <EMCLASS="emphasis">groff</EM>, you probably haveyet another kind of device independent output to deal with.Although they sound like they're standardized, device independentformats aren't.</P><PCLASS="para">At any rate, once your processor is finished, its device independentoutput (of whatever type) needs to be converted to commands for yourprinter. This is done by a postprocessor. The name of thepostprocessor depends entirely onwhat kind of printer you're using, which version of TeX or <EMCLASS="emphasis">troff</EM>you're using, and where you bought your software.One such program is<EMCLASS="emphasis">psroff</EM>, which is part of Adobe's <EMCLASS="emphasis">transcript</EM> package; itconverts <EMCLASS="emphasis">ditroff</EM> output to PostScript.</P><PCLASS="para">Although this may seem complex, most of this is invisible toyou; most often, you'll invoke <EMCLASS="emphasis">troff</EM> through a script that willhandle all the postprocessing (and possibly even the preprocessing)for you.However, when you need to debug something that isn'tworking, there's no substitute for understanding the machinery.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_14.htm"TITLE="43.14 nroff/troff and Macro Packages "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.14 nroff/troff and Macro Packages "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_16.htm"TITLE="43.16 groff "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.16 groff "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">43.14 nroff/troff and Macro Packages </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">43.16 groff </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -