latexorg-modepdflatexlatexmk

Table label reference breaks when using \addbibresource in Latex export in orgmode


When I export to latex the following simple file:

#+Title: Example
#+OPTIONS: H:2 ^:{} f:t toc:nil author:nil
#+LATEX_HEADER: \usepackage[backend=bibtex]{biblatex}
#+LATEX_HEADER: \addbibresource{$HOME/Bibliographies/bibliography}
#+LATEX_HEADER: \graphicspath{{$HOME/Pictures/images/}}
# #+BIBLIOGRAPHY: ~/Bibliographies/bibliography
# #+BIBLIOGRAPHY_STYLE: plain



* Foo
   #+CAPTION: Capitals
   #+NAME: tab:capitals
   | Country   | Capital  |
   |           |          |
   |-----------+----------|
   | Australia | Canberra |
   | Japan     | Tokyo    |
   | France    | Paris    |

* Bar 
  Please look this flamboyant table: Table [[tab:capitals]].

I get a result where the reference [[tab:capitals]] is renderd with "??" in latex, instead of "1".

I noticed that it works ok if I remove the #+LATEX_HEADER: \addbibresource{$HOME/Bibliographies/bibliography} line, but I need it for my bibliography and citations.

The variable org-latex-pdf-process is set to (list "latexmk -pdf -shell-escape %f") in my configuration. This is the .tex produced

% Created 2020-06-23 Tue 16:56
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\usepackage[backend=bibtex]{biblatex}
\graphicspath{{$HOME/Pictures/images/}}
\date{\today}
\title{Example}
\hypersetup{
 pdfauthor={Adam Oudad},
 pdftitle={Example},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 26.3 (Org mode 9.1.2)}, 
 pdflang={English}}
\begin{document}

\maketitle



\section{Foo}
\label{sec:org66385f7}
\begin{table}[htbp]
\caption{\label{tab:org2e022f6}
Capitals}
\centering
\begin{tabular}{ll}
Country & Capital\\
 & \\
\hline
Australia & Canberra\\
Japan & Tokyo\\
France & Paris\\
\end{tabular}
\end{table}

\section{Bar}
\label{sec:org22f0231}
Please look this flamboyant table: Table \ref{tab:org2e022f6}.
\end{document}

The reference and label match in the tex file, but still fail to produce a correct pdf output. What is the link between \addbibresource and reference to table producing this? Thanks for help :)


Solution

  • My setting of org-latex-pdf-process was the culprit:

    (setq org-latex-pdf-process (list "latexmk -pdf -shell-escape %f"))
    

    It was set like this because I had bibtex citations not working, and had this workaround from somewhere... But this broke reference to tables.

    So to fix this, I went back to the original value in emacs documentation:

    (setq org-latex-pdf-process
     '("%latex -interaction nonstopmode -output-directory %o %f"
     "%latex -interaction nonstopmode -output-directory %o %f"
     "%latex -interaction nonstopmode -output-directory %o %f"))
    

    However this does not run bibtex. So to get citations to work, I need to add "bibtex %b" between calls to latex compiler:

    (setq org-latex-pdf-process
     '("%latex -interaction nonstopmode -output-directory %o %f"
     "bibtex %b"
     "%latex -interaction nonstopmode -output-directory %o %f"
     "%latex -interaction nonstopmode -output-directory %o %f"))
    

    Thanks to @Dieter.Wilhelm 's solution from this thread!

    Link to my config here.