2012-03-12 31 views
3

我有一個org-mode文檔,我想將其導出爲PDF。我使用的乳膠上市軟件包生成格式良好的代碼清單,這看起來像這樣的組織:防止組織模式將評論翻譯爲分項環境

#+BEGIN_LaTeX 
\begin{lstlisting}[language=Java] 
    /** Comment comment comment 
    * 
    * blah blah blah 
    * 
    * @return comment 
    */ 
    public void foo() { 
     return; 
    } 
\end{lstlisting} 
#+END_LaTeX 

javadoc註釋也正在組織翻譯成乳膠itemize環境,就像這樣:

\begin{lstlisting}[language=Java] 
    /** Comment comment comment 
\begin{itemize} 
\item 
\item blah blah blah 
\item 
\item @return comment 
\end{itemize} 
    */ 
    public void foo() { 
     return; 
    } 
\end{lstlisting} 

如何防止發生這種情況並保留Javadoc,正如我最初編寫的那樣?如果我使用#+BEGIN_SRC而不是#+BEGIN_LaTeX,我回到的是verbatim環境,但是我想堅持使用列表而不是verbatim,或者因爲我已經盡力爲它設置一組不錯的樣式。

回答

6

你最終想要的是literal example。本質上你希望代碼能夠被導出,但是需要完成。您需要告知org-mode在出口時使用列表(或鑄造)。你可以在你的.emacs完成文件:

;; tell org to use listings with colors              
(setq org-export-latex-listings t) 
(add-to-list 'org-export-latex-packages-alist '("" "listings")) 
(add-to-list 'org-export-latex-packages-alist '("" "color")) 

而且,有了這個,你並不需要在頭參數文檔指定listings包。現在,源代碼塊將在適當的lstlistings環境導出:

#+begin_src java                 
    /** Comment comment comment             
    *                    
    * blah blah blah                
    * @return comment                
    */                   
    public void foo() {               
    return;                 
    }                    
#+end_src 

獲得出口到膠乳

\lstset{language=java} 
\begin{lstlisting} 
/** Comment comment comment 
* 
* blah blah blah 
* @return comment 
*/ 
public void foo() { 
    return; 
} 
\end{lstlisting} 

我不明白爲什麼,當您使用#+begin_latex ... #+end_latex在你的例子中阻止事情得到奇怪的解析。原則上,希望將LaTeX塊中的任何內容原樣傳遞給.tex文件。

+0

太棒了,謝謝! – snim2 2012-03-13 08:10:28

+1

LaTeX塊不會完全忽略組織模式語法。它充當了一種混合模塊。我記不清什麼是和沒有轉換的具體細節,但我相信大膽/下劃線/斜體仍然使用通常的組織模式轉義處理。這似乎也是列表(導出不正確的行都是Org中的有效列表元素) – 2012-03-14 12:53:40