How can I get an upright mu with latex interpreter?
108 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (4)
Roel
am 25 Okt. 2016
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 Kommentare
Walter Roberson
am 21 Jun. 2017
Bearbeitet: Walter Roberson
am 1 Mai 2023
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
am 27 Mär. 2024
Bearbeitet: Krystian Nowakowski
am 27 Mär. 2024
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1653301/image.jpeg)
That produces a nice upright my when plotted:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1653306/image.jpeg)
Same applies to any other greek symbol you want upright.
Thomas Lehmeier
am 30 Jul. 2023
Bearbeitet: Thomas Lehmeier
am 30 Jul. 2023
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 Kommentar
Walter Roberson
am 31 Jul. 2023
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
am 30 Apr. 2023
Bearbeitet: Thijs van Stralen
am 30 Apr. 2023
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1370479/image.png)
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...
0 Kommentare
Daniel Shub
am 17 Jan. 2013
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!