Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to pdf fails with \degree in notebook #2197

Open
spdavern opened this issue Dec 19, 2024 · 0 comments
Open

Export to pdf fails with \degree in notebook #2197

spdavern opened this issue Dec 19, 2024 · 0 comments

Comments

@spdavern
Copy link

While trying to convert a minimum Jupyter notebook to pdf, jupyter nbconvert fails:

▶ jupyter nbconvert --to pdf failing.ipynb

Gives the following traceback:

...
lse\n* (1in=72.27pt=25.4mm, 1cm=28.453pt)\n\n\nPackage hyperref Warning: Rerun to get /PageLabels entry.\n\n(/usr/local/texlive/2024/texmf-dist/tex/latex/amsfonts/umsa.fd)\n(/usr/local/texlive/2024/texmf-dist/tex/latex/amsfonts/umsb.fd)\n(/usr/local/texlive/2024/texmf-dist/tex/latex/jknapltx/ursfs.fd)\n\nLaTeX Warning: No \\author given.\n\n\nLaTeX Font Warning: Font shape `U/rsfs/m/n' in size <5.475> not available\n(Font)              size <5> substituted on input line 395.\n\n! Undefined control sequence.\nl.395     \\(\\degree\n                   \\)\n? \n! Emergency stop.\nl.395 \n      \nNo pages of output.\nTranscript written on notebook.log.\n"
Traceback (most recent call last):
  File "/Users/dave646/.conda/envs/cadet/bin/jupyter-nbconvert", line 10, in <module>
    sys.exit(main())
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/jupyter_core/application.py", line 283, in launch_instance
    super().launch_instance(argv=argv, **kwargs)
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/traitlets/config/application.py", line 1075, in launch_instance
    app.start()
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/nbconvertapp.py", line 412, in start
    self.convert_notebooks()
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/nbconvertapp.py", line 590, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/nbconvertapp.py", line 556, in convert_single_notebook
    output, resources = self.export_single_notebook(
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/nbconvertapp.py", line 479, in export_single_notebook
    output, resources = self.exporter.from_filename(
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/exporters/templateexporter.py", line 389, in from_filename
    return super().from_filename(filename, resources, **kw)  # type:ignore[return-value]
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/exporters/exporter.py", line 203, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/exporters/templateexporter.py", line 395, in from_file
    return super().from_file(file_stream, resources, **kw)  # type:ignore[return-value]
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/exporters/exporter.py", line 222, in from_file
    return self.from_notebook_node(
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/exporters/pdf.py", line 200, in from_notebook_node
    self.run_latex(tex_file)
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/exporters/pdf.py", line 169, in run_latex
    return self.run_command(
  File "/Users/me/.conda/envs/my_env/lib/python3.10/site-packages/nbconvert/exporters/pdf.py", line 159, in run_command
    raise raise_on_failure(msg)
nbconvert.exporters.pdf.LatexFailed: PDF creating failed, captured latex output:
Failed to run "['xelatex', 'notebook.tex', '-quiet']" command:
This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./notebook.tex
...

The following jupyter notebook failing.ipynb contains only the text \degree in a markdown cell. Literally, the 1st and only cell in the notebook is markdown and contains the word degree with a backslash preceding it.
failing.ipynb

{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\degree"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "my_env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
▶ jupyter --version
Selected Jupyter core packages...
IPython          : 8.20.0
ipykernel        : 6.28.0
ipywidgets       : 7.6.5
jupyter_client   : 8.6.0
jupyter_core     : 5.5.0
jupyter_server   : 2.10.0
jupyterlab       : 4.0.11
nbclient         : 0.8.0
nbconvert        : 7.10.0
nbformat         : 5.9.2
notebook         : 7.0.8
qtconsole        : 5.4.2
traitlets        : 5.7.1

What I expect is to get is the following which was obtained by removing the backslash before degree in the notebook cell:

▶ jupyter nbconvert --to pdf failing.ipynb
[NbConvertApp] Converting notebook failing.ipynb to pdf
[NbConvertApp] Writing 19514 bytes to notebook.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running xelatex 3 times: ['xelatex', 'notebook.tex', '-quiet']
[NbConvertApp] Running bibtex 1 time: ['bibtex', 'notebook']
[NbConvertApp] WARNING | bibtex had problems, most likely because there were no citations
[NbConvertApp] PDF successfully created
[NbConvertApp] Writing 8363 bytes to failing.pdf

I originally encountered this issue because I was using $\degree$ in a different notebook to get a degree ($\degree$) symbol in my markdown. This SO issue caused me to investigate this avenue. However, I came to realize that the issue could be reproduced without the LaTeX.

\degree in a python cell, for example in a comment, does not reproduce the failure. For example this notebook is successfully exportable:

{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "degree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# \\degree"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "my_env",
   "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.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant