# Change location of latex options (\bibliography{}) in exported .tex file

I just spend hours trying to figure out why bibtex citations don't work. Turns out it's because \bibliography{testbib} needs to come after begin{document}.

This is my test.org:

#+LATEX_HEADER: \usepackage{natbib}
#+LATEX_HEADER: \bibliographystyle{plainnat}

* Test
This is a test. \citep{Nobody06}

#+LATEX_HEADER: \bibliography{testbib}


This is the generated test.tex (only the relevant parts):

% Created 2018-11-01 Thu 13:28
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
[ ... ]
\usepackage{natbib}
\bibliographystyle{plainnat}
\bibliography{testbib}
[ ... ]
\section{Test}
\label{sec:orgfb2727b}
This is a test. \citep{Nobody06}
\end{document}


Manually changing the file to this:

% Created 2018-11-01 Thu 13:28
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
[ ... ]
\usepackage{natbib}
\bibliographystyle{plainnat}
[ ... ]
\section{Test}
\label{sec:orgfb2727b}
This is a test. \citep{Nobody06}
\bibliography{testbib}
\end{document}


Fixes the issue so that I can run the pdflatex and bibtex commands to generate the references in the final pdf file.

Is there some way I can force the line \bibliography{testbib} to be inserted in the right spot from within Emacs? I.e. so that I can just run C-c C-e l p to export a pdf without having to manually run pdflatex and bibtex?

## 1 Answer

Why don't you just put the \bibliography{} line at the end of your org-file where you want it? I usually do that, and put the bibliographystyle line right above it.

If you are trying to get org-mode to automatically compile your pdf with bibtex, you may need to configure the org-latex-pdf-process variable. See

https://github.com/jkitchin/org-ref/blob/master/org-ref.org#latex-export

for some examples of how to do that.

• It had to be something so obvious of course... Removing the #+LATEX_HEADER: and changing the Latex Run Command to pdflatex solved the problem. Thanks a lot! – user20726 Nov 1 '18 at 13:19