1

我正在将 ipython 笔记本文件 (mynotebook.ipynb) 转换为 PDF 文件以用于模型文档。它包含一些 LaTex 格式的数学方程式、markdown 文本、代码和图表。

例如,ipython 笔记本文件如下所示:

$$c = \sqrt{a^2 + b^2}$$
TEXT: Companies must take risks if they are to survive and prosper.

import pandas as pd
%load_ext rmagic

%%R
plot(rnorm(1000))

我没有足够的声誉来发布图片,所以我希望你能理解它的样子。

我已经安装了 MikTeX 和 Pandoc 的完整版本。

我尝试了几种我在网上找到的方法:

1.

ipython nbconvert mynotebook.ipynb --to latex --post PDF

它给了我错误:

[NbConvertApp] Using existing profile dir: u'C:\\Users\\John Smith\\.ipython\\prof
ile_default'
[NbConvertApp] Converting notebook mynotebook.ipynb to latex
[NbConvertApp] Support files will be in mynotebook_files\
[NbConvertApp] Loaded template latex_article.tplx
[NbConvertApp] Writing 13601 bytes to mynotebook.tex
[NbConvertApp] Building PDF: ['pdflatex', 'mynotebook.tex']
[NbConvertApp] CRITICAL | PDF conversion failed: ['pdflatex', 'mynotebook.tex']
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9 64-bit)
entering extended mode
("C:\Users\John Smith\Anaconda\mynotebook.tex"
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, afrikaans, ancientgreek, ar
abic, armenian, assamese, basque, bengali, bokmal, bulgarian, catalan, coptic,
croatian, czech, danish, dutch, esperanto, estonian, farsi, finnish, french, ga
lician, german, german-x-2013-05-26, greek, gujarati, hindi, hungarian, iceland
ic, indonesian, interlingua, irish, italian, kannada, kurmanji, latin, latvian,
 lithuanian, malayalam, marathi, mongolian, mongolianlmc, monogreek, ngerman, n
german-x-2013-05-26, nynorsk, oriya, panjabi, pinyin, polish, portuguese, roman
ian, russian, sanskrit, serbian, slovak, slovenian, spanish, swedish, swissgerm
an, tamil, telugu, turkish, turkmen, ukenglish, ukrainian, uppersorbian, usengl
ishmax, welsh, loaded.

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.11

?
! Emergency stop.
 ...

l.11

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on mynotebook.log.

2.

ipython nbconvert mynotebook.ipynb --to latex
pandoc mynotebook.tex -o mynotebook.pdf

然后生成的PDF文件完美的展示了markdown和latex的公式;它显示图表,但不能很好地显示 R 代码。

3.

ipython nbconvert mynotebook.ipynb --to html

然后 html 文件很好地显示了代码、markdown 文本和图形,但是乳胶公式没有很好地显示。

==================================================== =

我没想到会遇到这样的困难,因为当我编辑它们时,ipython notebook 中的所有东西看起来都那么花哨。iPython Notebook使用mathjax显示公式,其他部分也完美显示。但由于某种原因,我尝试过的这些技术无法将所有主题转换为正确的格式。

我想知道有一个解决方案可以很好地将所有这些东西(降价、代码、图形和 LaTex 公式)转换为 PDF 文件吗?

4

0 回答 0