1

This .Rnw compiles fine in RStudio Version 0.99.862

\documentclass{book}
\usepackage{Rd} % Rstudio will be able to find this .sty file

\begin{document}

<<label=Test, echo=FALSE, results='asis'>>=
library(noamtools)
help_console(topic="mean", format = "latex")
@ 

\end{document}

However importing this .Rnw into LyX Version 2.1.4 throws the following error in Ubuntu 14.0.2.

LaTeX Error: File `Rd.sty' not found.

enter image description here Any help will be highly appreciated. Thanks

The R package noamtools can be installed by devtools::install_github('noamross/noamtools')

MYaseen208
  • 8,587
  • What OS are you on? On Mac OS X, Rd.sty is located in /Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/, so it's not in the LaTeX path. If you have TeX Live on a unix-like system, you could probably do ln -s /Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/Rd.sty $(kpsewhich -var-value TEXMFHOME)/tex/latex/ (assuming you've set up a TEXMFHOME folder). – Adam Liter Jan 21 '16 at 13:52
  • @AdamLiter he is on Ubuntu. – scottkosty Jan 21 '16 at 15:23
  • I have not had this problem on Ubuntu. Can you export to .tex in LyX and in RStudio and confirm that both exports are equivalent? What happens when you compile the .tex file on the command line? – scottkosty Jan 21 '16 at 15:24
  • @scottkosty: Thanks for your suggestion. I imported .tex (created by RStudio) to Lyx and getting the same error. Any thoughts. – MYaseen208 Jan 21 '16 at 15:32
  • What happens when you try to compile the .tex file on the command line? – scottkosty Jan 21 '16 at 15:48
  • @scottkosty lol, thanks. I don't know how I missed that in the original post. :p Anyway, roughly the same command should work on Ubuntu. Just symlink Rd.sty into TEXMFHOME and everything should work. – Adam Liter Jan 21 '16 at 16:24
  • @scottkosty I assume you must have done something similar already if you're not getting this problem on Ubuntu because Rd.sty is not on CTAN (and thus not part of TeX Live). – Adam Liter Jan 21 '16 at 16:26

1 Answers1

1

The problem here is that RStudio knows where to look for Rd.sty, which is not part of CTAN and thus not part of TeX Live. (Rd.sty is something that is distributed with the base R packages and binaries but is not included in any TeX distribution that I know of.)

TeX Live, by default, is configured to only look in certain places for TeX things. The link provides more information about these predefined texmf trees. LyX is built atop a TeX distribution, and so it only knows to look in the places that your TeX distribution tells it to look for files.

It's possible to change the places that your TeX distribution will search, which is what is actually discussed in this question, a near duplicate.

However, I would suggest a different solution to this problem than the one that is discussed in that linked question and its answer.

TeX Live actually makes two texmf trees available out of the box that are intended for local files. These texmf trees are specified by the TeX Live variables TEXMFLOCAL and TEXMFHOME, which are discussed in more detail here. I would recommend using the TEXMFHOME tree in this case because the TEXMFLOCAL folder is overwritten when a new version of TeX Live is installed. (Note that there are actually advantages to using TEXMFLOCAL which are discussed if you follow the link. Given that Rd.sty has not yet made it onto CTAN and into TeX Live in all of its years of existence, it seems unlikely to me that it would make its way onto CTAN and into TeX Live ever. In this case, the advantages of installing to TEXMFLOCAL, which are discussed if you follow the link, are mooted; it makes much more sense to install Rd.sty into TEXMFHOME.)

To "install" Rd.sty into TEXMFHOME, it is sufficient to create a symbolic link (symlink) from wherever Rd.sty is on your computer to your TEXMFHOME folder.

If you haven't already created a TEXMFHOME folder (see also Where do I place my own .sty or .cls files, to make them available to all my .tex files?), you could do the following, which will set up a basic texmf tree that should cover most use cases and needs (there are, of course, more directories in a maximally TDS-compliant directory).

mkdir -p $(kpsewhich -var-value=TEXMFHOME)/{doc,generic,scripts,source} && \
mkdir -p $(kpsewhich -var-value=TEXMFHOME)/bibtex/{bib,bst} && \
mkdir -p $(kpsewhich -var-value=TEXMFHOME)/fonts/{afm,map,misc,pk,source,tfm,type1} && \
mkdir -p $(kpsewhich -var-value=TEXMFHOME)/tex/{context,generic,latex,plain,xelatex,xetex} && \
mkdir -p $(kpsewhich -var-value=TEXMFHOME)/tex/latex/biblatex/{bbx,cbx}

Now that you have a TEXMFHOME folder set up, you can symlink Rd.sty into the appropriate place.

If you are on Mac OS X, Rd.sty should be located at:

/Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/Rd.sty

On my Ubuntu 14.04 machine, Rd.sty is located at:

/usr/share/texmf/tex/latex/R/tex/latex/Rd.sty 

You might wish to check that the file is indeed there before trying to symlink it into TEXMFHOME, which you could do by running:

[ -f /usr/share/texmf/tex/latex/R/tex/latex/Rd.sty ] && ln -s /usr/share/texmf/tex/latex/R/tex/latex/Rd.sty $(kpsewhich -var-value=TEXMFHOME)/tex/latex/ || echo 'File does not exist'
Adam Liter
  • 12,567