LaTeX conversion error, '\inputencoding'

I just debugged an interesting problem that showed up as failure to convert a notebook to PDF. I found a workaround and some related things, so I don’t currently need help but posting here so that others can find it. I think most likely the problem is in some other component of Jupyter, not nbconvert itself. But it shows up here, so I’ll initially post here and let others reorganize.

To reproduce it:

  • use IRKernel
  • It seems you have to create the notebook with jupyterlab (at least my notebook server shows the help separately and doesn’t embed the output in the ipynb)
  • Make a cell that says ?plot
  • Try to convert this to PDF (happens both from jupyterlab download, and from nbconvert command line on the notebook made that way)

Compiling the PDF to LaTeX fails with:

! Undefined control sequence.
l.463     \inputencoding
                        {utf8}

Solution:

  • First I figured out it was ?plot. Then, I saw the ipynb file has a output for that cell with mime type “text/latex”, and the first line of that output is “\inputencoding{utf8}\n”.
    {
     "cell_type": "code",
     "execution_count": 17,
     "metadata": {
      "collapsed": true,
      "jupyter": {
       "outputs_hidden": true
      }
     },
     "outputs": [
      {
       "data": {
        "text/html": [
         "\n",
         ...
        ],
        "text/latex": [
         "\\inputencoding{utf8}\n",
         "\\HeaderA{plot}{Generic X-Y Plotting}{plot}\n",
         ...
        ],
       },
       "metadata": {},
       "output_type": "display_data"
      }
     ],
     "source": [
      "?plot"
     ]
    },
    

Workaround:

  • Delete the offending cell.

I’m not quite sure the root cause is, and I haven’t debugged too much (nor am I a very good person to do so…), but the above may be useful to someone. My guess is some tool is inserting a LaTeX rendering that somehow isn’t compatible with newer nbconvert PDF tooling.