Jupyter导出PDF中文异常解决

前言

导出jupyter文档为PDF时出现导出的中文都显示不了,所以记录解决过程

问题和解决方案

问题

texlive中未支持中文字体。

解决方式

安装texlive中文支持,并且设置导出模板支持中文。

安装exlive-lang-chinese

$ sudo apt install texlive-lang-chinese

模板调整:

在文档模板base.tex.j2中的对应内容插入usepackage{ctex}


...
((*- block header -*))
    ((* block docclass *))\documentclass[11pt]{article}((* endblock docclass *))

    ((* block packages *))

    % Basic figure setup, for now with no caption control since it's done
    % automatically by Pandoc (which extracts ![](path) syntax from Markdown).
    \usepackage{graphicx}
    \usepackage{ctex}
    % Maintain compatibility with old templates. Remove in nbconvert 6.0
    \let\Oldincludegraphics\includegraphics
    % Ensure that by default, figures have no caption (until we pro
...

模板文件如何查找?

在控制台中输入

$jupyter --path

后看到的路径中查找是否有nbconvert字样的文件夹中查找template文件夹,在里面则能找到base.tex.j2

后记

虽然导出的文档有中文,但是在matplotlib中的图像中显示还是有问题,后续再看看如何解决吧。


EOF

Comments