File paths in Pandoc arguments

I hope this is the right place for a Pandoc query. I’m having a little trouble with post-processing a compiled Markdown file, and I’d appreciate any advice. It’s like this:

  1. If I specify my path to Pandoc and put all my arguments in the “Arguments” field (see below) then all is fine.
  2. If I move everything to a script, Scrivener produces the expected Markdown file but it doesn’t seem to get passed to Pandoc.
  3. In the script, if I replace <$outputname> and <$inputfile> with fixed paths it works.

For the “Path” version (which works) I use:


-s --data-dir ~/Dropbox/Application\ Support/Pandoc/templates --bibliography ~/Dropbox/Application\ Support/Pandoc/bibliography/Chas-Zotero.bib --filter pandoc-citeproc
–csl ~/svn-git-stuff/git.csl-styles/harvard-staffordshire-university.csl --number-sections -t docx -o <$outputname>.docx <$inputfile>[/code]

It’s a bit clumsy having all that in the Arguments box, so I’d prefer to move most of it to a script. If I use:


pandoc -s
–data-dir ~/Dropbox/Application\ Support/Pandoc/templates
–bibliography ~/Dropbox/Application\ Support/Pandoc/bibliography/Chas-Zotero.bib
–filter pandoc-citeproc
–csl ~/svn-git-stuff/git.csl-styles/harvard-staffordshire-university.csl
-o ~/Desktop/mydoc.docx

with fixed filenames and paths, it works. But if I delete the last two lines of the script and put “-o <$outputname>.docx <$inputfile>” in the Arguments field, all I get is the Markdown file. What am I doing wrong?

I’ve tried “$HOME” instead of “~”, but that made no difference and in any case the “~” works in the script above. I thought I might have misunderstood the role of the Arguments field when using a script, but moving “<$outputname>” and “<$inputfile>” into the script gave an error. Adding “-t docx” to the arguments makes no difference.

This is probably the sole problem. The codes you refer to are meant to be used in Scrivener itself, not within an embedded script. You would want to put these into the Arguments field, which will be passed to your script using the typical $1, $2, etc. Bash variables. Scrivener will not attempt to parse your script and look for tokens within it.

So to put it another way, the Arguments go to your script, not to anything inside of it. If you put “-t docx” into the Argumenents field, unless you specifically code your script to look for these arguments and pass them to Pandoc within the script, they will simply be ignored.

Amber, many thanks for your instant reply. It took me a while to get my head round this, but setting the Arguments field to “<$outputname> <$inputfile>” and then referencing those in the script as “-o $1.docx $2” works fine and allows me to set the file name at compile time. I hope that’s what you meant :slight_smile:

You do say in the manual:

so I apologise for not taking this in first time around. Perhaps in the next revision of the manual it would help to include a simple example script and its corresponding arguments?

You’re welcome!

Yeah that wouldn’t be too difficult to throw into the extras pack, I’ll make a note of it. Of course every language is going to have its own way of referencing arguments, so it can only demonstrate one approach, but an example shell script is probably going to be the most broadly useful.

Thank you. Those of us to whom this stuff isn’t obvious are likely to be starting with a Unix shell, just because it’s a logical first step from pandoc on the command line. Anyone using Python, Perl or whatever probably knows what to do :slight_smile: