很早以前有篇文章介绍了如何用sphinx写文档。以前没有使用Sphinx写过中文文档,所以也没有碰到什么问题。最近写了一份中文文档,由于Sphinx对中文的支持不太友好,转中文PDF的时候遇到不少坑,网上做了很多搜索,很多尝试后终于搞定。这里写篇文章记录下,希望对大家有帮助。
Mac上安装Sphinx
easy_install sphinx
创建Sphinx项目
sphinx-quickstart
Sphinx直接编译输出PDF
使用sphinx输出pdf文档需要安装额外的插件。可以使用rst2pdf,它是一个python开发的插件,安装和使用都比较方便。
安装rst2pdf
easy_install rst2pdf
在conf.py中配置rst2pdf
添加rst2pdf扩展
extensions = ['rst2pdf.pdfbuilder']
增加pdf文档的变量
# index - master document # rst2pdf - name of the generated pdf # Sample rst2pdf doc - title of the pdf # Your Name - author name in the pdf pdf_documents = [('index', u'rst2pdf', u'Sample rst2pdf doc', u'Y