Latex fonts in matlab

Is it possible to convert the font of a matlab plot to be the same of latex fonts. For example I can modify the font of a plot by:

x = -pi:.1:pi;
y = sin(x);
plot(x,y)
set(gca,'FontName','Helvetica');

Is it possible to do the same but for latex fonts (I say latex fonts as I am not sure of the actual name of the font latex uses as its basic font).


For any text object you just need to set the 'Interpreter' property to 'latex'. So, for example you could do

xlabel('$$int_0^x!int_y dF(u,v)$$','Interpreter','latex');

For tick labels it is more difficult, though there may be files available to make it easier (example).


I'd recommend setting the default interpreter to LaTex at the beginning of your script/function:

set(0,'defaulttextinterpreter','latex')

You can also download a version of Computer Modern (The LaTeX Font Family) and install it to your machine. Techniques may vary if you're running windows or mac, for Mac you'll need to download the OTF version and add it into the FontBook (Cmd-Space: FontBook)

Next, restart Matlab

Finally, you can use the LaTeX Font in Matlab:

   set(0,'DefaultTextFontname', 'CMU Serif')
   set(0,'DefaultAxesFontName', 'CMU Serif')

This is a nice work-around for having constant fonts in your tick-labels, although it has some trouble exporting in some formats.


You can define the font within the latex strings. For instance, to change between serif font (Roman) and sans serif font (Helvetica, I guess):

text(0.5, 0.8, 'textsf{sans serif}','interpreter','latex')
text(0.5, 0.7, 'textrm{roman}','interpreter','latex')
text(0.5, 0.6, '$$mathsf{math,,mode,,sans,,serif}$$','interpreter','latex')
text(0.5, 0.5, '$$mathrm{math,,mode,,roman}$$','interpreter','latex')
链接地址: http://www.djcxy.com/p/33414.html

上一篇: Matlab字体在打印或导出时不能正确渲染

下一篇: 乳胶字体在matlab中