htdebeer / pandocomatic

Automate the use of pandoc
https://heerdebeer.org/Software/markdown/pandocomatic/
GNU General Public License v3.0
158 stars 14 forks source link

Error using pandoc reference-docx option #7

Closed iandol closed 7 years ago

iandol commented 7 years ago

Hi, I'm using Pandoc 1.19.2.1 and Pandocomatic 0.1.2 on macOS 10.12.4 and ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

I'm using the following YAML and I get a undefined method 'reference-docx' for #<Paru::Pandoc:0x007fea7b05ba78> (NoMethodError)

---
templates:
  paper-with-references:
    preprocessors: []
    pandoc:
      from: markdown
      to: docx
      standalone: true
      filter: 
        - pandoc-citeproc
      bibliography: /Users/ian/.pandoc/core.bib
      csl: /Users/ian/.pandoc/apa.csl
      reference-docx: /Users/ian/.pandoc/custom-reference.docx
      dpi: 300
      toc: false
      mathjax: true
      base-header-level: 1
    postprocessors: []
  paper-no-references:
    preprocessors: []
    pandoc:
      from: markdown
      to: docx
      standalone: true
      reference-docx: /Users/ian/.pandoc/custom-reference.docx
      toc: false
      mathjax: true
    postprocessors: []
---

Here's the ruby error

👉  pandocomatic -c $HOME/.dotfiles/pandoc/pandocomatic.yaml -i min.md
/Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/lib/pandocomatic/command/convert_file_command.rb:136:in `block in pandoc': undefined method `reference-docx' for #<Paru::Pandoc:0x007fea7b05ba78> (NoMethodError)
    from /Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/lib/pandocomatic/command/convert_file_command.rb:127:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/lib/pandocomatic/command/convert_file_command.rb:127:in `pandoc'
    from /Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/lib/pandocomatic/command/convert_file_command.rb:89:in `convert_file'
    from /Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/lib/pandocomatic/command/convert_file_command.rb:49:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/lib/pandocomatic/command/command.rb:81:in `execute'
    from /Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/lib/pandocomatic/pandocomatic.rb:101:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/pandocomatic-0.1.2/bin/pandocomatic:3:in `<top (required)>'
    from /usr/local/bin/pandocomatic:23:in `load'
    from /usr/local/bin/pandocomatic:23:in `<main>'

Also while I'm here there is an error on your pandoc option documentation examples, you always say cls when it should be csl

htdebeer commented 7 years ago

The issue with "reference-docx" seems to be another issue with the documentation: it should be "referencedocx". All words in multi-word options to pandoc are separated by an underscore ("") instead of a dash ("-").

However, now that you pointed this issue out to me, I do start wondering: would using dashes make more sense? Or maybe pandocomatic should support both underscores and dashes?

Thanks for letting me know about the issues with the documentation! I will update the documentation today.

iandol commented 7 years ago

@htdebeer : well I naively assumed I could use the same pandoc options in pandocomatic, and pandoc uses hyphens (latex-engine, citation-abbreviations, epub-cover-image etc.), so unless there is a technical reason to convert the hypen to underscores it makes sense to use the option names chosen by pandoc as the documented default (though keeping underscore for backwards compatibility seems perfectly reasonable).

Regarding the documentation, I also wonder why you specify a bibliography and csl but you don't specify filter: pandoc-citeproc in the examples? These examples will not use bibliography and csl unless pandoc-citeproc is called?

Thanks for such a quick reply, and double thanks for an excellent tool. I also added pandocomatic to the workflow section of https://github.com/jgm/pandoc/wiki/Pandoc-Extras#workflow as I didn't see it on that page which is how most people will come across such tools 👍

htdebeer commented 7 years ago

You're right, it makes sense to allow dashes as well. As you mentioned, it is consistent with pandoc's options, but also with pandocomatic's configuration properties like "use-template". I'll add it this weekend.

With respect to the "pandoc-citeproc" filter, I am not sure it is an undocumented feature, but it is run by pandoc automatically. There is no need to specify this filter explicitly: when I run:

echo "the program pandoc [@pandoc]" | pandoc -f markdown -t html5 --bibliography bib.bib

with bib.bib containing an entry on pandoc, I get as output:

<p>the program pandoc <span class="citation" data-cites="pandoc">(MacFarlane 2006)</span>     
</p>
<div id="refs" class="references">
<div id="ref-pandoc">
<p>MacFarlane. 2006. <em>Pandoc</em>.</p>
</div> 
</div>
iandol commented 7 years ago

OK, so there is an implicit command line argument added by pandoc (I just assumed it needed to be explicitly made). I suppose for the documentation examples it would still be nice to add it explicitly as an example of filter specification (once the path fixes are made from #9 )

EDIT: if you specify bibliography in the metadata, then pandoc-citeproc is not called, and must be called explicitly if you want a bibliography:

---  
bibliography: /Users/ian/.pandoc/core.bib  
citation-style: /Users/ian/.pandoc/apa.csl  
---  
# Summary #
The background question is sound [@usrey2000], and of substantial importance for systems neuroscience.
👉  pandoc -s -f markdown -t plain  min.md

SUMMARY

The background question is sound [@shipp2013], and of substantial
importance for systems neuroscience.
👉  pandoc -s --filter pandoc-citeproc -f markdown -t plain  min.md

SUMMARY

The background question is sound (Shipp, Adams, & Friston, 2013), and of
substantial importance for systems neuroscience.

Shipp, S., Adams, R., & Friston, K. J. (2013). Reflections on agranular
architecture: Predictive coding in the motor cortex. _Trends in
Neuroscience_, _36_(12), 706–716.
https://doi.org/10.1016/j.tins.2013.09.004
htdebeer commented 7 years ago

Added to version 0.1.3: Words in multi-word pandoc options specified in a YAML block can now be separated by dash (-) or underscore (_).