Open N0rbert opened 3 years ago
Thanks for the report @N0rbert
I have look into where it comes from and the culprit is #1120
Sorry we missed out this and caused a regression.
I'll fix that quickly
I now remember where this change came from. The :
was not supposed to show for any of the theorem environment
bookdown:::theorem_abbr
#> theorem lemma corollary proposition conjecture definition
#> "thm" "lem" "cor" "prp" "cnj" "def"
#> example exercise hypothesis
#> "exm" "exr" "hyp"
It was an issue in the code initially that was "fixed" during this PR : https://github.com/rstudio/bookdown/pull/1120/files#r605115658
A <span>
should have been included in the first place, and the :
sep was unset.
I understand this is a breaking change to you.
@yihui do you remember why a :
sep was unset specifically for theorem env ?
See change in https://github.com/rstudio/bookdown/pull/1120/files#r605115658
I wonder if we could just use :
for non HTML/PDF output in order to not change older output ?
We got here another case where putting back the :
broke something: https://community.rstudio.com/t/how-to-change-the-figure-table-caption-style-in-bookdown/110397/2
do you remember why a
:
sep was unset specifically for theorem env ?
@cderv I think it is uncommon to use :
in theorem/proof environments: https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems In LaTeX/PDF and HTML output, the environment name and number are in bold text. In other output formats, they do not have any special styling, which is probably why @N0rbert said it affected readability. If we can make them bold like PDF and HTML output, I guess it should be much better and more consistent; otherwise we may have to use the following idea of yours as the last resort.
I wonder if we could just use
:
for non HTML/PDF output in order to not change older output ?
If we can make them bold like PDF and HTML output,
I think we can do that using markdown syntax by adding **
around the label only for those environment.
diff --git a/R/ebook.R b/R/ebook.R
index 4f38b42e..22974f75 100644
--- a/R/ebook.R
+++ b/R/ebook.R
@@ -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
}
diff --git a/R/html.R b/R/html.R
index 6b04a4cd..a422bd6b 100644
--- a/R/html.R
+++ b/R/html.R
@@ -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)) {
{
}
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
}
}
The aim of resolve_refs_md
is to replace in the markdown file the reference part by the labels. Then it is process by Pandoc again. So it seems to work as expected.
What do you think ?
If we want to offer a mechanism to customize / opt-out from this, we could extend the mechanism of passing a function also for those environments. We only offer it for figure, table and equation for now: https://github.com/rstudio/bookdown/pull/1120#pullrequestreview-625759445
The PR #1206 looks good to me. @N0rbert What do you think of the bold style? It will look like this:
Example 1.1 Simple C Program
Will that help?
If possible, @yihui , please add colon (:) instead of bold style:
Example 1.1: Simple C Program
as it was in previous versions.
I think we can provide an option to add the colon, but by default, I hope not to include the colon, to be consistent with other output formats (PDF and HTML). Will that be okay to you?
Providing an option is okay for me. Thanks!
@yihui should it be an option specific for the colon or extending the mechanism to pass a function to customise labels ?
With this mechanism I believe it could be customized any way a user wants it to be.
should it be an option specific for the colon or extending the mechanism to pass a function to customise labels ?
The latter (if possible) would be better. Either way is fine to me.
I think I can extend the mechanism I put in place for fig
, tab
and eq
for now. Otherwise, I'll add an option.
I have the following minimal Rmd bookdown example file named
index.Rmd
:With 0.21 it was rendered as "Example 1.1: Simple C program", but with 0.22 and latest version from github it renders as "Example 1.1 Simple C program". It breaks readability. See image below for odt-output:
I think that it is a regression bug.
Below is the table with Example separators comparison.
:
:
:
Please confirm and fix this bug in the next version.