在Mac上使用Sphinx产生文档并生成中文PDF文档
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在Mac上使用Sphinx产生文档并生成中文PDF文档,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2547字,纯文字阅读大概需要4分钟。
内容图文
![在Mac上使用Sphinx产生文档并生成中文PDF文档](/upload/InfoBanner/zyjiaocheng/557/2e3486d70f7a411e857e897bac5ec246.jpg)
什么是sphinx ? Sphinx is a tool that makes it easy to create intelligent and beautiful documentation, written by Georg Brandl and licensed under the BSD license. It was originally created for the new Python documentation, and it has excell
什么是sphinx ?
Sphinx is a tool that makes it easy to create intelligent and beautiful documentation, written by Georg Brandl and licensed under the BSD license.
It was originally created for the new Python documentation, and it has excellent facilities for the documentation of Python projects, but C/C++ is already supported as well, and it is planned to add special support for other languages as well.
安装Sphinx
pip install sphinx
使用Sphinx创建文档工程
mkdir docs
sphinx-quickstart
sphinx-quickstart
会问你一连串的问题,完成之后会创建基本的文档工程文件。其中配置文件为conf.py
。
Sphinx支持输出html和pdf文档。输出html很简单:
make html
它会把生成的html文档存放在_build/html
目录下。
要生成pdf的话,需要先安装Latex,推荐使用MacTex,它的安装包约有2GB,安装需要4GB的空间。
如果文档是纯英文文档,要生成pdf很简单,只需要执行下面的命令即可:
make latexpdf
它会把生成的html文档存放在_build/pdf
目录下。
如果在文档中有中文,使用这种方法产生pdf的话pdflatex
会提示错误。
要解决这个问题,需要修改conf.py
中的latex配置,在生成的latex文件中添加对中文的支持。
在conf.py
中找到latex_elements
并修改为如下:
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
'pointsize': '12pt',
'label': '\\usepackage[english]{babel}',
# Additional stuff for the LaTeX preamble.
'preamble': '''
\usepackage{xeCJK}
\usepackage{indentfirst}
\setlength{\parindent}{2em}
\setCJKmainfont[BoldFont=SimHei, ItalicFont=STKaiti]{SimSun}
\setCJKmonofont[Scale=0.9]{STKaiti}
\setCJKfamilyfont{song}[BoldFont=SimSun]{SimSun}
\setCJKfamilyfont{sf}[BoldFont=SimSun]{SimSun}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt
'''
}
其中字体的设置是需要根据你系统中可用的中文字体来确定,
可以使用fc-list
命令来查看系统支持的中文字体:
fc-list :lang=zh
在获取到系统支持的中文字体后,选择喜欢的字体即可。
要在latex中支持中文,需要使用xelatex
命令来产生pdf文档。
make latex
cd _build/latex
xelatex *.tex
参考
- http://sphinx-doc.org/tutorial.html
- http://sphinx-doc.org/rest.html
- http://people.ee.ethz.ch/~creller/web/tricks/reST.html
- http://kkdevs.tumblr.com/post/38275843739/sphinx-latex-pdf
- http://www.tug.org/mactex/
原文地址:在Mac上使用Sphinx产生文档并生成中文PDF文档, 感谢原作者分享。
内容总结
以上是互联网集市为您收集整理的在Mac上使用Sphinx产生文档并生成中文PDF文档全部内容,希望文章能够帮你解决在Mac上使用Sphinx产生文档并生成中文PDF文档所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。