{Note:  I haven't yet written a real version of this document.  What follows is a cursory description for until I do.

Description
This library provides procedures for converting multi­font text created with the jrichtext.tcl library (or with compatible tags) in a Tk text widget to a variety of other formats, including a generic `Save As...' panel you can use to prompt your users for a filename and file type.

The library contains a lot of procedures, currently only the most important public procedures are documented.  If all you want to do is let your users save the contents of a rich­text widget in various formats, the only procedure you'll need is j:tc:saveas.

Currently, the following output formats are supported:
* Tcl­format richtext as supported by jrichtext.tcl
* TeX
* HTML
* PostScript

With one exception, only font information is converted; underlining, colours, and other tags are not (yet :-) converted.  The exception is that jdoc hypertext links to other documents (i.e., not within the same document) are preserved after a fashion when converting to HTML.  The HTML links generated for links to other jdoc documents (as opposed to standard URLs) may need hand­editing, however, since relative links in HTML documents and jdoc don't follow the same rules.

Thanks
Thanks to Miguel Santana <santana@imag.fr> for permission to use the /reencodeISO procedure from his a2ps program when converting rich­text to PostScript.

Tags
This library considers the following tags:
	richtext:font:roman
	richtext:font:italic
	richtext:font:bold
	richtext:font:bolditalic
	richtext:font:typewriter
	richtext:font:heading0
	richtext:font:heading1
	richtext:font:heading2
	richtext:font:heading3
	richtext:font:heading4
	richtext:font:heading5
	jdoc:link:link
(where link is a URL or the name of a jdoc document)

See Also
	jtexttags.tcl
	jrichtext.tcl

j:tc:saveas
Usage
	j:tc:saveas t
Argument
	t is the text widget whose content is to be converted

Description
This procedure brings up a File Selection panel with an option button that lets the user choose among the supported file formats.  When the user chooses a format and a name and clicks OK or presses Return, the text widget t is saved in the chosen format in the specified file.

Warning
The File Selection panel seems to cause Tk scripts to crash under at least some beta versions of Tk 4.0.

Conversion Procedures
All of the following take as their sole argument a text widget whose contents are to be converted, and return the contents of that text widget converted to the given format as their value.  (Note that this can mean that you're schlepping around some fairly large strings.)

j:tc:tclrt:convert_text t - convert to Tcl­format richtext; see jrichtext.tcl
j:tc:tex:convert_text t - convert to TeX source
j:tc:html:convert_text t - convert to HTML (without links, currently)
j:tc:ps:convert_text t - convert to PostScript

Comments on Formats
Tcl­Format Richtext
Because it's designed to write into a text widget, this is the most faithful format.

The distinction between j:rt:par and two successive j:rt:cr's is lost when converting text that was generated with the jrichtext.tcl library, but it's not actually reflected in the text widget in the first place.

TeX
The TeX generated by j:tc:tex:convert_text works, but it's really weird and unnecessarily verbose.  It makes lots of characters active and changes some standard parameters, so if you try to embed it in TeX documents of your own you should enclose it in braces.  If you don't use any non­ASCII characters, you can trim off most of the preamble, which provides support for the ISO 8859-1 character set.

Tabs are converted to a fixed amount of whitespace, and spaces at the beginning of a line are lost.  Multiple blank lines are also lost.

HTML
When converting to HTML, tabs are lost, as is any spacing at the beginnings of lines.

The distinction between paragraphs and line breaks is lost; all sequences of line breaks are translated as a single <P> code.

PostScript
The line­breaking algorithm is hideous, and long words are likely to be wrapped across lines.

Tabs are rendered as a fixed amount of space.  Spaces occasionally appear at the beginnings of lines when they shouldn't (similarly to the way they do in the Tk text widget).

What is generated is actually a PostScript program that generates the formatting, rather than a set of simple page descriptions, so it makes a lot of demands on your PostScript interpreter, and may print more slowly than you expect.  Also, it doesn't conform to the PostScript comment conventions (it can't), so tools that need to work with PostScript files page­by­page will fail.

The ISO 8859-1 character set is supported only if you have a Level 2 PostScript interpreter (or at least an interpreter than knows ISOLatin1Encoding).

Bugs and Misfeatures
* The code needs to be reorganised.  Code is shared between different formats that shouldn't be, and code isn't shared that should be.

* Whitespace is often lost or garbled in many of the formats.

* Much of the code is pretty inefficient.

* Tags other than font tags should be handled, for instance, colour and underlining should be supported (where possible).

Future Directions
* In addition to improving the existing conversions (and they really need it!), I'd like to provide modes for plain­text (with lines broken sensibly, and maybe capitalisation for headers) and formatted text (like nroff(1) output).  LaTeX, RTF, and troff are other possibilities.

* It would be nice to support WYSIWYG writing of manual pages, or generation of them from jdoc documents.  This would probably require a little additional information beyond what's in the text widget (e.g. name and description, section of the manual, etc.)

* When jdoc documents are converted to HTML, I'd like to translate hypertext links and anchors as well as fonts.  (The capabilites of jdoc are closely modelled after those expressible in HTML.)

* The exact fonts used when generating PostScript and TeX should be user preferences.

* The TeX conversion does a lot of work to support ISO 8859-1.  This should only be done if there are actually non­ASCII characters in the text (or perhaps it should be a user preference).  The PostScript conversion should support ISO 8859-1 even on Level 1 interpreters (it's easy enough).
} {{{jdoc:xref:link {6.245 6.256 9.38 9.51 14.144 14.148 14.321 14.325 33.38 33.42 36.1 36.14 37.1 37.14 54.64 54.77}} {jdoc:anchor:anchorname {39.0 40.0 54.0 54.23 55.0 55.21 56.0 56.22 57.0 57.20 59.0 60.0}} {richtext:font:roman {1.116 3.0 4.0 4.81 4.94 6.245 6.256 9.38 9.51 14.144 14.148 14.165 14.183 14.321 14.325 14.441 14.445 16.0 17.0 17.25 17.42 17.69 17.81 17.101 17.105 19.0 20.0 21.1 21.20 22.1 22.21 23.1 23.19 24.1 24.25 25.1 25.25 26.1 26.23 27.1 27.23 28.1 28.23 29.1 29.23 30.1 30.23 31.1 31.23 32.1 32.15 33.7 33.11 33.38 33.42 34.0 36.0 36.1 37.14 39.0 41.0 41.1 41.14 42.0 43.0 43.1 43.2 45.0 46.0 46.198 46.204 46.222 46.223 48.0 49.0 51.0 52.0 54.0 54.23 54.24 54.25 54.64 54.77 55.0 55.21 55.22 55.23 56.0 56.22 56.23 56.24 57.0 57.20 57.21 57.22 59.0 61.0 63.24 63.32 63.52 63.59 63.119 63.132 65.0 66.0 66.21 66.29 66.30 66.42 70.0 71.0 73.116 73.119 75.0 76.0 82.131 82.148 84.0 85.0 93.0 94.0 94.213 94.218 94.248 94.253 96.90 96.94 98.7 98.11 98.134 98.138 103.0}} {richtext:font:italic {1.5 1.116 14.165 14.183 32.11 32.15 33.7 33.11 41.13 41.14 43.1 43.2 46.222 46.223 54.24 54.25 55.22 55.23 56.23 56.24 57.21 57.22}} {richtext:font:bold {4.81 4.94 9.38 9.51 36.1 37.14 46.198 46.204 54.64 54.77 63.119 63.132}} {richtext:font:bolditalic {1.0 1.5}} {richtext:font:typewriter {6.245 6.256 14.144 14.148 14.321 14.325 14.441 14.445 17.25 17.42 17.69 17.81 17.101 17.105 21.1 21.20 22.1 22.21 23.1 23.19 24.1 24.25 25.1 25.25 26.1 26.23 27.1 27.23 28.1 28.23 29.1 29.23 30.1 30.23 31.1 31.23 32.1 32.11 33.38 33.42 34.0 35.0 41.1 41.13 54.0 54.23 55.0 55.21 56.0 56.22 57.0 57.20 63.24 63.32 63.52 63.59 66.21 66.29 66.30 66.42 73.116 73.119 82.131 82.148 94.213 94.218 94.248 94.253 96.90 96.94 98.7 98.11 98.134 98.138}} {richtext:font:heading1 {3.0 4.0 16.0 17.0 19.0 20.0 35.0 36.0 39.0 40.0 51.0 52.0 59.0 60.0 84.0 85.0 93.0 94.0}} {richtext:font:heading2 {40.0 41.0 42.0 43.0 45.0 46.0 48.0 49.0 60.0 61.0 65.0 66.0 70.0 71.0 75.0 76.0}} {jdoc:link:jrichtext.tcl.jdoc {9.38 9.51 37.1 37.14 54.64 54.77}} {jdoc:link:jtexttags.tcl.jdoc {36.1 36.14}} {jdoc:link:#j:tc:saveas {6.245 6.256}} {jdoc:anchorname:j:tc:saveas {39.0 40.0}} {jdoc:anchorname:j:tc:tclrt:convert_text {54.0 54.23}} {jdoc:anchorname:j:tc:tex:convert_text {55.0 55.21}} {jdoc:anchorname:j:tc:html:convert_text {56.0 56.22}} {jdoc:anchorname:j:tc:ps:convert_text {57.0 57.20}} {jdoc:anchorname:Comments_on_Formats {59.0 60.0}} {jdoc:link:jdoc.jdoc {14.144 14.148 14.321 14.325 33.38 33.42}}} {{abbrevstart 33.52} {matchend 66.65} {richptr 54.39} {abbrevend 33.52} {insert 1.0} {anchor 37.14} {matchstart 66.59} {current 3.11}}}