[Tex/LaTex] Emacs org-mode minted export with #+ATTR_LATEX

emacsminted

When I try to export a file like this:

#+LaTeX_CLASS: tufte

#+ATTR_LaTeX: :float t :options label={test}
#+begin_src c
    #include <iostream>
    using namespace std;

    int main() {
        cout << "Hello world!" << endl;
        return 0;
    }
#+end_src

The options attribute is ignored (it does not go the the generated tex file) and only the default options are passed:

\begin{listing}[H]
\begin{minted}[frame=lines, linenos=true]{c}
#include <iostream>
using namespace std;

int main() {
    cout << "Hello world!" << endl;
    return 0;
}
\end{minted}
\end{listing}

Any idea why? My org version is 8.2.7c.

Edit: my setup for this:

#+begin_src emacs-lisp
  (require 'ox-latex)
  (require 'org-latex)
  (add-to-list 'org-latex-packages-alist '("" "minted"))

  (setq org-latex-listings 'minted)

  (setq org-latex-minted-options
        '(("frame" "lines") ("linenos=true")))

  (setq org-latex-pdf-process (list "latexmk -pdf %f"))
#+end_src


** Tufte
#+begin_src emacs-lisp
(add-to-list 'org-latex-classes
               `("tufte"
                 "\\documentclass{tufte-handout}"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" "\\newpage" "\\subsection*{%s}" "\\newpage")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}" . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
               )
#+end_src

Best Answer

Lucas, I myself don't use org-mode, but if I were to have, as an example, the first MWE in your question, and add #+NAME, to the following line after #+ATTR_LaTeX: subsequently followed by whatever name, you want to reference the label to, the document compiles fine, as long as one of the three classes, that is, report, book or article are specified in #+LaTeX_CLASS, instead of tufte.

EDIT: Second edit. Yes Lucas. The options, the environment, the non-environment, and everything in between, gets passed along, once the options, the environment, the non-environment, and everything in between is loaded by the initialization file.

So, to get the minted options, the right default options, and the right environment to get the options, the initialization file needs to have at least:

  (setq org-latex-listings 'minted)
  (setq org-latex-minted-options
     '(("frame" "lines") ("linenos=true")))

So that gives you:

  \begin{listing}[H]
  \begin{minted}[frame=lines,linenos=true]{c}
  #include <iostream>
  using namespace std;

  int main() {
    cout << "Hello world!" << endl;
    return 0;
  }
  \end{minted}
  \label{ref:sourC}
  \end{listing}

So for example:

  #+LaTeX_CLASS: book

  #+ATTR_LaTeX: :float t :options label={test}
  #+NAME: ref:source 
  #+begin_src c
      #include <iostream>
      using namespace std;

      int main() {
          cout << "Hello world!" << endl;
          return 0;
      }


  #+end_src

Gives you a tex file with the following lines:

  \begin{figure}[H]
  \begin{verbatim}
  #include <iostream>
  using namespace std;

  int main() {
    cout << "Hello world!" << endl;
    return 0;
  }
  \end{verbatim}\label{ref:source}

  \end{figure}