【问题标题】:How can I tell to Nbconvert: "Please, this time use pdfLaTeX in place of XeLaTeX"我如何告诉 Nbconvert:“请使用 pdfLaTeX 代替 XeLaTeX”
【发布时间】:2021-03-26 17:26:13
【问题描述】:

我有不同的 ANCIENT 模板来将 Jupyter 笔记本转换为 PDF,但从 5.0 版开始jupyter-nbconvert(至少,这是 Debian 上的二进制文件的名称)默认使用 XeLaTeX,而且碰巧有些这些模板中的一些在与 XeLaTeX 一起使用时很好,其他模板仍然需要 pdfLaTeX。

我可以使用jupyter-nbconvert --to latex --template old_template MyNotebook,然后从CLI 运行pdflatex,这就是我到目前为止所做的,但我想知道是否有办法告诉Jupyter 我想使用pdflatex

我知道 NBConvert 有一个配置选项,

PDFExporter.latex_command : List
Default: ['xelatex', '{filename}', '-quiet']

Shell command used to compile latex.

但我更喜欢命令行上的东西,这样我就可以定义别名以针对不同的用例使用不同的 TeX 引擎。

【问题讨论】:

  • nbconvert.readthedocs.io/en/latest/config_options.html 说“配置选项可以在文件中设置,~/.jupyter/jupyter_nbconvert_config.py或在启动 nbconvert 时的命令行,即jupyter nbconvert --Application.log_level=10”跨度>
  • 看起来您还可以在 CLI 上指定配置文件 (nbconvert.readthedocs.io/en/latest/…) 也许您可以在 CLI 上指定的配置文件中定义 PDFExporter.latex_command,就像您指定模板一样?
  • @PranavHosangadi 我对与 jupyter 相关的配置感到相当困惑,我需要一个详细的、逐步的、可验证的答案...您不介意提供这样的答案吗?

标签: python jupyter-notebook jupyter nbconvert


【解决方案1】:

PDFExporter.latex_command 确实是你想要的;它对应于命令行选项--PDFExporter.latex_command

因此,由于使用 pdfLaTeX 将 TeX 转换为 PDF 是通过命令 pdflatex <file> 完成的,因此需要将列表选项 PDFExporter.latex_command 设置为 ['pdflatex', '{filename}']。这可以通过两次指定选项从命令行完成:

jupyter-nbconvert \
    --to pdf \
    --PDFExporter.latex_command pdflatex \
    --PDFExporter.latex_command {filename} \
    MyNotebook.ipynb

jupyter-nbconvert(和其他 IPython / Jupyter 工具)的配置系统来自一个名为 traitlets 的库,其命令行语法详细说明为here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 2016-12-12
    相关资源
    最近更新 更多