catex (Concatenate and expand files)

This C program requires the names of one or more files as arguments, and will copy each of them in turn to standard output, eg

   catex file1 file2  >tempfile
The single file ("tempfile" in this case) will contain the contents of "file1" and "file2". In the process of copying the files, certain special text strings are scanned for and processed without copying verbatim.

File inclusion

If the string

   %include name%
is found, the name is interpreted as a file name; reading of the original file is suspended, and the new file is inserted in the output stream.

A file being included will itself be checked in the same way as the original file for occurrences of instructions such as

   %include newname%
and such new files will be inserted appropriately. Calls to include files can be nested to any depth.

A file-name is interpreted relative to the file from which it was called, and simple names are interpreted as being in the same directory. Names beginning with '..' are interpreted as being in a higher level directory.

Current date

A string %DATE% within a file will be replaced by the current local date.

Macro definition and invocation

Macros can be defined using the form

   %DM,name:string:%
and such strings will not be copied to the output. These set up text substitutions that will apply to the remainder of the document.

Such macros can be invoked with %M,name%, so that this text will be replaced by the string in the definition. Invocation is recursive, by which I mean that the replacement text is not simply copied directly to standard output, but instead is processed as the input stream. Within this replacement text may be other macro invocations (%M,othername%), new macro definitions, or %include.. directives. (A macro cannot be redefined within its own body; our simple syntax will not allow colons to appear in the 'string' part of a definition).

A situation where macros might be useful is if we wanted to use two paragraph styles within the one document. Paragraphs have four attributes, the body alignment, the first line indentation, the inter-paragraph gap, and the minimum distance from the bottom of the page for the start of a new paragraph. If we needed to use the style of paragraph with indented first line for most of the document, but in some areas to switch to a hanging first line style for numbered points, we could define two macros for each style:      

   %DM,Num:%P,15,-10,-.5%:%

   %DM,Par:%P,0,5,0%:%
Then to commence a normal paragraph, we would use %M,Par%, and commence a numbered paragraph, %M,Num%. The parameters of the two styles would be defined once, and we could switch between the two styles as needed without needing to remember to reset the parameters of the original style at the end of a section.

Similar styles can be set up for section titles, where a little extra space before the title, a change in font size and paragraph style, and the use of bold will be used systematically for all headings throughout the document.      

   %DM,Head:%L%%SZ,16%%PH,0,0,0%%BD%:%

   %DM,Body:%SZ,11%%P,0,0,0%%LT%:%

A file is provided (macros.qs) which contains a set of macro definitions that are useful for structured documents, with lists possibly containing sub-lists. In this way, a layout style can be established in the one place, so that measurements of offsets or indentations do not need to be actually used within the document.