How can I specify pandoc's markdown extensions using a YAML block?
Solution 1
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
Solution 2
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.
Solution 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
...
Solution 4
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.
Solution 5
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"]
----
Related videos on Youtube
briandk
I'm a graduate student in Science Education research. I like math and programming, but I'm not fantastic at either.
Updated on June 28, 2022Comments
-
briandk almost 2 years
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, andmarkdown-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
- Can I set command line arguments using the YAML metadata - This one deals with how to specify output options, but I'm trying to tell pandoc about the structure of my input
-
What can I control with YAML header options in pandoc? - Answerers mention pandoc's templates, but neither the latex output template nor the markdown template indicate any sort of option for
grid_tables
. So, it's not clear to me from these answers how knowing about the templates will help me figure out how to structure my YAML.
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.
-
scoa over 8 yearsI think this is not possible with pandoc. See this answer by John MacFarlane on the pandoc mailing list: groups.google.com/d/msg/pandoc-discuss/F5p85SQ7ejY/3cRny3RqTgkJ
-
mb21 over 5 yearsI wrote a small script that makes this possible: github.com/mb21/panrun
-
Merchako over 6 yearsWouldn't that be
pandoc yourfile.rmd -o yourfile.pdf
then? -
meenaparam over 6 years@Merchako No, the output type is
md_document
. -
Merchako over 6 yearsI 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? -
meenaparam over 6 yearsSay your original file is called
yourfile.Rmd
- following the instructions to add the extra text in your YAML header results in theyourfile.md
file being created, which you can then use in pandoc. -
Merchako over 6 yearsI 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.
-
meenaparam over 6 yearsThe 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.