Expand: The Macro Preprocessor

While the html script tag does allow for programmable constructs on the client side, it falls short of ideal in several respects. Foremost, it can not be used for server side preprocessing, which is often used to present a uniform look across multiple pages. Secondly, the syntax of using puts can be somewhat awkward to use and read when applied to large quantities of documentation. eg.

  set title {Hello World}
  puts "$title
" }

There are numerous macro preprocessors available for HTML, and Expand is one based upon Tcl. Normally Expand is used from the commandline to generate output files which are then used within a web server. However, PDQ has retrofitted Expand so that it can run within Safe-Tcl inside the browser to provide macro preprocessing. In doing so, two new document types/extensions have been created.

  .mehtml   text/mehtml       # Expand Demo Man-Macro
  .ehtml    text/ehtml        # Site Default Expand Macro
The first uses the predefined macros included as a demo with the Expand packages. The second (in /usr/lib/pdq1.0/expand/exprules.tcl) is a set of rules that are just wrappers for HTML. Here is an example.
  [eval { proc title {} { return {Hello World} } }]
  [B [title]]
The inline nature of the Expand approach is more natural and readable. Also the document is retargetable to say latex or even XML. See expand.mehtml for a the source to the extend man page which was written using manrules.tcl.

There are two implications of imbedding Expand inside PDQ. The first is that .ehtml files can be viewed directly by PDQ without manually preprocessing the files. This works only because the source file is local (a file:) and therefore Safe-Tcl permits open for read in the embedded Expand-Tcl. Thus file includes, etc should work fine.

The second implication is that it is possible for Web servers to return documents of type text/ehtml and have the PDQ browser process the document tags correctly. This will however work only with PDQ, so caution should be exercised with this practice. Also, the site specific tags would need to be embedded in an eval statement at top.

Note: be aware the using script/embed with Expand may or may not produce the desired results.