XTRAN Example — Format Text Items into Columns
Scenario — you have a list of text items, and you want to format them into descending columns. It is an onerous editing task, even using edit macros.
XTRAN to the rescue!
The following example uses an XTRAN rules file comprising 120 non-comment lines of "meta-code" (XTRAN's rules language) to format text items into columns.
The rules took less than 1½ hours to write and 1 hour to debug. (That's right, less than 2½ hours total!)
The rules read a series of text items from a file, one per line, format them into columns, and write out the result. They allow you to specify, via environment variables:
- Whether to create the output file or append to it.
- The number of columns you want.
- Whether each item in a column is to be left-justified, right-justified, or centered.
- The number of spaces between columns (column padding).
How can such powerful and generalized text manipulation be automated in less than 2½ hours and only 120 lines of rules? Because there is so much capability already available as part of XTRAN's rules language. These rules take advantage of the following functionality:
- Text file input and output
- Text manipulation
- Text formatting
- Delimited list manipulation
- Environment variable manipulation
- Content-addressable data bases
The input to and output from XTRAN are untouched.
Process Flowchart
Here is a flowchart for this process, in which the elements are color coded:
- BLUE for XTRAN versions (runnable programs)
- ORANGE for XTRAN rules (text files)
- PURPLE for text data files

Input to XTRAN:
When in the course of human events it becomes necessary for one nation to dissolve the political bonds which have connected it with another
Output from XTRAN — left justified:
When events nation which in it to have the becomes dissolve connected course necessary the it of for political with human one bonds another
Output from XTRAN — right justified:
When events nation which in it to have the becomes dissolve connected course necessary the it of for political with human one bonds another
Output from XTRAN — centered:
When events nation which in it to have the becomes dissolve connected course necessary the it of for political with human one bonds another