Home | Download | Wiki | About ANTLR | Feedback | Support |

Latest version is 2.7.7.
Download now! »

» Home
» Download
» News
»Using ANTLR
» Documentation
» Wiki
» Articles
» Grammars
» File Sharing
» Code API
» Tech Support
» Bug Tracking
»About ANTLR
» What is ANTLR
» Why use ANTLR
» Showcase
» Testimonials
» Getting Started
» Software License
» ANTLR WebLogs
» ANTLR Workshops

Support StringTemplate, ANTLR Project by making a donation! Terence often pays for things like the antlr.org server, conference travel, and this site design (that alone cost US$1000). Buy him a beer and pizza remotely ;)


Terence's Markup Language

Version 0.1, March 24, 2004

Terence Parr
University of San Francisco & jGuru

[This doc is inadequate at best, but with the source and some samples, you can figure it out. ;)]

Useful links

Source, Doc


I do all of my course materials in TML; it's just fabulous for generating HTML, though I've given up using TML for anything but HTML. I use LaTeX for papers. Anyway, any *.tml file in these directories should give the idea.

Introduction and Motivation

Humans brains gravitate towards WYSIWYG editors because the formatted text is just the text with a visual layout and possibly some font twiddling like bold and italics. In constrast, reading the computer representation of this (HTML, RTF<shudder>, PostScript) can be difficult. Your brain has to filter out the formatting instructions to get at the text.

The problems with WYSIWYG editors in my view are:

  1. They are very heavyweight (compared to a text editor)
  2. You are usually providing lots of formatting and layout instructions rather than "this is a title". You end up spending a lot of time just laying out your text, which may not even make it into the book.
  3. While some WYSIWYG editors like Word provide styles so that you can say "this is a title", I found the layout interaction between styles cumbersome. It is often difficult to get things to look right. I also like to do search, replace operations on non word items like "find the next section". Many editors won't allow this.
  4. Getting your document correctly converted into a different format like HTML, PDF, raw text, or whatever can be difficult with commercial products as they don't want to let you "escape." You can get tied to a particular OS even.
  5. From my perusal of publishers' websites, they all say the same thing: don't format your text with anything beyond section markers and typewriter font changes. No footnotes, no fancy tables etc... I.e., they are going to ignore all your formatting anyway when you turn in the book. They all will accept straight text.
  6. I like to think of my documents as "programs". Being able to add a "plugin" that does something interesting with a text argument is cool and really useful.

The alternative of choice for technical folks is to use a text-based formatting system like LaTeX or nroff or even HTML. Again, though, you are providing formatting information not high-level document components. DOCBOOK on the other hand has the high-level nature you want, but it adds so much markup that I find it very hard to read the text I'm writing.

My solution to this problem is take the best of WYSIWYG and text-based systems and merge them into a system that covers 90% of my document needs. This system, TML (Terence's Markup Language), is a Wiki-inspired document language that I've used successful to produce course materials, web pages, and slides.

Consider writing a piece of email. You specify your formatting visually with newlines and simple markup like *bold this* and so on. The idea in TML is to use the visual information as markup for paragraphs and sections rather than explicit tags. This allows you to read your document naturally in a text editor. A translator on the back end can generate Lout, DOCBOOK, HTML, or whatever you want.

This document describes the basic syntax of TML and, because it is written in itself, this document provides a simple example.


The first line of any document is the title. Sections are denoted with multiple # characters where #### indicates the outermost section. In other words, the bigger the visual display the more major the section. All paragraphs start with a blank line. Here is a simple TML document:

A sample TML document

This is the first paragraph.

#### Outermost section

Here is the first paragraph of the outermost section

Here is the second paragraph of the outermost section

### A nested section

Here is the first paragraph of the nested section

Bullet lists are just like you do in email text:

o first bullet
o second bullet

To make numbered lists use

1 first numbered item
1 second numbered item

For formatting words, you can use the following
Operator Meaning
{x} Teletype font
*x* Bold font
_x_ Italics font
\x Escape char x
\ end of line <br>; line break
\ line by itself <br><br> blank line
"x" block quote ('"' preceded by two spaces)

Tables are done sort of visually:

*header col 1* | *header col 2*
row 1 col 1 | col 2
row 2 col 1 | col 2

Links. Use style @(http://www.antlr.org) and @(http://www.antlr.org, ANTLR).

Plugins. %foo(...) invokes org.tml.plugin.foo.translate(...), sending the result to the output file.



to include a file or

%include("file", code)

to have it appear in <pre> tags.


%output <<
send this to the output

to send something straight to output.

Can put a box around something:

%box <<
put this in a box

Running TML

To run TML on your TML files, just run stdin to org.antlr.tml.Tool. Here is the shell script I use to run tml via $ tml foo (takes foo.tml and makes foo.html):

java org.antlr.tml.Tool < $1.tml >$1.html

Note that you must have ANTLR in your CLASSPATH to build and run TML.