简体   繁体   中英

Converting Rmarkdown to PDF without RStudio

I would like to convert a *.Rmd to document to PDF without being available.

Current approach

Current approach follows the following steps:

  1. *.Rmd document is passed to knitr : knit(input = "report.Rmd"))
  2. Obtained md is converted via pandoc:

     # Convert pandoc --smart --to latex \\ --latex-engine pdflatex \\ -s report.md \\ -o report.PDF 

Problems

This results in the following problems, the top section of the Rmarkdown document:

---
title:  "Report Title"
author: "Person"
output: pdf_document
classoption: landscape
---

and shows as:

顶部文件部分

all text is centered, whereas I would like for it to be left-aligned:

没有左对齐

Possible approach

I would like to make use of the rmarkdown::render ; however, despite setting RSTUDIO_PANDOC (as discussed here ), the command fails on pandoc not being available.

Desired outcome

I don't care much whether the utilised mechanism makes use of the rmarkdown::render , what I want to achieve is:

  • Landscape page layout across all pages
  • Left-aligned text
  • Ability to exercise minimum control over the document by controlling default fonts

  • Ideally, I would like to do as much as in the *.Rmd file as possible without the need to add parameters to the pandoc command.

Updates, following comments

  • I'm working on Linux and pandoc is installed, I can execute pandoc command pass files and generate exports with no problems. It only doesn't work with the rmarkdown::render package.
  • Concerning the hooks and *.Rmd files, this is what I'm trying to understand as I see that that the first section of my *.Rmd file is ignored. The current process looks as follows:
    • *.Rmd (not much in it, just title section and dummy text and code that renders but wrongly justified) >
    • *.R file running one line knit(input = "report.Rmd")) >
    • *.sh file running pandoc command and generating PDF

Concerning:

if all that is in place, it is indeed just a call to rmarkdown::render(...)

The rmarkdown::render(...) fails: Error: pandoc version 1.12.3 is required and was not found ... However:

>> rmarkdown::pandoc_available()
[1] TRUE

and:

$ pandoc -v
pandoc 1.9.4.1 (...)

The RSTUDIO_PANDOC points to pandoc.

A few things:

  • "the command fails on pandoc not being available." well you must have pandoc installed in order to call it -- but you didn't say what OS you have. On Linux it is pretty trivial to install pandoc from the package manager; otherwise jgm has binaries for you on the site; "should" be similar on OS X

  • for different styling you need to modify the LaTeX code which you can via numerous hooks to include macro files; see the RMarkdown cheat sheets for detail

  • if you want to exercise more control, you can supply your own template; I have done so in the tint package (which is also on CRAN)

  • if all that is in place, it is indeed just a call to rmarkdown::render(...)

Error: pandoc version 1.12.3 is required and was not found

I think the error says it plainly: you need pandoc 1.12.3 and you have pandoc 1.9.4.1

I do not know, however, why such a specific version is required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM