1

I have got an Org buffer like

#+LaTeX_CLASS_OPTIONS: [a4paper]
#+LATEX_HEADER: \usepackage{listings}
* How to group ATTR_LATEX options?
#+ATTR_LATEX: :options language=bash,basicstyle=\small\ttfamily, numbers=left,numberstyle=\tiny,numbersep=3pt,frame=tb
This is a demo of what the listings package produce.
#+BEGIN_SRC sh
echo "hello world"
#+END_SRC

Which I can export to LaTeX. However, I would like to group the options passed to the LaTeX listings by defining a macro for the lstlisting environment. For example, I want Org Mode to generate something like :

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstdefinestyle{BashInputStyle}{
    language=bash,
    basicstyle=\small\ttfamily,
    numbers=left,
    numberstyle=\tiny,
    numbersep=3pt,
    frame=tb
}
\begin{document}
\section{How to group ATTR\(_{\text{LATEX}}\) options?}
This is a demo of what the listings package produce.
\begin{lstlisting}[style=BashInputStyle]
echo "hello world"
\end{lstlisting}
\end{document}

I am able to get the lstdefinesstyle into the LaTex buffer with:

#+LATEX_HEADER: \lstdefinestyle{BashInputStyle}{language=bash,basicstyle=\small\ttfamily, numbers=left,numberstyle=\tiny,numbersep=3pt,frame=tb}

However, I do not know what do to go get that definitions exported to \begin{lstlisting}[style=BashInputStyle]. Any advice ?

2

The org manual suggests doing it as follows, passing the options via a #+ATTR_LATEX: tag just before the source block.

#+LaTeX_CLASS_OPTIONS: [a4paper]
#+LATEX_HEADER: \usepackage{listings}
#+LATEX_HEADER: \lstdefinestyle{BashInputStyle}{language=bash,basicstyle=\small\ttfamily, numbers=left,numberstyle=\tiny,numbersep=3pt,frame=tb}

* How to group ATTR_LATEX options?

This is a demo of what the listings package produce.
#+ATTR_LATEX: :options style=BashInputStyle
#+BEGIN_SRC bash
echo "hello world"
#+END_SRC

Sample output

Note that org writes out a new \lstset before each listing regardless of whether you specify options or not. This means the above settings apply just to the one given listing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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