all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] fontified source-code on latex export with listings package
@ 2009-08-08 18:59 Eric Schulte
  2009-08-09 10:13 ` Carsten Dominik
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Eric Schulte @ 2009-08-08 18:59 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1141 bytes --]

Hi,

The attached patch allows for fontified source code blocks on export to
LaTeX.  It does this using the 'listings' latex package.  A new variable
is introduced; `org-export-latex-listings' which should be set to
non-nil for source-code to be exported as listings blocks.  This
variable defaults to nil in which case the current practice of exporting
source code to verbatim latex blocks remains unchanged.

To use this functionality add the following to your org-mode config.

--8<---------------cut here---------------start------------->8---
  ;; tell org to use listings
  (setq org-export-latex-listings t)
  
  ;; you must include the listings package
  (add-to-list 'org-export-latex-packages-alist '("" "listings"))
  
  ;; if you want colored source code then you need to include the color package
  (add-to-list 'org-export-latex-packages-alist '("" "color"))
--8<---------------cut here---------------end--------------->8---

In addition to the patch, I'm attaching an example org-mode file, along
with the generated LaTeX file and PDF file.

Do you think this would be appropriate for inclusion into org-mode?

Thanks -- Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: listings.patch --]
[-- Type: text/x-patch, Size: 2887 bytes --]

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 00fd6c8..9de5e5f 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -2204,6 +2204,8 @@ in the list) and remove property and value from the list in LISTVAR."
 (defvar htmlp)  ;; dynamically scoped
 (defvar latexp)  ;; dynamically scoped
 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
