rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.79k stars 1.27k forks source link

incorrect type of font in list for bookdown + bse_book + litera #1153

Closed strimmerlab closed 3 years ago

strimmerlab commented 3 years ago

I enountered the following issue with bookdown + bse_book + litera theme: the main text is set in a serif font (such as Times) but the text in a list is set in a sans-serif font (such as Arial).

Too me this appears not to be intentional as this looks odd typographically. Ideally, the text in the list should be set in serif font if the main text is also in serif font.

Here is an example file "index.Rmd":

---
title: "A Book"
author: "The Author"
output:
  bookdown::bs4_book:
    theme:
      bootswatch: "litera"
---

# Fonts in Lists

The main text is set in a serif font.  However, text in the lists is set in sans-serif. Ideally, the text in the list should also use the same font as this text (i.e. in serif):

* This is first item (sans serif)
* Second item (sans serif)
* Third item (sans serif)

The same issue arises with numbered lists (note this text is again in serif font):

1. This is first item (sans serif)
2. Second item (sans serif)
3. Third item (sans serif)

And with Roman numbers:

i. This is first item (sans serif)
ii. Second item (sans serif)
iii. Third item (sans serif)

Compiling this in R using

library("bookdown")
bookdown::render_book('index.Rmd', output_format="bookdown::bs4_book")

yields the following HTML output:

screenshot

xfun::session_info() yields:

R version 4.0.5 (2021-03-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Package version:
  base64enc_0.1.3   bookdown_0.22     brio_1.1.2        bslib_0.2.4      
  cli_2.5.0         compiler_4.0.5    crayon_1.4.1      digest_0.6.27    
  downlit_0.2.1     ellipsis_0.3.2    evaluate_0.14     fansi_0.4.2      
  fs_1.5.0          glue_1.4.2        graphics_4.0.5    grDevices_4.0.5  
  highr_0.9         htmltools_0.5.1.1 jquerylib_0.1.4   jsonlite_1.7.2   
  knitr_1.33        lifecycle_1.0.0   magrittr_2.0.1    markdown_1.1     
  methods_4.0.5     mime_0.10         pillar_1.6.0      pkgconfig_2.0.3  
  R6_2.5.0          rappdirs_0.3.3    rlang_0.4.11      rmarkdown_2.8    
  rstudioapi_0.13   sass_0.3.1        stats_4.0.5       stringi_1.5.3    
  stringr_1.4.0     tibble_3.1.1      tinytex_0.31      tools_4.0.5      
  utf8_1.2.1        utils_4.0.5       vctrs_0.3.8       xfun_0.22        
  xml2_1.3.2        yaml_2.2.1   
cderv commented 3 years ago

When you use a theme with bs4_book(), it will use the boostwatch theme bundled in bslib. Here you are asking for litera and it seems this theme specifically set serif font for <p> element https://github.com/rstudio/bslib/blob/39976d51f07d3b30998a13a0a4ebed9dc36c49ac/inst/lib/bsw/dist/litera/_bootswatch.scss#L29-L31

But it does not change the default which is to use sans-serif font for all body. https://getbootstrap.com/docs/4.0/content/reboot/#native-font-stack

$font-family-base:            $font-family-sans-serif !default;

So it seems it is something related to bootstrap directly. ~I believe this has been fixed for litera theme specifically in v5 has sans serif fonts seems to be used for all body element.~

~https://github.com/thomaspark/bootswatch/blob/v5/dist/litera/bootstrap.css#L55~

~bslib does not support v5 yet so in the meantime~ I think you would need to customize yourself the theme if you want this change. Maybe this could be tweaked in bslib directly also.

Hope it helps.

strimmerlab commented 3 years ago

Many thanks, that's indeed very helpful! I think for me as end user it is probably best to wait until v5 is supported.

I noticed this because I am using bs4_book + litera in my lecture notes in statistics, and in these there are lots of lists. So see MATH2082 Statistical Methods and MATH38161 Multivariate Statistics and Machine Learning for real life examples.

I am very happy about bookdown, bs4_book and the related packages, so many thanks for developing! So I thought the little I can do is to report back if there are (small) problems. Thanks!

cderv commented 3 years ago

I think for me as end user it is probably best to wait until v5 is supported.

In fact I am not sure that litera changed this in V5. it seems the theme still uses serif for p element and sans serif for the rest. https://bootswatch.com/litera/

sorry for misleading you.

Anyway, if there is something not correct in litera theme in bslib compare to bootswatch original, this is to be reported in bslib.

I'll close this here.

Thanks for the report!

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.