New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back to default font if Libertinus is unavailable #7

Merged
merged 1 commit into from Oct 2, 2018

Conversation

Projects
None yet
3 participants
@izahn
Collaborator

izahn commented Oct 2, 2018

I had a hard time deciding whether to throw a warning or an error if the preferred font is unavailable. When using rmarkdown::render() there doesn't seem to be a way to continue past xelatex errors, so the only improvement for rmarkdown users would be a more informative error that instructs them to install the fonts. I went with a warning for now, but unfortunately rmarkdown::render() doesn't even display warnings, so many users will probably never get the message.

For now I'm throwing a warning and relying on the README to inform users that they should install the Libertinus font. Feedback welcome!

@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 2, 2018

(Conceptual level: I am totally with you. I think the reporting back from rmarkdown::render() is insufficient / unclear / nonexistent. The insistence on tinytex does not help as that component is simply dysfunctional on my Linux systems ... So when I asked yesterday about "how to test for fonts in a portable way" I was thinking (dreaming !!) more about package-level components. Binb is an R package, so we have a built-time hook, as well as a load time hook (though nobody does library(binb) I presume. This may remain an issue.)

Will try to study the PR more this evening.

@izahn

This comment has been minimized.

Collaborator

izahn commented Oct 2, 2018

From the R side we might use https://cran.r-project.org/web/packages/sysfonts/ to check for preferred fonts. It has some system requirements, but worked on my Linux system as well as the Windows and Mac machines in our computer lab.

@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 2, 2018

That's a really good suggestion. I'll play with that on my side, and maybe via rhub too.

@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 2, 2018

Works like a charm, silently:

edd@rob:~/git/binb/inst/iqssDemo(feature/iqss_font_fallback)$ wajig purge fonts-libertinus 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  fonts-libertinus*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 5,812 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 422756 files and directories currently installed.)
Removing fonts-libertinus (6.6-0local1) ...
Processing triggers for fontconfig (2.12.6-0ubuntu2) ...
edd@rob:~/git/binb/inst/iqssDemo(feature/iqss_font_fallback)$ render.r iqssDemo.Rmd 
Loading required package: methods


processing file: iqssDemo.Rmd
  |.................................................................| 100%
  ordinary text without R code


output file: iqssDemo.knit.md

/home/edd/bin/pandoc +RTS -K512m -RTS iqssDemo.utf8.md --to beamer --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output iqssDemo.tex --template /usr/local/lib/R/site-library/binb/rmarkdown/templates/iqss/resources/template.tex --slide-level 3 --variable theme=iqss --highlight-style haddock --pdf-engine xelatex --self-contained 

Output created: iqssDemo.pdf
edd@rob:~/git/binb/inst/iqssDemo(feature/iqss_font_fallback)$ xdg-open iqssDemo.pdf 
edd@rob:~/git/binb/inst/iqssDemo(feature/iqss_font_fallback)$ 

Document is generated, but does of course look little different.

@eddelbuettel eddelbuettel merged commit 6594830 into master Oct 2, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 2, 2018

