无法在 Jupyter 的 PDF 输出中显示 Unicode 字符(如 λ)

Cannot display Unicode Characters (like λ) in PDF output of Jupyter

我在 jupyter notebook 中使用 Julia。

我想为我的工作结果生成一个 pdf 文件。但是,在生成pdf时,数学表达式λ=3λ丢失了,所以pdf中的输出是=3.

这里是 jupyter notebook 代码

In[1]: λ=3 
Out[1]: 3

这里是用jupyter notebook生成的pdf

In[1]: =3 
Out[1]: 3

使用 nteract 生成的 pdf 不是这种情况,其中表达式 λ=3 已完全打印出来。然而,用 nteract 生成的 pdf 的整体外观不如用 jupyter notebook 生成的 pdf 好。

这是用 nteract 生成的打印 pdf(看起来与代码本身完全一样):

In[1]: λ=3
Out[1]: 3

有人知道如何用 jupyter notebook 打印这样的字符吗?

非常感谢

这个问题与Jupyter本身如何生成和编译latex文件有关。 Jupyter 默认情况下使用 xelatex 编译文件以支持 Unicode。 我的猜测 但是,xelatex 需要在文件中进行一些配置,而 Jupyter 不会生成使用普通 xelatex 命令开箱即用的文件。

您可以更改 Jupyter 的配置以编译使用 pdflatexlatex 命令生成的 latex 文件。

解法: 找到您的 Jupyter 配置目录(即 jupyter --config-dir 的输出,通常在 Linux 上 ~/.jupyter。要找出 IJulia 使用哪个 jupyter 运行 using IJulia; IJulia.jupyter 然后找出配置该 jupyter 的目录)

如果没有,请在此目录中创建文件 jupyter_notebook_config.py

将以下代码行放在该文件的末尾并保存:

c.PDFExporter.latex_command = ['pdflatex', '{filename}']

然后您就可以像往常一样使用笔记本导出PDF文件了。字符应该出现,恰到好处。如果在 shell.

中找到 pdflatex 命令,这应该可以工作

如果您没有 pdflatex 但有 latex,您也可以使用以下行代替上面的代码:

c.PDFExporter.latex_command = ['latex', '--output-format=pdf', '{filename}']

如果无法更改Jupyter的配置,请下载latex文件并使用命令latex --output-format=pdf filename.tex.

进行编译

希望有用!