I’ve recently started doing a lot of writing in Markdown: I’ve been taking notes on my iPad in Byword and syncing them through Dropbox so I could open them in Sublime Text on my Mac and Windows computers. And, at least for now, I’ve settled on pandoc as my markdown renderer of choice.

I was using the SublimePandoc plugin for a week or two when I realized that SmartMarkdown had built-in support for SublimePandoc: so there was no reason to duplicate the plugins (this also explains why my command menu had all of those pandoc duplicates…). Also, SublimePandoc hard-codes its html template in its package directory (so using a different template means changing the plugin package) and SmartMarkdown actually uses the template from your regular pandoc data directory. Huzzah. (Of course, I ended up having to edit the SmartMarkdown package directory anyway, but I’m assuming this is a bug that will be fixed one day and not a deliberate design choice.)

So tonight I wanted to dump SublimePandoc and just use SmartMarkdown. I had to fiddle a bit to make it work on my Mac, unfortunately, so I want to document those steps here in case I ever need to do it again.

The biggest problem is that I would get the error "[Errno 2] No such file or directory" whenever I’d try to use SmartMarkdown’s pandoc renderer. It took me a while to track this down (using printf debugging of the plugin: yay Python!) but this error resulted because the plugin couldn’t see my pandoc binary. I don’t really understand this because pandoc is clearly in my path (and I can run it freely from the commandline).

Unfortunately, SmartMarkdown does not currently support setting the pandoc path as a configuration option, so I just hardcoded it in the plugin (yay Python!). I used the terminal command

where pandoc

to find the full path of my pandoc binary and then opened up pandoc_render.py (in $SUBLIME_PACKAGES_DIRECTORY$/SmartMarkdown) and found the run_pandoc method. I changed the line

cmd = ['pandoc'] + args

to

cmd = ['/usr/local/bin/pandoc'] + args

which saved me from that error.

And in my user settings file for SmartMarkdown, I had to add the key

"pandoc_args": ["--standalone"]

to convince pandoc to actually use my template. After that, everything is peachy.

For completeness sake, my full settings for SmartMarkdown and my keyboard shortcuts are:

SmartMarkdown Users Setting File

{
    /* Please specify the PATH of pdflatex if you wanna generate PDF */
    "tex_path": ["/usr/texbin",
                 "/usr/texbin"],
    /* Provide your arguments here as a list e.g.: ["--latex-engine=xelatex", "--toc"]
    arguments that are separated by space must be in separate slots. e.g. ["-H", "template.tex"] */
    "pandoc_args": ["--standalone"],
    "pandoc_args_pdf": [],
    "pandoc_args_html": [],
    "pandoc_args_docx": []
}

User Keyboard Setting (Snippet)

{
    "keys": ["super+shift+m"],
    "command": "pandoc_render",
    "args": {"open_after": true, "target": "html", "save_result": false}
}
blog comments powered by Disqus