Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   groff    ( 1 )

интерфейс для системы форматирования документов GNU roff (front end to the GNU roff document formatting system)

Использование (Usage)

The architecture of the GNU roff system follows that of other device-independent roff implementations, comprising preprocessors, macro packages, output drivers (or 'postprocessors'), a suite of utilities, and the formatter troff at its heart. See roff(7) for a survey of how a roff system works.

The front end programs available in the GNU roff system make it easier to use than traditional roffs that required the construction of pipelines or use of temporary files to carry a source document from maintainable form to device-ready output. The discussion below summarizes the constituent parts of the GNU roff system. It complements roff(7) with groff-specific information.

Getting started Those who prefer to learn by experimenting or are desirous of rapid feedback from the system may wish to start with a 'Hello, world!' document.

$ echo "Hello, world!" | groff -Tascii | sed '/^$/d' Hello, world!

We used a sed command only to eliminate the 65 blank lines that would otherwise flood the terminal screen. (roff systems were developed in the days of paper-based terminals with 66 lines to a page.)

Today's users may prefer output to a UTF-8-capable terminal.

$ echo "Hello, world!" | groff -Tutf8 | sed '/^$/d'

Producing PDF, HTML, or TeX's DVI is also straightforward. The hard part may be selecting a viewer program for the output.

$ echo "Hello, world!" | groff -Tpdf > hello.pdf $ evince hello.pdf $ echo "Hello, world!" | groff -Thtml > hello.html $ firefox hello.html $ echo "Hello, world!" | groff -Tdvi > hello.dvi $ xdvi hello.html

Using groff as a REPL Those with a programmer's bent may be pleased to know that they can use groff in a read-evaluate-print loop (REPL). Doing so can be handy to verify one's understanding of the formatter's behavior and/or the syntax it accepts. Turning on all warnings with -ww can aid this goal.

$ groff -ww -Tutf8 \# This is a comment. Let's define a register. .nr a 1 \# Do integer arithmetic with operators evaluated left-to-right. .nr b \n[a]+5/2 \# Let's get the result on the standard error stream. .tm \n[b] 3 \# Now we'll define a string. .ds name Leslie\" This is another form of comment. .nr b (\n[a] + (7/2)) \# Center the next two text input lines. .ce 2 Hi, \*[name]. Your secret number is \n[b]. \# We will see that the division rounded toward zero. It is \# Here's an if-else control structure. .ie (\n[b] % 2) odd. .el even. \# This trick sets the page length to the current vertical \# position, so that blank lines don't spew when we're done. .pl \n[nl]u <Control-D> Hi, Leslie. Your secret number is 4. It is even.

Paper size In groff, the page dimensions for the formatter troff and for output devices are handled separately. In the formatter, requests are used to set the page length (.pl), page offset (or left margin, .po), and line length (.ll). The right margin is not explicitly configured; the combination of page offset and line length provides the information necessary to derive it. The papersize macro package, automatically loaded by troffrc at start-up, provides an interface for configuring page dimensions by convenient names, like 'letter' or 'A4'; see groff_tmac(5). The default used by the formatter depends on its build configuration, but is usually one of the foregoing, as geographically appropriate.

It is up to each macro package to respect the page dimensions configured in this way. Some offer alternative mechanisms.

For each output driver, the size of the output medium can be set in its DESC file. Most also recognize a command-line option -p to override the default dimensions and an option -l to use landscape orientation. See groff_font(5) for a description of the papersize directive, which takes an argument of the same form as -p. The output driver's man page, such as grops(1), may also be helpful. groff uses the command-line option -P to pass options to output devices; for example, use the following for PostScript output on A4 paper in landscape orientation.

groff -Tps -dpaper=a4l -P-pa4 -P-l -ms foo.ms > foo.ps

Front end The groff program is a wrapper around the troff(1) program. It allows one to specify preprocessors via command-line options and automatically runs the appropriate postprocessor for the selected output device. Doing so, the manual construction of pipelines or management of temporary files required of users of traditional roff(7) systems can be avoided. The grog(1) program can be used to infer an appropriate groff command line to format a document.