Next question, then: shall we move the inst/iqssDemo/* back to vignettes/` ? That tends to get more visibility...

@izahn

This comment has been minimized.

Collaborator

izahn commented Oct 2, 2018

I do think moving inst/iqssDemo to vignettes would be good, but I'd like to clean it up a little bit first. Right now it shows off a lot of features of the theme, but it can and should be made simpler and more concise. I'll open a couple of issues to track these tasks.

@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 2, 2018

Good process. You can also just edit the 'omnibus' ticket #2 we have for IQSS.

@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 2, 2018

Not bad:

R> library(sysfonts) 
R> ff <- font_files() 
R> head(ff[grepl("FiraSans-", ff)]) 
[1] "FiraSans-Bold.otf"       "FiraSans-Bold.ttf"       "FiraSans-BoldItalic.otf" "FiraSans-BoldItalic.ttf" 
[5] "FiraSans-Book.otf"       "FiraSans-Book.ttf"       
R> head(ff[grepl("libertinus", ff)]) 
[1] "libertinuskeyboard-regular.otf" "libertinusmath-regular.otf"     "libertinusmono-regular.otf"     
[4] "libertinussans-bold.otf"        "libertinussans-italic.otf"      "libertinussans-regular.otf"
R>

Is it normal that libertinus comes out lower-cased?

I was expecting the names at the end here, not the files:

edd@rob:~$ fc-list | grep -i libertinus
/usr/share/fonts/opentype/libertinus/libertinuskeyboard-regular.otf: Libertinus Keyboard:style=Regular
/usr/share/fonts/opentype/libertinus/libertinusserif-semibolditalic.otf: Libertinus Serif:style=Semibold Italic
/usr/share/fonts/opentype/libertinus/libertinusserifinitials-regular.otf: Libertinus Serif Initials:style=Regular
/usr/share/fonts/opentype/libertinus/libertinusserifdisplay-regular.otf: Libertinus Serif Display:style=Regular
/usr/share/fonts/opentype/libertinus/libertinussans-italic.otf: Libertinus Sans:style=Italic
/usr/share/fonts/opentype/libertinus/libertinusserif-semibold.otf: Libertinus Serif:style=Semibold
/usr/share/fonts/opentype/libertinus/libertinusserif-italic.otf: Libertinus Serif:style=Italic
/usr/share/fonts/opentype/libertinus/libertinusserif-bold.otf: Libertinus Serif:style=Bold
/usr/share/fonts/opentype/libertinus/libertinussans-bold.otf: Libertinus Sans:style=Bold
/usr/share/fonts/opentype/libertinus/libertinusmath-regular.otf: Libertinus Math:style=Regular
/usr/share/fonts/opentype/libertinus/libertinussans-regular.otf: Libertinus Sans:style=Regular
/usr/share/fonts/opentype/libertinus/libertinusserif-bolditalic.otf: Libertinus Serif:style=Bold Italic
/usr/share/fonts/opentype/libertinus/libertinusserif-regular.otf: Libertinus Serif:style=Regular
/usr/share/fonts/opentype/libertinus/libertinusmono-regular.otf: Libertinus Mono:style=Regular
edd@rob:~$ 
@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 3, 2018

I lobbed a question over to @yixuan but haven't heard back.

In the meantime, I came across the extrafont package by @wch and it seems to fit the bill:

R> library(extrafont)
Registering fonts with R
R> ft <- fonts()
R> str(ft)
 chr [1:323] "aakar" "Abyssinica SIL" "Alegreya Black" "Alegreya" "Alegreya ExtraBold"  ...
R>

So we could add a helper function using this via a (tested for) Suggests: extrafont. Thoughts?

@izahn

This comment has been minimized.

Collaborator

izahn commented Oct 3, 2018

I had to run font_import() before fonts() would see anything. It works, but import_fonts() takes quite a long time (2-3 minutes on my laptop).

@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 3, 2018

Maybe it tricked me? I ran that too, then started a fresh session and got results. Maybe a cache?

In a fresh Docker I get nuttin' like you. Oh well. "No Free Lunch" theorem still valid. We could still wait that (optional) checker and just warn it may take a moment...

@izahn

This comment has been minimized.

Collaborator

izahn commented Oct 3, 2018

I'm inclined to just rely on the documentation to inform people of the benefits of installing the preferred fonts. We already mention font preferences in the README, and can also mention it in the DESCRIPTION and Vignettes. If it were easy to display a message encouraging people to install the fonts that would be nice, but I don't know that its worth a lot of time and effort.

@yixuan

This comment has been minimized.

yixuan commented Oct 3, 2018

Hi @eddelbuettel @izahn, sysfonts is mostly used to support the showtext package, and it provides some basic functions to search fonts in the system.
It doesn't display the font names since they are usually non-standard, but it seems that for the most common formats like ttf and otf, the font name is coded in the font file. I'll check if FreeType is able to extract such information, and if it is useful I can add this feature to sysfonts in the future.

@eddelbuettel eddelbuettel deleted the feature/iqss_font_fallback branch Oct 10, 2018

@yixuan

This comment has been minimized.

yixuan commented Oct 11, 2018

Not sure if it is still useful, but I have updated sysfonts on GitHub and the function font_files() can now report family names and other information. Below is an example of output result on my machine:

> head(font_files())
                                  path                       file       family        face       version                ps_name
1         /home/qyx/.local/share/fonts       GandhiSerif-Bold.otf Gandhi Serif        Bold Version 1.001       GandhiSerif-Bold
2         /home/qyx/.local/share/fonts GandhiSerif-BoldItalic.otf Gandhi Serif Bold Italic Version 1.001 GandhiSerif-BoldItalic
3         /home/qyx/.local/share/fonts     GandhiSerif-Italic.otf Gandhi Serif      Italic Version 1.001     GandhiSerif-Italic
4         /home/qyx/.local/share/fonts    GandhiSerif-Regular.otf Gandhi Serif     Regular Version 1.001    GandhiSerif-Regular
5 /usr/share/fonts/truetype/clear-sans         ClearSans-Bold.ttf   Clear Sans        Bold  Version 1.00         ClearSans-Bold
6 /usr/share/fonts/truetype/clear-sans   ClearSans-BoldItalic.ttf   Clear Sans Bold Italic  Version 1.00   ClearSans-BoldItalic
@eddelbuettel

This comment has been minimized.

Owner

eddelbuettel commented Oct 11, 2018

I think that is excellent. Once on CRAN we can use this for at least diagnostics.

@eddelbuettel

This comment has been minimized.

@yixuan

This comment has been minimized.

yixuan commented Oct 11, 2018

Actually I have procrastinated for months on submitting a new version that fixed an earlier bug. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment