Skip to content

evince not showing "greek" and "math" in *.pdf plots

11 messages · Martin Maechler, Tim Taylor, pstiis m@iii@g oii gm@ii@com +2 more

#
This problem has bugged me for several years now,
and our own IT staff has tried a few things, but then never
cared enough to persist fixing it.

It *is* a bug in evince, the standard pdf viewer on Fedora and
IIUC also quite few other Linux distributions, and
*not* a bug in R;  hence I am asking for help/hints here.

A very simple example:

-------------------------------------------------------------------------------

(pdfil <- paste0("plotmath-example_R",
                 with(R.version, paste0(major, sub("[.]", "", minor))), ".pdf"))
## "plomath-example_R433.pdf"

pdf(pdfil)
example(plotmath); mtext(R.version.string)
dev.off()

if(interactive())
    system(paste("evince", pdfil, "&"))

-------------------------------------------------------------------------------

The pdf contains 4 pages, and in all of them *some* of the math
symbols are replaced by open rectangles -- because evince does
not find the fonts it should.

E.g.
- page 1: \pi is properly shown,  \phi not
- page 2: all greek letters,  \theta, \xi, \eta  are *not* shown
...

Simply typing

       example(plotmath)

in the R console will show you everything as it should be but is
not for us, using evince.

However, *everything* is rendered correctly, if I use very old
'xpdf' {which you may have to install

    ## OTOH: This always work fine with the very old  'xpdf' :
    system(paste("xpdf", pdfil, "&"))

So the fonts *are* somewhere on my machine, but evince does not
find them;

How should our IT people fix this?

IIRC they did install the Zapf Dingbats fonts -- which then are
found by xpdf but not by evince ?


Thank you in advance,
Martin
#
Hi Martin

Probably not the answer you're looking for but on the latest Fedora 39 (workstation edition) both locally, and on a freshly installed VM (with just R-core installed), all fonts render correctly for me in evince.

$ evince --version
GNOME Document Viewer 45.0

$ R --version
R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)

It may be worth sharing more details about your installation (e.g. Fedora version) to see if anyone has any ideas.

Tim
On Mon, 11 Mar 2024, at 10:51 AM, Martin Maechler wrote:

  
  
#
> Hi Martin
    > Probably not the answer you're looking for but on the latest Fedora 39 (workstation edition) both locally, and on a freshly installed VM (with just R-core installed), all fonts render correctly for me in evince.

    > $ evince --version
    > GNOME Document Viewer 45.0

    > $ R --version
    > R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
    > Copyright (C) 2024 The R Foundation for Statistical Computing
    > Platform: x86_64-redhat-linux-gnu (64-bit)

    > It may be worth sharing more details about your installation (e.g. Fedora version) to see if anyone has any ideas.

    > Tim

Thank you, Tim.


Fedora is 38 :

$ lsb_release -a
LSB Version:	:core-5.0-amd64:core-5.0-noarch:cxx-5.0-amd64:cxx-5.0-noarch:desktop-5.0-amd64:desktop-5.0-noarch:languages-5.0-amd64:languages-5.0-noarch:printing-5.0-amd64:printing-5.0-noarch
Distributor ID:	Fedora
Description:	Fedora release 38 (Thirty Eight)
Release:	38
Codename:	ThirtyEight

$ evince --version
GNOME Document Viewer 44.3

R version does not matter at all.
Same phenomenon in several versions of R I have installed
simultaneously (from source).
As I mentioned, I'm slightly misusing the list for non-R problem
that I encounter a lot with R  {because I like to use
"plotmath"}, so I apologize in advance.

Maybe it's rather a matter of fonts installed in
/usr/share/fonts/ ??

