Learn R Programming

Hmisc (version 5.3-0)

latex: Convert an S object to LaTeX, and Related Utilities

Description

latex converts its argument to a .tex file appropriate for inclusion in a LaTeX2e document. latex is a generic function that calls one of latex.default, latex.function, latex.list.

latex.default does appropriate rounding and decimal alignment and produces a file containing a LaTeX tabular environment to print the matrix or data.frame x as a table.

latex.function prepares an S function for printing by issuing sed commands that are similar to those in the S.to.latex procedure in the s.to.latex package (Chambers and Hastie, 1993). latex.function can also produce verbatim output or output that works with the Sweavel LaTeX style.

latex.list calls latex recursively for each element in the argument.

latexTranslate translates particular items in character strings to LaTeX format, e.g., makes a^2 = a\$^2\$ for superscript within variable labels. LaTeX names of greek letters (e.g., "alpha") will have backslashes added if greek==TRUE. Math mode is inserted as needed. latexTranslate assumes that input text always has matches, e.g. [) [] (] (), and that surrounding by \$\$ is OK.

htmlTranslate is similar to latexTranslate but for html translation. It doesn't need math mode and assumes dollar signs are just that.

latexSN converts a vector floating point numbers to character strings using LaTeX exponents. Dollar signs to enter math mode are not added. Similarly, htmlSN converts to scientific notation in html.

latexVerbatim on an object executes the object's print method, capturing the output for a file inside a LaTeX verbatim environment.

dvi uses the system latex command to compile LaTeX code produced by latex, including any needed styles. dvi will put a \documentclass{report} and \end{document} wrapper around a file produced by latex. By default, the geometry LaTeX package is used to omit all margins and to set the paper size to a default of 5.5in wide by 7in tall. The result of dvi is a .dvi file. To both format and screen display a non-default size, use for example print(dvi(latex(x), width=3, height=4),width=3,height=4). Note that you can use something like xdvi -geometry 460x650 -margins 2.25in file without changing LaTeX defaults to emulate this.

dvips will use the system dvips command to print the .dvi file to the default system printer, or create a postscript file if file is specified.

dvigv uses the system dvips command to convert the input object to a .dvi file, and uses the system dvips command to convert it to postscript. Then the postscript file is displayed using Ghostview (assumed to be the system command gv).

There are show methods for displaying typeset LaTeX on the screen using the system xdvi command. If you show a LaTeX file created by latex without running it through dvi using show.dvi(object), the show method will run it through dvi automatically. These show methods are not S Version 4 methods so you have to use full names such as show.dvi and show.latex. Use the print methods for more automatic display of typesetting, e.g. typing latex(x) will invoke xdvi to view the typeset document.

Usage

latex(object, ...)

# S3 method for default latex(object, title=first.word(deparse(substitute(object))), file=paste(title, ".tex", sep=""), append=FALSE, label=title, rowlabel=title, rowlabel.just="l", cgroup=NULL, n.cgroup=NULL, rgroup=NULL, n.rgroup=NULL, cgroupTexCmd="bfseries", rgroupTexCmd="bfseries", rownamesTexCmd=NULL, colnamesTexCmd=NULL, cellTexCmds=NULL, rowname, cgroup.just=rep("c",length(n.cgroup)), colheads=NULL, extracolheads=NULL, extracolsize='scriptsize', dcolumn=FALSE, numeric.dollar=!dcolumn, cdot=FALSE, longtable=FALSE, draft.longtable=TRUE, ctable=FALSE, booktabs=FALSE, table.env=TRUE, here=FALSE, lines.page=40, caption=NULL, caption.lot=NULL, caption.loc=c('top','bottom'), star=FALSE, double.slash=FALSE, vbar=FALSE, collabel.just=rep("c",nc), na.blank=TRUE, insert.bottom=NULL, insert.bottom.width=NULL, insert.top=NULL, first.hline.double=!(booktabs | ctable), where='!tbp', size=NULL, center=c('center','centering','centerline','none'), landscape=FALSE, multicol=TRUE, math.row.names=FALSE, already.math.row.names=FALSE, math.col.names=FALSE, already.math.col.names=FALSE, hyperref=NULL, continued='continued', ...) # x is a matrix or data.frame

