如何将ipynb转换为html,md,pdf等格式
jupyter notebook是一個(gè)非常棒的工具,關(guān)于jupyter的入門(mén)教程請(qǐng)參考我之前寫(xiě)的兩篇博客:
Jupyter notebook入門(mén)教程(上)
Jupyter notebook入門(mén)教程(下)
那么用jupyter notebook寫(xiě)的后綴名是.ipynb的文件如何轉(zhuǎn)換成html,md,pdf等格式呢?本文將做簡(jiǎn)單介紹。
ipynb轉(zhuǎn)為html格式
在Ubuntu命令行輸入:
jupyter nbconvert --to html notebook.ipynb另外,jupyter提供了一些命令,可以對(duì)生成的html格式進(jìn)行配置:
jupyter nbconvert --to html --template full notebook.ipynb這是默認(rèn)配置,提供完整的靜態(tài)html格式,交互性更強(qiáng)。
jupyter nbconvert --to html --template basic notebook.ipynb簡(jiǎn)化的html,用于嵌入網(wǎng)頁(yè)、博客等,這不包括html標(biāo)題。
ipynb轉(zhuǎn)換為md格式
在Ubuntu命令行輸入:
jupyter nbconvert --to md notebook.ipynb簡(jiǎn)單的Markdown格式輸出,cell單元不受影響,代碼cell縮進(jìn)4個(gè)空格。
ipynb轉(zhuǎn)換為tex格式
在Ubuntu命令行輸入:
jupyter nbconvert --to letex notebook.ipynbLetex導(dǎo)出格式,生成后綴名為NOTEBOOK_NAME.tex的文件。jupyter提供的額外模板配置為:
jupyter nbconvert --to letex -template article notebook.ipynb這是默認(rèn)配置,Latex文章。
jupyter nbconvert --to letex -template report notebook.ipynbLatex報(bào)告,提供目錄和章節(jié)。
jupyter nbconvert --to letex -template basic notebook.ipynb最基本的Latex輸出,經(jīng)常用來(lái)自定義配置。
ipython轉(zhuǎn)換為pdf格式
在Ubuntu命令行輸入:
jupyter nbconvert --to pdf notebook.ipynb轉(zhuǎn)換為pdf格式分模板配置與latex配置是一樣的。但是直接轉(zhuǎn)換為pdf格式經(jīng)常會(huì)出現(xiàn)下列錯(cuò)誤:
該錯(cuò)誤提示沒(méi)有安裝xelatex。所以,我們需要提前安裝xelatex,方法是安裝texLive套裝:
sudo apt-get install texlive-fulltexlive-full的安裝包有點(diǎn)大,約1G多。
簡(jiǎn)單的轉(zhuǎn)換方法
ipynb轉(zhuǎn)換為html、md、pdf等格式,還有另一種更簡(jiǎn)單的方法:在jupyter notebook中,選擇File->Download as,直接選擇需要轉(zhuǎn)換的格式就可以了。需要注意的是,轉(zhuǎn)換為pdf格式之前,同樣要保證已經(jīng)安裝了xelatex。
參考文獻(xiàn):
Converting notebooks to other formats
Markdown+Pandoc 最佳寫(xiě)作拍檔 (mailp.in)
總結(jié)
以上是生活随笔為你收集整理的如何将ipynb转换为html,md,pdf等格式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 地表上最强编程语言——C语言
- 下一篇: 台湾大学林轩田机器学习技法课程学习笔记1