RTF
Rich Text Format

RTF is a document format used for exchanging documents 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, and is vastly more straightforward than ODT or DOCX formats. RTF has been around since about 1990, while hundreds of other binary formats have come and gone.

This is an introduction to the language in terms of someone who wants to understand RTF, either in order to generate RTF, or as an introduction to concepts you'll need if you want to parse RTF.

The formal specifications for RTF— from Microsoft's "official" commands, to commands that are specific to particular applications (to say nothing of undocumented commands)— are useful as reference, but not quite as friendly as I hope you will find this page to be.


The cover of the first edition "RTF Pocket Guide"

I wrote RTF Pocket Guide in 2002, and this page started as content of that book. But long story short: Don't buy the book. That book has some annoying typos and serious omissions, so, long story short, don't buy it. In a way, this page is like a highly revised and expanded 2nd edition of that book from so long ago.


Note: It's Not All Here Yet...

At the moment, I'm in the process of converting and correcting content from the book, section by section by section. Bear with me...

[]


Why RTF?

RTF is a handy format for several reasons.

[ -todo- anything else need copying from this section of the book?]

And so it begins...

This Guide's Approach

-todo-

RTF "Hello, World!"

-todo-

Overview of Simple RTF

-todo-

Basic RTF Syntax

-todo-

Paragraphs

-todo-

Character Formatting

-todo-

Document Structure

-todo-

The {\*\command ... } Construct

-todo-

Faking comments with {\*\command ... }

-todo-

Language Tagging

-todo-

Newspaper Columns

-todo-

Footnotes

-todo-

Changing Text Color

-todo-

Page Margins

-todo-

Page Size and Orientation

-todo-

Line Drawing

-todo-

p060_horizrule_rtf

{\pard {\*\do
\dobxcolumn \dobypara \dodhgt7200
\dpline \dpptx0 \dppty0 \dpptx7200
\dppty0 \dpx0 \dpy0 \dpxsize7200
\dpysize0 \dplinew15
\dplinecor0 \dplinecog0 \dplinecob0 }\par}

-todo-

p061_horizrule_rtf

{\pard \brdrb \brdrs \brdrw10 \brsp20 \par}
{\pard\par}

-todo-

-todo-

p062_horizrule_rtf

{\pard \li2268 \ri567
\brdrb \brdrs \brdrw10 \brsp20 \par}
{\pard\par}

-todo-

-todo-

-todo-

Embedding Images

-todo-

[The section in the book is absolutely and completely banjaxed! Rewrite starting from scratch.]

-todo-

Overstrike in RTF

Some word-processing programs, such as WordPerfect, support a feature called overstrike, in which two (or more) characters can be printed one on top of each other. For example, an overstrike consisting of B and | would give you ฿, which happens to be the (otherwise usually unavailable) symbol for the Thai currency, the baht. Unfortunately, there's no way to express overstrikes in RTF, and no workaround that I know of.

Centering Vertically and Horizontally

-todo-

-todo-

p065_vhcenter_rtf

{\pard \pvmrg\phmrg\posxc\posyc \qc
\fs60 {\i Motherboard, May I?}
\line
\line\fs50 Screenplay by S. Burke
\line\fs40 Draft 7\par}
{\pard \page \par}

-todo-

Symbols

-todo-

Styles

-todo-

-todo-

p069_styles_rtf

