Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
LaTeX interpreter inner workings

Subject: LaTeX interpreter inner workings

From: R Wat

Date: 7 Aug, 2013 14:53:11

Message: 1 of 9

Although MATLAB's implementation of LaTeX for use in figures has gotten better over the years, it still leaves something to be desired. Some work arounds have been developed, such as laprint and psfrag, which take a figure and export it in two parts: the underlying graphics and a .tex file containing all of the text for the figure. These two file parts can then be added to a LaTeX document to have nice consistent fonts between figures and the document itself. This also has the added benefit of allowing for full usage of LaTeX packages, etc. Unfortunately, there are some drawbacks to using this method: these functions struggle with complex graphics (such as 3D plots) and this framework cannot be used when creating videos (unless you use a rather convoluted scripting procedure involving something like ffmpeg). So, for me, it comes down to working with MATLAB's attempt at LaTeX. My
understanding of the LaTeX implementation is as follows (which is based on MATLAB version R2009b):
    - All of the LaTeX related files can be found in the folder <matlabpath>/sys/tex and <matlabpath>/sys/fonts. Within the tex folder are the class files (mwarticle.cls), tfm files (or font metric files), font definition files (.fd files which are used to map font calls to tfm files), and a couple other things. This set of LaTeX files is about as barebones as you can get, missing files such as the map files which are used to convert from DVI to PS files (or PDF) amongst other things. Within the fonts folder, a basic set of Type1 (and correspondingly, TrueType) fonts can be found, predominately covering the Computer Modern font family. My understanding is that these files are used to render the tex output in figure windows (where the ttf files are used on Unix systems and pfb files are used on Windows) and embedding fonts in exported vector graphics.
    - There is a helper function called tex.m which takes in a LaTeX string and creates the corresponding DVI, calling MATLAB's builtin LaTeX engine. As the builtin LaTeX engine references the files found in <matlabpath>/sys/tex, you can in theory build upon the barebones LaTeX with addition style files, etc.

Ultimately, I would like to be able to build up the barebones LaTeX distribution, installing new fonts and packages. Specifically, I would like to use the phv and syr font families in my figures (due to some stipulations on formatting). It is relatively trivial to install a more expanded version of LaTeX into the <matlabpath>/sys/tex folder; however, I have not been able to figure out how to get MATLAB to properly render (and/or export) newly installed fonts. I have tried placing the appropriate ttf and pfb files into the <matlabpath>/sys/fonts folder, but this works inconsistently at best (and not at all in more recent versions of MATLAB where the font naming scheme has been modified).

So, my question stems from how MATLAB uses the output DVI file from tex.m to a) render it in the figure window and b) export the figure to a vector graphic (such as eps or pdf). As DVI files are sparse files, only containing the metric information for fonts and not the actual bitmap or postscript fonts themselves, MATLAB must be using some version of DVIPS (or something of its liking) to convert the DVI to something human readable in the figure window. Unfortunately, I have not been able to locate DVIPS (or any other dvi converters) within the MATLAB installation. My guess is that is this functionality lives somewhere in the function "hardcopy". Does anyone know if this is true? Also, does anyone know how this all works in general?

Any help or insight would be greatly appreciated. Let me know if any of this is unclear so that I can elaborate more.

Thanks!

Subject: LaTeX interpreter inner workings

From: Carsten

Date: 17 Oct, 2013 12:49:40

Message: 2 of 9

Hello,

I've just come up with the same question, during an attempt at getting cmss10 working again under a recent Matlab (R2013a). There is a page at
  http://undocumentedmatlab.com/blog/matlab-latex-interface/
discussing the degrading extent of LaTeX support in Matlab, and people there suggest to hack into tex.m; but like you I believe that in order to get fonts to actually render, one needs to find out what Matlab does with the generated dvi. Did you have any success in getting more insight into this, or found another way to make your fonts work? Did you try to contact Matlab support about this?

Thank you,
Carsten

Subject: LaTeX interpreter inner workings

From: R Wat

Date: 17 Oct, 2013 14:47:05

Message: 3 of 9

"Carsten" wrote in message <l3omd3$bgl$1@newscl01ah.mathworks.com>...
> Hello,
>
> I've just come up with the same question, during an attempt at getting cmss10 working again under a recent Matlab (R2013a). There is a page at
> http://undocumentedmatlab.com/blog/matlab-latex-interface/
> discussing the degrading extent of LaTeX support in Matlab, and people there suggest to hack into tex.m; but like you I believe that in order to get fonts to actually render, one needs to find out what Matlab does with the generated dvi. Did you have any success in getting more insight into this, or found another way to make your fonts work? Did you try to contact Matlab support about this?
>
> Thank you,
> Carsten

I haven't gotten anywhere since I wrote the original post. In previous versions of Matlab (R2009 and R2010), I have been able to install fonts such as Helvetica and Symbol which took a decent amount of work to get up and running, but now works flawlessly. Unfortunately, as stated in http://undocumentedmatlab.com/blog/matlab-latex-interface/, Mathworks as changed how they deal with LaTeX, messing up my previous hack. I would ultimately like to upgrade to a newer version of Matlab, but if I can't install my own fonts, I won't.

I have not contacted Mathworks about his. I'm not sure how helpful they will be, but it might be worth a shot.

Let me know if you get anywhere.

Subject: LaTeX interpreter inner workings

From: Carsten

Date: 19 Oct, 2013 19:03:08

Message: 4 of 9

Hello,

I too commented on that thread on undocumentedmatlab.com, and only now realized that "Ryan W." is "R. Wat" :)

For your information: I posted a question concerning this matter on SO, see
http://stackoverflow.com/questions/19435848/how-to-make-fonts-available-to-the-latex-interpreter-in-matlab-r2013a
Several people seem to be interested in this matter, but I haven't gotten any solution yet. One answer by Daniel E. Shub, who also wrote in that thread on um.com.

