How can I get an upright mu with latex interpreter?
151 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (4)
Roel
el 25 de Oct. de 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 comentarios
Walter Roberson
el 21 de Jun. de 2017
Editada: Walter Roberson
el 1 de Mayo de 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
el 27 de Mzo. de 2024
Editada: Krystian Nowakowski
el 27 de Mzo. de 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:
That produces a nice upright my when plotted:
Same applies to any other greek symbol you want upright.
Thomas Lehmeier
el 30 de Jul. de 2023
Editada: Thomas Lehmeier
el 30 de Jul. de 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 comentario
Walter Roberson
el 31 de Jul. de 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
el 30 de Abr. de 2023
Editada: Thijs van Stralen
el 30 de Abr. de 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:
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 comentarios
Daniel Shub
el 17 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Labels and Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!