我需要做什么来为Sphinx“注册”'latexpdf'?

问题描述 投票:4回答:4

当我使用'latexpdf'运行Sphinx时,我得到一个错误,即使我在我的机器上安装了完整的TeX:

Sphinx错误:未注册构建器名称latexpdf

我需要做什么来“注册”latexpdf

latex python-sphinx pdflatex
4个回答
5
投票

latexpdf不是Sphinx构建器;它是sphinx-quickstart创建的Makefile中目标的名称。该目标使用乳胶制造商。

执行sphinx-build -b latexpdf . _build会在问题中产生错误(如预期的那样)。

如果你运行make latexpdf,它的工作原理。


在评论中提到了PyCharm,问题似乎源于该计划。当latexpdf配置为“命令”(Sphinx task)时,将运行以下命令:

sphinx_runner.py -b latexpdf <indir> <outdir> 

sphinx_runner.py脚本非常类似于sphinx_buildsphinx.cmdline.main()的包装)。由于-b选项应该提供实际构建器的名称,因此存在错误。


3
投票

现在让Pycharm 2016.3根据这里的信息生成一个pdf形式:https://www.quora.com/How-to-create-a-PDF-out-of-Sphinx-documentation-tool

安装rst2pdf:

pip install rst2pdf

编辑新的Python Docs sphinx配置并选择pdf作为命令。设置输入目录和目录以保存.pdf作为输出。

编辑conf.py文件并添加提及pdf的两行:

 extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.viewcode',
    'rst2pdf.pdfbuilder'
]

pdf_documents = [('index', u'documentation', My Docs', u'Me'), ]

现在运行配置,您应该在输出目录中获得一个名为documentation.pdf的文件。


1
投票

使用-M而不是-b。这与sphinx-build类似地调用make latexpdf,例如:

sphinx-build -M latexpdf . _build

有关详细信息,请参阅@ mzjn的答案。


0
投票

如果您对纯Python解决方案感兴趣,以下内容适用于我:

import sphinx.cmd.make_mode as sphinx_build

OUT_DIR = "docs"  # here you have your conf.py etc
build_output = os.path.join(OUT_DIR, "_build")

# build HTML (same as `make html`)
build_html_args = ["html", OUT_DIR, build_output]
sphinx_build.run_make_mode(args=build_html_args)

# build PDF latex (same as `make latexpdf`)
build_pdf_args = ["latexpdf", OUT_DIR, build_output]
sphinx_build.run_make_mode(args=build_pdf_args)

实际上,我已经制作了一个complete Python3 script,它给出了一些方便的参数,从头开始生成整个包文档为HTML和PDF,带有RTD主题。如果你想让它在不同的OS或Python解释器上运行它(在我的情况下我想在Blender中运行它),或者根据你的需要调整它,它可以非常方便。由于一些变量被硬编码到conf.py,它仍然有一些脏点。如果您发现任何问题,请告诉我们!

这是它的样子:

干杯, 安德烈斯

© www.soinside.com 2019 - 2024. All rights reserved.