Scroll to navigation

grog(1) General Commands Manual grog(1)

Name

grog - “groff guess”—infer thegroffcommand a document requires

Synopsis

grog [--run][--ligatures][groff-option ...][--][file ...]
grog -h
grog --help
grog -v
grog --version

Description

grogreads its inputand guesses whichgroff(1)options are needed to render it.If no operands are given,or iffileis“-”,grogreads the standard input stream.The correspondinggroffcommand is normally written to the standard output stream.With the option--run,the inferred command is written to the standard error stream and thenexecuted.

Options

-hand--helpdisplay a usage message,whereas-vand--versiondisplay version information;all exit afterward.

includes the arguments-P-y -PUin the inferredgroffcommand.These are supported only by thepdfoutput device.
writes the inferred command to the standard error stream and thenexecutes it.

All other specified short options(that is,arguments beginning with a minus sign“-”followed by a letter)are interpreted asgroffoptions or option clusters with or without an option argument.Such options are included in the constructedgroffcommand line.

Details

grogreads eachfileoperand,pattern-matching strings that are statistically likely to becharacteristic ofroff(7)documents.It tries to guess which of the followinggroffoptions are required to correctly render the input:-e,-g,-G,-j,-p,-R,-t(preprocessors);and-man,-mdoc,-mdoc-old,-me,-mm,-mom,and-ms(macro packages).The inferredgroffcommand including these options and anyfileparameters is written to the standard output stream.

It is possible to specify arbitrarygroffoptions on the command line.These are included in the inferred command without change.Choices ofgroffoptions include-Cto enable AT&Ttroffcompatibility mode and-Tto select a non-default output device.If the input is not encoded in US-ASCII,ISO 8859-1,or IBM code page 1047,specification of agroffoption to run thepreconv(1)preprocessor is advised;see the-D,-k,and-Koptions ofgroff(1).For UTF-8 input,-kis a good choice.

groffmay issue diagnostic messages when an inappropriate-moption,or multiple conflicting ones,are specified.Consequently,it is best to specify no-moptions togrogunless it cannot correctly infer all of the-marguments a document requires.Aroffdocument can also be written without recourse to any macro package.In such cases,grogwill infer agroffcommand without an-moption.

Limitations

grogpresumes that the input does not change the escape,control,or no-break control characters.grogdoes not parseroffinput line continuation or control structures(brace escape sequences and the“if”,“ie”,and“el”requests)norgroff's“while”.Thus the input

.if \
t .NH 1
.if n .SH
Introduction
will conceal the use of themsmacrosNHandSHfromgrog.Such constructions are regarded bygrog'simplementors as insufficiently common to cause many inference problems.Preprocessors can be even stricter when matching macro calls thatbracket the regions of an input file they replace.pic,for example,requiresPS,PE,andPFcalls to immediately follow the default control character at thebeginning of a line.

Detection of the-soption(thesoelim(1)preprocessor)is tricky;to correctly infer its necessity would requiregrogto recursively open all files given as arguments to the.sorequest under the same conditions thatsoelimitself does so;see its man page.Recall thatsoelimis necessary only if sourced files need to be preprocessed.Therefore,as a workaround,you may want to run the input throughsoelimmanually,piping it togrog,and compare the output to runninggrogon the input directly.If the“soelim”edinput causesgrogto infer additional preprocessor options,then-sis likely necessary.

$ 
printf ".TS\nl.\nI'm a table.\n.TE\n" > 3.roff
$ 
printf ".so 3.roff\n" > 2.roff
$ 
printf ".XP\n.so 2.roff\n" > 1.roff
$ 
grog 1.roff
groff -ms 1.roff
$ 
soelim 1.roff | grog
groff -t -ms -

In the foregoing example,we see that this procedure enabledgrogto detecttbl(1)macros,so we would add-sas well as the detected-toption to a revisedgrogorgroffcommand.

$ 
grog -st 1.roff
groff -st -ms 1.roff

Exit status

grogexits with error status1if a macro package appears to be in use by the input document,butgrogwas unable to infer which one,or2if there were problems handling an option or operand.It otherwise exits with status0.(If the--runoption is specified,groff'sexit status is discarded.)Inferring no preprocessors or macro packages is not an error condition;a validroffdocument need not use either.Even plain text is valid input,if one is mindful of the syntax of the control and escape characters.

Examples

Running

grog /usr/share/doc/groff-base/meintro.me
at the command line results in
groff -me /usr/share/doc/groff-base/meintro.me
becausegrogrecognizes that the filemeintro.meis written using macros from themepackage.The command
grog /usr/share/doc/groff-base/pic.ms
outputs
groff -e -p -t -ms /usr/share/doc/groff-base/pic.ms
on the other hand.Besides discerning themsmacro package,grogrecognizes that the filepic.msadditionally needs the combination of-tfortbl,-eforeqn,and-pforpic.

Consider a filedoc/grnexampl.me,which uses thegrnpreprocessor to include agremlin(1)picture file in anmedocument.Let's say we want to suppress color output,produce a DVI file,and get backtraces for any errors thattroffencounters.The command

grog -bc -Idoc -Tdvi doc/grnexmpl.me
is processed bygroginto
groff -bc -Idoc -Tdvi -e -g -me doc/grnexmpl.me
where we can see thatgroghas inferred thememacro package along with theeqnandgrnpreprocessors.(The input file is located in/usr/share/doc/groff-baseif you'd like to try this example yourself.)

Authors

grogwas originally written in Bourne shell by James Clark.The current implementation in Perl was written byBernd Warkenand heavily revised byG. Branden Robinson.

See also

groff(1)

26 December 2024 groff 1.23.0