1

EDIT: According to a ShareLatex Github discussion, I should create a .latexmkrc file and add the following code (I tried already in the home directory but it didn't work) :

my $root_file = $ARGV[-1];

add_cus_dep( 'Rtex', 'tex', 0, 'rtex_to_tex');
sub rtex_to_tex {
    do_knitr("$_[0].Rtex");
}

sub do_knitr {
    my $dirname = dirname $_[0];
    my $basename = basename $_[0];
    system("Rscript -e \"library('knitr'); setwd('$dirname'); knit('$basename')\"");
}

my $rtex_file = $root_file =~ s/\.tex$/.Rtex/r;
unless (-e $root_file) {
    if (-e $rtex_file) {
        do_knitr($rtex_file);
    }
}

EDIT END

It is possible to use knitr on the official ShareLatex server by creating a filed called *.Rtex. I have my own ShareLatex server with R and Knitr already installed. Everything works on the command line, but when I create a *.Rtex file in my ShareLatex project, it won't compile.

Here is my error code when using this knitr code (\Sexpr{pi}) in my Rtex file.

This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex 2015.3.20)  28 MAY 2015 05:52
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**main.tex
! Emergency stop.
<*> main.tex

*** (job aborted, file error in nonstop mode)

Something very interesting is that I have no main.tex file only a main.Rtex and I declared this file in my project as main file.

0

The last time I checked, ShareLaTeX did not support .Rnw syntax, which is what you used there \Sexpr{}. The syntax for .Rtex is \rinline{}: http://yihui.name/knitr/demo/minimal/

  • Thanks for that was not the problem. It can't read Rtex files. – Jürgen Brandstetter May 29 '15 at 1:40
0

After some back and forth with the developer (James Allen), I finally made it work.

How to config the server to compile *.Rtex files

0) go to your sharelatex server (if it's a docker server use sudo docker exec -i -t sharelatex bash to connect)

1) Navigate to cd /usr/local/share/latexmk/

2) Create a file called LatexMk

3) Post the following code into it

my $root_file = $ARGV[-1];

add_cus_dep( 'Rtex', 'tex', 0, 'rtex_to_tex');
sub rtex_to_tex {
    do_knitr("$_[0].Rtex");
}

sub do_knitr {
    my $dirname = dirname $_[0];
    my $basename = basename $_[0];
    system("Rscript -e \"library('knitr'); setwd('$dirname'); knit('$basename')\"");
}

my $rtex_file = $root_file =~ s/\.tex$/.Rtex/r;
unless (-e $root_file) {
    if (-e $rtex_file) {
        do_knitr($rtex_file);
    }
}

4) Restart the server (for docker use sudo docker restart sharelatex)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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