简体   繁体   English

如何在Windows中使用Sphinx创建PDF文档

[英]How to create PDF documentation with Sphinx in Windows

I am using Sphinx to create documentation for my Python project in Windows. 我正在使用Sphinx为我在Windows中的Python项目创建文档。 I need to generate PDF documentation. 我需要生成PDF文档。 I found many explanation how to do this in Linux, but no good explanation how to do this in Windows. 我在Linux中找到了很多解释如何做到这一点,但没有很好的解释如何在Windows中执行此操作。 As far as i understand I need to create Latex format with Sphinx, and than use Texworks to convert Latex to PDF. 据我所知,我需要使用Sphinx创建Latex格式,而不是使用Texworks将Latex转换为PDF。 Can someone provide step by step explanation how can I do this, assuming I created documentation in Latex format and installed Texworks? 假设我创建了Latex格式的文档并安装了Texworks,那么有人可以一步一步解释我该怎么做?

Install MiKTeX (< 200mb) 安装MiKTeX(<200mb)

wget -nv -N http://mirrors.ctan.org/systems/win32/miktex/setup/miktex-portable-2.9.4757.exe
7z.exe x -y miktex-portable-2.9.4757.exe -o"miktex"

Add the bin directory to your path 将bin目录添加到路径中

SET Path=%Path%;%CD%\miktex\miktex\bin

Run Sphinx's "make.bat" to generate the .tex file. 运行Sphinx的“make.bat”来生成.tex文件。

SET SPHINXOPTS=-W -E
make.bat latex

Invoke MiKTeX's pdflatex: 调用MiKTeX的pdflatex:

cd build/latex
pdflatex.exe YOUR_PROJECT_NAME.tex

The resultant PDF will be in your build/latex directory 生成的PDF将位于build / latex目录中

Install the full tex live distribution, it will install latex, PDF backends and texworks. 安装完整的 tex实时发布,它将安装latex,PDF后端和texworks。 Yes it is much, yes, it will dl and install for a fat hour depending on your pipe. 是的,很多,是的,根据您的管道,它将安装一个小时。 But it will be sub gig total, and harddisks are large nowadays. 但它总是次要的,现在硬盘很大。

From what I see, Texworks is just a simple LaTeX editor with some build functionality and latex syntax highlighting. 从我看来, Texworks只是一个简单的LaTeX编辑器,具有一些构建功能和乳胶语法高亮。 It is not really needed for just compiling (you could use notepad) 只是编译它不是真的需要(你可以使用记事本)

Then it should be a matter of simply putting the tex live binary directory i the path and doing 然后它应该是简单地把tex实时二进制目录i路径和做

    pdflatex <yourlatexdocument.tex>

on the cmdline, at least that is what I do with the latex output of our own documentation generating tool 在cmdline上,至少这是我用自己的文档生成工具的乳胶输出做的

As you have figured out: use Sphinx to generate LaTeX source, and then run it through a LaTex compiler to produce your PDF. 正如您已经想到的那样:使用Sphinx生成LaTeX源代码,然后通过LaTex编译器运行它来生成PDF。

Instead of troubling yourself with installing LaTeX (which can be daunting) and getting an editor set up, I suggest that you use one of the on-line LaTeX services. 我建议您使用其中一个在线LaTeX服务,而不是因为安装LaTeX(这可能令人生畏)并设置编辑器而烦恼。 You then only have to create a project in ShareLaTeX or Overleaf, for example (which are in the process of merging), upload the contents of the Sphinx build\\latex directory, compile on-line, and download the finished PDF. 然后,您只需要在ShareLaTeX或Overleaf中创建项目(正在合并的过程中),上传Sphinx build \\ latex目录的内容,在线编译,并下载完成的PDF。

This works reasonably well, but since the output targets are very different (HTML vs a formal document), you may have to fiddle with the reST to get things the way you like it. 这种方法运行得相当不错,但由于输出目标非常不同(HTML与正式文档相比),您可能不得不使用reST来按照自己喜欢的方式进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM