I FINALLY managed to do it!! It's a tiny bit painful and requires some patience, but the result looks VERY similar to in LaTeX and which is recognised when exporting to PDF. It's definitely worth it in my opinion.
Specifically for my own case, this worked:
xlabel('$x$ ($\mu$m)','Interpreter','latex')
ylabel('$y$ ($\,\,\,$m)','Interpreter','latex')
text(-1.155,4.825,char(181),'interpreter','tex','Rotation',90, ...
'FontSize',15.4,'FontName','Century','Color',0.15*ones(1,3))
export(ax,'directory/filename.pdf')
A rundown:
- I wanted to have a label "$y$ (um)" with a fancy, upright mu. Note that I added the ylabel as usual, but I left some space where the mu will go. The solution involves manually adding a text label using the text() command, so that the mu goes into that space...
- (1) you have to manually find the coordinates. This is very much a trial-and-error process, depending on how far you want to go. I can highly recommend using the "Open Property Inspector" button (the icon below the "Desktop" button in the figure), and clicking the mu which you created with text(). Then you can move it to roughly where you want to place it, and copy the "Position" coordinates and paste them into your text() command.
- (2) char(181) created the upright mu, where you should add the tex interpreter.
- (3) The 90 degree rotation is just because the label I added is on the vertical axis.
- (4) The font size has to be roughly 15.4 to match the font size of 14 of the rest of the figure. (Has to do with the fact that I'm using a different font type I guess)
- (5) The font type which you should use is "Century". I accidentally selected it and noticed it looked really quite similar to the mu you see in LaTeX.
- (6) The colour is by default not exactly black (0,0,0), but it is a bit grayish (0.15,0.15,0.15), so I accounted for that using the 'Color' tag.
- I used a font size of 14 for the figure, which also determines where you would have to manually place the mu, so that's why I added the set('fontsize') thing.
The result is as follows:
If you use
exportgraphics(ax,'directory/filename.pdf')
then the file will be vector format and the text will be recognised (unless you are plotting a LOT of data, in that case MATLAB automatically pixelates everything...).
Hope this helps many many people, because this seems to be quite problematic in MATLAB for some reason...