Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing Umlauts in Matlab

I’m am trying to create a pdf file from matlab figure using cmyk colors, but facing a problem with umlauts and also some other special characters. Is there any other way to handle this than Latex? The following example demonstrates the issue.

plot(rand(199,1))
title_string = ['Some text:äö' char(228) ':2005' char(150) '2008:end text'];
title(title_string);
print(gcf,'-dpdf','cmykfile.pdf','-r600','-cmyk'); 
print(gcf,'-dpdf','rgbfile.pdf','-r600');

As you can see from the pdf-files the RGB-version handles umlauts, but not en-dash, and CMYK skips them all.

PDF is generated in Matlab using Ghostscript, but I have not found how to configure character encoding for GS.

I am using Windows and Matlab R2014.

like image 838
Pekka Avatar asked Aug 21 '14 07:08

Pekka


1 Answers

I'm not completely sure this is the solution you was looking for. Anyway, if you create an eps first and then convert it to pdf the output file doesn't have any issue with the special characters in the title, provided that you don't build your title string using char.

plot(rand(199,1))
title_string = 'Some text:äöä:2005—2008æ:end text';
title(title_string);
print(gcf,'-depsc','cmykfile.eps','-r600','-cmyk'); 
!ps2pdf cmykfile.eps cmykfile.pdf

The code above works if you have the ps2pdf utility in your system path. You already have ps2pdf on your computer if you have MiKTeX installed, but you might need to update your system path. Basically ps2pdf should be a shortcut to gs, therefore also if you have only gs and not MiKTeX installed, you should be able to achieve the same result.


EDIT

On my machine (Windows 7, MATLAB R2014b), also this code works well, without the need to use ps2pdf:

plot(rand(199,1))
title_string = 'Some text:äöä:2005—2008æ:end text';
title(title_string);
print(gcf,'-dpdf','cmykfile.pdf','-r600','-cmyk');

It seems that the issue happens when you build the title string using char.

like image 136
lmillefiori Avatar answered Oct 21 '22 21:10

lmillefiori