作者:Yihui Xie
译者:郑宝童
日期:2021.06.21
LaTeX is required only if you want to convert your book to PDF. You may see https://www.latex-project.org/get/ for more information about LaTeX and its installation, but we strongly recommend that you install the lightweight and cross-platform LaTeX distribution named TinyTeX and based on TeX Live. TinyTeX can be easily installed through the R package tinytex (which should be automatically installed when you install bookdown):
仅当您要将图书转换为 PDF 时才需要 LaTeX。您可以访问 https://www.latex-project.org/get/ 了解有关 LaTeX 及其安装的更多信息,但我们强烈建议您安装名为 TinyTeX 并基于 TeX Live 的轻量级跨平台 LaTeX 发行版。 TinyTeX 可以通过 R 包 tinytex 轻松安装(安装 bookdown 时应该会自动安装):
tinytex::install_tinytex()
With TinyTeX, you should never see error messages like this:
使用 TinyTeX,您永远不会看到这样的错误消息:
! LaTeX Error: File `titling.sty' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)
Enter file name:
! Emergency stop.
<read *>
l.107 ^^M
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
The above error means you used a package that contains
titling.sty
, but it was not installed. LaTeX package names are often the same as the*.sty
filenames, so in this case, you can try to install thetitling
package. If you use TinyTeX with R Markdown, missing LaTeX packages will be installed automatically, so you never need to worry about such problems. LaTeX distributions and packages are also updated from time to time, and you may consider updating them especially when you run into LaTeX problems. You can find out the version of your LaTeX distribution by:
上面的错误意思是您使用了一个包含 title.sty
的包,但它没有安装。 LaTeX 包名称通常与 *.sty
文件名相同,因此在这种情况下,您可以尝试安装 titleling
包。如果您在 R Markdown 中使用 TinyTeX,将自动安装缺少的 LaTeX 包,因此您无需担心此类问题。 LaTeX 发行版和软件包也会不时更新,您可以考虑更新它们,尤其是在遇到 LaTeX 问题时。您可以通过以下方式找到您的 LaTeX 发行版的版本:
system("pdflatex --version")
## pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021)
## kpathsea version 6.3.3
## Copyright 2021 Han The Thanh (pdfTeX) et al.
## There is NO warranty. Redistribution of this software is
## covered by the terms of both the pdfTeX copyright and
## the Lesser GNU General Public License.
## For more information about these matters, see the file
## named COPYING and the pdfTeX source.
## Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
## Compiled with libpng 1.6.37; using libpng 1.6.37
## Compiled with zlib 1.2.11; using zlib 1.2.11
## Compiled with xpdf version 4.03
To update TinyTeX, you may run:
要更新 TinyTeX,您可以运行:
tinytex::tlmgr_update()
From year to year, you may need to upgrade TinyTeX, too (otherwise you cannot install or update any LaTeX packages), in which case you may reinstall TinyTeX:
年复一年,您可能也需要升级 TinyTeX(否则您无法安装或更新任何 LaTeX 包),在这种情况下,您可以重新安装 TinyTeX:
tinytex::reinstall_tinytex()