不带In [#]字词的IPython nbconvert输出pdf [英] IPython nbconvert output pdf without In[#] words

查看:314
本文介绍了不带In [#]字词的IPython nbconvert输出pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下命令将IPython笔记本转换为pdf时,我希望删除开头的单词"In [#]",但仅显示单元格内容.

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

推荐答案

一些有用的信息,请参见 nbconvert-example .

Some useful information at nbconvert-example.

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

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

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

Run below command to generate pdf output:

ipython nbconvert  test.ipynb 

输出如下:

这篇关于不带In [#]字词的IPython nbconvert输出pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