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

ecj*_*cjb 4 pdf unicode mathematical-expressions julia jupyter-notebook

我在jupyter notebook.

我想为我的工作结果生成一个 pdf。但是,在生成 pdf 时,?数学表达式?=3的 丢失了,因此 pdf 中的输出为=3

这是 jupyter 笔记本代码

In[1]: ?=3 
Out[1]: 3
Run Code Online (Sandbox Code Playgroud)

这是使用 jupyter notebook 生成的 pdf

In[1]: =3 
Out[1]: 3
Run Code Online (Sandbox Code Playgroud)

对于完全打印出nteract表达式的生成的pdf,情况并非如此?=3。但是,使用 .pdf 生成的 pdf 的整体外观nteract不如使用 .pdf 生成的 pdf 好jupyter notebook

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

In[1]: ?=3
Out[1]: 3
Run Code Online (Sandbox Code Playgroud)

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

提前谢谢了

hck*_*ckr 5

该问题与 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}']
Run Code Online (Sandbox Code Playgroud)

然后您可以像往常一样使用笔记本导出 PDF 文件。字符应该出现,恰到好处。如果pdflatex在您的 shell 中找到命令,这应该可以工作。

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

c.PDFExporter.latex_command = ['latex', '--output-format=pdf', '{filename}']
Run Code Online (Sandbox Code Playgroud)

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

希望它有效!