What is a macro processor?

A macro processor is a program that reads a file (or files) and scans them for certain keywords. When a keyword is found, it is replaced by some text. The keyword/text combination is called a macro.

A simple example is the C language preprocessor. When you write

#define MAX_BANANAS 6

int banana;

for (banana = 0; banana < MAX_BANANAS; banana++){
   ...;
}

in a C program, the C preprocessor reads the first line and stores it as a macro definition. When it comes across the later reference to MAX_BANANAS in the for loop, it replaces it with the macro's definition, 6. The output of the C preprocessor is then fed to the C compiler proper.

M4 and the htm4l macros work in a very similar way. For example, the htm4l macros allow me to write

m4_http(`www.teclata.es/terry', `my homepage')

in a .htm4l file, which produces

<a href="http://www.teclata.es/terry">my homepage</a>

when run through m4. This is a very simple example. The htm4l macros get much more complicated (and useful!).


Back to the htm4l home page.
© Terry Jones (terry <AT> jon.es). Last modified: Mon Oct 2 02:22:03 CEST 2006