Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to return Greek symbols through MathLink from a C function. However, returning the usual escape sequence (such as \[Alpha]) does not seem to work. Here's a minimal example .tm file ( which creates a function that should simply return \[Alpha] :

void myAlpha P(( ));

:Function:          myAlpha
:Pattern:           myAlpha[ ]
:Arguments:         { }
:ArgumentTypes:     { }
:ReturnType:        Manual

#include "mathlink.h"
void myAlpha() { MLPutSymbol( stdlink, "\\[Alpha]" ); }
int main(int argc, char *argv[]) { return MLMain(argc, argv); }

To compile it (on OSX) I use :

/Applications/ -o myalphatm.c
/usr/bin/clang -c -I/Applications/ myalphatm.c
/usr/bin/clang++ myalphatm.o -L/Applications/ -lMLi3 -lstdc++ -framework Foundation -o myalpha

And to run it I execute this little script :

link = Install["<fullpath>/myalpha"];

Inside a Mathematica notebook this produces some binary symbol, and if I run it with MathKernel from the commandline then I get :

$IterationLimit::itlim: Iteration limit of 4096 exceeded.
    Hold[Out[$Line - 1]]

My guess is that I haven't escaped everything correctly in the C string, but I'm not sure what the right escape sequence is. Since \ is the escape character in C I have escaped that, so the C-string reads "\\[Alpha]" and I've tried a variety of other options but to no avail.

share|improve this question

I'm not an expert here, but one way to achieve what you want is to transfer UTF8 codes. I guess the assumption that you can simply transfer a string "\[Alpha]" as Symbol over MathLink and Mathematica interprets this for you, cannot be made. Therefore, the following is a different solution which works as expected (at least on my Linux here)

void myAlpha() { 
  MLPutUTF8Symbol( stdlink, "\u03B1", 2); 

Mathematica graphics

share|improve this answer
This works on OSX as well but MLPutUTF8Symbol needs a pointer to an unsigned char, so an explicit cast before the string is necessary. I.e. MLPutUTF8Symbol( stdlink, (const unsigned char *) "\u03B1", 2);. – Rasmus Apr 15 '14 at 14:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.