Matlab in Linux (Ubuntu 11.10) doesn't display Unicode (Hebrew) in plot figure

时光总嘲笑我的痴心妄想 提交于 2019-11-30 19:40:44

Have you tried disabling the text interpreter?

So either adding 'interpreter', 'none' as the last few arguments of your call to text or setting this for the entire figure set(gcf,'defaulttextinterpreter','none'). To apply that globally, just replace gcf by 0 (that is the root window).

If that doesn't work, you might try the LateX interpreter (replace none by 'latex' above), which might have support for Hebrew characters.

On the other hand, but this is a personal preference, English labels allow (virtually) anyone to read your figures which only allows you to exchange ideas with other people.

edit As said in the question you referenced, it is a font problem, not a MATLAB problem. I tried it here on my Arch install (which has its fonts problems of its own), but I can get it to display your Hebrew characters just fine using the Arial font.

edit 2 Again, this is a font problem, not MATLAB. I again tried this on my Arch install, and now Hebrew works fine with your first code. So I assume the fonts you have installed are not the right versions.

On Arch, I have these font-related packages installed:

extra/cantarell-fonts 0.0.7-1
extra/font-bitstream-speedo 1.0.1-2
extra/fontsproto 2.1.2-1
extra/gsfonts 1.0.7pre44-3
extra/sdl_ttf 2.0.11-2
extra/t1lib 5.1.2-3
extra/ttf-bitstream-vera 1.10-8
extra/ttf-dejavu 2.33-2
extra/ttf-freefont 20100919-2
extra/xorg-font-util 1.3.0-1
extra/xorg-fonts-100dpi 1.0.1-4
extra/xorg-fonts-75dpi 1.0.1-4
extra/xorg-fonts-alias 1.0.2-2
extra/xorg-fonts-encodings 1.0.4-3
extra/xorg-fonts-misc 1.0.1-2
extra/xorg-fonts-type1 7.4-2
extra/xorg-mkfontscale 1.1.0-1
extra/xorg-xfontsel 1.0.4-1
extra/xorg-xlsfonts 1.0.3-2
community/ttf-liberation 1.07.2-1
aur/ttf-microsoft-wingding 1.55-1
aur/ttf-ms-fonts 2.0-9

For Ubuntu, I don't remember the correct packages, but I guess you'd have the highest chances of success with ttf-liberation, ttf-ms-conts (msttcorefonts in Ubuntu), xorg-fonts-100dpi, xorg-fonts-alias or their Debian/Ubuntu counterparts.

So I think there are two possible solutions: either try another font. Arial worked for me before, Times New Roman now also works for me. Or install the proper fonts on your computer.

edit On this end, it seems that rendering in MATLAB works almost perfectly. However, export to PDF doesn't work. Any bitmap formats should work fine.

My next guess, is indeed that for the PDF case, MATLAB is to blame. I did some tests by using the regular PDF save and printing to a file. Both exhibit the same problem. This is not surprising, since the PDF save feature in MATLAB seems to generate PS which is converted to PDF afterwards. Presumably, there is something rotten and unicode incompatible going on in the PS generation.

I know it is not a complete solution to your problem, but you can at least export your figures into PNG, if your resolution is high enough, most people won't notice.

Another solution, if you use LaTeX to generate your report, is to use matlab2tikz to generate your figures, there I was able to get the Hebrew text to be inserted into LaTeX code. However, since I don't have experience with Hebrew in my TeX files, I don't know the tricks to get that to compile.

Using the following snippet you can see which fonts work easily

x=listfonts
for i=1:numel(x) 
    display(x{i})
    title('ירוק','Color','red','FontName',x{i},'FontSize',50)
    pause
end

For me Lucida Sans worked. However it will display Hebrew reversed.

You can export to EPS (print -deps -- I have found this to be unavailable in Windows; then again, you don't have the problem there) and do some modifications:

  • remove encoding horror from Matlab: simple remove all occurrences of \327
  • add an /Encoding section to map Hebrew characters to the codes output by Matlab

That is, change this:

%%IncludeResource: font FreeSans
/FreeSans /ISOLatin1Encoding 200 FMSR

-6384  483 mt 
(\327\220\327\221\327\222\327\223\327\224\327\225\327\226\327\227\327\230\327\231\327\233\327\234\327\236\327\240\327\241\327\242\327\244\327\246\327\250\327\247\327\251\327\252\327\237\327\232\327\245\327\235\327\243) s

to this:

/Encoding [
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/space /exclam /quotedbl /numbersign 
/dollar /percent /ampersand /quoteright 
/parenleft /parenright /asterisk /plus 
/comma /minus /period /slash 
/zero /one /two /three 
/four /five /six /seven 
/eight /nine /colon /semicolon 
/less /equal /greater /question 
/at /A /B /C 
/D /E /F /G 
/H /I /J /K 
/L /M /N /O 
/P /Q /R /S 
/T /U /V /W 
/X /Y /Z /bracketleft 
/backslash /bracketright /asciicircum /underscore 
/quoteleft /a /b /c 
/d /e /f /g 
/h /i /j /k 
/l /m /n /o 
/p /q /r /s 
/t /u /v /w 
/x /y /z /braceleft 
/bar /braceright /asciitilde /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/alefhebrew /bethebrew /gimelhebrew /dalethebrew 
/hehebrew /vavhebrew /zayinhebrew /hethebrew 
/tethebrew /yodhebrew /finalkafhebrew /kafhebrew /lamedhebrew 
/finalmemhebrew /memhebrew /finalnunhebrew /nunhebrew /samekhhebrew /ayinhebrew 
/finalpehebrew /pehebrew /finaltsadihebrew /tsadihebrew /qofhebrew /reshhebrew 
/shinhebrew /tavhebrew /.notdef /.notdef 
/.notdef /registered /macron 
/degree /plusminus /twosuperior /threesuperior 
/acute /mu /paragraph /periodcentered 
/cedilla /onesuperior /ordmasculine /guillemotright 
/onequarter /onehalf /threequarters /questiondown 
/Agrave /Aacute /Acircumflex /Atilde 
/Adieresis /Aring /AE /Ccedilla 
/Egrave /Eacute /Ecircumflex /Edieresis 
/Igrave /Iacute /Icircumflex /Idieresis 
/Eth /Ntilde /Ograve /Oacute 
/Ocircumflex /Otilde /Odieresis /multiply 
/Oslash /Ugrave /Uacute /Ucircumflex 
/Udieresis /Yacute /Thorn /germandbls 
/agrave /aacute /acircumflex /atilde 
/adieresis /aring /ae /ccedilla 
/egrave /eacute /ecircumflex /edieresis 
/igrave /iacute /icircumflex /idieresis 
/eth /ntilde /ograve /oacute 
/ocircumflex /otilde /odieresis /divide 
/oslash /ugrave /uacute /ucircumflex 
/udieresis /yacute /thorn /ydieresis 
] def

%%IncludeResource: font FreeSans
/FreeSans /Encoding 200 FMSR
1016  483 mt 
(\220\221\222\223\224\225\226\227\230\231\233\234\236\240\241\242\244\246\250\247\251\252\237\232\245\235\243) s

(The encoding section can be copies as-is; and the \327 occurences were removed)

This works, except that for some reason one final character doesn't display correctly. It's good enough for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!