+(defvar org-export-latex-listings) ;; defined in org-latex.el
+(defvar org-export-latex-listings-langs) ;; defined in org-latex.el
 
 (defun org-export-format-source-code-or-example
   (backend lang code &optional opts indent)
@@ -2310,8 +2312,20 @@ INDENT was the original indentation of the block."
 	     ((eq backend 'latex)
 	      (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
 	      (concat "\n#+BEGIN_LaTeX\n"
-		      (org-add-props (concat (car org-export-latex-verbatim-wrap)
-					     rtn (cdr org-export-latex-verbatim-wrap))
+		      (org-add-props
+                          (if org-export-latex-listings
+                              (concat
+                               (if lang
+                                   (let* ((lang-sym (intern (concat ":" lang)))
+                                          (lstlang (or (plist-get org-export-latex-listings-langs
+                                                                  lang-sym)
+                                                       lang)))
+                                     (format "\\lstset{language=%s}\n" lstlang))
+                                 "")
+                               "\\begin{lstlisting}\n"
+                               rtn "\\end{lstlisting}\n")
+                            (concat (car org-export-latex-verbatim-wrap)
+                                    rtn (cdr org-export-latex-verbatim-wrap)))
 			  '(org-protected t))
 		      "#+END_LaTeX\n\n"))
 	     ((eq backend 'ascii)
diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index fdf9ae2..f80e221 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -69,6 +69,9 @@
 	  org-deadline-string "\\|"
 	  org-closed-string"\\)")
   "Regexp matching special time planning keywords plus the time after it.")
+(defvar org-export-latex-listings nil
+  "If non-nil then source code blocks will be fontified using the
+listings package.")
 
 (defvar latexp)    ; dynamically scoped from org.el
 (defvar re-quote)  ; dynamically scoped from org.el
@@ -297,6 +300,12 @@ Defaults to \\begin{verbatim} and \\end{verbatim}."
   :type '(cons (string :tag "Open")
 	       (string :tag "Close")))
 
+(defcustom org-export-latex-listings-langs
+  '(:emacs-lisp "lisp")
+  "Property list mapping languages to their listing language counterpart."
+  :group 'org-export-latex
+  :type 'plist)
+
 (defcustom org-export-latex-remove-from-headlines
   '(:todo nil :priority nil :tags nil)
   "A plist of keywords to remove from headlines. OBSOLETE.

[-- Attachment #3: listngs.org --]
[-- Type: application/octet-stream, Size: 1300 bytes --]

#+TITLE: experimenting with the listings package
#+OPTIONS: toc:nil num:nil ^:nil

#+begin_latex
\lstset{basicstyle=\ttfamily\bfseries\footnotesize}
\lstset{keywordstyle=\color{blue},
  commentstyle=\color{red},
  stringstyle=\color{green}
}
\lstset{numbers=left,
  numberstyle=\ttfamily\footnotesize,
  stepnumber=1,
  numbersep=10pt,
  backgroundcolor=\color{white},
}
#+end_latex


* listings in org

The following can be used to begin using the listings package to
export fontified source code blocks to LaTeX.

#+begin_src emacs-lisp :results silent
  ;; tell org to use listings
  (setq org-export-latex-listings t)
  
  ;; you must include the listings package
  (add-to-list 'org-export-latex-packages-alist '("" "listings"))
  
  ;; if you want colored source code then you need to include the color package
  (add-to-list 'org-export-latex-packages-alist '("" "color"))
#+end_src

Here is a simple ruby example.

#+begin_src ruby
  class Example
    # this is just a simple example
    def says
      puts :with_listings
    end
  end
#+end_src

Note that the indentation is removed in the above example even when
the normal =verbatim= environment is used.

** subheading
another type of code in the same file

#+begin_src emacs-lisp
  (mapcar (lambda (el) (* el el)) '(1 2 3 4))
#+end_src

[-- Attachment #4: listngs.tex --]
[-- Type: application/x-tex, Size: 1652 bytes --]

% Created 2009-08-08 Sat 12:46
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{hyperref}
\usepackage{color}
\usepackage{listings}

\title{experimenting with the listings package}
\author{Eric Schulte}
\date{08 August 2009}

\begin{document}

\maketitle


\lstset{basicstyle=\ttfamily\bfseries\footnotesize}
\lstset{keywordstyle=\color{blue},
  commentstyle=\color{red},
  stringstyle=\color{green}
}
\lstset{numbers=left,
  numberstyle=\ttfamily\footnotesize,
  stepnumber=1,
  numbersep=10pt,
  backgroundcolor=\color{white},
}


\section*{listings in org}
\label{sec-1}


The following can be used to begin using the listings package to
export fontified source code blocks to \LaTeX{}.


\lstset{language=lisp}
\begin{lstlisting}
;; tell org to use listings
(setq org-export-latex-listings t)

;; you must include the listings package
(add-to-list 'org-export-latex-packages-alist '("" "listings"))

;; if you want colored source code then you need to include the color package
(add-to-list 'org-export-latex-packages-alist '("" "color"))
\end{lstlisting}



Here is a simple ruby example.


\lstset{language=ruby}
\begin{lstlisting}
class Example
# this is just a simple example
def says
puts :with_listings
end
end
\end{lstlisting}



Note that the indentation is removed in the above example even when
the normal \texttt{verbatim} environment is used.

\subsection*{subheading}
\label{sec-1.1}

another type of code in the same file


\lstset{language=lisp}
\begin{lstlisting}
(mapcar (lambda (el) (* el el)) '(1 2 3 4))
\end{lstlisting}



\end{document}

[-- Attachment #5: listngs.pdf --]
[-- Type: application/pdf, Size: 53789 bytes --]

[-- Attachment #6: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] fontified source-code on latex export with listings package
  2009-08-08 18:59 [PATCH] fontified source-code on latex export with listings package Eric Schulte
@ 2009-08-09 10:13 ` Carsten Dominik
  2009-08-09 12:54 ` Carsten Dominik
  2009-08-09 16:48 ` Sebastian Rose
  2 siblings, 0 replies; 8+ messages in thread
From: Carsten Dominik @ 2009-08-09 10:13 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode

Hi Eric,

I would like to include your patch, this was on my todo list for a  
long time, thanks for doing it!

- Carsten

On Aug 8, 2009, at 8:59 PM, Eric Schulte wrote:

> Hi,
>
> The attached patch allows for fontified source code blocks on export  
> to
> LaTeX.  It does this using the 'listings' latex package.  A new  
> variable
> is introduced; `org-export-latex-listings' which should be set to
> non-nil for source-code to be exported as listings blocks.  This
> variable defaults to nil in which case the current practice of  
> exporting
> source code to verbatim latex blocks remains unchanged.
>
> To use this functionality add the following to your org-mode config.
>
> --8<---------------cut here---------------start------------->8---
>  ;; tell org to use listings
>  (setq org-export-latex-listings t)
>
>  ;; you must include the listings package
>  (add-to-list 'org-export-latex-packages-alist '("" "listings"))
>
>  ;; if you want colored source code then you need to include the  
> color package
>  (add-to-list 'org-export-latex-packages-alist '("" "color"))
> --8<---------------cut here---------------end--------------->8---
>
> In addition to the patch, I'm attaching an example org-mode file,  
> along
> with the generated LaTeX file and PDF file.
>
> Do you think this would be appropriate for inclusion into org-mode?
>
> Thanks -- Eric
>
> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
> index 00fd6c8..9de5e5f 100644
> --- a/lisp/org-exp.el
> +++ b/lisp/org-exp.el
> @@ -2204,6 +2204,8 @@ in the list) and remove property and value  
> from the list in LISTVAR."
> (defvar htmlp)  ;; dynamically scoped
> (defvar latexp)  ;; dynamically scoped
> (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
> +(defvar org-export-latex-listings) ;; defined in org-latex.el
> +(defvar org-export-latex-listings-langs) ;; defined in org-latex.el
>
> (defun org-export-format-source-code-or-example
>   (backend lang code &optional opts indent)
> @@ -2310,8 +2312,20 @@ INDENT was the original indentation of the  
> block."
> 	     ((eq backend 'latex)
> 	      (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont  
> rpllbl fmt))
> 	      (concat "\n#+BEGIN_LaTeX\n"
> -		      (org-add-props (concat (car org-export-latex-verbatim-wrap)
> -					     rtn (cdr org-export-latex-verbatim-wrap))
> +		      (org-add-props
> +                          (if org-export-latex-listings
> +                              (concat
> +                               (if lang
> +                                   (let* ((lang-sym (intern (concat  
> ":" lang)))
> +                                          (lstlang (or (plist-get  
> org-export-latex-listings-langs
> +                                                                   
> lang-sym)
> +                                                       lang)))
> +                                     (format "\\lstset{language=%s} 
> \n" lstlang))
> +                                 "")
> +                               "\\begin{lstlisting}\n"
> +                               rtn "\\end{lstlisting}\n")
> +                            (concat (car org-export-latex-verbatim- 
> wrap)
> +                                    rtn (cdr org-export-latex- 
> verbatim-wrap)))
> 			  '(org-protected t))
> 		      "#+END_LaTeX\n\n"))
> 	     ((eq backend 'ascii)
> diff --git a/lisp/org-latex.el b/lisp/org-latex.el
> index fdf9ae2..f80e221 100644
> --- a/lisp/org-latex.el
> +++ b/lisp/org-latex.el
> @@ -69,6 +69,9 @@
> 	  org-deadline-string "\\|"
> 	  org-closed-string"\\)")
>   "Regexp matching special time planning keywords plus the time  
> after it.")
> +(defvar org-export-latex-listings nil
> +  "If non-nil then source code blocks will be fontified using the
> +listings package.")
>
> (defvar latexp)    ; dynamically scoped from org.el
> (defvar re-quote)  ; dynamically scoped from org.el
> @@ -297,6 +300,12 @@ Defaults to \\begin{verbatim} and \ 
> \end{verbatim}."
>   :type '(cons (string :tag "Open")
> 	       (string :tag "Close")))
>
> +(defcustom org-export-latex-listings-langs
> +  '(:emacs-lisp "lisp")
> +  "Property list mapping languages to their listing language  
> counterpart."
> +  :group 'org-export-latex
> +  :type 'plist)
> +
> (defcustom org-export-latex-remove-from-headlines
>   '(:todo nil :priority nil :tags nil)
>   "A plist of keywords to remove from headlines. OBSOLETE.
> < 
> listngs 
> .org 
> > 
> < 
> listngs 
> .tex><listngs.pdf>_______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fontified source-code on latex export with listings package
  2009-08-08 18:59 [PATCH] fontified source-code on latex export with listings package Eric Schulte
  2009-08-09 10:13 ` Carsten Dominik
@ 2009-08-09 12:54 ` Carsten Dominik
  2009-08-11 13:01   ` Eric Schulte
  2009-08-09 16:48 ` Sebastian Rose
  2 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2009-08-09 12:54 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode

I have added the patch, thanks!

Eric, color setup is relative complex, which i why I don't want
to discuss this in detail in the manual.  Maybe you could write
a Worg page about this, and/or a FAQ entry?

- Carsten

On Aug 8, 2009, at 8:59 PM, Eric Schulte wrote:

> Hi,
>
> The attached patch allows for fontified source code blocks on export  
> to
> LaTeX.  It does this using the 'listings' latex package.  A new  
> variable
> is introduced; `org-export-latex-listings' which should be set to
> non-nil for source-code to be exported as listings blocks.  This
> variable defaults to nil in which case the current practice of  
> exporting
> source code to verbatim latex blocks remains unchanged.
>
> To use this functionality add the following to your org-mode config.
>
> --8<---------------cut here---------------start------------->8---
>  ;; tell org to use listings
>  (setq org-export-latex-listings t)
>
>  ;; you must include the listings package
>  (add-to-list 'org-export-latex-packages-alist '("" "listings"))
>
>  ;; if you want colored source code then you need to include the  
> color package
>  (add-to-list 'org-export-latex-packages-alist '("" "color"))
> --8<---------------cut here---------------end--------------->8---
>
> In addition to the patch, I'm attaching an example org-mode file,  
> along
> with the generated LaTeX file and PDF file.
>
> Do you think this would be appropriate for inclusion into org-mode?
>
> Thanks -- Eric
>
> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
> index 00fd6c8..9de5e5f 100644
> --- a/lisp/org-exp.el
> +++ b/lisp/org-exp.el
> @@ -2204,6 +2204,8 @@ in the list) and remove property and value  
> from the list in LISTVAR."
> (defvar htmlp)  ;; dynamically scoped
> (defvar latexp)  ;; dynamically scoped
> (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
> +(defvar org-export-latex-listings) ;; defined in org-latex.el
> +(defvar org-export-latex-listings-langs) ;; defined in org-latex.el
>
> (defun org-export-format-source-code-or-example
>   (backend lang code &optional opts indent)
> @@ -2310,8 +2312,20 @@ INDENT was the original indentation of the  
> block."
> 	     ((eq backend 'latex)
> 	      (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont  
> rpllbl fmt))
> 	      (concat "\n#+BEGIN_LaTeX\n"
> -		      (org-add-props (concat (car org-export-latex-verbatim-wrap)
> -					     rtn (cdr org-export-latex-verbatim-wrap))
> +		      (org-add-props
> +                          (if org-export-latex-listings
> +                              (concat
> +                               (if lang
> +                                   (let* ((lang-sym (intern (concat  
> ":" lang)))
> +                                          (lstlang (or (plist-get  
> org-export-latex-listings-langs
> +                                                                   
> lang-sym)
> +                                                       lang)))
> +                                     (format "\\lstset{language=%s} 
> \n" lstlang))
> +                                 "")
> +                               "\\begin{lstlisting}\n"
> +                               rtn "\\end{lstlisting}\n")
> +                            (concat (car org-export-latex-verbatim- 
> wrap)
> +                                    rtn (cdr org-export-latex- 
> verbatim-wrap)))
> 			  '(org-protected t))
> 		      "#+END_LaTeX\n\n"))
> 	     ((eq backend 'ascii)
> diff --git a/lisp/org-latex.el b/lisp/org-latex.el
> index fdf9ae2..f80e221 100644
> --- a/lisp/org-latex.el
> +++ b/lisp/org-latex.el
> @@ -69,6 +69,9 @@
> 	  org-deadline-string "\\|"
> 	  org-closed-string"\\)")
>   "Regexp matching special time planning keywords plus the time  
> after it.")
> +(defvar org-export-latex-listings nil
> +  "If non-nil then source code blocks will be fontified using the
> +listings package.")
>
> (defvar latexp)    ; dynamically scoped from org.el
> (defvar re-quote)  ; dynamically scoped from org.el
> @@ -297,6 +300,12 @@ Defaults to \\begin{verbatim} and \ 
> \end{verbatim}."
>   :type '(cons (string :tag "Open")
> 	       (string :tag "Close")))
>
> +(defcustom org-export-latex-listings-langs
> +  '(:emacs-lisp "lisp")
> +  "Property list mapping languages to their listing language  
> counterpart."
> +  :group 'org-export-latex
> +  :type 'plist)
> +
> (defcustom org-export-latex-remove-from-headlines
>   '(:todo nil :priority nil :tags nil)
>   "A plist of keywords to remove from headlines. OBSOLETE.
> < 
> listngs 
> .org 
> > 
> < 
> listngs 
> .tex><listngs.pdf>_______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fontified source-code on latex export with listings package
  2009-08-08 18:59 [PATCH] fontified source-code on latex export with listings package Eric Schulte
  2009-08-09 10:13 ` Carsten Dominik
  2009-08-09 12:54 ` Carsten Dominik
@ 2009-08-09 16:48 ` Sebastian Rose
  2 siblings, 0 replies; 8+ messages in thread
From: Sebastian Rose @ 2009-08-09 16:48 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode

Ahhh - yeees, yes, yes!

I'm looking forward to stop using my old \variable{name} stuff!!!

:)

Thanks a bunch!

  Sebastian


"Eric Schulte" <schulte.eric@gmail.com> writes:
> Hi,
>
> The attached patch allows for fontified source code blocks on export to
> LaTeX.  It does this using the 'listings' latex package.  A new variable
> is introduced; `org-export-latex-listings' which should be set to
> non-nil for source-code to be exported as listings blocks.  This
> variable defaults to nil in which case the current practice of exporting
> source code to verbatim latex blocks remains unchanged.
>
> To use this functionality add the following to your org-mode config.
>
>
>   ;; tell org to use listings
>   (setq org-export-latex-listings t)
>   
>   ;; you must include the listings package
>   (add-to-list 'org-export-latex-packages-alist '("" "listings"))
>   
>   ;; if you want colored source code then you need to include the color package
>   (add-to-list 'org-export-latex-packages-alist '("" "color"))
>
> In addition to the patch, I'm attaching an example org-mode file, along
> with the generated LaTeX file and PDF file.
>
> Do you think this would be appropriate for inclusion into org-mode?
>
> Thanks -- Eric
>
>
> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
> index 00fd6c8..9de5e5f 100644
> --- a/lisp/org-exp.el
> +++ b/lisp/org-exp.el
> @@ -2204,6 +2204,8 @@ in the list) and remove property and value from the list in LISTVAR."
>  (defvar htmlp)  ;; dynamically scoped
>  (defvar latexp)  ;; dynamically scoped
>  (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
> +(defvar org-export-latex-listings) ;; defined in org-latex.el
> +(defvar org-export-latex-listings-langs) ;; defined in org-latex.el
>  
>  (defun org-export-format-source-code-or-example
>    (backend lang code &optional opts indent)
> @@ -2310,8 +2312,20 @@ INDENT was the original indentation of the block."
>  	     ((eq backend 'latex)
>  	      (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
>  	      (concat "\n#+BEGIN_LaTeX\n"
> -		      (org-add-props (concat (car org-export-latex-verbatim-wrap)
> -					     rtn (cdr org-export-latex-verbatim-wrap))
> +		      (org-add-props
> +                          (if org-export-latex-listings
> +                              (concat
> +                               (if lang
> +                                   (let* ((lang-sym (intern (concat ":" lang)))
> +                                          (lstlang (or (plist-get org-export-latex-listings-langs
> +                                                                  lang-sym)
> +                                                       lang)))
> +                                     (format "\\lstset{language=%s}\n" lstlang))
> +                                 "")
> +                               "\\begin{lstlisting}\n"
> +                               rtn "\\end{lstlisting}\n")
> +                            (concat (car org-export-latex-verbatim-wrap)
> +                                    rtn (cdr org-export-latex-verbatim-wrap)))
>  			  '(org-protected t))
>  		      "#+END_LaTeX\n\n"))
>  	     ((eq backend 'ascii)
> diff --git a/lisp/org-latex.el b/lisp/org-latex.el
> index fdf9ae2..f80e221 100644
> --- a/lisp/org-latex.el
> +++ b/lisp/org-latex.el
> @@ -69,6 +69,9 @@
>  	  org-deadline-string "\\|"
>  	  org-closed-string"\\)")
>    "Regexp matching special time planning keywords plus the time after it.")
> +(defvar org-export-latex-listings nil
> +  "If non-nil then source code blocks will be fontified using the
> +listings package.")
>  
>  (defvar latexp)    ; dynamically scoped from org.el
>  (defvar re-quote)  ; dynamically scoped from org.el
> @@ -297,6 +300,12 @@ Defaults to \\begin{verbatim} and \\end{verbatim}."
>    :type '(cons (string :tag "Open")
>  	       (string :tag "Close")))
>  
> +(defcustom org-export-latex-listings-langs
> +  '(:emacs-lisp "lisp")
> +  "Property list mapping languages to their listing language counterpart."
> +  :group 'org-export-latex
> +  :type 'plist)
> +
>  (defcustom org-export-latex-remove-from-headlines
>    '(:todo nil :priority nil :tags nil)
>    "A plist of keywords to remove from headlines. OBSOLETE.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fontified source-code on latex export with listings package
  2009-08-09 12:54 ` Carsten Dominik
@ 2009-08-11 13:01   ` Eric Schulte
  2009-08-11 13:23     ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2009-08-11 13:01 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Org Mode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> I have added the patch, thanks!
>

Thanks for adding the patch.

>
> Eric, color setup is relative complex, which i why I don't want
> to discuss this in detail in the manual.  Maybe you could write
> a Worg page about this, and/or a FAQ entry?
>

I've added a FAQ entry to worg which encapsulates the *very little* I do
know about using the listings and color packages in LaTeX documents.

http://orgmode.org/worg/org-faq.php#fontified_source_code_w_latex

Best -- Eric

>
> - Carsten
>
> On Aug 8, 2009, at 8:59 PM, Eric Schulte wrote:
>
>> Hi,
>>
>> The attached patch allows for fontified source code blocks on export
>> to
>> LaTeX.  It does this using the 'listings' latex package.  A new
>> variable
>> is introduced; `org-export-latex-listings' which should be set to
>> non-nil for source-code to be exported as listings blocks.  This
>> variable defaults to nil in which case the current practice of
>> exporting
>> source code to verbatim latex blocks remains unchanged.
>>
>> To use this functionality add the following to your org-mode config.
>>
>> --8<---------------cut here---------------start------------->8---
>>  ;; tell org to use listings
>>  (setq org-export-latex-listings t)
>>
>>  ;; you must include the listings package
>>  (add-to-list 'org-export-latex-packages-alist '("" "listings"))
>>
>>  ;; if you want colored source code then you need to include the
>> color package
>>  (add-to-list 'org-export-latex-packages-alist '("" "color"))
>> --8<---------------cut here---------------end--------------->8---
>>
>> In addition to the patch, I'm attaching an example org-mode file,
>> along
>> with the generated LaTeX file and PDF file.
>>
>> Do you think this would be appropriate for inclusion into org-mode?
>>
>> Thanks -- Eric
>>
>> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
>> index 00fd6c8..9de5e5f 100644
>> --- a/lisp/org-exp.el
>> +++ b/lisp/org-exp.el
>> @@ -2204,6 +2204,8 @@ in the list) and remove property and value
>> from the list in LISTVAR."
>> (defvar htmlp)  ;; dynamically scoped
>> (defvar latexp)  ;; dynamically scoped
>> (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
>> +(defvar org-export-latex-listings) ;; defined in org-latex.el
>> +(defvar org-export-latex-listings-langs) ;; defined in org-latex.el
>>
>> (defun org-export-format-source-code-or-example
>>   (backend lang code &optional opts indent)
>> @@ -2310,8 +2312,20 @@ INDENT was the original indentation of the
>> block."
>> 	     ((eq backend 'latex)
>> 	      (setq rtn (org-export-number-lines rtn 'latex 0 0 num
>> cont rpllbl fmt))
>> 	      (concat "\n#+BEGIN_LaTeX\n"
>> -		      (org-add-props (concat (car org-export-latex-verbatim-wrap)
>> -					     rtn (cdr org-export-latex-verbatim-wrap))
>> +		      (org-add-props
>> +                          (if org-export-latex-listings
>> +                              (concat
>> +                               (if lang
>> +                                   (let* ((lang-sym (intern (concat
>> ":" lang)))
>> +                                          (lstlang (or (plist-get
>> org-export-latex-listings-langs
>> +
>> lang-sym)
>> +                                                       lang)))
>> +                                     (format "\\lstset{language=%s}
>> \n" lstlang))
>> +                                 "")
>> +                               "\\begin{lstlisting}\n"
>> +                               rtn "\\end{lstlisting}\n")
>> +                            (concat (car org-export-latex-verbatim-
>> wrap)
>> +                                    rtn (cdr org-export-latex-
>> verbatim-wrap)))
>> 			  '(org-protected t))
>> 		      "#+END_LaTeX\n\n"))
>> 	     ((eq backend 'ascii)
>> diff --git a/lisp/org-latex.el b/lisp/org-latex.el
>> index fdf9ae2..f80e221 100644
>> --- a/lisp/org-latex.el
>> +++ b/lisp/org-latex.el
>> @@ -69,6 +69,9 @@
>> 	  org-deadline-string "\\|"
>> 	  org-closed-string"\\)")
>>   "Regexp matching special time planning keywords plus the time
>> after it.")
>> +(defvar org-export-latex-listings nil
>> +  "If non-nil then source code blocks will be fontified using the
>> +listings package.")
>>
>> (defvar latexp)    ; dynamically scoped from org.el
>> (defvar re-quote)  ; dynamically scoped from org.el
>> @@ -297,6 +300,12 @@ Defaults to \\begin{verbatim} and \
>> \end{verbatim}."
>>   :type '(cons (string :tag "Open")
>> 	       (string :tag "Close")))
>>
>> +(defcustom org-export-latex-listings-langs
>> +  '(:emacs-lisp "lisp")
>> +  "Property list mapping languages to their listing language
>> counterpart."
>> +  :group 'org-export-latex
>> +  :type 'plist)
>> +
>> (defcustom org-export-latex-remove-from-headlines
>>   '(:todo nil :priority nil :tags nil)
>>   "A plist of keywords to remove from headlines. OBSOLETE.
>> <
>> listngs
>> .org
>> >
>> <
>> listngs
>> .tex><listngs.pdf>_______________________________________________
>> Emacs-orgmode mailing list
>> Remember: use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fontified source-code on latex export with listings package
  2009-08-11 13:01   ` Eric Schulte
@ 2009-08-11 13:23     ` Carsten Dominik
  2009-08-11 13:34       ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2009-08-11 13:23 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode

Hi Eric, thanks!

BTW, when adding your patch, I added a few more languages to the  
default settings.

- Carsten

On Aug 11, 2009, at 3:01 PM, Eric Schulte wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> I have added the patch, thanks!
>>
>
> Thanks for adding the patch.
>
>>
>> Eric, color setup is relative complex, which i why I don't want
>> to discuss this in detail in the manual.  Maybe you could write
>> a Worg page about this, and/or a FAQ entry?
>>
>
> I've added a FAQ entry to worg which encapsulates the *very little*  
> I do
> know about using the listings and color packages in LaTeX documents.
>
> http://orgmode.org/worg/org-faq.php#fontified_source_code_w_latex
>
> Best -- Eric
>
>>
>> - Carsten
>>
>> On Aug 8, 2009, at 8:59 PM, Eric Schulte wrote:
>>
>>> Hi,
>>>
>>> The attached patch allows for fontified source code blocks on export
>>> to
>>> LaTeX.  It does this using the 'listings' latex package.  A new
>>> variable
>>> is introduced; `org-export-latex-listings' which should be set to
>>> non-nil for source-code to be exported as listings blocks.  This
>>> variable defaults to nil in which case the current practice of
>>> exporting
>>> source code to verbatim latex blocks remains unchanged.
>>>
>>> To use this functionality add the following to your org-mode config.
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> ;; tell org to use listings
>>> (setq org-export-latex-listings t)
>>>
>>> ;; you must include the listings package
>>> (add-to-list 'org-export-latex-packages-alist '("" "listings"))
>>>
>>> ;; if you want colored source code then you need to include the
>>> color package
>>> (add-to-list 'org-export-latex-packages-alist '("" "color"))
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>> In addition to the patch, I'm attaching an example org-mode file,
>>> along
>>> with the generated LaTeX file and PDF file.
>>>
>>> Do you think this would be appropriate for inclusion into org-mode?
>>>
>>> Thanks -- Eric
>>>
>>> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
>>> index 00fd6c8..9de5e5f 100644
>>> --- a/lisp/org-exp.el
>>> +++ b/lisp/org-exp.el
>>> @@ -2204,6 +2204,8 @@ in the list) and remove property and value
>>> from the list in LISTVAR."
>>> (defvar htmlp)  ;; dynamically scoped
>>> (defvar latexp)  ;; dynamically scoped
>>> (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
>>> +(defvar org-export-latex-listings) ;; defined in org-latex.el
>>> +(defvar org-export-latex-listings-langs) ;; defined in org-latex.el
>>>
>>> (defun org-export-format-source-code-or-example
>>>  (backend lang code &optional opts indent)
>>> @@ -2310,8 +2312,20 @@ INDENT was the original indentation of the
>>> block."
>>> 	     ((eq backend 'latex)
>>> 	      (setq rtn (org-export-number-lines rtn 'latex 0 0 num
>>> cont rpllbl fmt))
>>> 	      (concat "\n#+BEGIN_LaTeX\n"
>>> -		      (org-add-props (concat (car org-export-latex-verbatim-wrap)
>>> -					     rtn (cdr org-export-latex-verbatim-wrap))
>>> +		      (org-add-props
>>> +                          (if org-export-latex-listings
>>> +                              (concat
>>> +                               (if lang
>>> +                                   (let* ((lang-sym (intern (concat
>>> ":" lang)))
>>> +                                          (lstlang (or (plist-get
>>> org-export-latex-listings-langs
>>> +
>>> lang-sym)
>>> +                                                       lang)))
>>> +                                     (format "\\lstset{language=%s}
>>> \n" lstlang))
>>> +                                 "")
>>> +                               "\\begin{lstlisting}\n"
>>> +                               rtn "\\end{lstlisting}\n")
>>> +                            (concat (car org-export-latex-verbatim-
>>> wrap)
>>> +                                    rtn (cdr org-export-latex-
>>> verbatim-wrap)))
>>> 			  '(org-protected t))
>>> 		      "#+END_LaTeX\n\n"))
>>> 	     ((eq backend 'ascii)
>>> diff --git a/lisp/org-latex.el b/lisp/org-latex.el
>>> index fdf9ae2..f80e221 100644
>>> --- a/lisp/org-latex.el
>>> +++ b/lisp/org-latex.el
>>> @@ -69,6 +69,9 @@
>>> 	  org-deadline-string "\\|"
>>> 	  org-closed-string"\\)")
>>>  "Regexp matching special time planning keywords plus the time
>>> after it.")
>>> +(defvar org-export-latex-listings nil
>>> +  "If non-nil then source code blocks will be fontified using the
>>> +listings package.")
>>>
>>> (defvar latexp)    ; dynamically scoped from org.el
>>> (defvar re-quote)  ; dynamically scoped from org.el
>>> @@ -297,6 +300,12 @@ Defaults to \\begin{verbatim} and \
>>> \end{verbatim}."
>>>  :type '(cons (string :tag "Open")
>>> 	       (string :tag "Close")))
>>>
>>> +(defcustom org-export-latex-listings-langs
>>> +  '(:emacs-lisp "lisp")
>>> +  "Property list mapping languages to their listing language
>>> counterpart."
>>> +  :group 'org-export-latex
>>> +  :type 'plist)
>>> +
>>> (defcustom org-export-latex-remove-from-headlines
>>>  '(:todo nil :priority nil :tags nil)
>>>  "A plist of keywords to remove from headlines. OBSOLETE.
>>> <
>>> listngs
>>> .org
>>>>
>>> <
>>> listngs
>>> .tex><listngs.pdf>_______________________________________________
>>> Emacs-orgmode mailing list
>>> Remember: use `Reply All' to send replies to the list.
>>> Emacs-orgmode@gnu.org
>>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fontified source-code on latex export with listings package
  2009-08-11 13:23     ` Carsten Dominik
@ 2009-08-11 13:34       ` Eric Schulte
  2009-08-11 13:46         ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2009-08-11 13:34 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Org Mode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Eric, thanks!
>
> BTW, when adding your patch, I added a few more languages to the
> default settings.
>

Oh, wonderful,

Actually looking at your additions I have a few more which may make
sense.

:gnuplot "Gnuplot"
:ocaml "Caml"
:caml "Caml"
:sql "SQL"

Thanks -- Eric

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fontified source-code on latex export with listings package
  2009-08-11 13:34       ` Eric Schulte
@ 2009-08-11 13:46         ` Carsten Dominik
  0 siblings, 0 replies; 8+ messages in thread
From: Carsten Dominik @ 2009-08-11 13:46 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode

Added, thanks.

- Carsten

On Aug 11, 2009, at 3:34 PM, Eric Schulte wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> Hi Eric, thanks!
>>
>> BTW, when adding your patch, I added a few more languages to the
>> default settings.
>>
>
> Oh, wonderful,
>
> Actually looking at your additions I have a few more which may make
> sense.
>
> :gnuplot "Gnuplot"
> :ocaml "Caml"
> :caml "Caml"
> :sql "SQL"
>
> Thanks -- Eric

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-08-11 13:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-08 18:59 [PATCH] fontified source-code on latex export with listings package Eric Schulte
2009-08-09 10:13 ` Carsten Dominik
2009-08-09 12:54 ` Carsten Dominik
2009-08-11 13:01   ` Eric Schulte
2009-08-11 13:23     ` Carsten Dominik
2009-08-11 13:34       ` Eric Schulte
2009-08-11 13:46         ` Carsten Dominik
2009-08-09 16:48 ` Sebastian Rose

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.