2
$\begingroup$

I want to add Greek letters to the ToMatlab package. The most recent publicly available version I found is here.

There is a section on symbols starting on line 242. I tried adding a line ToMatlabaux[\Phi] := "phi" and several similar variations. None of which worked. Any ideas?

I've read the prior discussions and found this one most useful but still not quite what I need.

$\endgroup$
0

1 Answer 1

3
$\begingroup$

It works if I make a definition like this:

ToMatlabaux[Global`\[Phi]] := "phi";

You have to be explicit about the context of the symbol inside the package, which also points out a limitation (that it will only work on global phi's).

I can take care of all Greek letters at one go, if I change the definition of ToMatlabaux[e_Symbol] to

ToMatlabaux[e_Symbol] := StringTrim[Convert`TeX`ExpressionToTeX[e],"\\"]

But I would test it thoroughly. It might have unintended consequences.

Use StringDelete with an appropriate pattern, if you want mult-letter symbol names to have Greek letters replaced by their Latin names:

StringDelete[Convert`TeX`ExpressionToTeX[\[Phi]\[Alpha]], 
 Whitespace | "\\"]
$\endgroup$
2
  • $\begingroup$ Thanks. There was a similar line in there already ToMatlabaux[e_Symbol] := ToString[e] that did not work (at least not in Mathematica 14). $\endgroup$
    – Roy
    Commented Feb 6 at 2:28
  • $\begingroup$ @Roy Yep, that's the line I changed to the above. $\endgroup$
    – Goofy
    Commented Feb 6 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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