I'd like the code which determines fonts for my (huxtable) tables in rmarkdown to work regardless of output to pdf or html, and allow for fallback fonts
For example, formatting the first row of a table called ht with a font is:
font(ht)[1,] <- "Agenda"
which works fine, pdf or html output, if the font is available.
Now I think either of these used to work for pdf output, but don't anymore.
font(ht)[1,] <- "Agenda, san-serif"
font(ht)[1,] <- paste0("Agenda, \"Source Sans Pro\", sans-serif")
I think the problem is fontspec not allowing for the possibility of a string with fallback fonts, which are separated by commas. It's possible fontspec maintainers would say check the font first, and only send it a font option that you know is available. But if you want a portable rmarkdown across users and output formats, that is not so helpful. Thoughts?
I'd upload a minimal RMarkdown file, but not an allowed format. I'll try to upload somewhere else.
[edit]
Here's an rmarkdown example that "should" work, though a few dependencies that most people with rmarkdown would already have installed?
---
title: "test fallback font"
output:
pdf_document:
latex_engine: xelatex
header-includes:
\usepackage[table]{xcolor}
\usepackage{sectsty}
\usepackage{fontspec}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(extrafont)
loadfonts()
library(huxtable)
options(huxtable.latex_use_fontspec = TRUE)
```
## R Markdown table with huxtable and formatted fonts
```{r table}
ht <- hux(iris[1:10,], add_colnames = TRUE)
#font(ht)[1,] <- "Agenda" #works
font(ht)[1,] <- "Agenda, san-serif" #doesn't work
#font(ht)[1,] <- paste0("Agenda, \"Source Sans Pro\", sans-serif") #doesn't work
set_background_color(ht, seq(2, 10, 2), 1:5, "#f2f9ec")
```