2016-06-21 98 views
0

我想從jupyter-nbconvert --to latex生成的LaTeX中刪除典型的IPython提示In [35]:nbconvert - 刪除所有提示

從前,有一個模板,style_simple.tplx,那幾乎做我想要什麼,但現在它已被刪除,OTOH它的同伴模板,style_bw_ipython.tplx等溫度。仍然是分佈式的,但對於新的nbconvert不再適用。

我明白,我必須寫在jinja2模板語言的特設模板,但兩者jinja2模板語法及其在nbconvert使用會躲過我的理解,儘管我做了嘗試的次數。

鑑於我無法編寫這樣的模板,我正在尋求有關任務的幫助。

回答

4

這兩個地方提示出現的是inputexecute_result塊。

default input block

((* block input scoped *)) 
    (((add_prompt(cell.source | highlight_code(strip_verbatim=True), cell, 'In ', 'incolor')))) 
((* endblock input *)) 

我們可以替換與直接在逐字塊把突出顯示源代碼的頁面上的塊,而不是添加提示:

((* block input scoped *)) 
\begin{Verbatim}[commandchars=\\\{\}] 
(((cell.source | highlight_code(strip_verbatim=True)))) 
\end{Verbatim} 
((* endblock input *)) 

對於輸出,我們可以使用execute_result輸出實際上與display_data輸出相同的事實,只添加提示。因此,我們可以告訴我們的模板來顯示execute_result輸出爲display_data:

((* block execute_result scoped *)) 
    ((* block display_data scoped *)) 
     (((super()))) 
    ((* endblock display_data *)) 
((* endblock execute_result *)) 

在一個自定義模板全部放在一起,延長了默認article模板:

% extend the default article template: 
((* extends 'article.tplx' *)) 

% display input without prompts: 
((* block input scoped *)) 
\begin{Verbatim}[commandchars=\\\{\}] 
(((cell.source | highlight_code(strip_verbatim=True)))) 
\end{Verbatim} 
((* endblock input *)) 

% treat execute_result (output with prompt) as display_data (output without prompt) 
((* block execute_result scoped *)) 
    ((* block display_data scoped *)) 
     (((super()))) 
    ((* endblock display_data *)) 
((* endblock execute_result *)) 

如果我們把這個文件noprompts.tplx ,那麼我們可以使用它:

+0

很好,爲什麼不把它標記爲答案? – saroele