8

I'm using Mathematica from Ubuntu. I need a normal font to display cyrillics inside PDFs. Any default font is very ugly, letters are too close together:

ImportString@
  ExportString[Style["Русский", FontFamily -> #, FontSize -> 50], 
   "PDF"]&/@ {"Times", "Courier", "Arial"}

enter image description here

Here is the longer example with also Latin mixed in:

enter image description here

As you can see Cyrillics letters are much bigger somehow.

It's happening to every text inside the notebook including graphics, even though it looks fine in the editor.

This is how it looks on MacOSX-x86-64 and Mathematica 8.0.4 which can be used as reference:

Mathematica graphics

VividD
  • 3,660
  • 4
  • 26
  • 42
swish
  • 7,881
  • 26
  • 48
  • Possible duplicate: http://mathematica.stackexchange.com/q/5660/121 (Sadly, no answers.) – Mr.Wizard Oct 21 '12 at 11:01
  • 1
    @Mr.Wizard I've seen it. I don't have nonsense in the output I just got ugly fonts. – swish Oct 21 '12 at 11:05
  • I understand now. Hopefully this one will be answered. – Mr.Wizard Oct 21 '12 at 11:07
  • This may be system dependent. On my OS, Win7-64 using Mathematica 8.0.4. I get this result which looks good to me. – Sjoerd C. de Vries Oct 21 '12 at 13:15
  • @SjoerdC.deVries Yes, I'm on linux – swish Oct 21 '12 at 14:07
  • Using the exact same fonts in a text processor do you get better results? I wonder whether you have Arial, for instance, as this is usually distributed with Windows and MacOS, but I believe not with Linux. – Sjoerd C. de Vries Oct 21 '12 at 14:24
  • @SjoerdC.deVries Text processor display everything fine, it's the exported PDF only that got this problem and if I print something of course since it converts to PDF first. And I have Arial, it's last in the picture. – swish Oct 21 '12 at 15:49
  • Did you install Arial yourself or did it come with your distribution? – Sjoerd C. de Vries Oct 21 '12 at 16:19
  • @SjoerdC.deVries Not sure, I've installed a lot of things, maybe some package came with Arial (probably wine). – swish Oct 21 '12 at 16:29
  • On macosx7.5 mma 8.0.4 I get the same result as Sjoerd – chris Oct 21 '12 at 18:58
  • For pdf files advance option ISO 19005-1 Compliant (PDF/A) embeds the fonts. If generating a PDF, you may use any fonts you like, but you must embed the fonts in the PDF. Keep in mind, that you may not have the printing rights for a font and that some fonts are only screen fonts and can't be used to print. With these kinds of fonts, you will not be able to embed them in your PDF or if they do embed, they won't print correctly. But not sure how to do it in mathematica... – s.s.o Oct 24 '12 at 13:24
  • Maybe you can create an empty cyrillics embedded pdf file and append the Mathematica work there... – s.s.o Oct 24 '12 at 13:34
  • @s.s.o But I would rather just select and export or print directly from Mathematica. Currently I forced to export as PNG and using TeX to make PDFs. – swish Oct 24 '12 at 13:41
  • If you can print as pdf file, then go to pdf printer preferences and change default settings to ISO 19005-1 Compliant (PDF/A). I hope your pdf printer has preferences options. – s.s.o Oct 24 '12 at 13:47
  • @s.s.o There are no any pdf printer options. – swish Oct 24 '12 at 15:03
  • @swish Can you include the text in copyable text so I can use to test the stuff? – halirutan Oct 26 '12 at 19:45
  • @halirutan Russian Wikipedia can provide as much copyable text as needed. – swish Oct 26 '12 at 19:49

1 Answers1

10

In my opinion you don't have many options here and honestly, I would not try to achieve this with Mathematica and Linux because the font-rendering was, is and will at least for some time be crappy. In the examples, I use the "Liberation Serif" which is the default serif font on my system.

Let me give some ideas: The easiest thing I know is to use FontTracking to widen the characters.

ImportString@
   ExportString[
    Style["Русский", FontFamily -> "Liberation Serif",
      FontSize -> 50, FontTracking -> "Wide"], "PDF"] // 
  First // Framed

Mathematica graphics

As you see the "y" is still touching the "P" and "Wide" is the maximal possible setting to this option. This brought me to my second idea where you adjust the low-level boxes to make the spacing right. Basically it works like that:

You split your string into characters and Riffle and invisible space between each character. This invisible space is wrapped in an AdjustmentBox where you have the option to set margins to all directions.

An outer StyleBox takes all your options for FontSize and so on. To see the spacing even to the left, right, bottom and top of the string, I used a FrameBox

ImportString@
  ExportString[
   FrameBox@
     StyleBox[
      RowBox[Riffle[Characters["Русский"], 
        AdjustmentBox["\[InvisibleSpace]", 
         BoxMargins -> {{0.15, 0}, {1, 1.5}}], {2, -1, 2}]], 
      FontFamily -> "Liberation Serif", FontWeight -> Plain, 
      FontSize -> 50] // DisplayForm, "PDF"] // First

Mathematica graphics

How to implement the method 1

Try first the easy way which is to select appropriate fonts and setting the FontTracking to "Wide". This is more fiddling than a science but what I basically tried was the following. I created two text-cells with the same content. I leave the first one as it is and adjust the second to try what changes. If you find settings which are acceptable, you can transfer them into a stylesheet and use it.

So here is my test-environment. Create a new document from within a notebook, this will make saving the pdf and looking at the result much easier:

nb = CreateDocument[];
Button["SAVE ME!",
 Export["/home/oliviaWild/Desktop/cyrillicTest.pdf", nb]]

Create 3 text-cells, where the first and the second one contain the same cyrillic text and the last one maybe an upper-case (see ToUpperCase) English text for comparison.

First thing is, to set the font manually by marking the second cell and using Format->Font. Then save the document and check in you pdf viewer, whether the font is embedded (in evince, File->Properties->Fonts). I used DejaVu Serif and get the following font properties in the pdf viewer

enter image description here

See, that the default text-cells use Times which could not be embedded since it is not installed.

Go again in the second text cell and press Ctrl+Shift+E. You can append the FontTracking option there

е).\\>","Text",
 CellChangeTimes->{3.5602729176824493`*^9},
 FontFamily->"DejaVu Serif",FontTracking->"Wide"]

Press Ctrl+Shift+E again and see the pdf. Like this you can play with all settings, either by marking the cell and use the *Format` menu or by adding the appropriat option directly in the cell expression.

When you are finished, you can store this in a style-sheet by using Format->Edit Stylesheet and selecting Text under "Choose a style". Click on this text cell, press Ctrl+Shift+E and add the font options at the end:

Cell[StyleData["Text"],FontFamily->"DejaVu Serif",FontTracking->"Wide"]

Press Ctrl+Shift+E and store the stylesheet.

How to implement the method 2

This is more work and I don't have time to investigate in this right now but what you basically have to do is to implement a function which transforms your text into this low-level box style. For some words Mathematica is doing this automatically. Make to text-cells, in the first you type "Latex is nice", in the other "LaTeX is nice". Look at the underlying expressions and you see that the word "LaTeX" was transformed in the same way I did above.

halirutan
  • 112,764
  • 7
  • 263
  • 474
  • It's surely looks great but how to apply it to every cyrillic text in the notebook before printing? – swish Oct 26 '12 at 18:38
  • 1
    Can you updated your question by giving a longer text, maybe 3-4 sentences, and by explaining exactly where the text appears? Is it in input-cells, text-cells, ..? – halirutan Oct 26 '12 at 19:21
  • It still doesn't solve an oversized letters over Latin. I think what requires tweaking are some font system settings and not Mathematica. – swish Oct 29 '12 at 19:36
  • @swish And it would really help to some of the developers, which works on the front-end in Linux. Unfortunately, John Fultz is the only FE expert I know and he is working on Windows only to my knowledge. – halirutan Oct 30 '12 at 00:31