Is there a clever way to do subscripts in LC text?

Richmond richmondmathewson at gmail.com
Fri Jan 3 11:33:02 EST 2014


On 03/01/14 17:47, Graham Samuel wrote:
> I'm having to show some simple mathematical expressions which involve subscripts (like say a little figure 2 below the line in an otherwise normal text); and in principle I'd like to have superscripts as well.
>
> As there's nothing in the Dictionary about this, I constructed my expressions (which luckily are static things) by creating a group of little fields and adjusting their vertical relationships. This seems very clunky and also doesn't work too well cross-platform since different fonts behave differently. Also if it wasn't static - I mean if I wanted my user to be able to write stuff like this - I have no idea how I'd do it.
>
> Is there a better way?
>
> TIA
>
> Graham
> _______________________________________________
>

NO . . . but there's an incredibly "unclever" way to do it . . .

I just typed a sentence into a fld and selected part of it and went to the
'Text' item in the menuBar and set it to subscript, and then another bit 
of text to superscript.

Lovely job.

HOWEVER I suspect you are wanting to know how to do that code-wise and 
that is "a right pox".

Here's what the documentation has to offer:

"The textStyle of an object or chunk is either "plain", empty, "mixed", 
or one or more of the following, separated by commas:
* bold
* italic
* underline
* strikeout
* box
* threeDbox
* link (or group)
* condensed
* expanded"

However, as the Livecode IDE is made with Livecode (I never quite worked 
how that was possible), and it is possible from the
menuBar to set text to sub or super script there has to be a way to do 
it programmatically.

I hacked open the script of the 'Text' menu and found a switch statement 
for textStyle and inside that switch loop there are the following:

case "subscript"   and

case "superscript"  wonders will never cease :)

I quote:

case "subscript"
       case "superscript"
          local tTextShiftAmount

          if pPickedItem is "superscript" then put -4 into tTextShiftAmount
          else put 4 into tTextShiftAmount
          if the textShift of tSelectedObject is a number then put 0 
into tTextShiftAmount

          set the textShift of tSelectedObject to tTextShiftAmount
          break

Wombling back over to the documentation I found 'textShift'  and "IT" is 
all described there.

One of the MAJOR problems with the inbuilt documentation is knowing what 
one actually has to look for
to get the information one wants.

Richmond.




More information about the use-livecode mailing list