5

当我想将 Jupyter 笔记本保存为 pdf 文件时,我收到以下错误:

nbconvert failed: PDF creating failed, captured latex output:
This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2018/W32TeX) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
! Undefined control sequence.
<*> .\notebook
              .tex
? 
! Emergency stop.
<*> .\notebook
              .tex
No pages of output.
Transcript written on ?.
4

2 回答 2

1

这是由于 Windows 和类 Unix 系统之间不幸的不兼容造成的。Jupyternotebook.tex在当前目录中创建一个临时文档,然后调用XeTeX编译该文档。

XeTeX在被调用后尝试使用大致以下算法解析命令行:

  1. XeTeX <arg1> <arg2> ...
  2. 检查是否<arg1>.tex文件,

    a)如果它是一个文件编译它

    b) 如果它不是文件,则假定这是在命令行上给出的实际文件的开始

在类 Unix 系统上./notebook.tex,由which exists 解析,然后编译。在 Windows 系统上,由于目录分隔符不同,命令行无法识别为文件,因此尝试解析为 LaTeX 文档但失败。XeTeXcurrent_directory/notebook.tex.\notebook.texXeTeX

一个临时补救措施(可能会破坏其他事情)是将构建目录pdf.py从 nbconvert (第 66 行)从

writer = Instance("nbconvert.writers.FilesWriter", args=(), kw={'build_directory': '.'})

writer = Instance("nbconvert.writers.FilesWriter", args=(), kw={'build_directory': ''})

于 2020-04-24T14:41:22.483 回答
0

作为紧急解决方案,您可以将 notebook 保存为 markdown (.md) 并在 RStudio 中打开它,您可以在其中 Knit 并将其保存为 pdf。

于 2021-10-04T16:03:07.317 回答