GTML - an HTML pre-processor   >>

HTML is a powerful markup language for individual Web pages, but it has some serious limitations for maintaining entire Web sites (i.e. a collection of Web pages which needs to be kept consistent).

GTML is an HTML pre-processor which adds some extra features specially designed for maintaining multiple Web pages.

How does it work?

You embed GTML commands among the HTML in your source files. GTML reads and processes the GTML commands, but leaves the rest of the text unchanged (so it will work straight away on your existing Web pages).

HTML files generated by GTML are just like any other HTML files. Because GTML doesn't attempt to interpret your HTML commands in any way, it's fully compatible with all versions of HTML, and doesn't require any specific browser or server.

Is GTML for you?

If you write the HTML in your Web pages by hand using a simple text editor, then you'll find GTML useful. If, on the other hand, you use a sophisticated graphical tool to generate your HTML, you probably won't be able to use GTML. There are three reasons for this:

  • Your sophisticated tool won't understand the GTML commands, and might even complain violently about them.
  • GTML operates in a command-line batch mode, and your sophisticated tool probably operates from a graphical environment.
  • The source for GTML is in files ending in .gtm (or .gtml), and it generates the .html files. Your sophisticated tool probably generates the .html files itself.


Here are some of the things you can do with GTML:

  • Create a project file with the names of all your Web pages, so you can update them all with one simple click or command.
  • Process only files which sources have changed directly, or with the help of makefiles.
  • Generate a makefile to control the process of your Web pages, based on their dependencies. [** NEW **]
  • Give a specific alias to a filename, useable as constants, so that it is easy to move files and have links preserved.
  • Specify a tree-like hierarchy of Web pages, so you can add Next, Previous and Up links automatically to your site.
  • Automatically generate a map of your site, with the possibility of customizing the way this table of contents will look like. [** NEW **]
  • Use named constants for HTML fragments to save typing, ensure consistency and make changes easily.
  • Use environment variables as named constants.
  • Include header, footer and other common files into all your HTML files. This doesn't require Server-Side Includes.
  • Include timestamps (in any format you like) to show the time of last process, or of last modification.
  • Use conditional commands to create different versions of the output under different circumstances.
  • Generate output to different directories to generate different versions of your site (for example, a Frames version and a non-Frames version).
  • Change extensions of output files from .html to whatever you want, so that you may, for instance, use MultiViews options of Apache server, or create non-HTML files. [** NEW **]
  • Guard special characters `<', `>' and `&' in normal text so that they don't get confused with HTML commands.
  • Define your own characters translations, so that you may easily input your non-ASCII characters into GTML source. [** NEW **]
  • Embed Perl or shell code into your source, so that you may easily generate pages with computed information. [** NEW **]
  • Generate pages with all superfluous HTML code removed, so that readers retrieve them faster and may save bandwidth. [** NEW **]

All the GTML features and commands are described on the GTML Reference page.

Downloading GTML

GTML is written in Perl. If you don't have Perl, it's easy to obtain it on

There are two methods to download GTML:

  • Download GTML Perl script, and save it to a file called If you're running this under UNIX, edit the first line to point to the location of your version of Perl, and give the execute right to the file.
  • Download GTML archives containing Perl script as well as documentations. Archives are available in zip format or gzipped tar format.

The home page of GTML is at, and archives may be found at

Running GTML

GTML source files end in .gtm (or .gtml), not .html. If you're using GTML on existing HTML files, simply rename them with the ending .gtm (or .gtml).

GTML is run from the command line, like this:

     perl fred.gtm harry.gtm bill.gtm

(The UNIX version won't need the Perl at the front, so long as the script is executable.)

The output of this command will be in fred.html, harry.html and bill.html.

If you have a GTML project file, you include this on the command line. In this case, it's not necessary to list any of the files in the project as well.

Remember that you can use -D on the command line to create named constants. You can have as many -D options as you like. Make sure they appear before the file names to which they apply. For example, if you say:

     perl -DNAME=Fred fred.gtm harry.gtm -DTYPE=car bill.gtm
then NAME is defined for all three files and TYPE is defined for bill.gtm only.

By default, GTML will try to process some project file. It will look at these configuration files in this order:

  • $HOME/.gtmlrc
  • $HOME/gtml.conf
  • .gtmlrc
  • gtml.conf

Thoses files, if they exist, are parsed before command line is processed.

You may have a look at the source of the documentation pages of GTML in the source directory. The project file is called gtml.gtp.

Other HTML pre-processors

Here is a list of other HTML pre-processors that I know of, in case GTML will not satisfy your needs:


GTML is distributed under the GNU General Public License (GPL).

Copyright © 1996-1999 Gihan Perera (

Copyright © 1999 Bruno Beaufils (

Copyright © 2004 Andrew E. Schulman (

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Some history

For a long time I was looking for a way of maintaining some of the sites that I set up for the research team which I am member of. I wanted to get a tool which would enable me to easily change the look and feel of all pages of a site, and easily move pages of a site from one location to another.

I then used all my favourite search engines on the web, and found some pages, describing such tools. I tried some. They all missed something, from ease of use, to important features. When I tried GTML, from Gihan, I found it was pretty cool, but lacking some important features that I needed.

I wrote to Gihan asking him to add those features which I needed, since I had no Perl programming skill. He told me that he doesn't have time to do that in the near future. So I decided to read his code, and to learn Perl with his script.

The script was pretty well written and I learnt Perl, or at least understand how GTML worked very fast. It was then easy to add the features that I needed in it. I then asked Gihan if he would mind if I distribute GTML under the GNU General Public License, since his license policy was not as open as GPL, and he accepted.

Then I just updated some of the docs, prepared an archive, in the GNU spirit, and that was it.

My biggest question was to understand where the name of the tool come from, and after some reflexions I got two possible answers:

  • `G' is the letter just before H, and GTML source production comes just before HTML file one.
  • `G' is the first letter of Gihan's first name.

Well this is not a question anymore, Gihan told me the truth. Guess what? I found it: the first of my two previous hypotheses is the right one. (Well I hope that as time goes by it will be interpreted as GNU :-)

After I distributed it on my web pages, and after announcing it only on Freshmeat, I got some feedback from users coming from all around the world. I added some features which were asked of me, but realized that the source of the script needed some reorganization, and that there were some bugs in GTML.

I have done this source reorganization, and so have been able to fix bugs, and add a lot of fancy features. So now I'm waiting for users' feedback, in order to verify that I did not add bugs :-), and that GTML is now sufficiently stable.

In one month or so I hope to be able to say that it does. So I really need your help for that, please give me some feedback!.

I will not add any features, before the next stable release.

I hope my version of GTML will help you as it helps me.

--Bruno, 31 August 1999

This page has been accessed times since .   Sitemap   Reference >>

GTML home page
Last modification: 2004/10/29 at 20:18
Copyright © 1996-1999 Gihan Perera  (
Copyright © 1999 Bruno Beaufils  (
Copyright © 2004 Andrew E. Schulman  (