Use Matlab 2014b figures (via Inkscape) in pdfTeX
12 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(4 个)
Nicolas
2015-10-31
编辑:Nicolas
2015-11-1
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.)
0 个评论
MSleiman
2016-3-9
Fonts can be interpreted by Latex, figures can be adjusted in Inkscape, and you get .pdf, .svg, .pdf_tex formats for your figures.
Mohammad
2 个评论
Jan de Jong
2016-3-10
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
andre rossi
2017-3-22
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!