How can I get an upright mu with latex interpreter?

145 次查看(过去 30 天)
I need an upright greek mu symbol to display microseconds on my x-axis label. I also have to use the latex interpreter.
figure
set(gcf,'defaulttextinterpreter','latex')
plot([1:10],[1:10]);
Xlabel(['$t$ [$\mu$s]'],'FontSize',12)
I tried \upmu, \muup, \mathrm{\mu}, which all do not work. For example, \upmu requires the package upgreek. I also tried to change the fontname for the axis label text to a latex equivalent and used tex-interpreter, but there was no sufficient similarity between the modified tex-font and the latex-font.
Is there any way to solve this problem? Thanks!

回答(4 个)

Roel
Roel 2016-10-25
You can do it without using the Latex interpreter:
xlabel(['{\itt} [' 956 's]'],'FontSize',12)
956 is the unicode code point of the letter mu, which can be found as:
>> 'μ'+0
ans =
956
  3 个评论
Walter Roberson
Walter Roberson 2017-6-21
编辑:Walter Roberson 2023-5-1
There is also the micro sign, char(181), U+00B5; it appears that the actual greek mu is "preferred" for the SI units https://en.wikipedia.org/wiki/Micro- .
Krystian Nowakowski
编辑:Krystian Nowakowski 2024-3-27
Hi, if you don't want to have to look up the unicode character for your mu (or other greek symbols) you can just add the greek keyboard to your system keyboards. It's very easy to switch between them. In the greek keyboard, pressing m will insert mu:
That produces a nice upright my when plotted:
Same applies to any other greek symbol you want upright.

请先登录,再进行评论。


Thomas Lehmeier
Thomas Lehmeier 2023-7-30
编辑:Thomas Lehmeier 2023-7-30
Can you please implement some decent solution to fix this annoying problem?
People already need to create workarounds to get this done - and these are actually working.
We are sure you can add this to your next update.
  1 个评论
Walter Roberson
Walter Roberson 2023-7-31
Mathworks Support does not read these postings. You should create a Feature Request.
We are sure you can add this to your next update.
You would be mistaken about that. The next update, R2023b, is already in beta testing, and does not have this as a possibility.
The latex package used by MATLAB is fairly restricted, and does not have the ability to load packages -- but packages such as isomath or eulergreek are needed to implement this.

请先登录,再进行评论。


Thijs van Stralen
Thijs van Stralen 2023-4-30
编辑:Thijs van Stralen 2023-4-30
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:
figure(1)
plot(x,y)
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))
set(gca,'fontsize', 14)
ax=gca
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...

Daniel Shub
Daniel Shub 2013-1-17
There is no easy way. There are packages in the FEX that can do certain things. The easiest way would probably be to overload tex.m to allow you to load packages.

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by