danielfrg / pelican-jupyter

Pelican plugin for blogging with Jupyter/IPython Notebooks
Apache License 2.0
422 stars 105 forks source link

Mathjax macro not included #23

Closed dsoto closed 9 years ago

dsoto commented 9 years ago

I'm having a problem getting latex to render using pelican-ipynb. It looks like the mathjax macro isn't getting inserted into the output html file. When I run nbconvert on the notebook outside of pelican, the mathjax macro is included and the latex renders. I noticed the command line nbconvert uses the "full" template while the ipynb.nb file uses "basic" when it configures the HTMLExporter.

Here is where I'm very puzzled: when I change the ipynb.py code to use template_file="full" in line 204, I still get the same behavior where the mathjax template is not included.

I'm not familiar enough with the Pelican machinery to guess if some other processing might strip it out...

dsoto commented 9 years ago

It looks like @peterwittek has a commit that may address this.

peterwittek commented 9 years ago

My solution is messy, which is why I did not send a pull request. To address this problem, I did two things:

  1. Replaced body = parser.body with body = parser.body.replace('\[', '$$').replace('\]','$$').replace('\(', '$').replace('\)','$')
  2. Added a custom script to include MathJax (lines 210-238 and 365 in my fork).
udibr commented 9 years ago

My solution was to use the _nb_header.html which was generated with the markdown ipython notebook plugin which is currently not working. I renamed it to nb_header.html

and add this code to pelicanconf.py:

if not os.path.exists('nb_header.html'):
    import warnings
    warnings.warn("nb_header.html not found.  "
                  "Rerun make html to finalize build.")
else:
    EXTRA_HEADER = open('nb_header.html').read().decode('utf-8')
danielfrg commented 9 years ago

Hi all, I fixed the missing mathjax javascript in master. Thanks @peterwittek for the fix!

Here is an example: http://danielfrg.com/drafts/ipython-notebook-test.html