[comp.text] Preprocessor for General Text Proce

rgh@inmet.UUCP (08/25/87)

Unix comes with a perfectly respectable general-purpose macro preprocessor --
see the man page for m4.  You can do things like
	define(`e_coli',`\fIE. coli\fP')
		-- blah e_coli blah   ==>
		-- blah \fIE. coli\fP blah
	define(`ital',`\fI$1\fP')
		-- blah ital(blah) blah  ==>
		-- blah \fIblah\fP blah
	include(source_file)

More sophisticated features allow for
    conditional macro expansion (ifdef, ifelse),
    multiple output streams (so you could, for instance,
	delay note text to the end of a chapter),
    rudimentary string handling and expression evaluation,
    and various other things you may well never want to do.

It's pretty efficiently implemented, but it does mean passing your input
through another filter -- a cost, it sounds like, that you're prepared
to pay.  As with any macro language, things like macro invocations within
macros, recursive macros, and the like can be bewildering.  But for
ordinary uses, the simple style shown above, of always quoting
the arguments to define, avoids most of the obscurities.  It may also
be wise to start most of your macro names with _, so that the ordinary
word doesn't get expanded in unexpected contexts.  One more gotcha:
you've got to quote the builtin command names when you don't mean
them:
	I divert myself by trying to define an index.
	==>
	I  myself by trying to  an .

	I `divert' myself by trying to `define' an `index'.
	==>
	I divert myself by trying to define an index.

Randy Hudson   ihnp4!inmet!rgh