I invested several hours in further investigating the matter and found out more details, but did not arrive at a solution. Still I posted my findings on SO, maybe using those might help you in future attempts. Please let me know in case you're getting somewhere.

I hoped for a Matlab-only solution, but now I'll have a look at psfrag & Co. I just need that illustration using Computer Modern Sans, there's no help.

Best,
Carsten

Subject: LaTeX interpreter inner workings

From: Steven Lord

Date: 20 Oct, 2013 20:34:46

Message: 5 of 9


"Carsten " <carsten.allefeld@googlemail.com> wrote in message
news:l3ul1c$sos$1@newscl01ah.mathworks.com...
> Hello,
>
> I too commented on that thread on undocumentedmatlab.com, and only now
> realized that "Ryan W." is "R. Wat" :)
>
> For your information: I posted a question concerning this matter on SO,
> see
> http://stackoverflow.com/questions/19435848/how-to-make-fonts-available-to-the-latex-interpreter-in-matlab-r2013a
> Several people seem to be interested in this matter, but I haven't gotten
> any solution yet. One answer by Daniel E. Shub, who also wrote in that
> thread on um.com.
>
> I invested several hours in further investigating the matter and found out
> more details, but did not arrive at a solution. Still I posted my findings
> on SO, maybe using those might help you in future attempts. Please let me
> know in case you're getting somewhere.
>
> I hoped for a Matlab-only solution, but now I'll have a look at psfrag &
> Co. I just need that illustration using Computer Modern Sans, there's no
> help.

I recommend that you contact Technical Support and describe what you're
trying to do. They may be able to suggest a solution or workaround, or they
may be able to report it to the development staff as an enhancement request
or bug report.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: LaTeX interpreter inner workings

From: Carsten

Date: 21 Oct, 2013 12:17:07

Message: 6 of 9

Hi Steve,

thanks for replying here. I did file a bug report, see
  http://www.mathworks.com/support/service_requests/Service_Request_Detail.do?ID=889376&filter=&sort=&statusorder=0&dateorder=0

However, I'm skeptical as to the possible outcome, because as described on
  http://undocumentedmatlab.com/blog/matlab-latex-interface/
it appears that the degradation of Latex support in Matlab is intentional?

C.

Subject: LaTeX interpreter inner workings

From: R Wat

Date: 21 Oct, 2013 12:46:06

Message: 7 of 9

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message
> I recommend that you contact Technical Support and describe what you're
> trying to do. They may be able to suggest a solution or workaround, or they
> may be able to report it to the development staff as an enhancement request
> or bug report.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

As per Steve's suggestion, I just submitted a service request to Mathworks regarding this topic. I'll keep you posted on what I hear back.

Subject: LaTeX interpreter inner workings

From: R Wat

Date: 4 Nov, 2013 16:45:09

Message: 8 of 9

"R Wat" wrote in message <l437me$mku$1@newscl01ah.mathworks.com>...
> "Steven Lord" <Steven_Lord@mathworks.com> wrote in message
> > I recommend that you contact Technical Support and describe what you're
> > trying to do. They may be able to suggest a solution or workaround, or they
> > may be able to report it to the development staff as an enhancement request
> > or bug report.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
>
> As per Steve's suggestion, I just submitted a service request to Mathworks regarding this topic. I'll keep you posted on what I hear back.

I just heard back from Mathworks regarding this questions. Here is the response that I received:

"Unfortunately, in the current releases of MATLAB, we do not support installing additional fonts for LaTeX. The fonts we use are customized for MATLAB and we do not document the mechanism for adding more fonts. This is a known issue in MATLAB and we have received multiple requests on this issue. An enhancement request has been submitted for the same. The development team may consider the enhancement request to be incorporated in the future releases of MATLAB. I would be glad to inform you regarding any updates on the enhancement request that are released by the development team."

So, it looks like we will have to hack something together on our own if we want this functionality. If I come up with any works arounds, I'll try to post the solution here.

Subject: LaTeX interpreter inner workings

From: Carsten

Date: 4 Nov, 2013 17:48:10

Message: 9 of 9

Thanks for the information. I filed that bug report I mentioned, specifically about the problem with Computer Modern Sans. The reply was:

"Thank you for writing to us about this issue. This is a known bug in the way that the LaTeX interpreter handles fonts in the axes and texts in graphics. Our development team is aware of the situation and is considering implementing a fix in a future release of MATLAB. We apologize for the inconvenience this is causing you."

I then pointed out that according to the page on undocumented matlab there is a progressive degradation of LaTeX support, which does not support the promises made.

"Thank you for your patience. I do understand the discomfort you are facing currently while using Latex fonts in MATLAB figures. As you have correctly mentioned, the ability to display Latex fonts in MATLAB graphics is currently unavailable.
We have received multiple requests from other customers as well. The developers have taken the bug reports under consideration and would be prioritizing the enhancement in future releases.
To answer your question on releasing an external bug report, the report is more of an enhancement request and unfortunately cannot be published externally. As the enhancement request has been submitted to the development team, the Service Request will be closed."

I'd like to say I'm disappointed, but actually this is exactly what I expected to happen. Some vague promises, and not even a clear understanding of the problem. And in contrast to the ability to install additional fonts, which might be considered a feature request (though documentation would already help), the problem with cmss is clearly a bug and in any serious software development it should be listed in the bug database. Well, whatever.

As a temporary workaround, I created a simple wrapper around psfrag. In contrast to other solutions, mine calls LaTeX itself and then produces an eps file with the correct text embedded, which therefore can be used not only with LaTeX documents but wherever eps is accepted. I'd be happy to share the code in case you are interested.

C.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us