5

When I export an Emacs OrgMode buffer like:

#+LATEX_HEADER: \usepackage{listings}
* How to pass options to LaTex listings?
#+ATTR_LATEX: :options [numbers=left]
#+BEGIN_SRC sh
echo "hello world"
#+END_SRC

the exported LaTex buffer does not contain the numbers=left but the default numbers=none.

...snip
\usepackage{listings}
\date{\today}
\title{demo-listings-2}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 24.5.1 (Org mode 8.2.10)}}
\begin{document}

\maketitle
\tableofcontents

\section{How to pass options to LaTex listings?}
\label{sec-1}
\lstset{language=sh,label= ,caption= ,numbers=none}
\begin{lstlisting}
echo "hello world"
\end{lstlisting}
% Emacs 24.5.1 (Org mode 8.2.10)
\end{document}

I expected the ATTR_LATEX: :options [numbers=left] to override the default value.

The only LaTex configuration I have in the .emacsfile is:

(require 'ox-latex)
(setq org-latex-listings t)

Any idea of what I am missing or doing wrong ?

2 Answers 2

2

You have to use #+ATTR_LATEX: :options numbers=left (without the []). More options can be separated by commas: :options numbers=left, captionpos=b.

3
  • Thanks for taking the time to answer. I tried your suggestion, but the result is the same. I am not able to override the default value. Commented Nov 6, 2017 at 20:39
  • I have Emacs 25.3.2 (Org mode 9.1.2), maybe you could consider to upgrade.
    – rvf0068
    Commented Nov 6, 2017 at 22:40
  • 1
    Thanks again! I tried with a default Ubuntu 17.10 distro, {Emacs 25.2.2 (Org mode 8.2.10)}} and got the same results. I upgraded the Org mode to {Emacs 25.2.2 (Org mode 9.1.2)} and now it works. Thanks for the help! Commented Nov 7, 2017 at 7:10
2

For numbered listings specifically, you'll need to add "-n" to your source block's header:

#+begin_src sh -n
echo "hello world"
#+end_src

Exports as:

1 echo "hello world"

1
  • This does work for me. I had been trying to include line numbers for my source code blocks in my Org mode's exports to LaTex, and then to PDF.
    – Punit Arya
    Commented Oct 19, 2023 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.