emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sebastian Rose <sebastian_rose@gmx.de>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] fontified source-code on latex export with listings package
Date: Sun, 09 Aug 2009 18:48:08 +0200	[thread overview]
Message-ID: <87y6ptndbr.fsf@kassiopeya.MSHEIMNETZ> (raw)
In-Reply-To: <m2prb6t9lw.fsf@gmail.com> (Eric Schulte's message of "Sat, 08 Aug 2009 12:59:39 -0600")

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.

      parent reply	other threads:[~2009-08-09 16:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y6ptndbr.fsf@kassiopeya.MSHEIMNETZ \
    --to=sebastian_rose@gmx.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).