PS TEXT FORMAT Reference Manual

Examples of Function and Macro Constructs
G-10 11387 Tandem Computers Incorporated
MACRO Example 3 This example demonstrates a macro designed to collect index entries and
then print the entries. You could use this macro by placing idx strings in
your input file with the particular index item in quotes at the point where
each item appears in your document. See the following input file example.
After you are finished with your document, you make a call to the macro
and tell it to build your index using all the collected index items.
This idx macro also uses a little trick. It takes advantage of the prescan
feature of TFORM: each line is scanned for indirection escape sequences
before the line is processed. By using different values of “j” in a line like
\ASSIGN x y\(j\)
you can treat “y” like an array with “j” as the subscript. What actually
happens is that the prescan substitutes the value of “j” on the line in place
of \(j\), and so different variables (y1, y2, y3, and so on) are used.
2
1
3
\MACRO idx BEGIN LOCAL j, k, first, last1
\ IF ARG(0)<1
\ ERROR "you forgot your parameter to the idx macro"
\ EXITMACRO
\ ENDIF
\ IF !DEFINE(idx_count)
\ ASSIGN idx_count 0
\ ENDIF