5

I'm trying to use pandoc to produce a html slideshow from a markdown file with some latex in it.

The file is here at github.

If I run the following pandoc command:

pandoc -s -t s5 --mathjax apresentacao.md -o index.html

The math is perfectly displayed by MathJax, but I only get a webpage with all the slides and no slideshow functionality.

If I run the follwing command:

pandoc -s --self-contained -t s5 --mathjax apresentacao.md -o index.html

I get a perfectly alright presentation, but MathJax fails to load. The resulting html file is (undestandably) full of binaries in it, for the images and javascript libraries that are loaded. But it seems to fail to incorporate MathJax correctly.

Do you guys had this issue? Are there any easy way to fix this?

I'm using the following pandoc version:

$ pandoc --version
pandoc 1.11.1
Compiled with citeproc-hs 0.3.8, texmath 0.6.1.3, highlighting-kate 0.5.3.8.
Syntax highlighting is supported for the following languages:
    actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog,
    clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d,
    diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang,
    fortran, fsharp, gnuassembler, go, haskell, haxe, html, ini, java, javadoc,
    javascript, json, jsp, julia, latex, lex, literatecurry, literatehaskell,
    lua, makefile, mandoc, matlab, maxima, metafont, mips, modula2, modula3,
    monobasic, nasm, noweb, objectivec, objectivecpp, ocaml, octave, pascal,
    perl, php, pike, postscript, prolog, python, r, relaxngcompact, rhtml, ruby,
    rust, scala, scheme, sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl,
    texinfo, verilog, vhdl, xml, xorg, xslt, xul, yacc, yaml
Default user data directory: /home/calsaverini/.pandoc
Copyright (C) 2006-2013 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.
Rafael S. Calsaverini
  • 13,582
  • 19
  • 75
  • 132

2 Answers2

11

It's a known issue: --mathjax doesn't work well with --self-contained. I haven't studied it enough to come up with a fix yet, but suggestions welcome.

John MacFarlane
  • 8,511
  • 39
  • 33
  • Wow! An anwer by John MacFarlane himself! :D Thanks for pointing it out. Any ideas why the first command fails to produce a working presentation? I tried it with s5, slidy, and some other backends and all of them just result in a simple webpage with all the content and no presentation. – Rafael S. Calsaverini Apr 25 '13 at 17:31
  • 1
    Quoting the README: "For Slidy, Slideous, reveal.js, and S5, the file produced by pandoc with the `-s/--standalone` option embeds a link to javascripts and CSS files, which are assumed to be available at the relative path `s5/default` (for S5), ..." I assume you don't have the s5 files there. – John MacFarlane Apr 25 '13 at 21:28
1

I just wrote a python script to compile markdown file into a standalone (requires internet connection) html file with mathjax support:

#!/usr/bin/env python
'''
pandoc_compile.py

Usage:
pandoc_compile.py markdown_file template_file
'''
import subprocess, re, sys, os

print("Compiling Markdown file: "+sys.argv[1])
print("Using template: "+sys.argv[2])
print("Output file: "+sys.argv[1]+".html")
pandoc_result = subprocess.Popen(['pandoc','--mathjax',sys.argv[1]], stdout=subprocess.PIPE).stdout.read()
with open(sys.argv[2]) as f: template = f.read()
final_result = re.sub('{{pandoc_output}}', pandoc_result, template)
with open(sys.argv[1]+".html", "w") as f: f.write(final_result)

It compiles markdown with pandoc and then places the result in the following html template.

<html>

<head>
<script type="text/javascript"
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</head>

<body>

{{pandoc_output}}

</body>
</html>
Giuseppe Galano
  • 10,412
  • 1
  • 12
  • 10