Language Input to a roff system is in plain text interleaved with control lines and escape sequences. The combination constitutes a document in one of a family of languages we also call roff; see roff(7) for background. An overview of GNU roff language syntax and features, including lists of all supported escape sequences, requests, and pre-defined registers, can be found in groff(7). groff extensions to the AT&T troff language, a common subset of roff dialects extant today, are detailed in groff_diff(7).

Preprocessors A preprocessor is an interpreter of a domain-specific language that produces roff language output. Frequently, such input is confined to sections or regions of a roff input file (bracketed with macro calls specific to each preprocessor), which it replaces. Preprocessors therefore often interpret a subset of roff syntax along with their own language. GNU roff provides reimplementations of most preprocessors familiar to users of AT&T troff; these routinely have extended features and/or require GNU troff to format their output. Preprocessors distributed with GNU roff include

eqn(1) for mathematical formulae,

grn(1) for pictures in gremlin(1) format,

pic(1) for diagrams,

chem(1) for chemical structure diagrams,

refer(1) for bibliographic references,

soelim(1) to preprocess files included with roff .so requests, and

tbl(1) for tables.

A preprocessor unique to GNU roff is preconv(1), which converts various input encodings to something GNU troff can understand. When used, it is run before any other preprocessors.

Macro packages Macro files are roff input files designed to produce no output themselves but instead ease the preparation of other roff documents. When a macro file is installed at a standard location and suitable for use by a general audience, it is termed a macro package.

Macro packages can be loaded prior to any roff input documents with the -m option. The groff system implements most well-known macro packages for AT&T troff in a compatible way, extends them, and adds some packages of its own. Several of them have one- or two-letter names due to the intense sense of naming economy practiced in early Unix culture. This laconic approach led to many of the packages being identified in general usage with the nroff and troff option letter used to invoke them, sometimes to punning effect, as with 'man' (short for 'manual'), and even with the option dash, as in the case of the s package, much better known as ms or even -ms.

Macro packages serve a variety of purposes. Some are 'full- service' packages, adopting responsibility for page layout among other fundamental tasks, and defining their own lexicon of macros for document composition; each such package stands alone and a given document can use at most one. GNU roff provides the following such packages.

an is used to compose man pages in the format originating in Version 7 Unix (1979); see groff_man(7). It can be specified on the command line as -man.

doc is used to compose man pages in the format originating in 4.3BSD-Reno (1990); see groff_mdoc(7). It can be specified on the command line as -mdoc.

e is the Berkeley general-purpose macro suite, developed as an alternative to AT&T's s; see groff_me(7). It can be specified on the command line as -me.

m implements the format used by the second-generation AT&T macro suite for general documents, a successor to s; see groff_mm(7). It can be specified on the command line as -mm.

om (invariably called 'mom') is a modern package written by Peter Schaffter specifically for groff. Consult the mom home page ⟨https://www.schaffter.ca/mom/⟩ for extensive documentation. She—for mom takes the female pronoun—can be specified on the command line as -mom.

s is the original AT&T general-purpose document format; see groff_ms(7). It can be specified on the command line as -ms.

Others are supplemental. For instance, andoc is a wrapper package specific to groff that recognizes whether a document uses man or mdoc format and loads the corresponding macro package. It can be specified on the command line as -mandoc. A man(1) librarian program may use this macro file to delegate loading of the correct macro package; it is thus unnecessary for man itself to scan the contents of a document to decide the issue.

Many macro files augment the function of the full-service packages, or of roff documents that do not employ such a package— the latter are sometimes characterized as 'raw'. These auxiliary packages are described, along with details of macro file naming and placement, in groff_tmac(5).

Formatters The central roff formatter within the groff system is troff(1). It provides the features of both the classical troff and nroff, as well as the groff extensions. The command-line option -C switches troff into compatibility mode which tries to emulate classical roff as much as possible.

There is a shell script nroff(1) that emulates the behavior of classical nroff. It tries to automatically select the proper output encoding, according to the current locale.

The formatter program generates a device-independent, but not device-agnostic, intermediate output format, documented in groff_out(5).

Devices Real devices in groff are

dvi TeX DVI format (postprocessor is grodvi(1)).

html xhtml HTML and XHTML output (preprocessors are soelim and pre-grohtml, postprocessor is post-grohtml).

