I can't tell in what update exactly did this happen but since not so long ago Org adds a label{orgsrcblock#}
to custom listings environments. Unfortunately, I can't find a way to tell listings to ignore this line, and it gets printed together with the source code. Here's an example:
#+BEGIN_SRC emacs-lisp :exports none
(setq org-latex-pdf-process
'("latexmk -pdflatex='pdflatex -shell-escape -interaction nonstopmode' -pdf -f %f")
org-latex-listings t
org-src-fontify-natively t
org-latex-custom-lang-environments '((maxima "maxima"))
org-babel-latex-htlatex "htlatex")
(defmacro by-backend (&rest body)
`(cl-case (when (boundp 'backend) (org-export-backend-name backend))
,@body))
#+END_SRC
#+BEGIN_LATEX
\definecolor{codebg}{rgb}{0.96,0.99,0.8}
\lstnewenvironment{maxima}{%
\lstset{%
backgroundcolor=\color{codebg},
aboveskip=20pt,
captionpos=b,
showstringspaces=false,
frame=single,
framerule=0pt,
basicstyle=\ttfamily\scriptsize,
columns=fixed}}{}
}
#+END_LATEX
then somewhere later:
*Solution:*
#+NAME: prob3
#+HEADER: :exports both
#+BEGIN_SRC maxima :results output raw
n: 4;
tex(sum(binomial(n, i) * 3^i * (-2)^(n - i), i, 0, n));
#+END_SRC
results in LaTeX code:
\textbf{Solution:}
\begin{maxima}
n: 4;
tex(sum(binomial(n, i) * 3^i * (-2)^(n - i), i, 0, n));
\label{orgsrcblock1}
\end{maxima}
and is displayed as:
The relevant part of Org code which generates this is:
org-latex-src-block
in ox-latex.el
;; Case 2. Custom environment.
(custom-env
(let ((caption-str (org-latex--caption/label-string src-block info)))
(format "\\begin{%s}\n%s\\end{%s}\n"
custom-env
(concat (and caption-above-p caption-str)
(org-export-format-code-default src-block info)
(and (not caption-above-p) caption-str))
custom-env)))
(setq org-latex-prefer-user-labels t)
. Does that fix it?\label{my-label}
. A bit more complicated than that, Org will try in order::custom_id
,:target
and:name
properties of the code block, but I need to have:name
set.