gpoore / codebraid

Live code in Pandoc Markdown
BSD 3-Clause "New" or "Revised" License
367 stars 13 forks source link

Failure when specifying local MathJax #43

Closed jaycunningham-8451 closed 3 years ago

jaycunningham-8451 commented 3 years ago

I'm trying to use codebraid with a standalone MathJax installation. Currently I can run Pandoc without any errors:

pandoc --mathjax=$MJPATH -t revealjs -s -i index.md -o docs/index.html

where MJPATH is the path to MathJax.js in a MathJax@2 installation. But if I try to run essentially the same line with the same markdown file through codebraid:

codebraid pandoc --mathjax=$MJPATH -t revealjs -s -i index.md -o docs/index.html

I get this error:

Traceback (most recent call last):
  File "/Users/j260381/.pyenv/versions/3.8.7/envs/package-dev/lib/python3.8/site-packages/codebraid/converters/pandoc.py", line 773, in _run_pandoc
    proc = subprocess.run(cmd_list,
  File "/Users/j260381/.pyenv/versions/3.8.7/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['pandoc', '--from', 'json', '--to', 'revealjs', '--standalone', '--preserve-tabs', '--output', 'docs/index.html', '--variable', 'theme:simple', '--incremental', '--css', 'style.css', '--mathjax', '/Users/j260381/Projects/Training/pkg-dev-week1/node_modules/mathjax/MathJax.js']' returned non-zero exit status 64.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/j260381/.pyenv/versions/package-dev/bin/codebraid", line 8, in <module>
    sys.exit(main())
  File "/Users/j260381/.pyenv/versions/3.8.7/envs/package-dev/lib/python3.8/site-packages/codebraid/cmdline.py", line 107, in main
    args.func(args)
  File "/Users/j260381/.pyenv/versions/3.8.7/envs/package-dev/lib/python3.8/site-packages/codebraid/cmdline.py", line 159, in pandoc
    converter.convert(to_format=args.to_format, standalone=args.standalone,
  File "/Users/j260381/.pyenv/versions/3.8.7/envs/package-dev/lib/python3.8/site-packages/codebraid/converters/pandoc.py", line 1244, in convert
    converted_bytes, stderr_bytes = self._run_pandoc(input=json.dumps(self._final_ast),
  File "/Users/j260381/.pyenv/versions/3.8.7/envs/package-dev/lib/python3.8/site-packages/codebraid/converters/pandoc.py", line 788, in _run_pandoc
    raise PandocError(message)
codebraid.converters.pandoc.PandocError: Failed to run Pandoc:
JSON parse error: Error in $: Failed reading: not a valid json value at '*'

It doesn't seem to make a difference what's actually in the markdown file. Using --mathjax without a path works just fine, though, so that makes it a somewhat academic exercise (as grabbing it from the CDN works well enough for my use case).

I'm using:

Python 3.8.7 macOS 10.15.7 codebraid 0.5.0 MathJax 2.7.9 Pandoc 2.13

gpoore commented 3 years ago

I think I've had issues with one or two of the Pandoc command-line options that take optional URL arguments in the past. I think I suspected that it might be related to the document being in Pandoc's JSON format within Codebraid when these arguments are applied, but never tracked down exactly what was happening.

You might try something like this (untested):

codebraid pandoc -t markdown index.md | pandoc -f markdown --mathjax=$MJPATH -t revealjs -s -i -o docs/index.html

Basically, use codebraid to produce markdown, then pipe through pandoc as normal.

jaycunningham-8451 commented 3 years ago

I think this can be closed. Running it through Pandoc doesn't cause an error, so I missed the fact that it doesn't actually render the equations at all. I don't know if this is a Pandoc issue or (more likely) an I'm-doing-it-wrong issue, but either way I suspect it's not codebraid-related.

Sorry for the trouble.