我有一个Jupyter笔记本,我想将其转换为pdf。使用In[XX]
和Out[XX]
时,默认提示很烦人,所以我想更改它们。在我编写的新template.tplx
文件中
((* block input scoped *))
((( add_prompt_in(cell.source | highlight_code(strip_verbatim=True), cell, 'Code', 'incolor') )))
((* endblock input *))
% Name: draw_prompt
% Purpose: Renders an input prompt
((* macro add_prompt_in(text, cell, prompt, prompt_color) -*))
((*- if cell.execution_count is defined -*))
((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*))
((*- else -*))
((*- set execution_count = " " -*))
((*- endif -*))
((*- set indention = " " * (execution_count | length + 4 ) -*))
\begin{Verbatim}[commandchars=\\\{\}]
((( text | add_prompts(first='{[{\\color{' ~ prompt_color ~ '}' ~ prompt ~ '}]:} ', cont=indention) )))
\end{Verbatim}
((*- endmacro *))
成功将输入内容的提示更改为Code:
但是,当我尝试修改输出提示时,它以某种方式失败了。以下是我的代码
{% if execute_result != None %}
((* block execute_result scoped *))
((*- for type in output.data | filter_data_type -*))
\texttt{\color{outcolor}Execute Result:}((( super() )))
((*- endfor -*))
((* endblock execute_result *))
{% elif stream != None %}
((* block stream scoped *))
((*- for type in output.text | filter_data_type -*))
\texttt{\color{outcolor}Output:}((( super() )))
((*- endfor -*))
((* endblock stream *))
{% elif display_data != None %}
((* block display_data scoped *))
((*- for type in output.data | filter_data_type -*))
\texttt{\color{outcolor}Figure:}((( super() )))
((*- endfor -*))
((* endblock display_data *))
{% end if %}
Execute Result:
和Figure
显示正确。但是,stdout
下的任何stream
都已消失。他们只是在pdf文件中消失了。这似乎有些不对劲。任何建议都表示赞赏!