Whole document tree
Input control
This chapter describes various builtin macros for controlling the input
to Deleting whitespace in input
The builtin dnl
and it is often used in connection with define(`foo', `Macro `foo'.')dnl A very simple macro, indeed. foo =>Macro foo. The input up to and including the next newline is discarded, as opposed to the way comments are treated (see section Comments).
Usually, Changing the quote characters
The default quote delimiters can be changed with the builtin
changequote(opt start, opt end)
where start is the new start-quote delimiter and end is the
new end-quote delimiter. If any of the arguments are missing, the default
quotes (
The expansion of changequote([, ]) => define([foo], [Macro [foo].]) => foo =>Macro foo. If no single character is appropriate, start and end can be of any length. changequote([[, ]]) => define([[foo]], [[Macro [[[foo]]].]]) => foo =>Macro [foo]. Changing the quotes to the empty strings will effectively disable the quoting mechanism, leaving no way to quote text. define(`foo', `Macro `FOO'.') => changequote(, ) => foo =>Macro `FOO'. `foo' =>`Macro `FOO'.'
There is no way in Neither quote string should start with a letter or `_' (underscore), as they will be confused with names in the input. Doing so disables the quoting mechanism. Changing comment delimiters
The default comment delimiters can be changed with the builtin
macro changecom(opt start, opt end)
where start is the new start-comment delimiter and end is
the new end-comment delimiter. If any of the arguments are void, the
default comment delimiters (
The expansion of define(`comment', `COMMENT') => # A normal comment =># A normal comment changecom(`/*', `*/') => # Not a comment anymore =># Not a COMMENT anymore But: /* this is a comment now */ while this is not a comment =>But: /* this is a comment now */ while this is not a COMMENT Note how comments are copied to the output, much as if they were quoted strings. If you want the text inside a comment expanded, quote the start comment delimiter.
Calling define(`comment', `COMMENT') => changecom => # Not a comment anymore =># Not a COMMENT anymore Changing the lexical structure of words
A file being processed by [_a-zA-Z][_a-zA-Z0-9]*
Using changeword(`[_a-zA-Z0-9]+') define(1, 0) =>1 Tightening the lexical rules is less useful, because it will generally make some of the builtins unavailable. You could use it to prevent accidental call of builtins, for example: define(`_indir', defn(`indir')) changeword(`_[_a-zA-Z0-9]*') esyscmd(foo) _indir(`esyscmd', `ls')
Because
changecom(`/*', `*/') changeword(`#\([_a-zA-Z0-9]*\)') #esyscmd(ls)
\def\a{\message{Hello}} \catcode`\@=0 \catcode`\\=12 =>@a =>@bye
Then, the define(a, `errprint(`Hello')') changeword(`@\([_a-zA-Z0-9]*\)') =>@a
In the TeX example, the first line defines a macro
When the
You should note that using Saving input
It is possible to `save' some text until the end of the normal input has
been seen. Text can be saved, to be read again by
To save input text, use the builtin m4wrap(string, ...) which stores string and the rest of the arguments in a safe place, to be reread when end of input is reached. define(`cleanup', `This is the `cleanup' actions. ') => m4wrap(`cleanup') => This is the first and last normal input line. =>This is the first and last normal input line. ^D =>This is the cleanup actions.
The saved input is only reread when the end of normal input is seen, and
not if
It is safe to call Go to the first, previous, next, last section, table of contents. |