IPython nbconvert output pdf without In[#] words

血红的双手。 提交于 2019-12-13 02:37:29

问题


When I run below command to convert a IPython notebook to pdf, I wish to remove the leading word "In[#]" but only display the cell content.

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

回答1:


Some useful information at nbconvert-example.

Just copy style_notebook.tplx to local directory and do some minor modify:

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

Then copy below files to your notebook directory:

style_notebook.tplx
ipython_nbconvert_config.py
use_cell_style.tplx

Run below command to generate pdf output:

ipython nbconvert  test.ipynb 

Output as below:



来源:https://stackoverflow.com/questions/28641069/ipython-nbconvert-output-pdf-without-in-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!