Question: 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?

MWE:

```
\documentclass{article}

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

\begin{document}

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

\printbibliography

\end{document}

```

From the `log`-file:

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

```

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

```
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{Doe,author={John Doe},title={Title}}
\end{filecontents}
\usepackage[backend=biber]{biblatex}
\addbibresource{\jobname.bib}
\begin{document}

Test \cite{Doe}

\printbibliography
\end{document}

<<biber>>=
system(paste("biber", sub("\\.Rnw$", "", current_input())))
@

```
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/rstudiolatex.sh`. 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.

2. Make the file (`~/bin/rstudiolatex`) executable.
3. add the following line to the R startup `~/.Rprofile`:

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

Make sure to insert your proper path to `rstudiolatex.sh`.