Skip to content

Commit 847e629

Browse files
authored
Fix font package detection for fonts with spaces in names (#478) (#479)
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).
1 parent 2b2e28d commit 847e629

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

R/latex.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ miss_font = function() {
662662

663663
font_ext = function(x) {
664664
i = !grepl('[.]', x)
665+
x[i] = gsub('\\s+', '\\\\s*', x[i]) # Replace spaces with \s*
665666
x[i] = paste0(x[i], '(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
666667
x
667668
}

tests/test-cran/test-latex.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
library(testit)
22

3+
assert('font_ext() handles spaces in font names correctly', {
4+
# Issue #478: font names with spaces should have spaces replaced with \s*
5+
(font_ext("Noto Emoji") %==% 'Noto\\s*Emoji(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
6+
(font_ext("DejaVu Sans") %==% 'DejaVu\\s*Sans(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
7+
# Font names without spaces should work as before
8+
(font_ext("FandolSong-Regular") %==% 'FandolSong-Regular(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
9+
})
10+
311
assert('detect_files() can detect filenames from LaTeX log', {
412
# Fonts are also tested in test-tlmgr.R
513
(detect_files("! Font U/psy/m/n/10=psyr at 10.0pt not loadable: Metric (TFM) file not found") %==% font_ext("psyr"))
614
(detect_files('! The font "FandolSong-Regular" cannot be found.') %==% font_ext("FandolSong-Regular"))
715
(detect_files('!pdfTeX error: /usr/local/bin/pdflatex (file tcrm0700): Font tcrm0700 at 600 not found') %==% font_ext('tcrm0700'))
816
(detect_files('(fontspec) The font "LibertinusSerif-Regular" cannot be') %==% font_ext('LibertinusSerif-Regular'))
917
(detect_files('! Font \\JY3/mc/m/n/10=file:HaranoAjiMincho-Regular.otf:-kern;jfm=ujis at 9.24713pt not loadable: metric data not found or bad.') %==% 'HaranoAjiMincho-Regular.otf')
18+
# Fonts with spaces in names (issue #478)
19+
(detect_files('! The font "Noto Emoji" cannot be found.') %==% font_ext("Noto Emoji"))
20+
(detect_files('! The font "DejaVu Sans" cannot be found.') %==% font_ext("DejaVu Sans"))
1021

1122
(length(detect_files("asdf qwer")) == 0)
1223
(detect_files("! LaTeX Error: File `framed.sty' not found.") %==% 'framed.sty')

0 commit comments

Comments
 (0)