필터 지우기
필터 지우기

How can I get an upright mu with latex interpreter?

조회 수: 113 (최근 30일)
Mandy
Mandy 2013년 1월 17일
편집: Krystian Nowakowski 2024년 3월 27일
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일
편집: 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