Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify pandoc's markdown extensions using a YAML block?

Tags:

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

  • 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.

like image 475
briandk Avatar asked Sep 10 '15 02:09

briandk


People also ask

Can pandoc convert PDF to markdown?

You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.

What is pandoc used for?

Pandoc is a command-line tool for converting files from one markup language to another. Markup languages use tags to annotate sections of a document. Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX.

Can pandoc convert HTML to markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

Where are pandoc templates?

The default LaTeX template of Pandoc can be found at https://github.com/jgm/pandoc/tree/master/data/templates (named default.


1 Answers

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

like image 171
meenaparam Avatar answered Oct 11 '22 13:10

meenaparam