2

我有一个自定义模板,用于从我的 Jupyter 笔记本导出到 LaTeX。

((*- extends 'article.tplx' -*))

% Disable input cells
((* block input_group *))
((* endblock input_group *))

这工作正常,但有时笔记本中的 Python 代码会产生警告和错误,这些警告和错误对笔记本有帮助,但在导出中没有帮助。例如,在一个笔记本中有这个块:

  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\me\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:3: FutureWarning: currently extract(expand=None) means expand=False (return Index/Series/DataFrame) but in a future version of pandas this will be changed to expand=True (return DataFrame)\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    }
   ],
   "source": [
    "# Some Python code using Pandas\n",
    "df = d.join(df.mycol.str.extract((?P<foo>\\d)')\n",
    ")"
   ]
  }

我想在导出时排除此类错误。我尝试将以下行添加到我的模板中:

% Hide Stderr output
((* block stream_stderr *))
((* endblock stream_stderr *))

但是,我仍然在 LaTeX 输出中看到相应的错误。我究竟做错了什么?

4

1 回答 1

2

我发现自己在同样的问题上苦苦挣扎,并想出了一个解决办法。把它放在你的模板文件中:

((* block stream *))
((*- if output.name == 'stderr' -*))
((*- else -*))
    \begin{Verbatim}[commandchars=\\\{\}]
((( output.text | escape_latex | ansi2latex )))
    \end{Verbatim}
((*- endif -*))
((* endblock stream *))
于 2020-09-30T10:30:46.523 回答