reddit / emacs

Export a babel block code with same settings for LaTex lstlisting

maxle0312 · 2022-03-25 10:50
Apologize if the title is not as clear. I have an org file, it includes the `listing` package, and setup its own `lstlisting`: #+LATEX_HEADER: \usepackage{listings} #+LATEX_HEADER: \lstdefinestyle{BashInputStyle}{language=bash,basicstyle=\large\ttfamily, numbers=left,numberstyle=\tiny,numbersep=3pt,frame=tb} Normal include code from outside #+BEGIN_EXPORT latex \lstinputlisting[language=Python,style=BashInputstyle]{hello.py} #+END_EXPORT which renders like this: ​ https://preview.redd.it/csk8azf2eip81.png?width=806&format=png&auto=webp&s=555cd95538074f5ad7316b5446e89901f3342a3c I use this to include long code block, it has its own file outside of org mode. For short codes, I tried to use org babel. I want this org babel, when exported, to have the same listing style as above, when you include from outside. [This](https://emacs.stackexchange.com/questions/36715/orgmode-is-it-possible-to-group-options-and-pass-them-to-latex-listings) answer suggests doing: #+LATEX_HEADER: \usepackage{listings} #+LATEX_HEADER: \lstdefinestyle{BashInputStyle}{language=bash,basicstyle=\large\ttfamily, numbers=left,numberstyle=\tiny,numbersep=3pt,frame=tb} Normal include code from outside #+BEGIN_EXPORT latex \lstinputlisting[language=Python,style=BashInputstyle]{hello.py} #+END_EXPORT Now org babel block #+ATTR_LATEX: :options style=BashInputStyle #+BEGIN_SRC bash echo "hello world" #+END_SRC I tried and got error, in fact it rendered incorrectly. This is my [log](https://pastebin.com/Er1vfpLG) and resulting [tex](https://pastebin.com/V4YfVU5z) file. ​ https://preview.redd.it/f4tymzymeip81.png?width=787&format=png&auto=webp&s=d8955e95c2a5b4eed7ba1805868934380c414136 Is it possible to have the include code and the org babel code to have consistent style?
maxle0312 · 2022-03-25 12:29
UPDATE: So I mess with the .tex output file (linked in original post). The .tex file has the bash script part like this: \begin{minted}[breaklines=true,breakanywhere=true,style=BashInputStyle]{bash} echo "hello world" \end{minted} Not sure why it is `minted` , I had to rewrite it like this: \begin{lstlisting}[style=BashInputStyle] echo "hello world" \end{lstlisting} This would give correct format. But I had to go to a .tex file, change stuff, compile the .tex file again. Perhaps, the org block 's header was not written correctly? Please let me know.
h-m-b-tu · 2022-03-25 13:06
You need to set `org-latex-listings` to `t`.
maxle0312 · 2022-03-25 13:38
Thank you so much ! I didnt even think of that, my was set to "minted" so I set it to "listing"