Jupyter笔记本:如何为LaTeX使用packagepackage {}

Tok*_*rby 12 latex jupyter-notebook

我想知道如何\usepackage{}在Jupyter笔记本中使用LaTeX.

use*_*366 5

不确定这是唯一或什至是最好的方法,但似乎可行。在与ipynb笔记本文件(“ mynotebook.ipynb”)相同的目录中写入模板文件(“ mytemplate.tplx”)。mytemplate.tplx看起来像:

((*- extends 'article.tplx' -*))

((* block packages *))
((( super() )))
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}
((* endblock packages *))
Run Code Online (Sandbox Code Playgroud)

通过执行以下操作来构建pdf LaTex文件:

jupyter nbconvert mynotebook.ipynb --to latex --template mytemplate.tplx
pdflatex mynotebook.tex
Run Code Online (Sandbox Code Playgroud)

  • 请注意,此答案用于从 ipython 笔记本生成乳胶文档 - 它不会修改 jupyter 笔记本/jupyterlab 渲染 Markdown 单元的方式。正如答案所述,可以使用命令 [`jupyter nbconvert --to Latex`](https://nbconvert.readthedocs.io/en/latest/usage.html#convert-latex) 运行该解决方案,该命令用于导出 .tex 文件。 (3认同)
  • 你能添加一个例子吗?我不确定你对模板文件的意思。 (2认同)