在没有RStudio的情况下将Rmarkdown转换为PDF [英] Converting Rmarkdown to PDF without RStudio

查看:712
本文介绍了在没有RStudio的情况下将Rmarkdown转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将*.Rmd转换为PDF格式的文档 可用.

当前方法

当前方法遵循以下步骤:

  1. *.Rmd文档传递到knitr: knit(input = "report.Rmd"))
  2. 通过pandoc转换获得的md:

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

问题

这会导致以下问题,即 Rmarkdown 文档的顶部:

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

并显示为:

所有文本都居中,而我希望将其左对齐:

可能的方法

我想使用 ;但是,尽管设置了RSTUDIO_PANDOC(如在此处所述),该命令在pandoc不可用时仍会失败.

所需结果

我不太在乎所使用的机制是否利用了rmarkdown::render,我想要实现的是:

  • 所有页面的横向页面布局
  • 左对齐文本
  • 通过控制默认字体对文档进行最小控制的能力

  • 理想情况下,我希望在*.Rmd文件中尽可能多地执行操作,而无需在pandoc命令中添加参数.

更新,以下评论

  • 我正在Linux上工作,并且已安装pandoc,我可以执行pandoc命令传递文件并毫无问题地生成导出文件.它只对rmarkdown::render包不起作用.
  • 关于钩子和*.Rmd文件,这是我试图理解的内容,因为我发现我的*.Rmd文件的第一部分被忽略了.当前过程如下:
    • *.Rmd (其中不多,只是标题部分以及呈现但错误辩解的伪文本和代码)>
    • *.R 文件只运行一行knit(input = "report.Rmd")) >
    • *.sh 文件运行pandoc命令并生成PDF

有关:

如果一切就绪,那实际上只是对 rmarkdown::render(...)

rmarkdown::render(...)失败: Error: pandoc version 1.12.3 is required and was not found ... 但是:

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

和:

$ pandoc -v
pandoc 1.9.4.1 (...)

RSTUDIO_PANDOC指向pandoc.

解决方案

几件事:

  • 该命令在无法使用pandoc时失败." 很好,您必须安装了pandoc才能调用它-但您没有不要说您拥有什么操作系统.在Linux上,从软件包管理器安装pandoc非常简单.否则,jgm在网站上为您提供了二进制文件; 应该"在OS X上类似

  • 对于不同的样式,您需要修改LaTeX代码,您可以通过大量的钩子来包含宏文件;有关详细信息,请参见RMarkdown备忘单

  • 如果您想行使更多控制权,则可以提供自己的模板;我已经在 tint包中完成了此操作 (也位于CRAN上)

  • 如果一切就绪,实际上只是对rmarkdown::render(...)
  • 的调用

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(...)

这篇关于在没有RStudio的情况下将Rmarkdown转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