LJ Archive

Blank Line Macro

A useful extension that groff offers the macro writer is the possibility to define a macro that is executed in the presence of blank lines in the input file. This feature is first useful when preparing a macro command file itself, as any blank lines that creep in will turn up in the output document. Later, the blank line macro can be reassigned to, say, the default paragraph formatting for the user's document.

The following macro defined near the top of a macro collection will alert the user (through stderr) to the presence of any blank lines in the file:

\# continuing the alias scheme:
.ALIAS     BLANKMAC    blm
.ALIAS     MESSAGE     tm
.ALIASNR   _FILE       .F
.ALIASNR   _LINE       .c
\# define the macro:
.MACRO     GOTBLANK    __END__
.  MESSAGE \
Notice: blank line in file \\n[_FILE], line \\n[_LINE].
.__END__
\# assign this macro to fire at blank lines:
.BLANKMAC  GOTBLANK
At the end of the macro command file, the blank line macro could be reassigned to another macro, such as the default paragraph control:
.BLANKMAC  <p>
Notice also from this example that the technique of reporting messages during groff processing can be built into any macro definition.
.MACRO  MYMACRO  __END__
(some stuff here) . MESSAGE Execution of \\$0 in file \\n[_FILE], line \\n[_LINE]. (some more stuff) .__END__
Groff enables the \\$0 escape inside a macro to list the name with which the macro was called. While you are developing macros, such messages can be used to show the state of internal variables and otherwise help in debugging.
LJ Archive