lbp Canon CAPSL printers (LBP-4 and LBP-8 series laser printers; postprocessor is grolbp(1)).

lj4 HP LaserJet4-compatible (or other PCL5-compatible) printers (postprocessor is grolj4(1)).

ps PostScript output (postprocessor is grops(1)).

pdf Portable Document Format (PDF) output (postprocessor is gropdf(1)).

For the following TTY output devices (where postprocessor is grotty(1)), -T selects the output encoding:

ascii ISO 646 1991:IRV, also known as US-ASCII.

cp1047 IBM code page 1047, an EBCDIC arrangement of ISO Latin-1.

latin1 ISO Latin-1 (ISO 8859-1).

utf8 ISO 10646 ('Unicode') character set in UTF-8 encoding. This encoding has the largest character repertoire, so it is the best choice for terminal output.

The following arguments select gxditview as the postprocessor.

X75 75dpi resolution, 10pt document base font.

X75-12 75dpi resolution, 12pt document base font.

X100 100dpi resolution, 10pt document base font.

X100-12 100dpi resolution, 12pt document base font.

The default device is ps. In roff, the output targets are called devices. A device can be a piece of hardware, e.g., a printer, or a software file format. A device is specified by the option -T. The groff devices are as follows.

ascii Text output using the ascii(7) character set.

cp1047 Text output using the EBCDIC code page IBM cp1047 (e.g., OS/390 Unix).

dvi TeX DVI format.

html HTML output.

latin1 Text output using the ISO Latin-1 (ISO 8859-1) character set; see iso_8859_1(7).

lbp Output for Canon CAPSL printers (LBP-4 and LBP-8 series laser printers).

lj4 HP LaserJet4-compatible (or other PCL5-compatible) printers.

ps PostScript output; suitable for printers and previewers like gv(1).

pdf PDF files; suitable for viewing with tools such as evince(1) and okular(1).

utf8 Text output using the Unicode (ISO 10646) character set with UTF-8 encoding; see unicode(7).

xhtml XHTML output.

X75 75dpi X Window System output suitable for the previewers xditview(1x) and gxditview(1). A variant for a 12pt document base font is X75-12.

X100 100dpi X Window System output suitable for the previewers xditview(1x) and gxditview(1). A variant for a 12pt document base font is X100-12.

The postprocessor to be used for a device is specified by the postpro directive in the device description file; see groff_font(5). This can be overridden with the -X option.

The default device is ps.

Postprocessors groff provides 3 hardware postprocessors:

grolbp(1) for some Canon printers,

grolj4(1) for printers compatible to the HP LaserJet 4 and PCL5,

grotty(1) for text output using various encodings, e.g., on text- oriented terminals or line printers.

Today, most printing or drawing hardware is handled by the operating system, by device drivers, or by software interfaces, usually accepting PostScript. Consequently, there isn't an urgent need for more hardware device postprocessors.

The groff software devices for conversion into other document file formats are

grodvi(1) for the DVI format,

grohtml(1) for HTML and XHTML formats,

grops(1) for PostScript.

gropdf(1) for PDF.

Combined with the many existing free conversion tools this should be sufficient to convert a troff document into virtually any existing data format.

Utilities The following utility programs around groff are available.

addftinfo(1) Add information to troff font description files for use with groff.

afmtodit(1) Create font description files for PostScript device.

eqn2graph(1) Convert an eqn image into a cropped image.

gdiffmk(1) Mark differences between groff, nroff, or troff files.

grap2graph(1) Convert a grap diagram into a cropped bitmap image.

gxditview(1) The groff X viewer, the GNU version of xditview.

hpftodit(1) Create font description files for lj4 device.

indxbib(1) Make inverted index for bibliographic databases.

lkbib(1) Search bibliographic databases.

lookbib(1) Interactively search bibliographic databases.

pdfroff(1) Create PDF documents using groff.

pfbtops(1) Translate a PostScript font in .pfb format to ASCII.

pic2graph(1) Convert a pic diagram into a cropped image.

tfmtodit(1) Create font description files for TeX DVI device.

xditview(1x) roff viewer historically distributed with the X Window System.

xtotroff(1) Convert X font metrics into GNU troff font metrics.