首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安装MikTex、pandoc和nbconvert后,将Jupyter笔记本转换为PDF时出错

安装MikTex、pandoc和nbconvert后,将Jupyter笔记本转换为PDF时出错
EN

Stack Overflow用户
提问于 2020-06-05 11:20:54
回答 1查看 670关注 0票数 1

我一直在尝试将我的Jupyter Notebook转换成PDF(通过LaTeX)。我已经在MikTeX控制台、pandoc和nbconvert中安装了所有的包。但是,我仍然看到以下错误。

非常感谢您的建议!

MikTeX packages all installed and updated

Pandoc installed

在anaconda提示符下运行代码并单击文件->下载为->通过LaTeX (.pdf)下载PDF时出错:

代码语言:javascript
运行
复制
(base) C:\Users\justm>jupyter nbconvert notebook.ipynb --to pdf
[NbConvertApp] Converting notebook notebook.ipynb to pdf
[NbConvertApp] Support files will be in notebook_files\
[NbConvertApp] Making directory .\notebook_files
[NbConvertApp] Making directory .\notebook_files
[NbConvertApp] Making directory .\notebook_files
[NbConvertApp] Making directory .\notebook_files
[NbConvertApp] Making directory .\notebook_files
[NbConvertApp] Making directory .\notebook_files
[NbConvertApp] Writing 66012 bytes to .\notebook.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running xelatex 3 times: ['xelatex', '.\\notebook.tex', '-quiet']
[NbConvertApp] CRITICAL | x failed: xelatex .\notebook.tex -quiet
notebook.tex:385: Unable to load picture or PDF file '
notebook.tex:404: Missing number, treated as zero
notebook.tex:404: Illegal unit of measure (
notebook.tex:404: Missing number, treated as zero
notebook.tex:404: Illegal unit of measure (
notebook.tex:490: Missing number, treated as zero
notebook.tex:490: Illegal unit of measure (
notebook.tex:490: Missing number, treated as zero
notebook.tex:490: Illegal unit of measure (
notebook.tex:600: Missing number, treated as zero
notebook.tex:600: Illegal unit of measure (
notebook.tex:600: Missing number, treated as zero
notebook.tex:600: Illegal unit of measure (
notebook.tex:896: Missing number, treated as zero
notebook.tex:896: Illegal unit of measure (
notebook.tex:896: Missing number, treated as zero
notebook.tex:896: Illegal unit of measure (
notebook.tex:1007: Unable to load picture or PDF file '
Traceback (most recent call last):
  File "c:\users\justm\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\justm\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\justm\anaconda3\Scripts\jupyter-nbconvert.EXE\__main__.py", line 7, in <module>
  File "c:\users\justm\anaconda3\lib\site-packages\jupyter_core\application.py", line 268, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\users\justm\anaconda3\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
    app.start()
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\nbconvertapp.py", line 340, in start
    self.convert_notebooks()
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\nbconvertapp.py", line 510, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\nbconvertapp.py", line 481, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\nbconvertapp.py", line 410, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 179, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 197, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\exporters\pdf.py", line 185, in from_notebook_node
    self.run_latex(tex_file)
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\exporters\pdf.py", line 156, in run_latex
    self.latex_count, log_error, raise_on_failure)
  File "c:\users\justm\anaconda3\lib\site-packages\nbconvert\exporters\pdf.py", line 145, in run_command
    command=command, output=out))
nbconvert.exporters.pdf.LatexFailed: PDF creating failed, captured latex output:
Failed to run "xelatex .\notebook.tex -quiet" command:
notebook.tex:385: Unable to load picture or PDF file '
notebook.tex:404: Missing number, treated as zero
notebook.tex:404: Illegal unit of measure (
notebook.tex:404: Missing number, treated as zero
notebook.tex:404: Illegal unit of measure (
notebook.tex:490: Missing number, treated as zero
notebook.tex:490: Illegal unit of measure (
notebook.tex:490: Missing number, treated as zero
notebook.tex:490: Illegal unit of measure (
notebook.tex:600: Missing number, treated as zero
notebook.tex:600: Illegal unit of measure (
notebook.tex:600: Missing number, treated as zero
notebook.tex:600: Illegal unit of measure (
notebook.tex:896: Missing number, treated as zero
notebook.tex:896: Illegal unit of measure (
notebook.tex:896: Missing number, treated as zero
notebook.tex:896: Illegal unit of measure (
notebook.tex:1007: Unable to load picture or PDF file '
EN

Stack Overflow用户

发布于 2021-05-12 02:16:02

这是一个很老的问题,但我也是偶然发现的。问题是,LaTeX代码中的某些内容需要calc包,但该包并未导入。

在我的例子中,notebook包含一些表,其中包含列的计算,比如下面这样

代码语言:javascript
运行
复制
\begin{longtable}[]{@{}>{\raggedright\arraybackslash}p{(\columnwidth - 10\tabcolsep) * \real{0.17}}lllll@{}}

这是由Pandoc2.11.2在this commit中引入的。然而,由于我使用的是一个自定义模板文件,它遗漏了\usepackage{calc}。在添加它之后,它工作得很完美。它也没有包含在当前的nbconvert包中(请参阅#1566)。

另请参阅this questionthis thread in pandoc-discuss

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62207577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档