Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ miss_font = function() {

font_ext = function(x) {
i = !grepl('[.]', x)
x[i] = gsub('\\s+', '\\\\s*', x[i]) # Replace spaces with \s*
x[i] = paste0(x[i], '(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
x
}
Expand Down
11 changes: 11 additions & 0 deletions tests/test-cran/test-latex.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
library(testit)

assert('font_ext() handles spaces in font names correctly', {
# Issue #478: font names with spaces should have spaces replaced with \s*
(font_ext("Noto Emoji") %==% 'Noto\\s*Emoji(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
(font_ext("DejaVu Sans") %==% 'DejaVu\\s*Sans(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
# Font names without spaces should work as before
(font_ext("FandolSong-Regular") %==% 'FandolSong-Regular(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)')
})

assert('detect_files() can detect filenames from LaTeX log', {
# Fonts are also tested in test-tlmgr.R
(detect_files("! Font U/psy/m/n/10=psyr at 10.0pt not loadable: Metric (TFM) file not found") %==% font_ext("psyr"))
(detect_files('! The font "FandolSong-Regular" cannot be found.') %==% font_ext("FandolSong-Regular"))
(detect_files('!pdfTeX error: /usr/local/bin/pdflatex (file tcrm0700): Font tcrm0700 at 600 not found') %==% font_ext('tcrm0700'))
(detect_files('(fontspec) The font "LibertinusSerif-Regular" cannot be') %==% font_ext('LibertinusSerif-Regular'))
(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')
# Fonts with spaces in names (issue #478)
(detect_files('! The font "Noto Emoji" cannot be found.') %==% font_ext("Noto Emoji"))
(detect_files('! The font "DejaVu Sans" cannot be found.') %==% font_ext("DejaVu Sans"))

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