MATLAB: Are Russian characters published as “####” in PDF Format in MATLAB 7.13 (R2011b)

charactersMATLABpublishrussian

I have a MATLAB file that I want to publish as a PDF using the PUBLISH command. The file contains Russian characters. For example, the contents of the file are as follows:
disp('Привет')
Executing this displays the string 'Привет' on the command window. However, when I use the PUBLISH command with the PDF option, the characters Russian characters show as "####". The publishing works fine for other formats, for example the Russian characters display properly, in other formats like HTML or PPT.

Best Answer

For Release 2012a (R2012a) and newer, this bug has been fixed. In order to correctly display any non-ASCII characters, the undocumented font option must be used:
publish('myScript.m','format','pdf','font','fontName');
This line will publish 'myScript' into a PDF file using the 'fontName' font. The font used must have the non-ASCII characters used in 'myScript'. For Russian characters, for example, using the 'Candara' font available in Windows 7. If this font is not available, a font with the necessary non-ASCII characters must be installed first.
For product releases prior to R2012a, read below for any possible bug workarounds:
There is a bug in MATLAB 7.13 (R2011b) in the way that PUBLISH handles foreign fonts for publishing PDFs. To work around this issue:
1) Edit the “fop_config.xml” files in the following two locations:
$MATLABROOT\toolbox\shared\rptgen\@rpt_xml\@db_output
$MATLABROOT\toolbox\matlab\codetools\private
Here $MATLABROOT is the MATLAB installation directory that can be found by executing the command MATLABROOT inside the MATLAB command window.
Locate the line that reads "</fonts>" within the “fop_config.xml” files and add the following line just before the "</fonts>" line.
<auto-detect/>
2) From your MATLAB command window, open the “publish.m” file by using the following command:
edit publish.m
In this file, locate the line that reads the following:
addAttribute(styleDom,attributeSet,'color','blue')
Add the following lines after the above line in the “publish.m” file:
fontName = '''Arial''';
addVariable(styleDom,de,'body.font.family',fontName)
addVariable(styleDom,de,'dingbat.font.family',fontName)
addVariable(styleDom,de,'monospace.font.family',fontName)
addVariable(styleDom,de,'symbol.font.family',fontName)
addVariable(styleDom,de,'title.font.family',fontName)
addVariable(styleDom,de,'sans.font.family',fontName)
Publishing to PDF files should now work fine after restarting MATLAB.