• R语言已解决
  • TinyTex生成中文PDF时出现字体缺失报错,如何安装相应字体?

用TinyTex运行Rstudio示例的中文模板时,出现字体缺失的报错,该怎么安装呢?
报错信息如下:

! Package fontspec Error: The font "KaiTi" cannot be found.

! kpathsea:make_tex: Invalid filename `KaiTi/OT:script=hani;language=dflt;', contains ':'

! kpathsea:make_tex: Invalid filename `KaiTi/B/OT:script=hani;language=dflt;', contains ':'

! kpathsea:make_tex: Invalid filename `KaiTi/OT:script=hani;language=dflt;', contains ':'

错误: LaTeX failed to compile Chinese.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Chinese.log for more info.
停止执行

我的系统信息如下:

sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 14393)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_China.936 
#> [2] LC_CTYPE=Chinese (Simplified)_China.936   
#> [3] LC_MONETARY=Chinese (Simplified)_China.936
#> [4] LC_NUMERIC=C                              
#> [5] LC_TIME=Chinese (Simplified)_China.936    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_4.0.1  magrittr_1.5    tools_4.0.1     htmltools_0.5.0
#>  [5] yaml_2.2.1      stringi_1.4.6   rmarkdown_2.2   highr_0.8      
#>  [9] knitr_1.28      stringr_1.4.0   xfun_0.14       digest_0.6.25  
#> [13] rlang_0.4.6     evaluate_0.14

<sup>Created on 2020-09-18 by the reprex package (v0.3.0)</sup>

    InfinityLoop 感谢您的回复!我装了字体,运行时又出现这个报错信息了

    ! LaTeX Error: Option clash for package fontspec.
    
    错误: LaTeX failed to compile Chinese.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Chinese.log for more info.
    停止执行

    yihui
    感谢谢老大的回复!
    我重装字体后,运行if (tinytex:::is_tinytex()) tinytex::reinstall_tinytex() else tinytex::install_tinytex()之后,重新生成中文PDF时,弹出来了! LaTeX Error: Option clash for package fontspec.的报错,还是未能成功生成PDF。

      yihui
      Pandoc的版本是1.19.2.1

      xfun::session_info('rmarkdown')
      #> R version 4.0.2 (2020-06-22)
      #> Platform: x86_64-w64-mingw32/x64 (64-bit)
      #> Running under: Windows 10 x64 (build 14393)
      #> 
      #> Locale:
      #>   LC_COLLATE=Chinese (Simplified)_China.936 
      #>   LC_CTYPE=Chinese (Simplified)_China.936   
      #>   LC_MONETARY=Chinese (Simplified)_China.936
      #>   LC_NUMERIC=C                              
      #>   LC_TIME=Chinese (Simplified)_China.936    
      #> 
      #> Package version:
      #>   base64enc_0.1.3 digest_0.6.25   evaluate_0.14   glue_1.4.1     
      #>   graphics_4.0.1  grDevices_4.0.1 highr_0.8       htmltools_0.5.0
      #>   jsonlite_1.6.1  knitr_1.28      magrittr_1.5    markdown_1.1   
      #>   methods_4.0.1   mime_0.9        rlang_0.4.6     rmarkdown_2.2  
      #>   stats_4.0.1     stringi_1.4.6   stringr_1.4.0   tinytex_0.25   
      #>   tools_4.0.1     utils_4.0.1     xfun_0.14       yaml_2.2.1     
      #> 
      #> Pandoc version: 1.19.2.1

      <sup>Created on 2020-09-19 by the reprex package (v0.3.0)</sup>

        yihui 好啦好啦,终于可以生成中文PDF啦,谢谢大大!我的Rstudio没更新的问题