I try to use Hebrew characters in a Matlab figure plot on my Ubuntu to no avail. I tried:
text(0.6,0.5,'ירוק','fontname','times new roman','rotation',180,'fontsize',50,'color','r')
and
title('ירוק','fontname','times new roman','fontsize',50,'color','r')
similar to what was proposed in the answer to this question. I got garbled text (see attached image).
Matlab is in version R2009b. Of course I'm set to UTF-8 encoding.
>> slCharacterEncoding
ans =
UTF-8
I also have access to a remote computer via ssh, with version R2011a. That didn't work either. (There I had to slCharacterEncoding('UTF-8')
)
The other option, using a javax.swing.JLabel
component, is too difficult to use with the amount of graphing I have.
I can continue producing graphs with English axes and titles, but that's a pity. Any advice?
Edit: as suggested by Egon, if I can print -deps
and then replace the text (from code within Matlab) in the resulting EPS file, that's pretty cool too. But I don't know how to place Unicode in EPS and I think that's stretching it...
Yet another edit: I'm starting to think this is an X-server issue. Though different, I wouldn't be surprised if these issues are related:
I tried uninstalling Ubuntu supplied NVidia drivers (I have an 9300GS card) and re-installing NVidia supplied ones (v295). I tried changing DPI in xorg.conf to "100 x 100"
. Installed all packages listed in HebrewLocalizationHowto and then some. Nothing worked. Suggestions?
Another edit Fonts located under matlab/sys/fonts/ttf
or matlab/sys/fonts/type1
aren't rendered correctly. When I edit the figure and double click the title, I see the characters are there, but when I finish editing it returns to the bad rendering. Also, the JLabel solution for rendering Unicode characters suggested here renders text correctly under the same figure.
Another edit Matlab R2011a exhibits the same issue. Here's the output of listfonts
>> listfonts
ans =
'aharoni'
'andale mono'
'anka clm'
'arial'
'arial black'
'avant garde gothic'
'AvantGarde'
'batang'
'bitstream charter'
'biwidth'
'Bookman'
'caladings'
'century schoolbook l'
'charter'
'clean'
'clearlyu'
'clearlyu alternate glyphs'
'clearlyu arabic'
'clearlyu arabic extra'
'clearlyu devanagari'
'clearlyu devangari extra'
'clearlyu ligature'
'clearlyu pua'
'cmex10'
'cmmi10'
'cmr10'
'cmsy10'
'comic sans ms'
'comix no2 clm'
'Courier'
'courier 10 pitch'
'courier new'
'dingbats'
'dorian clm'
'dotum'
'drugulin'
'ellinia'
'fangsong ti'
'fixed'
'frank ruehl'
'gan clm'
'georgia'
'gladia clm'
'gothic'
'Helvetica'
'Helvetica-Narrow'
'impact'
'itc avant garde gothic'
'itc bookman'
'itc zapf chancery'
'itc zapf dingbats'
'ktav yad clm'
'latin modern roman'
'latin modern sans'
'latin modern sansquotation'
'latin modern typewriter'
'latin modern typewriter variable width'
'lucida'
'lucida bright'
'lucidabright'
'lucidasans'
'lucidasans typewriter'
'lucidatypewriter'
'mincho'
'msam10'
'msbm10'
'nachlieli'
'new century schoolbook'
'newcenturyschlbk'
'NewCenturySchoolBook'
'newspaper'
'nil'
'nimbus mono l'
'nimbus roman no9 l'
'nimbus sans l'
'open look cursor'
'open look glyph'
'ozrad clm'
'Palatino'
'song ti'
'standard symbols l'
'Symbol'
'terminal'
'texgyreadventor'
'texgyrebonum'
'texgyrecursor'
'texgyreheros'
'texgyrepagella'
'texgyreschola'
'texgyretermes'
'Times'
'times new roman'
'trebuchet ms'
'urw bookman l'
'urw chancery l'
'urw gothic l'
'urw palladio l'
'verdana'
'wasy10'
'webdings'
'yehuda'
'zapf chancery'
'zapf dingbats'
'ZapfChancery'
'ZapfDingbats'
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:
\327
/Encoding
section to map Hebrew characters to the codes output by MatlabThat 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With