{\rtf1\ansi\deff0

{\fonttbl {\f0\fswiss Arial;}{\f1\froman Bookman;}}

{\stylesheet
{\s0 Normal;}
{\*\cs1 Default Paragraph Font;}
{\*\cs2 \additive \fs26\i\f1 \sbasedon1 ChannelName;}
{\*\cs3 \additive \fs26\i\f1\b \sbasedon2 PromoChannelName;}
{\s4 \li560\sa180 \sbasedon0 Listing_Item;}
}

\deflang1033\plain\fs24

{\pard
On February 19{\super th}, we at Keystone Kable TV will
 change the channel line-up.
 {\cs2 \fs26\i\f1 CSPAN} will move from channel 18 to channel 17.
 {\cs2 \fs26\i\f1 CSPAN-2} will move from channel 19 to channel 18.
 And a new channel,
 {\cs2 \fs26\i\f1 Classic Arts Showcase}, will
 be on channel 19. All hail cable television!!
\par}

{\pard
As a bonus, channel 20 will show
 {\cs3 \fs26\i\f1\b HBO-Espa\'f1ol} free for a month!
\par}

{\pard\sb180\sa180\qc ~\par}

{\pard \s4 \li560\sa180 17: CSPAN \par}
{\pard \s4 \li560\sa180 18: CSPAN-2 \par}
{\pard \s4 \li560\sa180 19: Classic Arts Showcase \par}
{\pard \s4 \li560\sa180 20: HBO-Espa\'f1ol \par}

}

-todo-

....

Tables

-todo-

-todo-

p076a_table_single_cell_no_border_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd \trgaph180
\cellx1440
\pard\intbl Fee.\cell
\row


}

-todo-

-todo-

p076b_table_2x1_no_border_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl Fee.\cell
\pard\intbl Fie.\cell
\row


}

-todo-

-todo-

p076c_table_2x2_no_border_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl Fee.\cell
\pard\intbl Fie.\cell
\row
\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl Foe.\cell
\pard\intbl Fum.\cell
\row

}

-todo-

-todo-

p077_table_2x2_groups_no_border_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

{
\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl {Fee.}\cell
\pard\intbl {Fie.}\cell
\row
}{
\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl {Foe.}\cell
\pard\intbl {Fum.}\cell
\row
}

}

-todo-

-todo-

p078_table_cell_stretches_down_still_no_border_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl Fee.\cell
\pard\intbl Fie.\cell
\row
\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl Foe.\cell
\pard\intbl Fum -- and what on earth is a fum?\cell
\row


}

-todo-

-todo-

p082_table_all_borders_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd \trgaph180
\clbrdrt\brdrw15\brdrs
\clbrdrl\brdrw15\brdrs
\clbrdrb\brdrw15\brdrs
\clbrdrr\brdrw15\brdrs\cellx1440
\clbrdrt\brdrw15\brdrs
\clbrdrl\brdrw15\brdrs
\clbrdrb\brdrw15\brdrs
\clbrdrr\brdrw15\brdrs\cellx2880
\pard\intbl Fee.\cell
\pard\intbl Fie.\cell
\row

\trowd \trgaph180
\clbrdrt\brdrw15\brdrs
\clbrdrl\brdrw15\brdrs
\clbrdrb\brdrw15\brdrs
\clbrdrr\brdrw15\brdrs\cellx1440
\clbrdrt\brdrw15\brdrs
\clbrdrl\brdrw15\brdrs
\clbrdrb\brdrw15\brdrs
\clbrdrr\brdrw15\brdrs\cellx2880
\pard\intbl Foe.\cell
\pard\intbl Fum.\cell
\row


}

-todo-

-todo-

p083_table_some_borders_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd \trgaph180
\clbrdrt\brdrw35\brdrdot
\clbrdrl\brdrw35\brdrdot
\clbrdrb\brdrw35\brdrdot
\clbrdrr\brdrw35\brdrdot\cellx1440
\clbrdrt\brdrw35\brdrdot
\clbrdrl\brdrw35\brdrdot
\clbrdrb\brdrw35\brdrdot
\clbrdrr\brdrw35\brdrdot\cellx2880
\pard\intbl Fee.\cell \pard\intbl Fie.\cell
\row
\trowd \trgaph180
\cellx1440\cellx2880
\pard\intbl Foe.\cell \pard\intbl Fum.\cell
\row

}

-todo-

-todo-

p085a_table_v_alignment_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24


\trowd\trleft0\trgaph120
\cellx1440
\clvertalt\cellx2880
\clvertalc\cellx4320
\clvertalb\cellx5760
\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl {\i The large print giveth}\cell
\pard\intbl {\i and the small print}\cell
\pard\intbl {\i taketh away.}\cell
\row


}

