Page MenuHomePhabricator

Installation of Computer Modern Unicode font family for SVG rendering
Closed, ResolvedPublic

Description

Author: gauravjuvekar

Description:
Install computer modern font(the one used by latex renderer to render <math></math> elements for SVG. Adds consistency to the rendered equations/proofs and the accompanying diagrams. If the exact font used by the Latex renderer is not available, this one (http://sourceforge.net/projects/cm-unicode) comes pretty close.


Version: unspecified
Severity: enhancement

Details

Reference
bz38299

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 1:04 AM
bzimport set Reference to bz38299.

http://en.wikipedia.org/wiki/Computer_Modern reference "Computer Modern" has the default font for TeX. The wikipage also mention the "Latin Modern" which we might want to use has a default instead?

Anyway the related Ubuntu Precise packages seems to be:

  • lmodern - Latin Modern
  • cm-super - all of Computer Modern

I am not sure which puppet class is used for math.

apaches::fonts just install texlive-fonts-recommended which, on Precise seems to provide cmextra which could be the Computer Modern font.

gauravjuvekar wrote:

I'm not sure. Isn't it possible to exactly find out which font is used by the renderer.

I proposed the addition of the 'cm-super' packages with https://gerrit.wikimedia.org/r/15550

Note that will not magically rerender the already rendered math PNG.

gauravjuvekar wrote:

That's not the point of this enhancement report. I'm not asking for the inline <math> equations to be SVG images. I want the same font to be available for SVG diagrams accompanying the equations/formulae.

gauravjuvekar wrote:

I read the change, it states "When rendering <math /> elements in SVG, the client side renderer seems to use the Computer Modern fonts as a default."
I don't suppose <math /> elements are in SVG. They are in normal wikitext. The <text /> elements with Computer Modern font should be rendered in SVG and the fonts not substituted to the fall back Liberation Serif font (as I believe happens currently. I'm talking purely of SVG image files, the reference to <math /> was just to identify the exact font although I believe cm-super would do it.

I have honestly no idea how librsvg select the default font or how it fallback. If it is somehow made to fallback to "Computer Modern", the change will make the font available.

Do you have any SVG file example?

gauravjuvekar wrote:

File:Test.svg on commons, version as of 00:09, 14 July 2012. The PNG rendering falls back to Liberation sans I suppose(i'm not sure). Firefox falls it back to Liberation serif (when opened in full) as I don't have any cm font on my ubuntu system (11.10).

gauravjuvekar wrote:

The same renders correctly with CM font in firefox on my winxp on which I have installed the cm font from sourceforge.

Gauravjuveker,

I have downloaded this file https://upload.wikimedia.org/wikipedia/commons/b/bd/Test.svg (it's 2012-07-13T18:39:49 UTC version) and I don't see any math element there.

What it does it tries to get

font-family="CMU Serif" font-style="italic"

from the rendering. On my system I don't have "CMU Serif" font so it gets substituted to something else by rsvg (and actually it goes a bit off-side)

Did you try to put a real MathML tags in the file?

(I have changed the subject line to be more precise)

gauravjuvekar wrote:

No, I don't know much about MathML or how it can be embedded in SVG. Also, I don't want to create SVG images of equations so MathMl wouldn't really be useful. Also, by
"On my system I don't have "CMU Serif" font so it gets substituted to something else by rsvg",
do you mean that the preview on the file description page gets its font substituted or opening it in full gets it substituted because opening it in full makes the image render by your browsers renderer. Doesn't rsvg convert the SVG image to raster thumbnails on various pages where the file is used including the file description page?

A similar request is Bug 38946 - Install Free Hebrew fonts, so that they will be available for SVG rendering

Gerrit change #15550 has been merged. Package cm-super is now installed on image scalers:

dsh -M -g image_scalers dpkg --get-selections cm-super
srv224: cm-super install
srv223: cm-super install
srv222: cm-super install
srv221: cm-super install
srv220: cm-super install
srv219: cm-super install
$

gauravjuvekar wrote:

Okay but it doesn't seem to work. See http://commons.wikimedia.org/wiki/File:Segment_definition.svg It uses the cmr10 font family from cm-super but still the text gets substituted for other fonts.

Indeed, cm-super provides fonts for Latex and no TTF fonts that librsvg could use :(

So we got them all according to font-config:

$ fc-match --all|grep -i 'pfb.*computer modern"'
sffb1000.pfb: "Computer Modern" "Fibonacci Medium"
sfrm1000.pfb: "Computer Modern" "Roman"
sfss1000.pfb: "Computer Modern" "Sans Serif"
sftt1000.pfb: "Computer Modern" "Typewriter"
sfvt1000.pfb: "Computer Modern" "Variable Width Typewriter"
sfcc1000.pfb: "Computer Modern" "Caps and Small Caps"
sfdh1000.pfb: "Computer Modern" "Dunhill Roman"
sftc1000.pfb: "Computer Modern" "Typewriter Caps and Small Caps"
sfssdc10.pfb: "Computer Modern" "Sans Serif Demi Condensed"
sfbm1000.pfb: "Computer Modern" "Roman Bold Variant"
sfrb1000.pfb: "Computer Modern" "Roman Bold"
sfbx1000.pfb: "Computer Modern" "Bold Extended"
sfsx1000.pfb: "Computer Modern" "Sans Serif Bold Extended"
sfxc1000.pfb: "Computer Modern" "Bold Extended Caps and Small Caps"
sfci1000.pfb: "Computer Modern" "Classical Serif Italic"
sfff1000.pfb: "Computer Modern" "Funny Roman"
sffi1000.pfb: "Computer Modern" "Funny Italic"
sffs1000.pfb: "Computer Modern" "Fibonacci Slanted"
sfit1000.pfb: "Computer Modern" "Typewriter Italic"
sfsi1000.pfb: "Computer Modern" "Sans Serif Slanted"
sfsl1000.pfb: "Computer Modern" "Slanted"
sfst1000.pfb: "Computer Modern" "Typewriter Slanted"
sfti1000.pfb: "Computer Modern" "Italic"
sfui1000.pfb: "Computer Modern" "Unslanted Italic"
sfvi1000.pfb: "Computer Modern" "Variable Width Typewriter Italic"
sfsc1000.pfb: "Computer Modern" "Slanted Caps and Small Caps"
sfbi1000.pfb: "Computer Modern" "Bold Extended Italic"
sfbl1000.pfb: "Computer Modern" "Bold Extended Slanted"
sfso1000.pfb: "Computer Modern" "Sans Serif Bold Extended Slanted"
sfoc1000.pfb: "Computer Modern" "Bold Extended Slanted Caps and Small Caps"
$

The file linked uses crm10 as a font name which in turns is resolved to "DejaVu Sans" "Book" :

$ fc-match cmr10
DejaVuSans.ttf: "DejaVu Sans" "Book"
$

I guess we need some alias in font-config.

I have created an alias using fontconfig: https://gerrit.wikimedia.org/r/22533

$ fc-match cmr10
sffb1000.pfb: "Computer Modern" "Fibonacci Medium"
$

Should be "Roman" style though, but I have not find a way to set the style preference :(

Running rsvg under strace, it se
open("/usr/share/fonts/X11/Type1/sffb1000.pfb", O_RDONLY) = 3
open("/proc/meminfo", O_RDONLY|O_CLOEXEC) = 3
open("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", O_RDONLY) = 3

Will attach the resulting output

Created attachment 11061
File showing rendering with the cmr10 alias enabled in fontconfig.

attachment Segment_definition-ComputerModern-1000px.png ignored as obsolete

Created attachment 11062
file rendered using a default Precise install (aka no Computer Modern font installed)

attachment Segment_definition-1000px.png ignored as obsolete

Let me know if the rendering from attachment 11061 looks correct to you.

gauravjuvekar wrote:

Attachment 11062 looks exactly the way I see it when opened in my browser and in inkscape.(I installed cm-super on my Linux Mint setup and I can select cmr10 as an option in Inkscape.)

Note:The intersection symbol that looks like an 'n' is slightly wider in my browser when opening the actual file from commons.

Font in attachment 11061 is slightly bigger(the overscore should be exactly on top of the last AB).

Are you sure you named the attachments right, because "file rendered using a default Precise install (aka no Computer Modern font installed) " is more correct and I suppose it has the exact computer modern font.(how could this be if the font is not installed?)

Created attachment 11066
Rendering with cmr10 aliases to "Computer Modern":style=Roman

attachment Segment_definition-ComputerModern-ROMAN-100px.png ignored as obsolete

Maybe I have mixed up the previous attachements (11062 & 11061).

File in attachement 11066 has been made using patchset 2 of Gerrit change #22533. Aka:

$ fc-match cmr10
sfrm1000.pfb: "Computer Modern" "Roman"
$

gauravjuvekar wrote:

Yup, rendering in attachment 11066 is perfect.

gauravjuvekar wrote:

On a similar note, could you also create aliases for cmmi10(mainly used in formulas where the convention is to use italic lowercase variables), cmsy10 and cmex10 fonts provided with the same cm-super package?

Most probably doable. Would you mind creating a SVG file containing example for all the four fonts? Would let me convert it to PNG on the integration machine so you can validate the output :-)

List of style available to the font family "Computer Modern" using Ubuntu Precise cm-super :

$ fc-match --all|grep Computer| sort -t: -k2
sfbx1000.pfb: "Computer Modern" "Bold Extended"
sfxc1000.pfb: "Computer Modern" "Bold Extended Caps and Small Caps"
sfbi1000.pfb: "Computer Modern" "Bold Extended Italic"
sfbl1000.pfb: "Computer Modern" "Bold Extended Slanted"
sfoc1000.pfb: "Computer Modern" "Bold Extended Slanted Caps and Small Caps"
sfbbx10.pfb: "Computer Modern Bright" "Bold Extended"
sfbtl10.pfb: "Computer Modern Bright" "Light"
sfbto10.pfb: "Computer Modern Bright" "Light"
sfbmo10.pfb: "Computer Modern Bright" "Oblique"
sfbmr10.pfb: "Computer Modern Bright" "Roman"
sfbsr10.pfb: "Computer Modern Bright" "Semibold"
sfbso10.pfb: "Computer Modern Bright" "Semibold Oblique"
sfcc1000.pfb: "Computer Modern" "Caps and Small Caps"
sfci1000.pfb: "Computer Modern" "Classical Serif Italic"
sfocc10.pfb: "Computer Modern Concrete" "Caps and Small Caps"
sfoti10.pfb: "Computer Modern Concrete" "Italic"
sform10.pfb: "Computer Modern Concrete" "Roman"
sfosl10.pfb: "Computer Modern Concrete" "Slanted"
sfdh1000.pfb: "Computer Modern" "Dunhill Roman"
sffb1000.pfb: "Computer Modern" "Fibonacci Medium"
sffs1000.pfb: "Computer Modern" "Fibonacci Slanted"
sffi1000.pfb: "Computer Modern" "Funny Italic"
sfff1000.pfb: "Computer Modern" "Funny Roman"
sfti1000.pfb: "Computer Modern" "Italic"
sfrm1000.pfb: "Computer Modern" "Roman"
sfrb1000.pfb: "Computer Modern" "Roman Bold"
sfbm1000.pfb: "Computer Modern" "Roman Bold Variant"
sfss1000.pfb: "Computer Modern" "Sans Serif"
sfsx1000.pfb: "Computer Modern" "Sans Serif Bold Extended"
sfso1000.pfb: "Computer Modern" "Sans Serif Bold Extended Slanted"
sfssdc10.pfb: "Computer Modern" "Sans Serif Demi Condensed"
sfsi1000.pfb: "Computer Modern" "Sans Serif Slanted"
sfsl1000.pfb: "Computer Modern" "Slanted"
sfsc1000.pfb: "Computer Modern" "Slanted Caps and Small Caps"
sftt1000.pfb: "Computer Modern" "Typewriter"
sftc1000.pfb: "Computer Modern" "Typewriter Caps and Small Caps"
sfit1000.pfb: "Computer Modern" "Typewriter Italic"
sfst1000.pfb: "Computer Modern" "Typewriter Slanted"
sfui1000.pfb: "Computer Modern" "Unslanted Italic"
sfvt1000.pfb: "Computer Modern" "Variable Width Typewriter"
sfvi1000.pfb: "Computer Modern" "Variable Width Typewriter Italic"
$

The possible style aliases would be:

cmmi10 : "Italic"

cmsy10 seems to be for symbols and cmex10 for extensions. Maybe that is included by default and we could reuse the "Roman" style there too.

Created attachment 11072
rendering with ttf-lyx package

Faidon pointed to the ttf-lyx package which provides TTF files for cmr10 and the like. Attached is the rendering of the second test file.

Attached:

ttf-tyx.png (1×1 px, 104 KB)

gauravjuvekar wrote:

(In reply to comment #29)

Created attachment 11072 [details]
rendering with ttf-lyx package

Faidon pointed to the ttf-lyx package which provides TTF files for cmr10 and
the like. Attached is the rendering of the second test file.

Rendering is correct. Now that you mention ttf-lyx, that's where the fonts become available in inkscape.

Attached:

ttf-tyx.png (1×1 px, 104 KB)

Change was merged but not yet deployed apparently:

dsh -M -g image_scalers dpkg --get-selections ttf-lyx
srv224: No packages found matching ttf-lyx.
srv223: No packages found matching ttf-lyx.
srv222: No packages found matching ttf-lyx.
srv221: No packages found matching ttf-lyx.
srv220: No packages found matching ttf-lyx.
srv219: No packages found matching ttf-lyx.

cm-super conflicts with tex-common anyway so I am removing it. https://gerrit.wikimedia.org/r/22907

fixed on srv219, the other servers will be fixed automatically whenever puppet run on them. Should not get long.

cm-super conflicted with tex-common:

dpkg: error processing /var/cache/apt/archives/cm-super-minimal_0.3.4-3_all.deb (--unpack): trying to overwrite '/usr/share/texmf/doc', which is also

in package tex-common 0:2.06ubuntu0.1

cm-super has been removed in this change:

https://gerrit.wikimedia.org/r/#/c/22907/

dist-upgraded
root@srv219:~# dpkg -l | grep lyx
ii ttf-lyx 1.6.5-1ubuntu1 TrueType versions of some TeX fonts

Now ttf-lyx is installed.

gauravjuvekar wrote:

Yup, it's fixed. Thanks a lot.