IPython nbconvert 输出没有 In[#] 字的 pdf

IPython nbconvert output pdf without In[#] words

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

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

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 *))

然后复制以下文件到你的notebook目录:

style_notebook.tplx
ipython_nbconvert_config.py
use_cell_style.tplx

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

ipython nbconvert  test.ipynb 

输出如下: