Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I got the help on R functions in .tex format using help_console function. I wonder what is the documentclass and required packages to compile this document correctly. Thanks in advance for your help. My MWE is:


Code


\documentclass{article}

\begin{document}

HeaderA{lm}{Fitting Linear Models}{lm}
aliasA{print.lm}{lm}{print.lm}
keyword{regression}{lm}
%
begin{Description}relax
code{lm} is used to fit linear models.
It can be used to carry out regression,
single stratum analysis of variance and
analysis of covariance (although code{LinkA{aov}{aov}} may provide a more
convenient interface for these).
end{Description}
%
begin{Usage}
begin{verbatim}
lm(formula, data, subset, weights, na.action,
   method = qr, model = TRUE, x = FALSE, y = FALSE, qr = TRUE,
   singular.ok = TRUE, contrasts = NULL, offset, ...)
end{verbatim}
end{Usage}
%


\end{document}

Output


enter image description here

share|improve this question
    
I think this is done with the sweave tool chain... –  Thruston Jan 8 at 11:23
    
Your code is wrong as all the \commands are lost (the obtained from R really is \HeaderA{lm}{Fitting Linear Models}{lm} \aliasA{print.lm}{lm}{print.lm} etc. –  Fran Jan 8 at 12:47
    
It looks like you lost the first column of the R output and are missing all the \ –  David Carlisle Jan 8 at 14:16
    
@DavidCarlisle: Thanks for your comment. I've checked again and have not lost the first column of the R output. –  MYaseen208 Jan 8 at 14:26
    
well R has then, either way something has dropped the \ (I notice the accepted answer doesn't give any indication of how to preserve the \ other than not removing them.) –  David Carlisle Jan 8 at 16:11

1 Answer 1

up vote 2 down vote accepted

The easy way: Left to R do all the work.

help(lm,help_type="pdf")

You obtain in this way a PDF really complied with pdflatex with the R help.

The hard way (only useful if you want to modify the source before compiling):

1) Locate Rd.sty (that you should have in your R installation).

In a Linux system:

$ locate Rd.sty
/usr/lib/R/site-library/scatterplot3d/doc/Rd.sty
/usr/share/R/share/texmf/tex/latex/Rd.sty

(If you have more than one, as in this case, your mileage may vary. The right here is the second.)

2) Make a simple template document with de Rd package. If LaTeX cannot find the path to Rd.sty, specify the absolute path, or make copy of this file to you working directory.

\documentclass{article}
\usepackage{/usr/share/R/share/texmf/tex/latex/Rd} 
\begin{document}
% paste your R code here
\end{document}

3) Paste the LaTeX chunk obtained with the R help_console function (without lossing the \ characters) in the template:

\documentclass{article}
\usepackage{/usr/share/R/share/texmf/tex/latex/Rd} 
\begin{document}
\HeaderA{lm}{Fitting Linear Models}{lm}
\aliasA{print.lm}{lm}{print.lm}
\keyword{regression}{lm}
%
\begin{Description}\relax
\code{lm} is used to fit linear models.
It can be used to carry out regression,
.
.
.
\end{document}

4) Modify the contents (add, delete, change tex) of this file** as you want and/or a local copy of Rd.sty to have your own style (redefining macros and environments, assuming that you know what are you doing). According to R documentation, the appearance of the output can be also customized through a file ‘Rhelp.cfg’ somewhere in your LaTeX search path, but I have not explored this option.

5) Compile it as usual with pdflatex.

share|improve this answer
    
(+1): Thanks @Fran for your answer. I need help document in .tex format to use in other documents. Can you explain the 1. Modify this file? –  MYaseen208 Jan 8 at 14:59
    
Got it. Thanks a lot. Much appreciated. –  MYaseen208 Jan 8 at 15:10
    
@MYaseen208 You're welcome. About the step 3 (not 1, sorry): "modify as you want" . Of course, is optional, but I included this point because otherwise would only make sense the faster and easier method of obtain the PDF directly with the help() function. Right? –  Fran Jan 8 at 18:16
    
Thanks @Fran for your help. Do you know any easy way to export the obtained .tex document to LyX? –  MYaseen208 Jan 8 at 18:20
    
@MYaseen208 Have you tried from Lyx menu File > Import > Latex ? But probably many commands will remain as ERT boxes since they are not common LaTeX commands. –  Fran Jan 8 at 18:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.