Math symbols in a message.

trev's icon

This is probably very simple, but how can I print math symbols such as psi and phi on-screen - for example in a message box? When using itoa once I go past 127 the correct symbols are not produced.

11OLSEN's icon

Try copy and paste from somewhere into your patch and send into atoi to find the correct number(combination).

ben sonic's icon

have you tried the other way round to get the integers?
YourSymbolMessagebox->atoi->InspectorNumbersMessagebox

Max Patch
Copy patch and select New From Clipboard in Max.


11OLSEN's icon

good idea, BEN ;)

ben sonic's icon

you too, 11OLSEN;)

trev's icon

Thanks for your help Ben and 11Olsen.
I had tried something like your suggestion, 11Olsen but it didn't work and now I see why - I was connecting the outlet from atoi to a number box, but that only shows one number while the full combination is made up of two or more numbers. Ben Sonic's patch showed me to use message boxes to see the full combination.

Then I had to experiment a bit to find out how to pack a message to send to atoi. Pack doesn't work but join does. I'm not entirely sure why.
What I'd like to be able to do is use the info on this page -

http://xahlee.info/comp/unicode_math_operators.html
to print messages.

Roman Thilenius's icon

unicode 10?

trev's icon

Yes. I'd like to be able to use the decimal codes for these symbols - i.e. small letter pi is 960, small letter psi is 968 - with itoa. I've figured some of the pieces out, but can't quite put it all together.

Floating Point's icon

I don't think itoa works with unicode (I think it's only 8-bit, up to 255)

11OLSEN's icon

@TREV First the site you're refering to gives you Unicode 10 chars (what ROMAN wrote). You need to use UTF8 chars in Max. Try to copy and paste this page http://csbruce.com/software/utf-8.html for example into a [comment] in your patch.
As an extra difficulty there are differences between Mac and Windows. On Windows I can't use full utf8 char set. Many symbols just end up as squares in Max.

What I don't understand, is how you got a number like 960 from [atoi]. For me (using Windows) the outcome for a single char is one or more ints but none of em higher then 255.
For example the π (pi) from the linked page, second row results in "207 128" for me. not for you?

Max Patch
Copy patch and select New From Clipboard in Max.



trev's icon

11OLSEN, you are right - atoi produces a combination of ints. The number 960 I quoted was just an example of a Unicode 10 number I'd like to convert into UTF-8 so that I can use itoa, because there are lots of resources for Unicode 10 online.

I found this page
https://cycling74.com/forums/extended-ascii-wrong-values-with-atoi
that has a patch by Peter Castine that does the opposite of what I'm trying to do:

https://cycling74-web-assets.s3.amazonaws.com/bb-attachments/1743.utf8toint.zip
It accepts a combination of 8-bit ints and produces the Unicode 10 equivalents. I want to go the other way. I'll try taking it apart to adapt it for my needs.
To be honest, I thought this would be pretty simple and was just curious about it.

Floating Point's icon

javascript to the rescue!
here's the patch:

Max Patch
Copy patch and select New From Clipboard in Max.


here's he code (save as a text file and name it "fromUnicode.js"):
var input;
var output;

function list()
{
    output="";
    input = arrayfromargs(arguments);

    for (i=0;i<input.length; i++)    {        
        output=output+String.fromCharCode(input[i]);
    }
    bang();
}

function bang()
{
    outlet(0,output);
}

trev's icon

That works great. Thanks Floating Point. I used an uzi to fill a dict with the symbols I need, so now I can use a umenu to select symbols.