12

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?

fraxture
  • 5,113
  • 4
  • 43
  • 83

4 Answers4

4

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!
Luis
  • 3,327
  • 6
  • 35
  • 62
2

A very common gotcha here might be the following:

Leading or trailing spaces are not allowed in the pandoc extension tex_math_dollars, which is used by nbconvert.

This means, that this won't work:

$ \epsilon  \gt 0 $

And we see the error message:

! Missing $ inserted.
<inserted text> 
                $
l.364     \$ \epsilon
                       \gt 0 \$
? 
! Emergency stop.
<inserted text> 
                $
l.364     \$ \epsilon
                       \gt 0 \$
No pages of output.
Transcript written on notebook.log.

The correct formula without spaces works fine:

$\epsilon  \gt 0$

This seems to be a bug in Jupyter nbconvert.

The pandoc documentation suggests that for pandoc this is by design to allow to use dollar symbols without escape sequence:

Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.

lumbric
  • 7,644
  • 7
  • 42
  • 53
1

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.

fraxture
  • 5,113
  • 4
  • 43
  • 83
1

For me it's caused by significant difference between LaTeX and MathJax. For example cases environment can be rendered outside math mode with MathJax, which is the default choice of jupyter notebook. However, it causes an error stating "missing $ insert" in LaTeX. The error message disappeared after correcting syntax in Markdown cells.

xq114
  • 169
  • 1
  • 3