I am using including Matlab-drawn figures into LaTeX. My usual workflow is as following:
- Script in matlab creates figure(s),
- I tweak what I find needs to be tweaked in visual figure editor,
- Figure is saved as .fig (for future modification) and .eps (for including in LaTeX),
- I convert .eps files to .pdf,
- PDF files are referenced in LaTeX source code.
To the point: when I try to use in axis labels, legend, titles, etc. non-ASCII chars, (to be exact: Polish national chars e.g. 'ą', 'ę', 'ś', 'ć') encoding in Matlab figure editor is fine and characters display properly. After exporting to .eps, they are all wrong (example: "Głębokość" turns into "G³êbokoœæ").
Does there exist a way to do this properly, either by tuning Matlab options or changing my workflow?
Note: I found that export to .png or other non-vector formats handles character encoding properly, but I would like to avoid having to do that -- I'm asking for a way to "keep it vector". Export directly to .pdf produces the same effect as .eps, e.g. it is producing wrong results.
PS. Matlab is R2008a, .latex files are compiled with pdflatex, .eps files with epstopdf from MikTeX 2.9 (all under Win7).
You could have a look at psfrag, that's what I usually use when I try to use Matlab figures in LaTeX. You basically put just tags into the figure in Matlab and replace those tags with LaTeX text afterwards. The biggest benefit is that this allows you to have identical symbols in text and figures.
Edit: when looking for the psfrag-URL, I found a Matlab script to simplify this: LaPrint.
For exporting a Matlab figure with non-ASCII ISO-8859-1 characters, there is no problem on Windows, but on Linux with a UTF-8 locale there is a Matlab bug and a workaround. The question here targets characters that are not in ISO-8859-1, which is more tricky. Here is a solution that I posted on a related question.
If the number of characters needed is less than 256 (8-bit format) and ideally in a standard encoding set, then one solution is to:
For example, if you want to export Polish text, you need to convert the file into ISO-8859-2. Here is an implementation with Python (multi-platform):
saved as eps_lat2.py; then running the command
python eps_lat2.py file.eps
, where file.eps is the eps created by Matlab, creates file_latin2.eps with Latin-2 encoding. The file ISOLatin2Encoding.ps contains the encoding vector:Here is another implementation on Linux with Bash:
saved as eps_lat2; then running the command
sh eps_lat2 file.eps
creates file_latin2.eps with Latin-2 encoding.It can easily be adapted to other 8-bit encoding standards by changing the encoding vector and the iconv (or codecs.open) parameter in the script.
For other characters in latin1 charset, Look at:
I am using pdflatex, so psfrag is not an option, and pdfrack seems to be broken.
Another possible solution would be to use matlab2tikz. It creates a tikz/pgfplot source file that may be included directly by your latex source. This means that it uses LaTeX's facilities for font rendering. You may directly edit the generated file to tweak the labels and such. Unfortunately, it doesn't work for all MATLAB figures.