Configure Kile for knitr under GNU/Linux

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. ~/

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 ~/

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: ~/
        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

Tagged with: , , ,
Posted in Blog/LaTeX, Blog/R-bloggers, Blog/R-knitr