0

The following code block,

#+NAME: fib-recur
#+CAPTION: Recursive Python function to calculate $n^{th}$ Fibonacci number.
#+BEGIN_src python :results output
def fib(n):
  if n == 0: return 0
  if n == 1: return 1
  return fib(n - 1) + fib(n - 2)
print(fib(20))
#+END_src

Translates to the following LaTeX code,

\lstset{language=Python,label= ,caption= ,captionpos=b,numbers=none}
\begin{lstlisting}
def fib(n):
  if n == 0: return 0
  if n == 1: return 1
  return fib(n - 1) + fib(n - 2)
print(fib(20))
\end{lstlisting}

Notice how it has used \lstset{...} right before the lstlisting environment? Is there a way to not do that? And instead pass the optional arguments using \begin{lstlisting}[language=Python]? And only those that are provided? I am using a LaTeX class that has some lstlisting styling defined by using \lset in the class .cls file. However, org's behaviour of defining a new \lset before each lstlisting overrides the class's definition, e. g., the class says \lstset{...,numbers=left,...} but org undesirably overrides it each time with \lstset{...,numbers=none}. To remedy that I have to add #+ATTR_LATEX: :options numbers=left to each code block.

Therefore, can we adjust or only set the optional arguments provided and leave others alone?

Your Answer

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

Browse other questions tagged or ask your own question.