# Missing leading spaces in code blocks when exporting to pdf

**URL:** <https://discourse.jupyter.org/t/missing-leading-spaces-in-code-blocks-when-exporting-to-pdf/17667>\
**Category:** nbconvert\
**Tags:** nbconvert\
**Created:** [January 24, 2023, 2:00pm UTC](https://discourse.jupyter.org/t/missing-leading-spaces-in-code-blocks-when-exporting-to-pdf/17667 "2023-01-24T14:00:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![t-bltg](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/t-bltg/32/8954_2.png) [@t-bltg](https://discourse.jupyter.org/u/t-bltg)\
**Post date:** [January 24, 2023, 2:00pm UTC](https://discourse.jupyter.org/t/missing-leading-spaces-in-code-blocks-when-exporting-to-pdf/17667/1 "2023-01-24T14:00:51Z")

</div>

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:

```python
def f(x):
    return None

```

```bash
$ 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:

```plaintext
[...]
\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**
>
> ```bash
> $ 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)
> 
> ```
