Site icon R-bloggers

Configure Kile for knitr under GNU/Linux

[This article was first published on Rexamine » Blog/R-bloggers, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Kile – a convenient LaTeX editor – may also be used to prepare knitr-generated reports. Here is how we may make our work much more efficient with a convenient compile-on-keypress feature.

Create a bash script in your home directory, named e.g. ~/knitr-compile.sh:

#!/bin/bash
echo "Compiling $1 with LC_CTYPE=pl_PL.UTF-8..."
LC_CTYPE="pl_PL.UTF-8" Rscript -e "knitr::knit2pdf('$1')"

Give the above file EXEC perms by calling chmod 700 ~/knitr-compile.sh

Now it’s time to configure Kile:

  1. Open Settings -> Configure Kile menu
    1. Tools -> Build in the options tree
      1. Click New and set:
        Name : knitr
        Default behavior : build
        
      2. General tab:
        Command: ~/knitr-compile.sh
        Options: '%source'
        
      3. Advanced tab:
        Type: Run Outside of Kile
        Class : Compile
        Source extension: Rnw
        Target extension: pdf
        Target file: /blank/
        Relative dir: /blank/
        State: Editor
        
      4. Menu tab:
        Add tool to Build menu: Compile
    2. Automatic syntax highlighting of .Rnw sources
      Select Editor -> Open/Save in the options tree,
      and then the Modes & Filetypes tab
      Filetype: Markup/LaTeX
      add "*.Rnw" to File extensions
      
    3. Click OK
  2. Click Settings -> Configure Shortcuts (I use ALT+1)


Marek Gągolewski

To leave a comment for the author, please follow the link and comment on their blog: Rexamine » Blog/R-bloggers.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.