将LaTeX表直接打印到图像(PNG或其他) [英] Print LaTeX Table Directly to an Image (PNG or other)

查看:352
本文介绍了将LaTeX表直接打印到图像(PNG或其他)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以从R内部将LaTeX表直接打印到图像文件(以包含在另一个文档/网页中).基本上,我想将LaTeX代码提供给一个函数,将其作为图像保存到工作目录中.

Is there a way to print, from within R, a LaTeX table directly to an image file (for inclusion in another document/webpage). Basically, I'd like to supply LaTeX code to a function that saves it as an image to the working directory.

做梦吗?

推荐答案

有各种LaTeX到图像转换器脚本,旨在执行将方程式转换为图像以便包含在网页上的操作.

There are various LaTeX-to-Image converter scripts, designed to do things like convert equations into images for including on web pages.

如果您可以找到其中之一(也许是dvipng?),则可以轻松地从R中的表转到LaTeX,然后从LaTeX转到png.

If you can find one of those (dvipng perhaps?) then you can go from a table in R to LaTeX easy enough and then from LaTeX to png.

如果您有dvipng,则可以利用Hmisc的乳胶转换功能来做一个更整洁的功能:

If you have dvipng, you can leverage Hmisc's latex conversions to make a neater function to do it:

dvipng.dvi <-
  function (object, file, ...) 
{
  cmd <- if (missing(file)) 
    paste("dvipng -T tight", shQuote(object$file))
  else paste("dvipng -T tight", "-o", file, shQuote(object$file))
  invisible(sys(cmd))
}

然后您可以执行以下操作:

And then you can do:

> tt   # here is a table
   y
x    1  2  3
  1  9 12 11
  2 18  9 10
  3 10  7 14
> dvipng.dvi(dvi.latex(latex(tt)))

这将在工作目录中生成一个带有随机名称的png文件. -T紧选项将裁剪所有空白.

And that will produce a png file with a random name in the working directory. The -T tight option will crop all the whitespace from round it.

这是我认为可能的最直接的方法.

That's about as direct as I can think it possible.

Linux或Windows或Mac或Atari?

Linux or Windows or Mac or Atari?

这篇关于将LaTeX表直接打印到图像(PNG或其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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