26

Background

Pandoc's markdown lets you specify extensions for how you would like your markdown to be handled:

Markdown syntax extensions can be individually enabled or disabled by appending +EXTENSION or -EXTENSION to the format name. So, for example, markdown_strict+footnotes+definition_lists is strict markdown with footnotes and definition lists enabled, and markdown-pipe_tables+hard_line_breaks is pandoc’s markdown without pipe tables and with hard line breaks.

My specific question

For a given pandoc conversion where, say, I use grid tables in my source:

pandoc myReport.md --from markdown+pipe_tables --to latex -o myReport.pdf

How can I write a pandoc YAML block to accomplish the same thing (specifying that my source contains grid tables?)

A generalized form of my question

How can I turn extensions on and off using pandoc YAML?

Stack Overflow Questions that I don't think completely answer my question

There may also not be a way to do this

It's always possible that pandoc isn't designed to let you specify those extensions in the YAML. Although, I'm hoping it is.

Community
  • 1
  • 1
briandk
  • 6,749
  • 8
  • 36
  • 46
  • 1
    I think this is not possible with pandoc. See this answer by John MacFarlane on the pandoc mailing list: https://groups.google.com/d/msg/pandoc-discuss/F5p85SQ7ejY/3cRny3RqTgkJ – scoa Sep 10 '15 at 08:25
  • 1
    I wrote a small script that makes this possible: https://github.com/mb21/panrun – mb21 Sep 18 '18 at 14:03

5 Answers5

10

You can use Markdown Variants to do this in an Rmarkdown document. Essentially, you enter your extensions into a variant option in the YAML header block at the start of the your .Rmd file.

For example, to use grid tables, you have something like this in your YAML header block:

---
title: "Habits"
author: John Doe
date: March 22, 2005
output: md_document
    variant: markdown+grid_tables
---

Then you can compile to a PDF directly in pandoc by typing in your command line something like:

pandoc yourfile.md -o yourfile.pdf

For more information on markdown variants in RStudio: http://rmarkdown.rstudio.com/markdown_document_format.html#markdown_variants

For more information on Pandoc extensions in markdown/Rmarkdown in RStudio: http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html#pandoc_markdown

meenaparam
  • 1,949
  • 2
  • 17
  • 29
  • Wouldn't that be `pandoc yourfile.rmd -o yourfile.pdf` then? – Merchako Oct 26 '17 at 16:03
  • @Merchako No, the output type is `md_document`. – meenaparam Oct 26 '17 at 16:15
  • I think it would be helpful to add some clarifying text to this answer. It sounds like you're taking two steps, but you don't explicitly say that. Where does `yourfile.md` come from? – Merchako Oct 26 '17 at 18:04
  • Say your original file is called `yourfile.Rmd` - following the instructions to add the extra text in your YAML header results in the `yourfile.md` file being created, which you can then use in pandoc. – meenaparam Oct 26 '17 at 18:11
  • 3
    I get that, but I think it should be incorporated into your answer for proper flow. It doesn't make sense to those who don't already use Rmarkdown. Since this question is about Pandoc, you can't assume familiarity with Rmarkdown. – Merchako Oct 26 '17 at 18:20
  • The original question asker puts Rmarkdown and RStudio in their tags for the question, and accepted the answer. If you need more clarity, go ahead and edit as you see fit or post another answer. – meenaparam Oct 26 '17 at 18:54
7

You can specify pandoc markdown extension in the yaml header using md_extension argument included in each output format.

---
title: "Your title"
output:
  pdf_document:
    md_extensions: +grid_tables
---

This will activate the extension. See Rmarkdown Definitive Guide for details.

cderv
  • 6,272
  • 1
  • 21
  • 31
3

Outside Rmarkdown scope, you can use Pandocomatic to it, or Paru for Ruby.

---
 title: My first pandocomatic-converted document
 pandocomatic_:
     pandoc:
         from: markdown+footnotes
         to: html
 ...
3

For people stumbling across this in or after 2021, this can be done without Rmarkdown. You can specify a YAML "defaults" file, which basically includes anything you could want to configure.

In order to do what OP wanted, all you'd need to do is

from: markdown+pipe_tables

in the defaults file, then pass it when you compile. You can also specify the input and output files, so you can end up with the very minimal command pandoc --defaults=defaults.yaml and have it handle the rest for you. See https://pandoc.org/MANUAL.html#extensions for more.

2

As Merchako noted, the accepted answer is specific to rmarkdown. In, for instance, Atom md_extensions: does not work.

A more general approach would be to put the extensions in the command line options. This example works fine:

----
title: "Word document with emojis"
author: me
date: June 9, 2021
output:
  word_document:
    pandoc_args: ["--standalone", "--from=markdown+emoji"]
----

Tycho
  • 73
  • 7