-todo-

-todo-

p085b_table_h_alignment_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24


\trowd\trleft0\trgaph120\cellx1440
\cellx2880\cellx4320\cellx5760
\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl\ql {\i The large print giveth}\cell
\pard\intbl\qc {\i and the small print}\cell
\pard\intbl\qr {\i taketh away.}\cell
\row


}

-todo-

-todo-

p086a_table_all_alignments_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd\trleft0\trgaph120\cellx1440
\clvertalt\cellx2880 \clvertalt\cellx4320 \clvertalt\cellx5760
\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl\ql {\i The large print giveth}\cell
\pard\intbl\qc {\i and the small print}\cell
\pard\intbl\qr {\i taketh away.}\cell
\row
\trowd\trleft0\trgaph120\cellx1440
\clvertalc\cellx2880 \clvertalc\cellx4320 \clvertalc\cellx5760
\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl\ql {\i The large print giveth}\cell
\pard\intbl\qc {\i and the small print}\cell
\pard\intbl\qr {\i taketh away.}\cell
\row
\trowd\trleft0\trgaph120\cellx1440
\clvertalb\cellx2880 \clvertalb\cellx4320 \clvertalb\cellx5760
\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl\ql {\i The large print giveth}\cell
\pard\intbl\qc {\i and the small print}\cell
\pard\intbl\qr {\i taketh away.}\cell
\row

}

-todo-

-todo-

p086b_table_all_alignments_with_borders_rtf

{\rtf1\ansi\deff0
{\fonttbl {\f0\fswiss Arial;}}
\deflang1033\plain\fs24

\trowd\trleft0\trgaph120
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\cellx1440
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalt\cellx2880
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalt\cellx4320
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalt\cellx5760

\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl\ql {\i The large print giveth}\cell
\pard\intbl\qc {\i and the small print}\cell
\pard\intbl\qr {\i taketh away.}\cell
\row

\trowd\trleft0\trgaph120
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\cellx1440
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalc\cellx2880
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalc\cellx4320
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalc\cellx5760

\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl\ql {\i The large print giveth}\cell
\pard\intbl\qc {\i and the small print}\cell
\pard\intbl\qr {\i taketh away.}\cell
\row

\trowd\trleft0\trgaph120
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\cellx1440
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalb\cellx2880
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalb\cellx4320
\clbrdrt\brdrw30\brdrs\clbrdrl\brdrw30\brdrs\clbrdrb\brdrw30\brdrs\clbrdrr\brdrw30\brdrs\clvertalb\cellx5760

\pard\intbl {\fs50 Wise man say:}\cell
\pard\intbl\ql {\i The large print giveth}\cell
\pard\intbl\qc {\i and the small print}\cell
\pard\intbl\qr {\i taketh away.}\cell
\row

}

-todo-

Example Programs

-todo-

A Datebook Generator

-todo-

A Directory Lister

-todo-

An Origami CD Case Maker

-todo-

The (Serious) Trouble With \bin

-todo-

Notes: it means RTF has two modes: normal parsing, and going out-of-band.

RTF for MSWindows .HLP Help Files

The RTF book had a section on producing .hlp (Winhelp) files, because it was based on the documentation being in RTF. (And it was an extremely bizarre dialect, which I covered only because it was still in some legacy systems.) But, to quote Paul F. Tompkins, "we are living in a year with a 2 in front of it!" Microsoft stopped shipping the part of the OS that could read .hlp files. Nobody can read .hlp files, so nobody needs to know how to make them, so nobody needs to know the aspects of RTF that go into it all, so... that's why I'm not bothering to reproduce the parts of the RTF book that discussed it all. If, somehow, for some reason, you need to deal with RTF-for-winhelp and you have a question, just email me.

Remarks on Parsing

-todo-

Reference Tables

-todo-

ASCII-RTF Character Chart

-todo-

RTF Language Codes

-todo-

Converting to Twips

-todo-

[also: try making a downloadable printable twips ruler.]

Ω


Sean M. Burke

https://interglacial.com/rtf/