Can I set command line arguments using YAML metadata

Pandoc supports the YAML metadata block in markdown documents. This may indicate the title and author, etc. It can also manipulate the appearance of PDF output by changing the font size, margin width, and border size specified for the shapes that are included. Details are given here .

I would like to use a metadata block to remember the command line arguments that I should use, for example --toc and --number-sections . I tried this by adding the following to the beginning of my markdown:

 --- title: My Title toc: yes number-sections: yes --- 

Then I used the command line:

 pandoc -o guide.pdf articheck_guide.md 

This created a table of contents, but did not separate the sections. I wondered why this was, and if there is a way, I can specify such a thing from the document so that I do not need to add it on the command line.

+4
yaml markdown pandoc
source share
2 answers

YAML metadata is 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. rather, it calls:

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

Why are you doing MWE current? Since the latex pattern uses the toc variable by default:

 ~$ pandoc -D latex | grep toc $if(toc)$ \setcounter{tocdepth}{$toc-depth$} 

Therefore, setting toc to any value should contain a table of contents, at least at the exit from latex. There are no number-sections variables in this template, so this does not work. However, there is a numbersections variable:

 ~$ pandoc -D latex | grep number $if(numbersections)$ 

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

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

The problem with this solution is that it only works with some output format. It seemed to me that I read somewhere on the pandoc mailing list that soon we will be able to use the metadata in YAML blocks as intended (i.e. as arguments, not variables), but I can no longer find them, so maybe This will happen very soon.

+3
source share

Check out the panzer (GitHub repository).

It was recently announced and released by Mark Sprevak, a piece of software that adds the concept of β€œstyles” to Pandoc.

This is basically a wrapper around Pandoc. He makes the most of the concept of YAML metadata blocks.

"Styles" provides a way to set all the parameters for the process of converting Pandoc documents with one line ("I want this document to be article / CV / note / letter").

You can see this as a more general abstraction than Pandoc templates. Styles are combinations ...

  • ... Pandoc command line options,
  • ... metadata settings,
  • ... patterns
  • ... instructions for starting filters and
  • ... instructions for starting pre / postprocessors.

These parameters can be configured for each type of output, as well as for each document. Styles may be ...

  • ... combined and
  • ... can carry inheritance relationships to each other.

panzer styles simplify the Makefile: they combine everything that relates to the appearance of the document in one place - YAML metadata (a block in the Markdown file or a separate file).

You simply add one line of metadata to your document ( style: ... ), and it will be considered as a letter / article / CV / notepad or something else.

+3
source share

All Articles