1

我有一个 Jupyter 笔记本,我想将其转换为 pdf。默认提示与In[XX]and令人讨厌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显示。但是,任何stdoutstream都消失了。它们只是在 pdf 文件中消失了。这里似乎有些不对劲。任何建议表示赞赏!

4

0 回答 0