Description
Render the input file to the specified output format usingpandoc. If the input requires knitting thenknit is called prior to pandoc.
Man pandoc (1): Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. It can read Markdown, CommonMark, PHP Markdown Extra. The pandoc and pandoc-citeproc binaries installed on my system. This kinda makes sense, but led to some frustrated debugging as to why I was getting different results (a bug in pandoc-citeproc 0.4.1 was causing my documents not to compile outside of RStudio). It would be nice to (a) direct rmarkdown to use the RStudio binaries of pandoc. See full list on github.com. Tables A table can be entered by using Pandoc’s table syntax. You can choose multiple styles as input, but they all are converted to the same style. At GitHub, we’re building the text editor we’ve always wanted: hackable to the core, but approachable on the first day without ever touching a config file. We can’t wait to see what you build with it.
Usage
Arguments
Input file (R script, Rmd, or plain markdown).
R Markdown output format to convert to. Pass 'all' to render all formats defined within the file. Pass the name of a format (e.g. 'html_document') to render a single format or pass a vector of format names to render multiple formats. Alternatively you can pass an output format object; e.g. html_document(). If NULL is passed then the output format is the first one defined in the YAML metadata of the input file (defaulting to HTML if none is specified).
List of output options that can override the options specified in metadata (e.g. could be used to force self_contained or mathjax = 'local'). Note that this is only valid when the output format is read from metadata (i.e. not a custom format object passed to output_format).
Output file. If NULL then a default based on the name of the input file is chosen.
Output directory. An alternate directory to write the output file to (defaults to the directory of the input file).

Intermediate files directory. If NULL, intermediate files are written to the same directory as the input file; otherwise.
The working directory in which to knit the document; uses knitr's root.dir knit option. NULL means to follow the knitr default, which is to use the parent directory of the document.
Using Pandoc To Find
The runtime target for rendering. static produces output intended for static files; shiny produces output suitable for use in a Shiny document (see run). The default, auto, allows the runtime target specified in the YAML metadata to take precedence, and renders for a static runtime target otherwise.
TRUE to clean intermediate files created during rendering.
List of named parameters that override custom params specified within the YAML front-matter (e.g. specifying a dataset to read or a date range to confine output to). Pass 'ask' to start an application that helps guide parameter configuration.
(For expert use) Meta data generated by knitr.
The environment in which the code chunks are to be evaluated during knitting (can use new.env() to guarantee an empty new environment).
Whether to run Pandoc to convert Markdown output.
TRUE to suppress printing of the pandoc command line.
The encoding of the input file; see file.
Value
When run_pandoc = TRUE, the compiled document is written into the outputfile, and the path of the output file is returned.
When run_pandoc = FALSE, the path of the Markdown output file, withattributes knit_meta (the knitr meta data collected from codechunks) and intermediates (the intermediate files/directories generatedby render()).
R Markdown
R Markdown supports all of the base pandoc markdown features as well as some optional features for compatibility with GitHub Flavored Markdown (which previous versions of R Markdown were based on). See rmarkdown_format for details.
Details
Note that the knitrerror option is set to FALSEduring rendering (which is different from the knitr defaultvalue of TRUE).
For additional details on rendering R scripts seeCompiling R scripts to a notebook.
If no output_format parameter is specified then the outputformat is read from the YAML front-matter of the inputfile. For example, the following YAML would yield a PDFdocument:
Additional format options can also be specified in metadata. For example:
Multiple formats can be specified in metadata. If no output_formatis passed to render then the first one defined will be used:
Formats specified in metadata can be any one of the built in formats(e.g. html_document,pdf_document) or a format defined in anotherpackage (e.g. pkg::custom_format).
If there is no format defined in the YAML thenhtml_document will be used.
See Also
knit, output_format,pandoc
Examples
Monday, 29 February, 2016
Markdown is a popular text formatting syntax among developers these days. Popular Sites like Github or Bitbucket use Markdown for project documentation and various other types of user generated content. These sites automatically convert markdown syntax to HTML, so it can be displayed in a browser.
However, maybe you want to use Markdown as document format without using a platform that does the conversion for you. Or you are in need of an output format other than HTML. In this case you need a tool that can convert markdown to the desired target format. Pandoc is is a document conversion tool that can be used for exactly this (and a lot of other things). With Pandoc you can convert Markdown documents to PDF, HTML, Words DOCX or many other formats.
After installing Pandoc, you can simply run it from command line.
Using Pandoc To Make
Note: By default, Pandoc uses LaTeX to generate PDF documents. So, if you want to generate PDF documents, you need to install a LaTex processor first (list of required LaTeX packages).
To convert a doc.md Markdown file into a PDF document, the following command can be used:
Pandoc is able to merge multiple Markdown files into a single PDF document. To generate a single PDF document out of two Markdown files you can use:
By default the page margins in the resulting PDF document are quite large. You can change this by passing a margin parameter:
To create HTML or DOCX documents you simply have to change the file extension of the target file:
The resulting documents are well formatted. The following two screenshot show a DOCX and a PDF document created out of two small example markdown files:
Resulting DOCX document:
Resulting PDF document:
Using Pandoc To Convert Latex To Docx
Comments
'By default, Pandoc uses LaTeX to generate PDF documents.' can CSS be used to style pdfs?
Hi, Michael! If you need to convert Markdown file to DOCX, you can use Writage plugin for MS Word. It allows to open, edit and save your MD files as DOCX (or DOCX as MD files) from the MS Word.
Leave a reply
