# RTFRich Text Format

RTF is a document language used for exchanging text between different word processors and text-processing applications.  RTF is much easier to generate than PDF or PostScript, and is more word-processor friendly than HTML.  RTF has been around for over thirty years, while hundreds of other binary formats have come and gone.

The book about RTF is RTF Pocket Guide by yours truly, from O'Reilly & Associates.  The book explains RTF as a format and lists common constructs, whereas the Microsoft RTF specification is at best a reference.

I wrote the book basically so that I could gather together, in one place for everyone to see, all the commonly used codes that I had to remember for all my RTF-generating programs. I prefaced it with a step-by-step intro to RTF syntax, and added some sections on some of the dustier corners of the language.

Along the way I got to stick in other goodies like a twips ruler (in the back cover), a decent Windows/ANSI/CP1252 character chart, and even an RTF generator for origami CD cases.

MSWord generates some scary RTF (just as bad as the HTML it writes out), but RTF doesn't need to be complicated. Here's a minimal "Hello World" document in RTF:

{\rtf {\fonttbl {\f0 Times New Roman;}} \f0\fs60 Hello, World! } 

Some people think RTF looks like TeX or LaTeX, but it's fundamentally very different.

## The RTF email list!

• RTF Tools and Documentation including past and present versions of the RTF spec.
• The RTF Cookbook — a handy quick-reference.
• Perl RTF modules at CPAN (and see also HTML-Format's and Pod-Simple's RTF modes)
• These are some open-source word processors that read and write RTF, among other formats:
• The RTF Specification, version 1.9.1.  (It's a 12MB file.  It has the same pagecount as v1.7, but is ten times its file-size because of more embedded illustrations.)
• MSWord Viewer — a free viewer that lets you faithfully view, but not edit, RTF (and MSWord .doc) files.
• rtf2rtf — an RTF parser that dumps the parse tree as, yes, RTF! Very handy for debugging RTF.
• rtf2xml — an RTF tokenizer that spits out an XML stream.
• "Making Dictionaries with Perl and RTF" — a perl.com article I wrote a while back. It's a decent introduction to "report generation" in RTF.
• datebook — a simple Perl program that generates a document containing a year's worth of datebook pages.
• mswin_rtf_clipboard_saver — a Perl program (for running under ActiveState Perl) that dumps to a file the contents of the RTF component of the clipboard. Handy for debugging clipboard-using applications.
• an RTF mode for emacs — if you're already an emacs user, that is, and want a mode for browsing RTF source. (Vim already has such a mode bundled with the standard install.)

### A note about whether RTF is proprietary and who "owns" it:

Microsoft devised and specifies the RTF format's very basic syntax (\foo, \bar123, {... ...} etc), and they defined some very rudimentaly tags for font size, italic, bold, paragraph, etc). But programs that read/write/interchange exchange RTF can (and very very frequently do) add their own custom tags, and they have been doing so from the very beginning of RTF, and as the RTF specification entirely allows. (In fact, the specification explicitly specifies a construct that makes that even easier.)

This is equivalent to how, in the 1990s, The World Wide Web Consortium invented HTML and CSS — and they specified the syntax (<zaz whut=123>, etc) and specified some fundamental tags, but HTML and CSS allow any program to use their own tags or attributes. RTF "belongs to" Microsoft only in the sense that HTML and CSS "belong to" The World Wide Web Consortium.

In other words, RTF is what you make of it.

2020-03-01 Sean M. Burke

http://interglacial.com/rtf/