I would like to write in Hebrew in an .Rnw
file, and use it with RStudio.
Searching around, I found an example for using Hebrew in LaTeX in general:
Numbers, punctuation and parenthesis reversed in RTL…
But when I try running the example from above in an RStudio session, I get a bunch of errors. e.g:
Sweave('aaa2.Rnw') Writing to file aaa2.tex
Processing code chunks with options ...
You can now run (pdf)latex on 'aaa2.tex'
Warning messages:
1: 'aaa2.Rnw' has unknown encoding: assuming Latin-1
2: invalid char string in output conversion
Running texi2dvi...
Error: running 'texi2dvi' on 'aaa2.tex' failed
LaTeX errors:
! ! The fontspec package requires either XeTeX or LuaTeX to function. ! The fontspec package requires either XeTeX or LuaTeX to function. ! ! ! You must change your typesetting engine to, e.g., "xelatex" or "lualatex" ! You must change your typesetting engine to, e.g., "xelatex" or "lualatex" ! instead of plain "latex" or "pdflatex". ! instead of plain "latex" or "pdflatex". ! ! ! See the fontspec documentation for further information. ! See the fontspec documentation for further information. ! ! ! For immediate help type H ! For immediate help type H |''''''''''''''''''''''''''''''''''''''''''''''' | This is a fatal error: LaTeX will abort |...............................................
In addition: Warning message:
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "aaa2.tex" -I "d:/R/R-214~1.0/share/texmf/tex/latex" -I "d:/R/R-214~1.0/share/texmf/bibtex/bst"' had status 1
Any suggestions?
Best Answer
There's no completely simple way to do this within RStudio. The reason for this is that the
compiledPdf
command that RStudio provides usestexi2dvi
to compile the LaTeX file generated bySweave
, andtexi2dvi
knows nothing aboutxelatex
, which is what you should be using for your Hebrew documents. So the solution is to runSweave
manually from within RStudio, and then runxelatex
from the console. To get you started, here's a test document that I had lying around for a separate question here on the site that I have adapted for use with Hebrew.Update The development version of RStudio (versions > 0.96.48) now supports XeLaTeX.
Rnw file (assume name is
sweave-test.Rnw
)Open this document within RStudio, and then run Sweave on it:
This should then exit with the following message:
Now you need to run
xelatex
(notpdflatex
) on the resultant.tex
file. Assuming your system is set up to run correctly from the command line, this is probably easiest to do by opening a Shell window from within RStudio, and then running the command from there.Then you will need to open the resulting
.pdf
file with your favourite viewer. Since the latest stable release of RStudio isn't very customizable, I don't think there's a simple way around this. I don't use RStudio myself, though; on a Mac I can run Sweave files directly from within my LaTeX IDE (TeXShop).Using XeLaTeX with later versions of RStudio
Currently version 0.96.48 of RStudio now has preferences to use XeLaTeX for Sweave compilation. In the preferences, choose XeLaTeX for compilation, and make sure the "Use texi2dvi to resolve cross references` is unchecked. Here's an image of the preference panel.
Output
Here is the output. Since I don't know Hebrew, I've just used Google translate to translate the little bit of text in the document. I'm imagine it's quite amusing.