How do I add latex fonts in matlab?

17 ビュー (過去 30 日間)
maxime debiossac
maxime debiossac 2018 年 7 月 30 日
コメント済み: maxime debiossac 2018 年 8 月 1 日
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 件のコメント
maxime debiossac
maxime debiossac 2018 年 7 月 30 日
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 2018 年 7 月 30 日
編集済み: dpb 2018 年 7 月 30 日
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.

サインインしてコメントする。

回答 (1 件)

Pa342
Pa342 2018 年 7 月 31 日
編集済み: Pa342 2018 年 7 月 31 日
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 件のコメント
maxime debiossac
maxime debiossac 2018 年 8 月 1 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by