Hi !
When exporting an ipynb
to pdf
, with nbconvert, I’m observing missing leading spaces (indent) in the pdf output (very inconvenient when copy / pasting a Python code block).
Very simple reproducer with a cell containing the following code:
def f(x):
return None
$ cat >foo.ipynb <<'EOF'
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "59933a4d",
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" return None"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13fbea60",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
EOF
$ jupyter-nbconvert --to pdf foo.ipynb
When I use --to latex
, the correct amount of spaces appears in the Verbatim
blocks:
[...]
\begin{Verbatim}[commandchars=\\\{\}]
\PY{k}{def} \PY{n+nf}{f}\PY{p}{(}\PY{n}{x}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{k+kc}{None}
\end{Verbatim}
[...]
Am I missing something or is it a limitation ?
versions
$ conda list nbconvert
# Name Version Build Channel
nbconvert 7.2.7 pyhd8ed1ab_0 conda-forge
nbconvert-core 7.2.7 pyhd8ed1ab_0 conda-forge
nbconvert-pandoc 7.2.7 pyhd8ed1ab_0 conda-forge
$ conda list jupyter
jupyter_client 7.4.9 pyhd8ed1ab_0 conda-forge
jupyter_core 5.1.3 py310hff52083_0 conda-forge
jupyter_events 0.6.3 pyhd8ed1ab_0 conda-forge
jupyter_server 2.1.0 pyhd8ed1ab_0 conda-forge
jupyter_server_terminals 0.4.4 pyhd8ed1ab_1 conda-forge
jupyterlab_pygments 0.2.2 pyhd8ed1ab_0 conda-forge
$ xelatex --version
XeTeX 3.141592653-2.6-0.999994 (TeX Live 2022)