knitr and biblatex

I'd like to create a PDF report with knitr with LaTeX-code in RStudio with biblatex for citations. However, the in-text-citations are always undefined and no bibliography is printed. The same bibliography works perfectly with a pure .tex-document stored in the same folder and containing the same citations, same path to the .bib-file etc. However, as for all references (also with hyperref) I have to compile twice. I thought this might be the problem with knitr (that the compilation is run only once), but the hyperref-references to figures work well. Any idea what might go wrong with the bibliography when using knitr and how I can solve the problem?



\usepackage[style=authoryear-comp, maxnames=1, bibencoding=utf8, backend=biber]{biblatex}


According to the literature \parencite{gonzalez2003} we can assume...



From the log-file:

Package biblatex Warning: Please (re)run Biber on the file:
(biblatex)                mwe
(biblatex)                and rerun LaTeX afterwards.


RStudio allows you to use a custom LaTeX program with that

  • you can set up a script that does the proper processing
  • there are automatic solutions for this, e.g. latexmk, like so: Sys.setenv(RSTUDIO_PDFLATEX = "/Library/TeX/texbin/latexmk") (or whatever you path may be)

Another option is that RStudio allows to specify build tools for a project. This may be

  • either a Makefile
  • or again a custom script

In addition, you may want to tell the RStudio developers about the need to have a bibliography in Sweave documents. You can tell them that I'd need it, too :-)

I think that the problem is in your backend, because Rstudio uses texi2dvi to write pdf and then it does not know about biber.

Try to change:




in the preamble.

Normally this work.

Even though the question was asked long ago, any reader in the future might find this useful:

It is actually really easy to produce a PDF with knitr with LaTeX-code in RStudio with biblatex for citations.

You have to use the option bib_engine = "biber" from the package tinytex::latexmk within knitr::knit2pdf.

Just like here: knitr::knit2pdf(file.Rnw, bib_engine = "biber")

This kinda works when I press the compile button twice. It is just an ugly system call to biber.

@misc{Doe,author={John Doe},title={Title}}

Test \cite{Doe}


system(paste("biber", sub("\\.Rnw$", "", current_input())))

The standard procedure for getting citations to work properly is that you have to:

1) Run LaTeX

2) Run BibTex

3) Run LaTeX

4) Run LaTeX

One option is to use the command texify, others use a makefile. I am not entirely sure about what knitr runs, but probably it does not run the sequence enough. Personally, I use Emacs with ESS, combined with AuCTeX; it really works well for me.

P.S. I don't think you need to specify that it's a .bib file.

It's an old question, which has no standard solution yet which I know of. (If I am wrong I would be pleased to be pointed to a better solution.)

I got the following to work with rstudio, knitr, biblatex, and biber. It probably only works for linux, but could possibly be adapted to other systems.

  1. create a wrapper file with the following content:

#!/usr/bin/bash /usr/bin/latexmk -pv- -quiet -pdf -xelatex $@

Let's assume, you called the file ~/bin/ Make sure to use the correct path to bash which might be /bin/bash on your machine. The command line options to latexmk could be shortened I guess.

  1. Make the file (~/bin/rstudiolatex) executable.

  2. add the following line to the R startup ~/.Rprofile:

Sys.setenv(RSTUDIO_PDFLATEX = "/your/path/to/")

Make sure to insert your proper path to

Need Your Help

NSTextView syntax highlighting

objective-c cocoa syntax-highlighting nstextview

I'm working on a Cocoa text editor which uses an NSTextView. Is it possible to change the color of certain portions of the text?

Could not load file or assembly System.Data.SqlClient, Version= when I use System.Data.SqlClient Version 4.4.3

c# azure-devops azure-web-sites .net-standard-2.0

I use System.Data.SqlClient Version 4.4.3 for all .NET Standard 2.0 class libraries in my ASP.NET Core 2.0 project. Why do I get