# Export org-mode code blocks with minted style

I am trying to export org-mode source blocks to pdf via Latex and I use minted to get syntax highlighting. My org file looks like this:

#+latex_header: \usepackage[utf8]{inputenc} %% For unicode chars

#+latex_header: \usemintedstyle{monokai}    %% sets default for all source-code blocks
#+latex_header: \definecolor{dark}{HTML}{272822}   %% custom colour for background

#+attr_latex: :options bgcolor=dark
#+BEGIN_SRC bash -i
rosrun rosbag topic_renamer.py <in topic> <in bag> <out topic> <out bag>
#+END_SRC


I read on this latex thread, that I have to manually specify the background colour, which is why I use that additional #+attr_latex: specifying bgcolor. That definitely does seem to help, but I cannot get the bash language to be correctly coloured. I get black text on the manually applied dark background:

So it seems the colour of the text is somehow affected by the bgcolor I manually apply to the source-block.

If I change the language, e.g. to c, I get something more like what I expect (which also happens to look pretty cool!):

#+attr_latex: :options bgcolor=dark
#+BEGIN_SRC c -i
rosrun rosbag topic_renamer.py <in topic> <in bag> <out topic> <out bag>
#+END_SRC


trying to set the style manually for the source-block also doesn't seem to help. Using this:

#+attr_latex: :options style=monokai, bgcolor=dark
#+BEGIN_SRC bash -i
rosrun rosbag topic_renamer.py <in topic> <in bag> <out topic> <out bag>
#+END_SRC


makes no difference, and I get the same as above, without the style option:

I can see in the generated tex files that options are being passed correctly to the minted block:

\begin{minted}[breaklines=true,breakanywhere=true,bgcolor=dark]{shell}
rosrun rosbag topic_renamer.py <in topic> <in bag> <out topic> <out bag>
\end{minted}


I have the following setup in my init file:

(setq org-latex-listings 'minted
org-latex-packages-alist '(("newfloat" "minted"))
org-latex-pdf-process
'("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))


which was taken from here.

I have tried looking in the list of language names to language modes (a mapping) that org-mode maintains, and see that bash was there, I also added (shell shell) so the name "shell" is mapped the shell-mode. Otherwise I don't really know where to start

EDIT:

Output when editing the .tex file and compiling in terminal:

\begin{minted}[style=monokai,bgcolor=dark]{bash}
#!/usr/bin/bash
for (( i=0; i != 10; i=i+1)); do
echo \$i
done
\end{minted}


some text remains dark and un-readable

• I do not use minted nor pygments. Nevertheless from pygments.org/demo I would have expected bash as language specifier for the minted LaTeX environment but you get shell which is not present in the Select a lexer box at pygments.org/demo. Maybe the mapping of bash source blocks to shell source blocks is the actual problem. Try to replace shell by bash in the LaTeX source file and to run pdflatex for that file. – Tobias Jul 19 '18 at 16:48
• I have tried both of them, to no avail. I also added special mappings between all combinations I thought reasonable via org-latex-listings-langs, but this also didn't help anything. As the tex file itself (when altered manually) isn't producing the expected output, I am starting to think the problem lies with tex/minted/pygments - not org-mode. – n1k31t4 Jul 19 '18 at 17:42
• Use an example which should have a prominent highlighting such as the linked bash script and try to get that highlighting with LaTeX. – Tobias Jul 19 '18 at 18:17
• It looks like LaTeX shell-escape and python are working since you get highlighting for the C example. Maybe you should also try an extended C example, for an instance a helloWorld.c code. – Tobias Jul 19 '18 at 18:26
• I tried them, compiling the tex file from terminal, and the style is not taken... I have \usemintedstyle{monokai} i.e. a dark theme in the pre-amble, however teh background is light and the text is dark. If I then force a dark background, the font colours remain the same as before, but it doesn't match the example from the pygments demo (see the added picture in my edit above). It is better than what org-mode manages, but still not right. I tried both bash and shell as languages, both giving that same result. – n1k31t4 Jul 20 '18 at 8:45