{Note:  I haven't yet written full documentation for these procedures.  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 ::jstools::tc::saveas.

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

Except when converting to HTML, only font information is converted; underlining, colours, and other tags are not (yet :-) converted.

However, when converting to HTML, jdoc or jhtml-mode hypertext links to other documents (i.e., not within the same document) are preserved after a fashion.  (These can be links to other jdoc documents, which will be converted to references to HTML documents, or standard Web URLs, which will be preserved without change.)  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.

Also, when converting to HTML, unordered lists are supported, to an arbitrary depth.  (The lists generated may be very strange if you haven't been careful when typing the list; all text within the list must be tagged as an unordered list of the appropriate level, and list item markers must appear within the list in appropriate places.)
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 tags matching the pattern richtext:font:font, where font is one of roman, italic, bold, bolditalic, typewriter, heading0 through heading5, l_em, l_cite, l_var, l_dfn, l_strong, l_kbd, l_code, or l_samp.  Any completely untagged text is assumed to be fixed­pitch (i.e. typewriter­style).

HTML conversion also considers tags matching the patterns jdoc:link:link (where link is a URL or the name of a jdoc document), special:anything (for special­purpose things like horizontal rules, list items, and literal html text), and list:level:number, where number is the depth of list nesting, for generating <ul> and </ul> tags.

(It's a historical anomaly that the tag for hypertext links starts with jdoc:, although you're most typically going to use it in jhtml mode for ordinary HTML links.)
See Also
· jtexttags.tcl
· jrichtext.tcl
::jstools::tc::saveas
Usage
	::jstools::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.)

::jstools::tc::tclrt_convert_text t - convert to Tcl­format richtext; see jrichtext.tcl
::jstools::tc::tex_convert_text t - convert to TeX source
::jstools::tc::html_convert_text t - convert to HTML (without links, currently)
::jstools::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 ::jstools::tc::tex_convert_text works if you have the right fonts, 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.

Some vertical whitespace may be lost; any sequence of more than one newline character will be translated to a <p> tag.
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.)
· The exact fonts used when generating TeX should be user preferences.  (PostScript fonts already are.)
· 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).
} {{{list:level:1 {8.0 12.0 27.0 29.0 69.0 73.0 74.0 78.0}} {jhtml:anchor:anchorname {29.0 30.0 43.0 43.33 44.0 44.31 45.0 45.32 46.0 46.30 47.0 48.0}} {jdoc:anchor:anchorname {29.15 30.0 43.0 43.33 44.0 44.31 45.0 45.32 46.0 46.30 47.0 48.0}} {sel {28.2 28.15}} {jdoc:xref:link {5.245 5.266 8.38 8.51 15.34 15.38 15.42 15.52 15.367 15.371 23.111 23.115 27.2 27.15 28.2 28.15 43.74 43.87}} {richtext:font:roman {1.124 2.0 3.0 3.81 3.94 5.245 5.266 8.38 8.51 15.34 15.38 15.42 15.52 15.69 15.87 15.186 15.190 15.367 15.371 15.487 15.491 18.0 19.0 19.25 19.42 19.69 19.81 19.101 19.105 20.0 21.0 21.49 21.67 21.75 21.79 21.90 21.95 21.97 21.103 21.105 21.109 21.111 21.121 21.123 21.133 21.135 21.143 21.152 21.160 21.162 21.166 21.168 21.174 21.176 21.181 21.183 21.188 21.190 21.198 21.200 21.205 21.207 21.213 21.218 21.224 23.58 23.72 23.80 23.84 23.111 23.115 23.127 23.143 23.235 23.252 23.260 23.266 23.312 23.316 23.321 23.326 25.72 25.77 25.129 25.134 25.165 27.0 27.2 28.0 28.2 28.15 29.0 31.0 31.1 31.24 32.0 33.0 33.1 33.2 35.0 36.0 36.198 36.204 36.222 36.223 38.0 39.0 40.0 41.0 43.0 43.33 43.34 43.35 43.74 43.87 44.0 44.31 44.32 44.33 45.0 45.32 45.33 45.34 46.0 46.30 46.31 46.32 47.0 49.0 51.24 51.32 51.52 51.59 51.119 51.132 52.0 53.0 53.21 53.52 56.0 57.0 59.110 59.113 60.0 61.0 67.131 67.148 68.0 69.0 73.0 74.0 74.213 74.218 74.248 74.253 75.90 75.94 78.0}} {richtext:font:italic {1.5 1.124 15.69 15.87 21.63 21.67 21.75 21.79 23.68 23.72 23.80 23.84 23.135 23.143 23.246 23.252 23.260 23.266 31.23 31.24 33.1 33.2 36.222 36.223 43.34 43.35 44.32 44.33 45.33 45.34 46.31 46.32}} {richtext:font:bold {3.81 3.94 8.38 8.51 27.2 28.0 28.2 28.15 36.198 36.204 43.74 43.87 51.119 51.132}} {richtext:font:bolditalic {1.0 1.5}} {richtext:font:typewriter {5.245 5.266 15.34 15.38 15.42 15.52 15.186 15.190 15.367 15.371 15.487 15.491 19.25 19.42 19.69 19.81 19.101 19.105 21.49 21.63 21.90 21.95 21.97 21.103 21.105 21.109 21.111 21.121 21.123 21.133 21.135 21.143 21.152 21.160 21.162 21.166 21.168 21.174 21.176 21.181 21.183 21.188 21.190 21.198 21.200 21.205 21.207 21.213 21.218 21.224 23.58 23.68 23.111 23.115 23.127 23.135 23.235 23.246 23.312 23.316 23.321 23.326 25.72 25.77 25.129 25.134 25.165 26.0 31.1 31.23 43.0 43.33 44.0 44.31 45.0 45.32 46.0 46.30 51.24 51.32 51.52 51.59 53.21 53.52 59.110 59.113 67.131 67.148 74.213 74.218 74.248 74.253 75.90 75.94}} {richtext:font:heading1 {2.0 3.0 18.0 19.0 20.0 21.0 26.0 27.0 29.0 30.0 40.0 41.0 47.0 48.0 68.0 69.0 73.0 74.0}} {richtext:font:heading2 {30.0 31.0 32.0 33.0 35.0 36.0 38.0 39.0 48.0 49.0 52.0 53.0 56.0 57.0 60.0 61.0}} {jdoc:link:jrichtext.tcl.jdoc {8.38 8.51 28.2 28.15 43.74 43.87}} {jdoc:anchorname:j:tc:saveas {29.15 30.0}} {jdoc:anchorname:j:tc:tclrt:convert_text {43.0 43.33}} {jdoc:anchorname:j:tc:tex:convert_text {44.0 44.31}} {jdoc:anchorname:j:tc:html:convert_text {45.0 45.32}} {jdoc:anchorname:j:tc:ps:convert_text {46.0 46.30}} {jdoc:anchorname:Comments_on_Formats {47.0 48.0}} {jdoc:link:jdoc.jdoc {15.34 15.38 15.367 15.371 23.111 23.115}} {list:1:ul {8.0 12.0 27.0 29.0 69.0 73.0 74.0 78.0}} {jdoc:link:jeditmodes/jhtml-mode.jdoc {15.42 15.52}} {jdoc:link:#::jstools::tc::saveas {5.245 5.266}} {jhtml:anchorname:::jstools::tc::saveas {29.0 30.0}} {jhtml:anchorname:::jstools::tc::tclrt_convert_text {43.0 43.33}} {jhtml:anchorname:::jstools::tc::tex_convert_text {44.0 44.31}} {jhtml:anchorname:::jstools::tc::html_convert_text {45.0 45.32}} {jhtml:anchorname:::jstools::tc::ps_convert_text {46.0 46.30}} {jhtml:anchorname:Comments_on_Formats {47.0 48.0}} {special:list_item:1 {8.0 8.1 9.0 9.1 10.0 10.1 11.0 11.1 27.0 27.1 28.0 28.1 69.0 69.1 70.0 70.1 71.0 71.1 72.0 72.1 74.0 74.1 75.0 75.1 76.0 76.1 77.0 77.1}} {jdoc:link:jtexttags.tcl.html {27.2 27.15}}} {{convert:place:23.68 23.68} {convert:place:12.0 12.0} {richptr 43.49} {convert:place:15.52 15.52} {convert:place:33.0 33.0} {convert:place:23.72 23.72} {convert:place:33.1 33.1} {convert:place:33.2 33.2} {current 1.0} {matchend 53.103} {convert:place:75.0 75.0} {convert:place:51.24 51.24} {convert:place:23.80 23.80} {convert:place:75.1 75.1} {convert:place:28.14 28.15} {convert:place:8.0 8.0} {convert:place:23.84 23.84} {convert:place:8.1 8.1} {convert:place:29.0 29.0} {convert:place:51.32 51.32} {convert:place:30.0 30.0} {convert:place:15.69 15.69} {convert:place:72.0 72.0} {convert:place:72.1 72.1} {convert:place:23.312 23.312} {convert:place:23.316 23.316} {convert:place:26.0 26.0} {insert_save 28.11} {convert:place:23.321 23.321} {convert:place:47.0 47.0} {convert:place:15.87 15.87} {convert:place:43.33 43.33} {convert:place:51.52 51.52} {convert:place:43.34 43.34} {convert:place:68.0 68.0} {convert:place:43.35 43.35} {convert:place:23.326 23.326} {convert:place:2.0 2.0} {convert:place:51.59 51.59} {convert:place:21.103 21.103} {convert:place:44.0 44.0} {convert:place:21.105 21.105} {matchstart 53.97} {convert:place:21.109 21.109} {convert:place:21.111 21.111} {convert:place:27.14 27.15} {convert:place:59.110 59.110} {convert:place:51.119 51.119} {abbrevend 53.86} {convert:place:20.0 20.0} {convert:place:19.0 19.0} {convert:place:59.113 59.113} {convert:place:41.0 41.0} {convert:place:21.121 21.121} {convert:place:21.49 21.49} {convert:place:21.123 21.123} {convert:place:51.132 51.132} {convert:place:15.487 15.487} {convert:place:43.74 43.74} {convert:place:21.133 21.133} {convert:place:21.63 21.63} {convert:place:21.135 21.135} {convert:place:15.491 15.491} {convert:place:36.204 36.204} {convert:place:79.0 79.0} {convert:place:21.67 21.67} {convert:place:19.25 19.25} {convert:place:36.198 36.198} {convert:place:21.143 21.143} {convert:place:15.186 15.186} {convert:place:43.87 43.87} {convert:place:21.75 21.75} {convert:place:15.190 15.190} {convert:place:21.152 21.152} {convert:place:21.79 21.79} {convert:place:76.0 76.0} {convert:place:76.1 76.1} {convert:place:36.222 36.222} {convert:place:36.223 36.223} {convert:place:19.42 19.42} {convert:place:10.0 10.0} {convert:place:9.0 9.0} {convert:place:10.1 10.1} {convert:place:9.1 9.1} {convert:place:21.160 21.160} {anchor 28.8} {convert:place:31.0 31.0} {convert:place:21.162 21.162} {convert:place:21.90 21.90} {insert 28.2} {convert:place:31.1 31.1} {convert:place:52.0 52.0} {convert:place:21.166 21.166} {convert:place:21.95 21.95} {convert:place:21.168 21.168} {convert:place:73.0 73.0} {convert:place:21.97 21.97} {convert:place:21.174 21.174} {abbrevstart 53.75} {convert:place:27.0 27.15} {convert:place:21.176 21.176} {convert:place:27.1 27.15} {convert:place:48.0 48.0} {convert:place:21.181 21.181} {convert:place:70.0 70.0} {convert:place:21.183 21.183} {convert:place:69.0 69.0} {convert:place:70.1 70.1} {convert:place:69.1 69.1} {convert:place:23.111 23.111} {convert:place:19.69 19.69} {convert:place:3.0 3.0} {convert:place:23.115 23.115} {convert:place:21.188 21.188} {convert:place:21.200 21.200} {convert:place:21.190 21.190} {convert:place:45.0 45.0} {convert:place:21.205 21.205} {convert:place:19.81 19.81} {convert:place:21.207 21.207} {convert:place:21.198 21.198} {convert:place:23.127 23.127} {convert:place:21.213 21.213} {convert:place:21.0 21.0} {convert:place:19.101 19.101} {convert:place:23.135 23.135} {convert:place:21.218 21.218} {convert:place:19.105 19.105} {convert:place:21.224 21.224} {convert:place:23.143 23.143} {convert:place:38.0 38.0} {convert:place:60.0 60.0} {convert:place:35.0 35.0} {convert:place:56.0 56.0} {convert:place:46.30 46.30} {convert:place:77.0 77.0} {convert:place:46.31 46.31} {convert:place:77.1 77.1} {convert:place:46.32 46.32} {convert:place:11.0 11.0} {convert:place:67.131 67.131} {convert:place:11.1 11.1} {convert:place:32.0 32.0} {convert:place:53.0 53.0} {convert:place:25.72 25.72} {convert:place:74.213 74.213} {convert:place:53.21 53.21} {convert:place:74.0 74.0} {convert:place:74.1 74.1} {convert:place:25.77 25.77} {convert:place:74.218 74.218} {convert:place:67.148 67.148} {convert:place:28.1 28.2} {convert:place:49.0 49.0} {convert:place:71.0 71.0} {convert:place:71.1 71.1} {convert:place:31.23 31.23} {convert:place:31.24 31.24} {convert:place:25.129 25.129} {convert:place:3.81 3.81} {convert:place:25.134 25.134} {convert:place:46.0 46.0} {convert:place:45.32 45.32} {convert:place:53.52 53.52} {convert:place:45.33 45.33} {convert:place:45.34 45.34} {convert:place:5.245 5.245} {convert:place:3.94 3.94} {convert:place:1.0 1.0} {convert:place:74.248 74.248} {convert:place:74.253 74.253} {convert:place:1.5 1.5} {convert:place:43.0 43.0} {convert:place:23.235 23.235} {convert:place:8.38 8.38} {convert:place:15.367 15.367} {convert:place:23.246 23.246} {convert:place:18.0 18.0} {convert:place:15.371 15.371} {convert:place:25.165 25.165} {convert:place:5.266 5.266} {convert:place:40.0 40.0} {convert:place:39.0 39.0} {convert:place:75.90 75.90} {convert:place:23.252 23.252} {convert:place:8.51 8.51} {convert:place:61.0 61.0} {convert:place:1.124 1.124} {convert:place:75.94 75.94} {convert:place:23.260 23.260} {convert:place:15.34 15.34} {convert:place:36.0 36.0} {convert:place:15.38 15.38} {convert:place:23.58 23.58} {convert:place:23.266 23.266} {convert:place:15.42 15.42} {convert:place:44.31 44.31} {convert:place:57.0 57.0} {convert:place:44.32 44.32} {convert:place:44.33 44.33} {convert:place:78.0 78.0}}} {{body_alink #ff0000} {body_vlink #000080} {body_link #0000ff} {body_text #000000} {body_bgcolor #ffffff}}