mrpiggi / svg

Handling SVG pictures in LaTeX documents using Inkscape, ImageMagick and/or Ghostscript
Other
65 stars 12 forks source link

Import of file containing special characters fails #15

Closed hoelzlem closed 4 years ago

hoelzlem commented 4 years ago

If the text inside a svg-file contains special characters (#$%&\^_{}~) the import fails. Looking at the produced name.pdf_tex the problem seems to be that these characters are not automatically escaped. Manually escaping these characters in name.pdf_tex fixes the problem an produces the expected result.

Example of a line producing an error: \put(0.5,0.5){\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}Relative Error [%]\end{tabular}}}}%

mrpiggi commented 4 years ago

Well, this is something I can't resolve within package svg as I am only using the *.pdf_tex file. So this issue has to be resolved during the file export done by Inkscape. And most of the characters you mentioned could not be escaped in general as I might do something like \def\foo#1{foo: #1}\foo{bar} or $x_{ind}^{sup}$ within a SVG graphic. So the only possible candidates being automatically escaped are % and & and even those could have a meaningful reason.

So in my eyes, it's up to you to escape special characters, if they should be escaped in sense of LaTeX.

hoelzlem commented 4 years ago

Thank you for your quick reply. I already suspected that this might be the case. In fact I found the issue was reported for Inkscape, but as you mentioned can not easily be fixed (Bug#719320). Sadly this means one can not use svg-files generated by Matlab without paying extra attention. Setting inkscapelatex=false can provide a workaround though if the font is not important.

Anyway thank you for clarifying the situation.

mrpiggi commented 4 years ago

Well, than it is related to the way, how MATLAB exports the figure to the svg format. Do you use something like fig2svg from MATLAB File Exchange? Maybe you can drop your issue at https://github.com/kupiqu/fig2svg?

hoelzlem commented 4 years ago

Thanks for the suggestion. I did not test it yet. fig2svg does however not provide an option for exporting Latex as far as i know. Also if it would already produce output specific for Latex using the files anywhere else would be problematic. It seems to me that this is just an inherent problem.

By manually editing the *.pdf_tex this problem can easily be resolved in my case.

mrpiggi commented 4 years ago

So, as you are not using fig2svg, how do you create the svg files?

hoelzlem commented 4 years ago

The Matlab-function saveas(fig,filename,formattype) can natively output svg if formattype is set to "svg". Unfortunatly I do not know on which release this option was added. So far I never had any problems using it.