How do I add latex fonts in matlab?

56 views (last 30 days)
maxime debiossac
maxime debiossac on 30 Jul 2018
Here is my problem: I would like to use a different font style for the latex interpreter, for example sans serif, which is required for figures in a scientific publication I am writing. Here is the matlab code I am using:
title('$\mathsf{a+\sqrt{b}}$','interpreter','latex');
I got the warning: "Warning: Error updating Text. Font cmss10 is not supported." because the font style cmss10 is not present on my system (I use Matlab2017b on Ubuntu 16.04 LTS). I tried to copy the files cmss10.ttf, cmss10.pfb, cmss10.pfm and cmss10.tfm obtained from CTAN in their respective folders but that did not solve the problem. I suspect I have to modify other files as well.
Is there a simple way to add new latex fonts in Matlab?
  3 Comments
maxime debiossac
maxime debiossac on 30 Jul 2018
I have to say I am quite disappointed by the way Matlab incorporates Latex. Changing the latex font is just an every day task for a latex user, also Python manages it without problem.
When I ask my colleagues how they tackle the issue, they say that they have to edit the figure with another software to change the latex font. What a waste of time!
dpb
dpb on 30 Jul 2018
Edited: dpb on 30 Jul 2018
Indeed. It's a complete mystery why it seems such a convoluted mess and it's worse that whatever it is is undocumented.
All I can suggest is to submit enhancement request and write a user complaint -- little hope anything will happen "real soon now" but without those efforts nothing ever will it seems.

Sign in to comment.

Answers (1)

Pa342
Pa342 on 31 Jul 2018
Edited: Pa342 on 31 Jul 2018
There is a work around which just worked for me, but I am using a Windows 10 PC and used Matlab 2016a - its not an ideal solution but maybe it will work for you on Ubuntu and get you started.
First download the latex fonts from here:
https://ctan.org/pkg/bakoma-fonts?lang=en
Find the "cmss10" font, right click it and install it on your PC (not sure on the process for Linux users but I guess its simple to do). You can also choose to install others if you wish.
Copy and paste the cmss10 font into this folder (whatever the equivalent is in Linux):
C:\Program Files\MATLAB\R2017b\sys\fonts\ttf\cm
Rename it to "mwa_cmss10"
Now copy and paste the cmss10 font into the same folder as above, but this time, rename it "mwb_cmss10".
Okay, now open Matlab (Note, for windows users, I opened it using windows compatibility for windows 7) and produce your figure. It may look a little strange but don't worry. Save it as a .svg file. Don't worry about any warnings or whatever.
Download and install inkscape (a free program):
https://inkscape.org/en/
Open the file in inkscape, and on the right hand menu, there will be an icon which looks like a magnifying glass which says "zoom to fit page on window (5) ". Hopefully it now looks as you intend it to? Thats pretty much it. You can then save the image in whatever format you want. I hope this works for you, good luck
  1 Comment
maxime debiossac
maxime debiossac on 1 Aug 2018
Interesting, although it solves only partially the problem. When I follow your suggestion, I indeed obtain the correct font in the svg file, same if I save in png or jpg format.
However, it renders the wrong font when you save it as a eps or pdf file. Also I am not sure now if by adding mwa_cmss10 and mwb_cmss10 actually corrected the issue. It is possible that even without those files you still get the correct font in the svg file.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!