0

could someone please point me to a document that explains how to make the texlive fonts available to R plots?

I used to have this working, but it no longer works. Here is my attempt to make the texlive 2018 bera fonts available to R:

$ R --no-init-file
> options(texlive= "~/Documents/texlive/2018/")
> options(texfonts= paste0(getOption("texlive"), "/texmf-dist/fonts/"))
>
> pdfFonts(Bera = Type1Font("Bera", paste0(getOption("texfonts"), "afm/public/bera/", c("fvsr8a","fvsb8a","fvsro8a","fvsbo8a"), ".afm")))
> options(pfbdir = c(paste0(getOption("texfonts"), "type1/public/bera/")))
> pdfFonts("Bera")
$Bera
$family
[1] "Bera"

$metrics
[1] "~/Documents/texlive/2018//texmf-dist/fonts/afm/public/bera/fvsr8a.afm"
[2] "~/Documents/texlive/2018//texmf-dist/fonts/afm/public/bera/fvsb8a.afm"
[3] "~/Documents/texlive/2018//texmf-dist/fonts/afm/public/bera/fvsro8a.afm"
[4] "~/Documents/texlive/2018//texmf-dist/fonts/afm/public/bera/fvsbo8a.afm"
[5] "Symbol.afm"

$encoding
[1] "default"

attr(,"class")
[1] "Type1Font"

> pdf(file="test.pdf")
> plot( 1 )
> dev.off()
null device
          1

$ pdffonts test.pdf  ## from brew poppler
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ZapfDingbats                         Type 1            ZapfDingbats     no  no  no      10  0
Helvetica                            Type 1            Custom           no  no  no      11  0
$ ls ~/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fv*
/Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fveb8a.afm   /Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvmro8a.afm
/Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fver8a.afm   /Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvsb8a.afm
/Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvmb8a.afm   /Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvsbo8a.afm
/Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvmbo8a.afm  /Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvsr8a.afm
/Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvmr8a.afm   /Users/ivo/Documents/texlive/2018/texmf-dist/fonts/afm/public/bera/fvsro8a.afm
$ ls ~/Documents/texlive/2018/texmf-dist/fonts/type1/public/bera/
fveb8a.pfb  fver8a.pfb  fvmb8a.pfb  fvmbo8a.pfb  fvmr8a.pfb  fvmro8a.pfb  fvsb8a.pfb  fvsbo8a.pfb  fvsr8a.pfb  fvsro8a.pfb

maybe the pfb fonts also need to be installed on macos itself, which used to be simple (requiring a double-click on the font name, but the latest macos no longer seems to like this. or something else is wrong?

Update: I also tried the showtext package (requires installing XQuartz). Same result:

n <- "~/Documents/texlive/2018//texmf-dist/fonts/type1/public/bera/"
library( showtext )
font_add("Bera", paste0(n,"fvsr8a.pfb"), bold=paste0(n,"fvsb8a.pfb"),italic=paste0(n,"fvsro8a.pfb"),bolditalic=paste0(n,"fvsbo8a.pfb"))
showtext_auto()
pdf(file="t.pdf")
showtext_auto()
plot(1:20)
dev.off()

Same result---my texlive bera (pfb) fonts are not visible to pdffonts.

a pointer to a step-by-step document (how to and diagnosing problems) would be great. please help.

ivo Welch
  • 2,427
  • 2
  • 23
  • 31
  • You can use either [extrafont](https://stackoverflow.com/questions/51885427/font-family-wont-change-in-ggplot?noredirect=1&lq=1) or [showtext](https://stackoverflow.com/questions/34522732/changing-fonts-in-ggplot2/51906008#51906008) packages – Tung Oct 31 '18 at 17:32
  • one badly missing step: the fonts need to be installed in mac OS itself. this is best done with https://www.fontconverter.org/ . xform the pfb files into otf files. – ivo Welch Nov 01 '18 at 20:48

1 Answers1

0

I finally got it to work. Steps:

[1] install the Bitstream Vera Sans font (=Bera). See https://tex.stackexchange.com/questions/457922/making-texlive-bera-font-accessible-on-macos-r-etc

brew tap homebrew/cask-fonts
brew install --cask font-bitstream-vera  # after 2021

to search for fonts, use brew search font-.

[2] follow the instructions in https://cran.r-project.org/web/packages/extrafont/README.html

install.packages('extrafont')
library(extrafont)
font_import()
loadfonts()

[3] use them

> pdf("test.pdf", family="Bitstream Vera Serif")
> plot(1:10)
> dev.off()

[4] check that the test.pdf file uses the fonts (poppler must be installed):

pdffonts test.pdf
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ZapfDingbats                         Type 1            ZapfDingbats     no  no  no      10  0
BitstreamVeraSerif-Roman             Type 1            Custom           no  no  no      11  0
ivo Welch
  • 2,427
  • 2
  • 23
  • 31