8

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
5
  • What is your org-mode set-up for the tufte class etc.? Sep 11, 2014 at 20:29
  • @AndrewSwann I have updated the question. Sep 11, 2014 at 20:36
  • Lucas so far the only classes it identifies, are: report book article. And I assume there's no way you could work around that? I compiled the above, with all them classes. And everything seemed good to me. .. as of today, the file ox-latex is the one you should blame. I haven't had time to change it directly, as it requires some time to compile. I also have to deal with the fact, not to be oblivious to the last touch, these files undergo, to understandable compressing measures, during compilation. If I were you, since you particularly need that class, ...
    – doed
    Sep 23, 2014 at 8:57
  • I'd request such a feature. Or work around with the tex file, that report, book, and article compile with C-c C-e l l
    – doed
    Sep 23, 2014 at 8:58
  • @doed even with the article, book or report classes the exported code goes without the label. what i've been doing is exporting the file to tex as you mentioned and then going one listing at a time and adapting. Sep 23, 2014 at 16:45

2 Answers 2

4

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}
7
  • However that is not what I need :( It should "caption" a minted source code, which it doesn't. Sep 26, 2014 at 19:51
  • Lucas, I honestly can't believe you are still stuck on the issue. Lucas. How would you expect to have the options, let alone the environment, unless it is loaded in the init file to start with... that's like saying what's wrong with my emacs. let me update the answer.
    – doed
    Sep 27, 2014 at 11:46
  • doed, perfect. everything you said is correct. however, the minted source should have a caption in it, and that cannot go on the config file, as the caption is not constant. that is the problem. my config generates the correct code apart from this... Sep 27, 2014 at 12:19
  • 1
    Lucas, then just add a #+CAPTION: caption
    – doed
    Sep 27, 2014 at 12:27
  • that does not work. the minted label, or any other option passed in the options command js ignored Sep 27, 2014 at 12:47
0

According to the description of org-latex-listings, you also need to configure org-latex-pdf-process to pass the -shell-escape option. The following works for me:

(setq org-latex-pdf-process
      (mapcar
       (lambda (s)
         (replace-regexp-in-string "%latex " "%latex -shell-escape " s))
       org-latex-pdf-process))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .