# Use Matlab 2014b figures (via Inkscape) in pdfTeX

27 views (last 30 days)
Fabio Muratore on 27 Feb 2015
Answered: andre rossi on 22 Mar 2017
Hello everybody,
I know there are many threads related to this topic, but I still could not find a satisfying solution.
Summary: Matlab 2014b figures -> export as .eps or .svg -> load into Inkscape ( problem is in here: text is not recognized ) -> use Inkscpe to save as .pdf_tex -> use in scrreprt document (pdfTeX)
----------
The goal: I want to use different Matlab 2014b plots in a scientific paper. Within those plot I want to use the same LaTeX font as it is used in my scrreprt document.
The problem: When I export or print the Matlab figures as .eps or .svg (possible in 2014b) it is not possible to use the document font (type and size) or access the text (labels, axisticks) Inkscape.
What I've done so far: I used matlab2tikz . This lets me access the plot with the "correct" font. But it does not create the results I want to have. This thread mentions a related problem.
I greated some figures in Inkscape (.svg) and used the export method which provides .pdf_tex files. Then I used \input to include them into the to the document. This works very well ("correct font and nice quality"), so I want to use this method, but in the first place I need to print/export the figures in a way that lets Inkscape read the text as text and notas pixels in a picture.
What is definitely not desired: Setting the Matlab figure 'Interpreter' to 'Latex' looks nice in the figure, but is useless when including it into a latex document
I appreciate any help. Thanks in advance.

Nicolas on 31 Oct 2015
Edited: Nicolas on 1 Nov 2015
I was struggling with the same problem and I think I may have found a solution. I'm posting this here in case you are still looking for a solution with SVGs and for other people who find this.
I'm using Matlab 2015b and exporting to SVG. I want to use SVG because some things look better than with matlab2tikz, e.g. transparent surfaces. I want text in my figures (labels, ticklabels, annotations) to be saved as text strings s.t. I can include the figure using the procedure described here . If my figure does not contain any complicated latex strings, the text is stored as text and everything works fine.
The problem arises when I have some text that is actually Latex stuff, e.g.
text(0,0,'$\rho$')
This is then saved with the symbol already inserted and the text in the SVG is a vector graphic, not text.
text(0,0,'$\rho$', 'interpreter', 'none')
creates an SVG that still has the '\rho' text, but its a vector graphic.
The Solution
If I do
text(0,0,'$\\rho$')
(i.e. using interpreter 'tex', NOT 'Latex', and NOT 'none') the text is stored as plain ascii text in the SVG file. Note the escaping '\'. Now we can even use custom commands defined in our latex documents. e.g.
text(0,0,'$\\mycommand\{\\rho\}$')
where '\mycommand{}' is some command defined in our Latex environment. Note that we have to escape every backslash '\' and also every curly brace {}.
I hope this helps somebody fighting with Matlab and Latex. (A fight that shouldn't be this hard considering what most people use Matlab for.)

MSleiman on 9 Mar 2016
If you are using pdflatex, an elegant method is proposed by Jan de Jong.
Fonts can be interpreted by Latex, figures can be adjusted in Inkscape, and you get .pdf, .svg, .pdf_tex formats for your figures.
##### 2 CommentsShowHide 1 older comment
Jan de Jong on 10 Mar 2016
I hope you think the function is useful. I had the same struggle as you described. I therefore wrote the function Plot2LaTeX. There are improvements possible, but I hope it can help. Especially for the people for who EPS is no longer an option since it is not supported by pdf+LaTeX

Fabio Muratore on 27 Feb 2015
Edited: Fabio Muratore on 27 Feb 2015
If anybody in the future encounters the same problem, please read this:
After a lot of trial, I came to the conclusion, that it is probably the best to use matlab2tikz or pgfplots . This link leads to a handy extension of Inkscape, which fulfills its purpose. All the text in the Matlab figures got recognized. The problem is the export from Inkscape later on. You could use .eps or even the .pdf export, which works as in this video. The problem is, that you have to ajust all the axistiks, labes and legend entries manually. This is ok for figures with less text, but inappropriate for scientific figures with many data (numbers and legends).

andre rossi on 22 Mar 2017
If someone have a similar problem that's what I did: Inkscape did not recognize some fonts that matlab uses. So I copied the matlab fonts from matlab directory to system fonts folder. For linux/mac something like that would work: 1- create a user fonts folder:
mkdir $HOME/.fonts 2- Copy matlab fonts to your user fonts folder cp /opt/MATLAB/R2016a/sys/fonts/ttf/cm/*.ttf$HOME/.fonts
3- Update font cache
fc-cache