## set latters in a string to different fontsizes with interpreter latex

yang yang

### yang yang (view profile)

さんによって質問されました 2013 年 6 月 17 日

### Elias de Korte (view profile)

さんによって コメントされました 2019 年 2 月 16 日
Daniel Shub

### Daniel Shub (view profile)

さんの 回答が採用されました
I want to set latters in a string to different fontsizes with interpreter latex, but the following commond doesn't work. Why?
text('position',[0.8 0.9 0],'interpreter','latex',...
'string','\$\fontsize{12}{xxx}\fontsize{8}{yyyy}\$',...
'fontname','Times New Roman');
Thanks!

Tom

### Tom (view profile)

2013 年 6 月 17 日
Do you get something like what you want when you use 'tex' not 'latex' as the interpreter?
Daniel Shub

### Daniel Shub (view profile)

2013 年 6 月 17 日
@Tom, have you tried it using TeX and not LaTeX. What makes you think that using LaTeX macros (|\fontsize|) would work with the TeX interpreter?
Tom

### Tom (view profile)

2013 年 6 月 17 日
@Daniel - I have and it appears to work, besides the \$ signs appearing as part of the text.

サインイン to comment.

## 1 件の回答

### Daniel Shub (view profile)

2013 年 6 月 17 日
採用された回答

Presumably by "doesn't work" you mean there is not a difference in the font size. The reason there is no difference in the font size is that your example has a number of different problems. The first problem is you are trying to set the font size within a math environment, but LaTeX doesn't allow you to do this. The second problem is that for whatever reason TMW have disabled the traditional LaTeX font size commands (e.g., \large) in MATLAB forcing us to use the lower level \fontsize macro. The problem is you are using this macro incorrectly. The \fontsize macro takes two arguments. The first argument is the font size, which you appear to be providing correctly. The second argument is the baselineskip, but you appear to be providing the text you want to increase the font size of. This argument doesn't really matter in MATLAB since for whatever reason TMW have disabled the ability to to put in line breaks. The final problem is that the \fontsize macro does not actually change the font. To do that you need to use the \selectfont macro.
On a somewhat unrelated note, choosing a font in LaTeX is very tricky. It is not clear what you hope to accomplish with the fontname PV that you are providing, but it is not going to change the font. There was a recent blog post on Undocumented Matlab about it.
Putting it all together gives:
text('position',[0.8 0.9 0],'interpreter','latex','string','\fontsize{12}{0}\selectfont\$xxx\$\fontsize{8}{0}\selectfont\$yyyy\$');

Elias de Korte

### Elias de Korte (view profile)

2019 年 2 月 16 日
How can I choose a default font size for the latex interpreter?

サインイン to comment.

Translated by