Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Missing $ inserted' error message when converting jupyter notebook to pdf with nbconvert

When attempting to convert a jupyter notebook to pdf with the following command:

jupyter nbconvert --to pdf "Search and Other Content Finding Features.ipynb"

I'm getting an error message:

! Missing $ inserted.
<inserted text>
                $
l.380 ... Other Content Finding Features_10_0.png}

?
! Emergency stop.
<inserted text>
                $
l.380 ... Other Content Finding Features_10_0.png}

I've found some discussion of what that is here.

However, I can't find these characters in my code. Could there be another cause?

like image 457
fraxture Avatar asked May 01 '18 18:05

fraxture


2 Answers

For me it was another, although related issue: underlines. I assume that the cause is that text in cells marked as Raw Text will be passed directly to LaTeX, where it can be interpreted as LaTeX code itself. Maybe the underlines in your figure's name?

  • At some point, I had a raw cell with three underlines ___ which were then making the conversion break. The temporary solution was to convert the cell to markdown, instead of raw (and not run it) to appear in the pdf.

To find the error, I used the following conversion (taken from this answer):

jupyter nbconvert thenotebook.ipynb --to latex
  • Another error, related, was caused by a link containing underlines:
[text](https://en.wikipedia.org/wiki/Python_(programming_language))

This was also in a Raw Text cell, which I converted to markdown to generate the pdf. The format (colors, links) are different, though.

  • Last note: My file's name also contains empty spaces, but that wasn't an issue at all!
like image 137
Luis Avatar answered Nov 19 '22 20:11

Luis


The problem in this case seems to have been caused by my notebook's filename. I don't fully understand what caused the problem, but the error message above includes a reference to some text:

... Other Content Finding Features_10_0.png}.

That text includes _ which can cause this error. I think what happens is that somewhere in the conversion script, if there are spaces in the filename, a file is generated with underscores as shown, and that then triggers the error. (This seems a little bit like a bug to me, or at least a weakness).

The fix that worked for me was simply to change the jupyter notebook's filename not to include any spaces. Then the conversion ran without a hitch.

like image 1
fraxture Avatar answered Nov 19 '22 21:11

fraxture