Version 0 of Super and Subscripts in a text widget

Updated 2001-11-07 13:01:42

A usenet poster to news:comp.lang.tcl asked how to display text with super and subscripts. Kevin Kenny was kind enough to demonstrate two ways to do this:

    font create normal -family times -size 12
    font create small -family times -size 10

    grid [text .t -width 40 -height 5 -font normal] -columnspan 2

    .t tag configure subscript -font small -offset -5p
    .t insert 1.0 "Little Willy took a drink,\n" {}
    .t insert 2.0 "   But he will drink no more,\n" {}
    .t insert 3.0 "For what he thought was H" {} "2" subscript "O\n" {}
    .t insert 4.0 "   Was H" {} "2" subscript "SO" {} "4" subscript "!" {}

    button .b1 -text "H\u2082O" -command { exit 0 }
    button .b2 -text "H\u2082SO\u2084" -command { exit 1 }

    grid .b1 .b2 -pady 5
    grid columnconfigure . { 0 1 } -weight 1