Discussion:
Is there a clever way to do subscripts in LC text?
Graham Samuel
2014-01-03 15:47:21 UTC
Permalink
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
Mark Schonewille
2014-01-03 16:00:48 UTC
Permalink
Hi Graham,

You can use the textShift property for subscript and superscript.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Use Color Converter to convert CMYK, RGB, RAL, XYZ, H.Lab and other
colour spaces. http://www.color-converter.com

Buy my new book "Programming LiveCode for the Real Beginner"
http://qery.us/3fi

Fill out this survey please
http://livecodebeginner.economy-x-talk.com/survey/
Post by Graham Samuel
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
Mark Wieder
2014-01-03 16:00:52 UTC
Permalink
Graham-
Post by Graham Samuel
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.
Look into the textshift property of chars. You can make it a positive
or negative value for superscripts or subscripts.
--
-Mark Wieder
***@gmail.com
Graham Samuel
2014-01-03 22:39:58 UTC
Permalink
Thanks - I learn something new every day. I did search for 'subscript' in the Dictionary, but although the word does appear in the description of 'textShift', the search doesn't look into descriptions, just into the dictionary entries themselves. So thank goodness someone knew about it already.
One of the MAJOR problems with the inbuilt documentation is knowing what one actually has to look for
to get the information one wants.
This is true. Maybe the next revised dictionary (you know there's gotta be one) could use keywords which one could search for (and which users could add), since there really a lot of instances like this.

Thanks again

Graham
Graham-
Post by Graham Samuel
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.
Look into the textshift property of chars. You can make it a positive
or negative value for superscripts or subscripts.
--
-Mark Wieder
Richmond
2014-01-03 16:33:02 UTC
Permalink
Post by Graham Samuel
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.
Loading...