Martin
> On Mon, 11 Mar 2024, at 10:51 AM, Martin Maechler wrote:
>> This problem has bugged me for several years now,
    >> and our own IT staff has tried a few things, but then never
    >> cared enough to persist fixing it.
    >> 
    >> It *is* a bug in evince, the standard pdf viewer on Fedora and
    >> IIUC also quite few other Linux distributions, and
    >> *not* a bug in R;  hence I am asking for help/hints here.
    >> 
    >> A very simple example:
    >> 
    >> -------------------------------------------------------------------------------
    >> 
    >> (pdfil <- paste0("plotmath-example_R",
    >> with(R.version, paste0(major, sub("[.]", "", minor))), ".pdf"))
    >> ## "plomath-example_R433.pdf"
    >> 
    >> pdf(pdfil)
    >> example(plotmath); mtext(R.version.string)
    >> dev.off()
    >> 
    >> if(interactive())
    >> system(paste("evince", pdfil, "&"))
    >> 
    >> -------------------------------------------------------------------------------
    >> 
    >> The pdf contains 4 pages, and in all of them *some* of the math
    >> symbols are replaced by open rectangles -- because evince does
    >> not find the fonts it should.
    >> 
    >> E.g.
    >> - page 1: \pi is properly shown,  \phi not
    >> - page 2: all greek letters,  \theta, \xi, \eta  are *not* shown
    >> ...
    >> 
    >> Simply typing
    >> 
    >> example(plotmath)
    >> 
    >> in the R console will show you everything as it should be but is
    >> not for us, using evince.
    >> 
    >> However, *everything* is rendered correctly, if I use very old
    >> 'xpdf' {which you may have to install
    >> 
    >> ## OTOH: This always work fine with the very old  'xpdf' :
    >> system(paste("xpdf", pdfil, "&"))
    >> 
    >> So the fonts *are* somewhere on my machine, but evince does not
    >> find them;
    >> 
    >> How should our IT people fix this?
    >> 
    >> IIRC they did install the Zapf Dingbats fonts -- which then are
    >> found by xpdf but not by evince ?
    >> 
    >> 
    >> Thank you in advance,
    >> Martin
    >> 
    >> _______________________________________________
    >> R-SIG-Fedora mailing list
    >> R-SIG-Fedora at r-project.org
    >> https://stat.ethz.ch/mailman/listinfo/r-sig-fedora
    >> 

    > [[alternative HTML version deleted]]
#
On Mon, 11 Mar 2024, at 1:15 PM, Martin Maechler wrote:
Apologies Martin - this *is not* working as of Fedora 39. I just had different symbols missing that I missed when checking (e.g. the sigma summation symbol).

Hopefully someone more knowledgeable than me will pop along to help.

Tim
#
Hi Martin and Tim, 

I also have this bug. Though I think not necessarily with all the same
fonts as Martin. 

Using Martin's code:

https://imgur.com/a/ILUoe3H

Fedora 39, Evince 45.0

It's a bug with Evince. I think. I think it's substituting in a font
set that doesn't have all the required symbols. I think it should be
possible to install the required fonts, but I haven't found a solution
that way, yet.?

Nevertheless, the following should work, and may be a better solution
anyway, given that embedding the fonts is probably more cross-
platform/viewer friendly: 


You can embed the fonts if you have Ghostscript installed (I think it
comes with Fedora already(?) if not then:?

sudo dnf install ghostscript 

)


You can then use the embedFonts() function in R:

(pdfil <- paste0("plotmath-example_R",
                 with(R.version, paste0(major, sub("[.]", "", minor))),
".pdf"))

pdf(pdfil)
example(plotmath); mtext(R.version.string)
dev.off()

# Use embedFonts to embed the fonts in the PDF
embedFonts(file = pdfil, outfile = paste0("embedded-example", pdfil),
options = "-dPDFSETTINGS=/prepress")


if(interactive()) {
  system(paste("evince", paste0("embedded-example", pdfil), "&"))
}



Or you can do it in the terminal:


gs -dNOPAUSE -dBATCH -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite -
dEmbedAllFonts=true -sOutputFile=plotmath-example-output_embedded.pdf -
f plotmath-example_R432.pdf 


Compare: 


Embedded:

? pdffonts plotmath-example-output_embedded.pdf
name                   type     encoding emb sub uni object ID
---------------------- -------- -------- --- --- --- ------ ---
KHEPSB+Helvetica       Type 1C  Custom   yes yes no      10   0
WNPVSJ+Symbol          Type 1C  Custom   yes yes no      12   0
MQBKOK+Helvetica-Bold  Type 1C  WinAnsi  yes yes no      20   0


Original:

? pdffonts plotmath-example_R432.pdf
name                   type     encoding emb sub uni object ID
---------------------- -------- -------- --- --- --- ------ ---
Helvetica              Type 1   Custom   no  no  no      16  0
Helvetica-Bold         Type 1   Custom   no  no  no      17  0
Symbol                 Type 1   Symbol   no  no  no      18  0


I hope this works for you. Like I said, I *think* it's a problem with
Evince so it's probably better to file a bug report with them, but I
also think embedding fonts isn't such a bad idea anyway - you'll know
the output will display as intended regardless of the viewer on the
user's system. It does lead to a larger file-size, but I think these
days we can live with that.

Thanks, 
Peter
On Mon, 2024-03-11 at 14:15 +0100, Martin Maechler wrote:
#
Martin, I wouldn't rule out an R issue yet. Fonts are... tricky. So I'm
cc'ing Paul Murrell here.

I tried several viewers here and I see the following: Chrome, Firefox and
Libreoffice Draw show the symbols; however, evince, okular and xournal++
agree on **not** showing the symbols. **If** there is a bug, the bug would
be in fontconfig, because these ones AFAIK properly delegate on fontconfig,
which is the system-wide component that decides what font substitution
should be made for any given font. However, I see:

$ fc-match Helvetica
NimbusSans-Regular.otf: "Nimbus Sans" "Regular"

which is the right choice. And okular confirms this by showing in a
properties dialog that it is substituting Helvetica with URW's Nimbus Sans
Regular. So why aren't the symbols displayed? My best guess is that this
has something to do with how R encodes such symbols. Paul introduced some
changes to fix similar issues for Cairo devices when Fedora dropped support
for Type 1 fonts, see [1]. Now, I'm no font expert, but it seems to me that
the pdf device may require similar fixes. (And why do xpdf or Firefox show
the glyphs... I have no idea. I guess they do their thing without asking
fontconfig).

[1]
https://blog.r-project.org/2020/04/17/changes-to-symbol-fonts-for-cairo-graphics-devices/

Peter, as an aside, note that cairo_pdf embeds the fonts by default.

Best,
I?aki
On Mon, 11 Mar 2024 at 15:31, <pstils at gmail.com> wrote:

            

  
    
#
HI I?aki,?

That's interesting.?

I may be wrong but I think it's the Symbol font that's got the
substitution bug, not Helvetica.?

? fc-match "Symbol"
StandardSymbolsPS.t1: "Standard Symbols PS" "Regular"

Is what I get, but then in the Evince properties it's telling me that
it's substituting Symbol with "Noto Sans Regular", despite the Standard
Symbols PS font being installed.?


When I make a ~/.font.config file (I didn't have one already) with the
contents:?

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <match target="pattern">
    <test name="family" qual="any" >
      <string>Symbol</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>OpenSymbol</string>
    </edit>
  </match>

</fontconfig>


(OpenSymbol is in libreoffice-opensymbol-fonts)?


Then evince shows me the symbols. (Whether they're the correct ones or
not, I don't know! They look right to me, but I'm a biologist, so...).
?

And now:?

? fc-match "Symbol"
opens___.ttf: "OpenSymbol" "Regular"


So, I think that's another option for you, Martin. But I think
embedding might still be the better choice, anyway.?

I now don't think the bug is with Evince. I suspect something's?telling
Evince (and Okular) to use the wrong font, but you can force a more
appropriate substitution.


Do you think it could be this?:?

https://bugzilla.redhat.com/show_bug.cgi?id=2088665


Thanks,?
Peter

?
On Mon, 2024-03-11 at 18:59 +0100, I?aki Ucar wrote:

  
  
#
Hi

I don't think this is an R issue (it is separate from the Cairo Symbol 
font problem).

For PDF output, R actually relies on the Symbol font having the Adobe 
Symbol Encoding (Appendix D of the PDF Reference 
https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf) 
and just outputs the font as "Symbol", which relies on it being one of 
the Standard 14 Fonts ...

"These fonts have built-in encodings that are unique to each
font."

... and ...

"These fonts, or their font metrics and suitable substitution fonts, 
must be available to the consumer application."

In other words, R passes the buck to the viewer to either have access to 
the Adobe Symbol font or use a substitute that has all of the necessary 
glyphs (and in that case, presumably to also take care of satisfying the 
Adobe Symbol Encoding).

It is possible for the R user to specify a different font name for the 
symbol font for PDF output, but that font has to have all of the 
necessary glyphs and it has to follow the Adobe Symbol Encoding or all 
bets are off.

Paul
On 12/03/24 06:59, I?aki Ucar wrote:

  
    
#
I see. Peter, you are right about the font that causes the issue. Paul,
thanks for your insights. I'll bring this to the Fedora font experts to see
if we can arrive at a more permanent fix. I'll report back with any
conclusion.

@Martin: Meanwhile, at least you have options. One is to embed the fonts,
either as Peter suggested or using cairo_pdf instead. Alternatively, Peter
also has shown how to instruct fontconfig to select other fonts as
replacements.

Hope it helps,
I?aki
On Tue, 12 Mar 2024 at 22:10, Paul Murrell <paul at stat.auckland.ac.nz> wrote:

            

  
    
#
Paul, what I still cannot understand is why Standard Symbols PS doesn't
show all the symbols, if it is supposed to be a replacement of the legacy
Standard Symbols L, see
https://github.com/ArtifexSoftware/urw-base35-fonts/blob/3c0ba3b5687632dfc66526544a4e811fe0ec0cd9/appstream/de.urwpp.StandardSymbolsPS.metainfo.xml#L14-L30
and
https://github.com/ArtifexSoftware/urw-base35-fonts/blob/3c0ba3b5687632dfc66526544a4e811fe0ec0cd9/fontconfig/urw-fallback-specifics.conf#L28
.

I?aki
On Wed, 13 Mar 2024 at 16:53, I?aki Ucar <iucar at fedoraproject.org> wrote:

            

  
    
1 day later
#
Indeed --- thank you, Peter !!

Once I found out to use
  ~/.fonts.conf   instead of
  ~/.font.config

indeed this instructs evince and okular to  "replace"
Symbol by OpenSymbol   and everything works fine.

Searching a bit, notably starting to read
    https://www.linux.org/docs/man5/fonts-conf.html

lead me to look into   /etc/fonts/fonts.conf
and that indeed contains a few such substitutions, e.g.,

<!--
  Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
-->
<match target="pattern">
	<test qual="any" name="family">
		<string>sans serif</string>
	</test>
	<edit name="family" mode="assign" binding="same">
		<string>sans-serif</string>
	</edit>
</match>


... so I guess a more global "fix" / workaround for a few years would be to
add the above   s/Symbol/OpenSymbol/  replacement also to the
fedora  fontconfig package
(I see I am using  2.14.2-2.fc38 currently).

Thank you for your help!
Martin