# --self-contained unfriendly towards --mathjax #682

Closed
opened this Issue Dec 3, 2012 · 10 comments

None yet

### 8 participants

commented Dec 3, 2012

I'd like to distribute my notes as standalone html files. They contain both maths to be rendered with mathjax and figures.

The problem is that enabling both --self-contained and --mathjax ends with error message:

pandoc: user error (https not supported)


But even if I provide an url without https, mathjax fails to load any of its assets.

commented Dec 20, 2012

I am also having this issue. Running with --mathjax but without --self-contained will make the mathjax formulas render properly. Also running with --stand-alone but without --mathjax will also stop the error. It seems that the combination of both is causing the issue.

commented Dec 20, 2012

To follow up, I believe the issue is related to how pandoc embeds the MathJax.js script. By default pandoc tries to fetch the MathJax.js script from the https address, which does not appear to be supported by Haskell. If you pass the http address for the script it will be embedded but the embedding seems to have issues.

A quick hack is to replace the line which embeds the script with <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script> to get the page to render properly. The file is no longer viewable offline though.

Owner
commented Apr 25, 2013

We get the error message: "Failed to load: /extensions/MathZoom.js" in the browser.

Owner
commented Apr 25, 2013

Given the way these extensions are loaded by the script, I don't see a good way for --self-contained to handle them. We might have to be content with a note in README that --mathjax won't work with --self-contained.

Owner
commented Apr 26, 2013

I can't think of a way to get --self-contained to work properly with --mathjax, so this bit of documentation will have to do.

closed this Apr 26, 2013

I understand that --self-contained does not work with --mathjax and have accepted that limitation, though I would like to request a halfway measure.

Is there an option to URL encode all the images and CSS while still forcing mathjax to link to external files?

That way my HTML document can contained almost all the necessary files and be easier to pass around or post on a webpage. Is this currently possible or easy to implement?

commented Aug 4, 2014

Seconding Jared's request. I don't mind pulling stuff off of CDNs, but I'd like to have a distributable HTML file that includes embedded images, which Pandoc is amazing for.

There is a hack you can do to get everything self-contained except for MathJax. Put the following code into your default.html template:

<script type="text/javascript">
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML")
</script>


I surrounded it in a $if(mathjaxcdn)$...$endif$ block and activate it by setting a key later, but that's not necessary. Then you run pandoc --self-contained --mathjax=""

The idea is that you dynamically insert the call to load MathJax AFTER pandoc does its javascript muckery, you prevent pandoc from inserting its own MathJax.js, and you tell pandoc to format math for MathJax.

I guess you could also put that script in a file (dynoload.js) and then pass that to pandoc (pandoc --self-contained --mathjax=dynoload.js). Maybe.

commented Nov 8, 2014

SORRY I got mixed up with -s (--standalone). I'll not delete my comment because this still might be useful for somebody wanting to create a presentation/document that has all files locally installed.

I don't see what the problem is (except that the approach I'm using is very verbose).

Setup: clone Reveal.js and MathJax (actually I have them as submodules), and then create an example.md

% My Talk

# Stuff

* blah
* $f(x)=\sum_{n=0}^\infty\frac{f^{(n)}(a)}{n!}(x-a)^n$


and type

 pandoc --mathjax=MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML -t revealjs -s example.md -o example.html


and I seem to have both revealjs and mathjax running from my local copies, so should work offline.

I understand that reveal.js tries to pull in mathjax automatically as an async plugin, I've not confirmed that it is not trying to use the CDN instead of my local copy.

commented Feb 8, 2015

I think there could be a self-contained document with mathjax:

What about letting mathjax render the math-blocks (i.e. as svg) when the document is created and embed only the rendered blocks, not mathjax itself?

@balachia Putting your script into an js-file and pass it with --mathjax=dynoload.js works, not nice but at least it works...