I'm exporting an ORG file to LaTeX with org-latex-listings
set to t
. The file contains some source listings, and I want to insert some references to them.
In the generated TEX file, the reference names included in \ref
seems to be translated by org-mode, but the label
option of \lstset
is keept as is. This way, pdflatex
can't find the correct reference and gives the message LaTeX Warning: There were undefined references.
Here is an example of a MWE:
#+latex_header: \usepackage{listings}
First simple java program in listing [[thesourcelisting]]
#+name: thesourcelisting
#+caption: Simple java program
#+BEGIN_SRC java
public static void main(String[] args){
System.exit(0);
}
#+END_SRC
When exported as a LaTeX file (C-c
C-e
l
t
), I got
% Created 2016-10-18 mar 14:50
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\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{listings}
\author{alvaro}
\date{\today}
\title{}
\hypersetup{
pdfauthor={alvaro},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 25.1.2 (Org mode 8.3.6)},
pdflang={English}}
\begin{document}
\tableofcontents
First simple java program in listing \ref{orgsrcblock1}
\lstset{language=java,label=thesourcelisting,caption={Simple java program},captionpos=b,numbers=none}
\begin{lstlisting}
public static void main(String[] args){
System.exit(0);
}
\end{lstlisting}
\end{document}
The original name thesourcelisting
is translated to orgsrcblock1
in the \ref
command, but not in the \lstset
command.
I'm using GNU Emacs 25.1.2.