Latex fonts in matlab

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')

Tags:

Matlab

Latex