Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use bold label by default for theorem env in non HTML or PDF output. #1206

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions R/ebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ resolve_refs_md = function(content, ref_table, to_md = output_md()) {
for (j in ids) {
m = sprintf('\\(\\\\#%s\\)', j)
if (grepl(m, content[i])) {
id = ''; sep = ':'
id = ''; sep = ':'; bold = FALSE
type = gsub('^([^:]+).*$', '\\1', j)
if (type %in% theorem_abbr) {
id = sprintf('<span id="%s"></span>', j)
sep = ''
bold = TRUE
}
label = label_prefix(type, sep = sep)(ref_table[j])
label = label_prefix(type, sep = sep, bold = bold)(ref_table[j])
content[i] = sub(m, paste0(id, label, ' '), content[i])
break
}
Expand Down
5 changes: 3 additions & 2 deletions R/html.R
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ parse_fig_labels = function(content, global = FALSE) {


# given a label, e.g. fig:foo, figure out the appropriate prefix
label_prefix = function(type, dict = label_names, sep = '') {
label_prefix = function(type, dict = label_names, sep = '', bold = FALSE) {
label = i18n('label', type, dict)
supported_type = c('fig', 'tab', 'eq')
if (is.function(label)) {
Expand All @@ -703,7 +703,8 @@ label_prefix = function(type, dict = label_names, sep = '') {
}
function(num = NULL) {
if (is.null(num)) return(label)
paste0(label, num, sep)
label = paste0(label, num, sep)
if (bold) sprintf("**%s**", label) else label
}
}

Expand Down
10 changes: 7 additions & 3 deletions tests/testit/test-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ assert("i18n config can be retrieved ", {
opts$set(config = list())
})

assert("label_prefix can set text to bold", {
(is.function(label_prefix("fig")))
(label_prefix("fig")(1) %==% "Figure 1")
(label_prefix("fig", bold = TRUE)(1) %==% "**Figure 1**")
(label_prefix("fig", sep = ":")(1) %==% "Figure 1:")
})

assert("label_prefix retrieves correct config", {
fun = function(i) paste0("TAB-", i)
opts$set(config = list(language = list(label = list(tab = fun))))
(label_prefix("tab") %==% fun)
(is.function(label_prefix("fig")))
(label_prefix("fig")(1) %==% "Figure 1")
(label_prefix("fig", sep = ":")(1) %==% "Figure 1:")
opts$set(config = list())
})