【问题标题】:KnitR: Is there a command to compile a tex file to a PDF?KnitR:是否有将 tex 文件编译为 PDF 的命令?
【发布时间】:2017-01-24 14:23:14
【问题描述】:

谁能告诉我如何使用 R 中的 Knitr 命令将 tex 文件编译为 pdf?

我正在为我的工作自动创建报告的过程,并且有一个特定的报告类型我需要编织一个 tex 文件,这是通过以下方式完成的:

knitr::knit('\somedirectory..')

然后,出于“正则表达式”的原因,我使用 shell 命令执行 Python 脚本。

此时,我得到了正确格式的 tex 文件,但无法弄清楚如何从 R 中执行创建 PDF 的最后一步。

整个过程需要自动化,因此很遗憾无法加载 TeXmaker 等。

我找到的最接近答案的是这篇文章: Is it possible to compile .tex files to PDF with 'pandoc'?

但是,我完全不熟悉直接使用 pandoc。这些 pandoc 命令可以在 R 中以某种方式执行吗?

非常感谢您提前提供的任何帮助。

【问题讨论】:

    标签: r latex knitr pandoc


    【解决方案1】:

    tools 包中,您会找到一个名为texi2pdf 的函数,它是texi2dvi 的包装器。如果您安装了所有正确的应用程序等,这将从 .tex 文件构建一个 pdf。

    因此,假设您将以下文本复制到名为 myTexFile.tex 的文件中,并将该文件放入您的工作目录中,

    texi2pdf("myTexFile.tex")
    

    将编译一个 pdf。

    要复制到文件的乳胶

    \documentclass{article}
    
    \begin{document}
    
    
    \title{My Article}
    \author{somebody\\
            some institution\\
            some place}
    
    \date{\today}
    \maketitle
    
    \begin{abstract}
    Here is an exciting abstract. Look at all the important stuff in my paper and publish it immediately.
    \end{abstract}
    
    \section{Introduction}
    This is a longer set of reasons why this paper is so important.
    
    \section{Data}
    Here is a description of my amazing dataset. No one else has ever had access to this in the history of civilazation.
    
    \subsection{Main Data}
    Some more stuff about it.
    
    \end{document}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多