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

Viewed 162

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.

2 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.

Or just use matplotlib, which gets along well with unicode:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10000)
y = np.sin(np.pi * x * 0.001) 
plt.plot(x, y)
plt.ylabel(u"\u03B1")
plt.xlabel('β')
plt.savefig(r'<insert your path here>/sinewave.pdf')
plt.show()
Related