-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
(Conceptual level: I am totally with you. I think the reporting back from Will try to study the PR more this evening. |
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. |
That's a really good suggestion. I'll play with that on my side, and maybe via |
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. |
Next question, then: shall we move the |
I do think moving |
Good process. You can also just edit the 'omnibus' ticket #2 we have for IQSS. |
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:~$ |
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:
So we could add a helper function using this via a (tested for) |
I had to run |
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... |
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. |
Hi @eddelbuettel @izahn, |
Not sure if it is still useful, but I have updated > 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 |
I think that is excellent. Once on CRAN we can use this for at least diagnostics. |
Actually I have procrastinated for months on submitting a new version that fixed an earlier bug. 😅 |
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 pastxelatex
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 unfortunatelyrmarkdown::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!