When R Markdown documents use fonts with spaces in their names (e.g., "Noto Emoji", "DejaVu Sans"), automatic package installation via tinytex::parse_install() fails.
Root Cause
The font_ext() function in R/latex.R:663-667 generates search patterns that preserve spaces:
font_ext = function(x) {
i = !grepl('[.]', x)
x[i] = paste0(x[i], '(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
x
}
When LaTeX reports Font "Noto Emoji" not found, this generates:
Noto Emoji(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)
But font files never have spaces in their names:
NotoEmoji-Regular.ttf ✓
DejaVuSans-Bold.ttf ✓
So tlmgr search --file fails to find the package.
Solution
Replace spaces with \s* pattern to match files with or without spaces:
font_ext = function(x) {
i = !grepl('[.]', x)
# Replace spaces with \s* for regex matching
x[i] = gsub('\s+', '\\s*', x[i])
x[i] = paste0(x[i], '(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
x
}
This generates: Noto\s*Emoji(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)
Verification
# Test that pattern works with tlmgr
system2('tlmgr', c('search', '--file', '--global', 'Noto\s*Emoji'))
# Returns: noto-emoji package ✓
system2('tlmgr', c('search', '--file', '--global', 'DejaVu\s*Sans'))
# Returns: dejavu package ✓
Related
This issue was discovered and fixed in quarto-dev/quarto-cli#13726, which uses patterns derived from tinytex.
When R Markdown documents use fonts with spaces in their names (e.g., "Noto Emoji", "DejaVu Sans"), automatic package installation via
tinytex::parse_install()fails.Root Cause
The
font_ext()function inR/latex.R:663-667generates search patterns that preserve spaces:When LaTeX reports
Font "Noto Emoji" not found, this generates:But font files never have spaces in their names:
NotoEmoji-Regular.ttf✓DejaVuSans-Bold.ttf✓So
tlmgr search --filefails to find the package.Solution
Replace spaces with
\s*pattern to match files with or without spaces:This generates:
Noto\s*Emoji(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)Verification
Related
This issue was discovered and fixed in quarto-dev/quarto-cli#13726, which uses patterns derived from tinytex.