sphinx+reStructuredText+latex生成pdf

安装sphinx

pip install sphinx

安装texlive

在清华大学开源软件镜像站下载镜像文件:https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/texlive2018-20180414.iso

创建sphinx项目

在项目文件夹中shift+鼠标右键,打开命令窗口。
输入创建项目命令,并且选择项目配置,大部分直接回车选择默认配置即可。

G:\test>sphinx-quickstart
> Separate source and build directories (y/n) [n]:
> Name prefix for templates and static dir [_]:
> Project name: pdftest		# 输入项目名称
> Author name(s): 123  	    # 作者
> Project release []:
> Project language [en]:
> Source file suffix [.rst]:
> Name of your master document (without suffix) [index]:
> autodoc: automatically insert docstrings from modules (y/n) [n]: y  # 重要,输入y
> doctest: automatically test code snippets in doctest blocks (y/n) [n]:
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]:
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]:
> coverage: checks for documentation coverage (y/n) [n]:
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]:
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]:
> ifconfig: conditional inclusion of content based on config values (y/n) [n]:
> viewcode: include links to the source code of documented Python objects (y/n) [n]: y  # 重要,输入y
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]:
> Create Makefile? (y/n) [y]:
> Create Windows command file? (y/n) [y]:

项目配置

修改conf.py文件

  • 要使用latex生成pdf,修改latex_elements选项。

    latex_elements = {
        # The paper size ('letterpaper' or 'a4paper').
        # 'papersize': 'letterpaper',
    
        # The font size ('10pt', '11pt' or '12pt').
        # 'pointsize': '10pt',
    
        # Additional stuff for the LaTeX preamble.
        'preamble': '''
        \\hypersetup{unicode=true}
        \\usepackage{CJKutf8}
        \\AtBeginDocument{\\begin{CJK}{UTF8}{gbsn}}
        \\AtEndDocument{\\end{CJK}}
        ''',
    
        # Latex figure (float) alignment
        # 'figure_align': 'htbp',
    }
    
  • 修改主题样式
    修改sphinx_rtd_theme主题要先在文件头部添加:

    import sphinx_rtd_theme
    

    再设置html_theme选项:

    html_theme = 'sphinx_rtd_theme'
    

生成pdf

写好rst文档后,添加到index.rst。
然后在项目根目录打开命令窗口,输入命令make latexpdf,之后在_build文件夹中找到生成的pdf文档。

参考

https://blog.csdn.net/suzyu12345/article/details/52923464
https://www.cnblogs.com/zzqcn/p/5096876.html#_label6

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值