RStudio (IDE for R) has a great MarkDown to PDF, Word or HTML using Pandoc. <a href="http:&#x2F;&#x2F;rmarkdown.rstudio.com&#x2F;pdf_document_format.html" rel="nofollow">http:&#x2F;&#x2F;rmarkdown.rstudio.com&#x2F;pdf_document_format.html</a><p>Might help you to see their process. You can do the whole thing with CLI but easy in their IDE.