IPython nbconvert输出pdf,不带[#]字

时间:2015-02-21 01:39:41

标签: ipython-notebook

当我在命令下运行将IPython笔记本转换为pdf时,我希望删除前导词“In [#]”,但只显示单元格内容。

ipython nbconvert --to=latex  --post=pdf input.ipynb

1 个答案:

答案 0 :(得分:0)

nbconvert-example上的一些有用信息。

只需将style_notebook.tplx复制到本地目录并进行一些小修改:

diff --git a/latex_cell_style/use_cell_style.tplx b/latex_cell_style/use_cell_style.tplx
index 72b3c24..9114157 100644
--- a/latex_cell_style/use_cell_style.tplx
+++ b/latex_cell_style/use_cell_style.tplx
@@ -1,5 +1,5 @@
 ((= This line selects the cell style. =))
-((* set cell_style = 'style_python.tplx' *))
+((* set cell_style = 'style_notebook.tplx' *))

 ((= This line inherits from the built in template that you want to use. =))
-((* extends 'latex_article.tplx' *))
\ No newline at end of file
+((* extends 'article.tplx' *))
diff --git a/notebook_cell_style/style_notebook.tplx b/notebook_cell_style/style_notebook.tplx
index 504cd52..7bd9f2a 100644
--- a/notebook_cell_style/style_notebook.tplx
+++ b/notebook_cell_style/style_notebook.tplx
@@ -1,6 +1,6 @@
 ((= Notebook input/output style =))

-((* extends 'latex_base.tplx' *))
+((* extends 'base.tplx' *))

 % Custom packages
 ((* block packages *))    
@@ -29,7 +29,7 @@
     \newlength{\inputpadding}
     \setlength{\inputpadding}{0.5em}
     \newlength{\cellleftmargin}
-    \setlength{\cellleftmargin}{0.15\linewidth}
+    \setlength{\cellleftmargin}{0\linewidth}
     \newlength{\borderthickness}
     \setlength{\borderthickness}{0.4pt}
     \newlength{\smallerfontscale}
@@ -177,15 +177,5 @@
 % Name: draw_prompt
 % Purpose: Renders an output/input prompt for notebook style pdfs
 ((* macro draw_prompt(prompt, number, color, space) -*))
-    \begin{minipage}{\cellleftmargin}%
-    \hfill%
-    {\smaller%
-    \tt%
-    \color{(((color)))}%
-    (((prompt)))[(((number)))]:}%
-    \hspace{\inputpadding}%
-    \hspace{(((space)))}%
-    \hspace{3pt}%
-    \end{minipage}%
 ((*- endmacro *))

然后将下面的文件复制到您的笔记本目录:

style_notebook.tplx
ipython_nbconvert_config.py
use_cell_style.tplx

运行以下命令以生成pdf输出:

ipython nbconvert  test.ipynb 

输出如下:

enter image description here