Rmarkdown文本突出显示未在PDF输出中显示

时间:2019-09-10 16:41:49

标签: r r-markdown

当我尝试使用单个反引号在Rmarkdown中突出显示文本时,我的html输出将同时包括突出显示和单间距,但是PDF输出仅生成具有等宽字体但没有突出显示的文本。语法高亮在两个输出中都可以正常工作。

这里是一个例子:

---
title: "Highlighting"
output: 
  pdf_document: default
  html_document: default
---

Syntax highlighting works fine, but when I highlight `text like this`, it highlights in the html output but not the pdf. 

我浏览了pandoc和rmarkdown文档,但无法找到有关此特定问题的任何指导。任何故障排除的想法,表示赞赏。

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] bookdownplus_1.5.7 bookdown_0.13      tinytex_0.15      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2      digest_0.6.20   crayon_1.3.4    magrittr_1.5    evaluate_0.14   xaringan_0.11   pillar_1.4.2    rlang_0.4.0     magick_2.0      rmarkdown_1.15  tools_3.6.0    
[12] xfun_0.7        yaml_2.2.0      compiler_3.6.0  pkgconfig_2.0.2 htmltools_0.3.6 knitr_1.24      tibble_2.1.3

1 个答案:

答案 0 :(得分:0)

根据@Gainz 的建议,这最终 (!) 对我有用(感谢 Gainz):

---
header-includes:
   - \usepackage{soul}
   - \usepackage{color}
output:
     pdf_document:
         latex_engine: xelatex
         extra_dependencies: xcolor
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

\hl{you text}