Home : Expand

Expand Home Page

There's a better way to do it

What's New?

Released Expand 2.2 (Expand 2.1 was never publicly released.) See the Expand man page for details.
Updated this page for non-Tcl users.
Re-released Expand 2.0; I fixed some of the examples in the man page.
Released Expand 2.0. See the Expand man page for details.
Released Expand 1.3.

Expand Overview

Having never found an HTML editor that suits me, I've written a lot of HTML by hand over the last few years, usually but not invariably in Emacs. What I've wanted the whole time is some kind of macro processor I could use to preprocess my HTML, and I've never found any such thing...at least, not that I was willing to use. Finally, armed with a neat idea, I wrote my own.

Expand for Non-Programmers

HTML is a wonderful tool for formatting documents for the World Wide Web. You can easily create headlines, section titles, table layouts, styled text, and all of the things we're used to seeing in web pages. The problem with HTML is that it's not extensible.

Let me give an example. A large portion of this website, wjduquette.com, is devoted to a monthly book review 'zine called ex libris reviews. In ex libris I frequently mention book titles, and I like to format them specially. I may, for example, want to see them in boldface, e.g., The Count of Monte Cristo. In HTML, that looks like this:

    <b>The Count of Monte Cristo</b>

This is all well and good...until the day comes when I want to redesign my website and I want to display book titles in italics: The Count of Monte Cristo. I have to search through every page, changing all of the "<b>" and "</b>" to "<i>" and "</i>"...being careful, of course, to change only the book titles and nothing else.

This is no fun. What I'd like to do instead is define my own HTML markup for book titles, and arrange for book titles to be displayed in bold face or italic as I choose. This is where Expand comes in. Using Expand, I can define new markup tags. For example, I might markup a book title as follows:

    [btitle "The Count of Monte Cristo"]

(Expand markup tags conventionally appear between square brackets, but you can change that if you like.) Now, the "btitle" macro is defined to expand to the HTML for boldface--or to expand to the HTML for italics. I can choose, just be changing the definition. When I've made my choice, I run my webpages through Expand, and the "btitle" tag new markup tags are converted to HTML. If I want italics instead of boldface, I just redefine "btitle", and run the webpages through Expand again.

By this time you might be saying (if you know a fair amount about HTML and web pages) that you can do the same thing with cascading style sheets...and so you can. But here's something you can't do that way.

In the ex libris archives I have many pages dedicated to particular authors. If I refer to an author in a particular issue of ex libris, I want to create a hyperlink to their page. I do this using the "hauthor" macro, e.g.,

  [hauthor "Alexandre Dumas"]

The macro formats the author's name however I'd like, and also creates a link to the author's page (e.g., Alexandre Dumas)...assuming I've created one yet. If I've not created a page for that author, it simply formats the name. What's so cool about this is that if I add a page for the author at a later time, and then reprocess my web pages, all the places I mention that author suddenly become hyperlinks to his page. You can't do that with style sheets.

Expand is a powerful tool, and using it takes a certain amount of skill. In particular, the macros are defined in a programming language called Tcl, which stands for Tool Command Language, and which is pronounced "Tickle". Soon I hope to write an introduction to Tcl for non-programmers; until then, you can find out more about it at TclTk.org.

Expand for Tcl Programmers

Expand is a macro expander based on the Tcl language; I use it for preprocessing HTML files for my web pages (including this one). Expand is described completely in the man page, but the basic notion is simple. Expand copies input files to output files, expanding any macros. A macro is nothing more than a valid Tcl command enclosed in square brackets. The copyright notice at the bottom of this page, for example, was expanded from a macro like the following:

    [copyright {William H. Duquette}]

In addition to the full set of Tcl commands, the author can write a rules file that defines new commands like "copyright". The rules files used for this page and for the Expand man page are included in the list below.

It's even possible to process an input file with several different sets of rules, for different purposes. I might use one set of rules to format a set of web pages for output, and another set to scan all of the pages and build an index.

Expand was written for use with Tcl 8.0 and has been tested with Tcl 8.3; it should work with any Tcl 8.x, and may also work with Tcl 7.6 and earlier versions, but that's not been tested. For more information about Tcl, visit TclTk.com. Tcl is an excellent, freely available scripting language, available for all major platforms.

Expand files and documentation

You can download the whole distribution or the individual pieces:

Expand 1.3 is the previous release:

If you have questions, comments, or suggestions about Expand, feel free to contact me at will@wjduquette.com.

Home : Expand
Copyright © 2003, by William H. Duquette. All rights reserved.
Search this site:

• The View from the Foothills
• Tcl/Tk
• E-Mail
• Links
• FAQs About Us

Amazon Honor System Click Here to Pay Learn More

Sites we like:

James Lileks
Banana Oil
2 Blowhards
God of the Machine
Goliard Dream
Reflections in d minor
Blithering Idiot