Bioconductor / BiocStyle

Issues and pull requests for BiocStyle should go here.
12 stars 19 forks source link

CSS for code chunks not applied #25

Closed LiNk-NY closed 3 years ago

LiNk-NY commented 7 years ago

Hi Andrzej, @aoles It seems like the CSS in bioconductor2.css isn't being applied across classes. Particularly, function calls are not highlighted in the resulting document.

See the following link for an example Rmd file: https://gist.github.com/LiNk-NY/85f655731ae141b792079a6cf3b147b5

> sessionInfo()
R version 3.4.0 Patched (2017-05-04 r72654)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.4.0  backports_1.0.5 BiocStyle_2.5.0 magrittr_1.5    rsconnect_0.7   rprojroot_1.2   htmltools_0.3.6 tools_3.4.0    
 [9] yaml_2.1.14     Rcpp_0.12.10    stringi_1.1.5   rmarkdown_1.5   knitr_1.15.1    stringr_1.2.0   digest_0.6.12   evaluate_0.10 

> BiocInstaller::biocVersion()
[1] ‘3.6’
aoles commented 7 years ago

Thanks Marcel for your feedback!

The story of code highlighting in rmarkdown is a bit complicated. The main problem is that the highlighting works differently for HTML and PDF output; in particular, the token classes are different such that there is no 1:1 relationship between them. When implementing BiocStyle I tried to provide possibly the same highlighting style across not only different Rmd outputs formats, but also match it to the PDFs produced by knitr. Consider the appearance of the following dummy code chunk in different outputs.

knitr with BiocStyle::latex2()

knitr

BiocStyle::pdf_document2()

pdf

BiocStyle::html_document2()

html

For pdf_document2() it is not possible to emphasize keywords such as function, if and else like it is done in knitr because they use the same class NormalTok as variable names. Similarly, TRUE and NULL are not distinguished and fall into the OtherTok category. On the other hand, for html_document2 function and variable names have the same CSS class identifier, so it is not possible to emphasize just function calls.

Back to your original question: if you inspect the resulting document you will notice that the highlighting classes actually used are in lines 312-319. These are not the original pandoc classes from lines 299-310. This is because rmarkdown uses a JS highlighting engine which overrides pandoc's functionality. At the moment I'm not entirely sure why they decided to go this path, and what consequences it would have to switch to pandoc's defaults. I'm afraid that with the current state of affairs it's not possible to improve the CSS for highlighting. I will need to investigate further whether using pandoc's syntax highlighter will allow to address the current shortcomings.

Cheers, Andrzej