• R语言软件
  • Package fontspec Error: The font "Inconsolata" cannot be found.

在用rmarkdown编译为pdf时出错,我的yaml为:

bookdown::pdf_book:
  includes:
    in_header: latex/preamble.tex
    before_body: latex/before_body.tex
    after_body: latex/after_body.tex
  keep_tex: true
  dev: "cairo_pdf"
  latex_engine: xelatex
  citation_package: natbib
  pandoc_args: ["--top-level-division=chapter", "--lua-filter=latex/sidebar.lua"]
  template: null
  quote_footer: ["\\hspace*{\\fill} ", ""]
  toc_unnumbered: false
  number_sections: true

编译错误的内容为:

"D:/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS _main.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output _main.tex --lua-filter "D:\R\R-4.3.1\library\bookdown\rmarkdown\lua\custom-environment.lua" --lua-filter "D:\R\R-4.3.1\library\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "D:\R\R-4.3.1\library\rmarkdown\rmarkdown\lua\latex-div.lua" --metadata-file "C:\Users\ADMINI~1\AppData\Local\Temp\RtmpSoHUNH\file4af443714d65" --embed-resources --standalone --table-of-contents --toc-depth 2 --number-sections --highlight-style tango --pdf-engine xelatex --natbib --include-in-header "latex\preamble.tex" --include-before-body "latex\before_body.tex" --include-after-body "latex\after_body.tex" --wrap preserve --top-level-division=chapter --lua-filter=latex/sidebar.lua --variable tables=yes --standalone -Mhas-frontmatter=false 
! Package fontspec Error: The font "Inconsolata" cannot be found.

! kpathsea: Running mktextfm Inconsolata

! The command name is F:\texlive\texlive\2023\bin\windows\mktextfm
! name = Inconsolata, rootname = Inconsolata, pointsize = 
! mktexmf: empty or non-existent rootfile!

! name = Inconsolata, rootname = Inconsolata, pointsize = 
! mktexmf: empty or non-existent rootfile!

! mktexmf: empty or non-existent rootfile!

! kpathsea: Running mktexmf Inconsolata.mf

! The command name is F:\texlive\texlive\2023\bin\windows\mktexmf

! Cannot find Inconsolata.mf.

! kpathsea: Appending font creation commands to missfont.log.

Error: LaTeX failed to compile _main.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See _main.log for more info.
Execution halted

本人使用的是Texlive 2023,错误提示显示缺少相应字体,但我不知道该如何安装对于字体。请教一下各位坛友,谢谢。

    y_duck 我的系统环境为:

    > xfun::session_info()
    R version 4.3.1 (2023-06-16 ucrt)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows 11 x64 (build 22621), RStudio 2023.6.2.561
    
    
    Locale:
      LC_COLLATE=Chinese (Simplified)_China.utf8 
      LC_CTYPE=C                                 
      LC_MONETARY=Chinese (Simplified)_China.utf8
      LC_NUMERIC=C                               
      LC_TIME=Chinese (Simplified)_China.utf8    
    
    time zone: Asia/Shanghai
    tzcode source: internal
    
    Package version:
      base64enc_0.1.3   bookdown_0.35     bslib_0.5.1       cachem_1.0.8     
      cli_3.6.1         compiler_4.3.1    cpp11_0.4.6       digest_0.6.33    
      ellipsis_0.3.2    evaluate_0.21     fastmap_1.1.1     fontawesome_0.5.2
      fs_1.6.3          glue_1.6.2        graphics_4.3.1    grDevices_4.3.1  
      highr_0.10        htmltools_0.5.6   jquerylib_0.1.4   jsonlite_1.8.7   
      knitr_1.44        lifecycle_1.0.3   magrittr_2.0.3    memoise_2.0.1    
      methods_4.3.1     mime_0.12         R6_2.5.1          rappdirs_0.3.3   
      rlang_1.1.1       rmarkdown_2.25    rstudioapi_0.15.0 sass_0.4.7       
      showtext_0.9-6    showtextdb_3.0    stats_4.3.1       stringi_1.7.12   
      stringr_1.5.0     sysfonts_0.8.8    systemfonts_1.0.4 tinytex_0.46     
      tools_4.3.1       utils_4.3.1       vctrs_0.6.3       xfun_0.40        
      yaml_2.3.7 

      推荐使用 TinyTeX。

      tinytex::tlmgr_install("inconsolata")