bookdown 正在使用 pdflatex,即使我明确声明了 xelatex

bookdown is taking pdflatex even though I explicitly stated xelatex

我正在尝试用 bookdown 创建一本 pdf 格式的书。它可以很好地创建 EPUB 文件。

我的 YAML 是这样的:

--- 
title: "Title Here"
subtitle: "Subtitle here"
author: "me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib]
biblio-style: apalike
link-citations: yes
description: "description goes here."
cover-image: "cover.png"
lang: "es"
always_allow_html: true
output:
  pdf_document:
    latex_engine: xelatex
  pdf_document2: 
    latex_engine: lualatex
---

在第4章的某个时候,我有一个日文字母,U+305B。

我尝试使用以下方法创建 pdf 图书:

bookdown::render_book("index.Rmd", output_format = bookdown::pdf_document2())

bookdown::render_book("index.Rmd", output_format = bookdown::pdf_book())

他们俩都抱怨:

! Package inputenc Error: Unicode character せ (U+305B)
(inputenc)                not set up for use with LaTeX.

并推荐我检查 this part of the rmarkdown cookbook。我从那里获取了 YAML 序言的最后 4 行。

我忍不住注意到对 pandoc 的调用将 pdflatex 作为 pdf-engine(见倒数第三行):

/usr/lib/rstudio/bin/pandoc/pandoc +RTS -K512m -RTS myFileName.knit.md --to latex 
  --from markdown+autolink_bare_uris+tex_math_single_backslash 
  --output herramientasBasicasMejoramiento.tex 
  --lua-filter /usr/local/lib/R/site-library/bookdown/rmarkdown/lua/custom-environment.lua 
  --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/pagebreak.lua 
  --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua 
  --metadata-file /tmp/RtmpAbwGga/file565f3d087e3c --self-contained 
  --table-of-contents --toc-depth 2 --number-sections 
  --highlight-style tango --pdf-engine pdflatex --variable graphics 
  --wrap preserve --variable tables=yes 
  --standalone -Mhas-frontmatter=false --citeproc  

我在 Ubuntu 工作并安装了 texlive 和 tinytex。

whereis xelatex
xelatex: /home/gp/bin/xelatex /usr/local/texlive/2019/bin/x86_64-linux/xelatex

有个unanswered question with a problem that looks similar.

我哪里做错了,我该怎么做才能让它发挥作用?

您需要以能够看到您的 latex_engine 参数的方式指定输出格式,例如

bookdown::render_book("index.Rmd", output_format = "pdf_document2")

(从 YAML 中命名一种输出格式),或

bookdown::render_book("index.Rmd", 
                      output_format = bookdown::pdf_document2(latex_engine = "xelatex"))

(独立指定)