Skip to content

Conversation

@cderv
Copy link
Contributor

@cderv cderv commented Nov 26, 2025

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 because tlmgr search cannot find the packages.

Root Cause

The font_ext() function generates search patterns that preserve spaces from the font name reported in LaTeX errors. When LaTeX reports "Font 'Noto Emoji' not found", the generated pattern is:

Noto Emoji(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)

Font files never have spaces in their names (NotoEmoji-Regular.ttf, DejaVuSans-Bold.ttf), so tlmgr search --file fails to find matching packages.

Fix

Spaces in font names are replaced with \s* regex pattern in R/latex.R:665:

x[i] = gsub('\s+', '\\s*', x[i])

This generates patterns like Noto\s*Emoji(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf) that match actual font files.

Tests were added in tests/test-cran/test-latex.R to verify both the font_ext() function directly and the full detect_files() workflow for fonts with spaces.

Fixes #478

Font names with spaces (e.g., "Noto Emoji", "DejaVu Sans") now work correctly
in automatic package installation. The font_ext() function replaces spaces
with \s* regex pattern to match actual font files that lack spaces
(e.g., NotoEmoji-Regular.ttf, DejaVuSans-Bold.ttf).
@cderv cderv requested a review from yihui November 26, 2025 15:36
Copy link
Contributor

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks!

@yihui yihui merged commit 847e629 into main Nov 26, 2025
13 checks passed
@yihui yihui deleted the fix-478-font-spaces branch November 26, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Font package detection fails for fonts with spaces in names

3 participants