# S3 method for function latex( object, title=first.word(deparse(substitute(object))), file=paste(title, ".tex", sep=""), append=FALSE, assignment=TRUE, type=c('example','verbatim','Sinput'), width.cutoff=70, size='', ...)

# S3 method for list latex( object, title=first.word(deparse(substitute(object))), file=paste(title, ".tex", sep=""), append=FALSE, label, caption, caption.lot, caption.loc=c('top','bottom'), ...)

# S3 method for latex print(x, ...)

latexTranslate(object, inn=NULL, out=NULL, pb=FALSE, greek=FALSE, na='', ...)

htmlTranslate(object, inn=NULL, out=NULL, greek=FALSE, na='', code=htmlSpecialType(), ...)

latexSN(x)

htmlSN(x, pretty=TRUE, ...)

latexVerbatim(x, title=first.word(deparse(substitute(x))), file=paste(title, ".tex", sep=""), append=FALSE, size=NULL, hspace=NULL, width=.Options$width, length=.Options$length, ...)

dvi(object, ...) # S3 method for latex dvi(object, prlog=FALSE, nomargins=TRUE, width=5.5, height=7, ...) # S3 method for dvi print(x, ...) dvips(object, ...) # S3 method for latex dvips(object, ...) # S3 method for dvi dvips(object, file, ...) # S3 method for latex show(object) # or show.dvi(object) or just object dvigv(object, ...) # S3 method for latex dvigv(object, ...) # or gvdvi(dvi(object)) # S3 method for dvi dvigv(object, ...)

Arguments

Value

latex and dvi return a list of class latex or dvi containing character string elements file and style. file contains the name of the generated file, and style is a vector (possibly empty) of styles to be included using the LaTeX2e \usepackage command.

latexTranslate returns a vector of character strings

Details

latex.default optionally outputs a LaTeX comment containing the calling statement. To output this comment, run options(omitlatexcom=FALSE) before running. The default behavior or suppressing the comment is helpful when running RMarkdown to produce pdf output using LaTeX, as this uses pandoc which is fooled into try to escape the percent comment symbol.

If running under Windows and using MikTeX, latex and yap must be in your system path, and yap is used to browse .dvi files created by latex. You should install the geometry.sty and ctable.sty styles in MikTeX to make optimum use of latex().

On Mac OS X, you may have to append the /usr/texbin directory to the system path. Thanks to Kevin Thorpe (kevin.thorpe@utoronto.ca) one way to set up Mac OS X is to install X11 and X11SDK if not already installed, start X11 within the R GUI, and issue the command Sys.setenv( PATH=paste(Sys.getenv("PATH"),"/usr/texbin",sep=":") ). To avoid any complications of using X11 under MacOS, users can install the TeXShop package, which will associate .dvi files with a viewer that displays a pdf version of the file after a hidden conversion from dvi to pdf.

System options can be used to specify external commands to be used. Defaults are given by options(xdvicmd='xdvi') or options(xdvicmd='yap'), options(dvipscmd='dvips'), options(latexcmd='latex'). For MacOS specify options(xdvicmd='MacdviX') or if TeXShop is installed, options(xdvicmd='open').

To use pdflatex rather than latex, set options(latexcmd='pdflatex'), options(dviExtension='pdf'), and set options('xdvicmd') to your chosen PDF previewer.

If running S-Plus and your directory for temporary files is not /tmp (Unix/Linux) or \windows\temp (Windows), add your own tempdir function such as tempdir <- function() "/yourmaindirectory/yoursubdirectory"

To prevent the latex file from being displayed store the result of latex in an object, e.g. w <- latex(object, file='foo.tex').

See Also

html, format.df, texi2dvi