Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print a figure to a pdf file with embedded greek letters or formulas in MATLAB?

Tags:

latex

matlab

tex

I cannot find a solution to print a figure with embedded Greek letters using the print function (or the File Exchange function export_fig() of Yair Altman).

While this functionality was available in earlier matlab releases (e.g. R2016a), the following code does not produce the desired result with version R2018a:

figure()
rng = 0:0.01:2;
plot(rng, sin(rng.*pi()))
text(1, 0.6, 'sin of {\alpha}')
print('simple_test_p', '-dpdf')
% export_fig('simple_test_e','-pdf', '-transparent')

enter image description here

While the text before '{\alpha}' is embedded in the resulting pdf file, alpha itself appears to be an image rather than an embedded font (see image).

I tried several different fonts to exclude the possibility of a missing default font (besides double-checking the font folder). Moreover, I used both latex and tex interpreters. Nevertheless, none of these procedures worked.

If this problem cannot be solved with Matlab, is there any other way to get a pdf file with embedded Greek letters and mathematical formulas?

I very much appreciate your help. Thank you in advance.

like image 680
quantguy Avatar asked Dec 10 '25 15:12

quantguy


1 Answers

MATLAB uses Unicode text everywhere. You should be able to simply do:

text(1, 0.6, 'sin of 𝛼')

If you can't type the Greek letters, you can always search for them on Google* and copy-paste them. I found the above here.

*or whatever your favorite search engine is.

like image 67
Cris Luengo Avatar answered Dec 13 '25 06:12

Cris Luengo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!