Can I set command line arguments using the YAML metadata

别说谁变了你拦得住时间么 提交于 2019-11-29 07:48:06

YAML metadata are not passed to pandoc as arguments, but as variables. When you call pandoc on your MWE, it does not produce this :

pandoc -o guide.pdf articheck_guide.md --toc --number-sections

as we think it would. rather, it calls :

pandoc -o guide.pdf articheck_guide.md -V toc:yes -V number-sections:yes

Why, then, does you MWE produces a toc? Because the default latex template makes use of a toc variable :

~$ pandoc -D latex | grep toc

$if(toc)$
\setcounter{tocdepth}{$toc-depth$}

So setting toc to any value should produce a table of contents, at least in latex output. In this template, there is no number-sections variables, so this one doesn't work. However, there is a numbersections variable :

~$ pandoc -D latex | grep number

$if(numbersections)$

Setting numbersections to any value will produce numbering in a latex output with the default template

---
title: My Title
toc: yes
numbersections: yes
---

The trouble with this solution is that it only works with some output format. I thought I had read somewhere on the pandoc mailing-list that we soon would be able to use metadata in YAML blocks as intended (ie. as arguments rather than variables), but I can't find it anymore, so maybe it won't happen very soon.

Have a look at panzer (GitHub repository).

This was recently announced and released by Mark Sprevak -- a piece of software, that adds the notion of 'styles' to Pandoc.

It's basically a wrapper around Pandoc. It exploits the concept of YAML metadata blocks to the maximum.

The 'styles' provide a way to set all options for a Pandoc document conversion process with one line ("I want this document be an article/CV/notes/letter.").

You can regard this as more general abstraction than Pandoc templates. Styles are combinations of...

  • ...Pandoc command line options,
  • ...metadata settings,
  • ...templates,
  • ...instructions to run filters, and
  • ...instructions to run pre/postprocessors.

These settings can be customized on a per output type as well as a per document basis. Styles can be...

  • ...combined and
  • ...can bear inheritance relations to each other.

panzer styles simplify Makefiles: they bundle everything concerning the look of a document in one place -- the YAML metadata (a block in the Markdown file, or a separate file).

You just add one line of metadata (style: ...) to your document, and it will be treated as a letter/article/CV/notebook or whatever.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!