tex2image: Transforming LaTeX Code Using ImageMagick or pdf2svg

Description Usage Arguments Details Value See Also Examples

Description

Transformation of LaTeX code into an image by compiling to PDF and then transforming to PNG (by default) via ImageMagick's convert command or to SVG via pdf2svg.

Usage

1
2
3
4
5
6
tex2image(tex, format = "png", width = NULL, pt = 12, density = 350,
  dir = NULL, tdir = NULL, idir = NULL,
  width.border = 0L, col.border = "white", resize = 650,
  packages = c("amsmath", "amssymb", "amsfonts"),
  header, header2 = NULL, tikz = NULL, Sweave = TRUE, show = FALSE,
  name = "tex2image")

Arguments

tex

character vector or list of character vectors. Each character vector is either the name of a LaTeX file or a vector containing LaTeX code directly.

format

character. Suffix for the type of graphic to convert to.

width

numeric. Width of the text in inch. If NULL (or 0), the width is chosen to fit the image in tex.

pt

numeric. Pointsize of the text.

density

numeric. Resolution density of the image.

dir

character specifying the output directory.

tdir

character specifying a temporary directory, by default this is chosen via tempdir.

idir

character specifying the path additional LaTeX inputs required.

width.border

numeric. Width of the framebox border.

col.border

character. Color of framebox border.

resize

numeric. Number of pixels for resizing the image.

packages

character. Names of LaTeX packages to be included.

header

character. LaTeX code to be included in the header of the LaTeX file before the beginning of the document. By default the parindent is set to 0 and sans serif fonts (phv) are used for both text and math.

header2

character. LaTeX code to be included in the header of the LaTeX file after the beginning of the document.

tikz

character. Options to be passed to \usetikzlibrary{}. If set, the tikz package is loaded per default.

Sweave

logical. Should the LaTeX package Sweave.sty be included in the header?

show

logical. Show the resulting image(s) using browseURL.

name

character. Base name of the image file.

Details

tex2image converts LaTeX code to image files, e.g., for inclusion in web pages. It proceeds in the following steps: (1) LaTeX code is embedded into a suitable .tex file. (2) This is compiled to PDF using texi2dvi. (3) The PDF is converted to an image file. By default, conversion is to PNG using R package magick functionalities or alternatively to SVG via pdfcrop followed by pdf2svg.

The LaTeX code is fit into the standalone document class using the tikzpicture environment as a default.

If tex is a list of LaTeX chunks, then these are compiled to separate pages of a single PDF in a single LaTeX run. Each page is subsequently converted to a separate image.

In case of SVG output, the respective image manipulation tools, i.e., pdfcrop/pdf2svg, are assumed to be installed and available in the search path.

Value

Character vector with path(s) to image(s) generated from the LaTeX code.

See Also

texi2dvi

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
## some simple LaTeX
tex <- c("This is \\textbf{bold} and this \\textit{italic}.",
  "Points on the unit circle: $x^2 + y^2 = 1$.")

## default settings: PNG with sans serif fonts
tex2image(tex, show = interactive())

## with fixed widths
tex2image(tex, width = 6, show = interactive())
tex2image(tex, width = 2, show = interactive())

## switch off header (-> LaTeX uses its standard serif fonts)
tex2image(tex, header = NULL, show = interactive())

## SVG output (system requirements: pdfcrop & pdf2svg)
tex2image(tex, format = "svg", show = TRUE)

## End(Not run)

flaviobarros/exams documentation built on May 28, 2019, 8:39 p.m.