From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [PATCH] fontified source-code on latex export with listings package Date: Tue, 11 Aug 2009 15:23:25 +0200 Message-ID: <76906100-71F8-4727-8162-4FD2373CF092@gmail.com> References: <077F1427-4DE7-4246-A0EC-BAEB0029FB62@gmail.com> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MarKA-0004ql-RF for emacs-orgmode@gnu.org; Tue, 11 Aug 2009 09:23:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MarK6-0004oC-8i for emacs-orgmode@gnu.org; Tue, 11 Aug 2009 09:23:34 -0400 Received: from [199.232.76.173] (port=52281 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MarK6-0004o9-5M for emacs-orgmode@gnu.org; Tue, 11 Aug 2009 09:23:30 -0400 Received: from mail-ew0-f211.google.com ([209.85.219.211]:64861) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MarK5-0005qI-OX for emacs-orgmode@gnu.org; Tue, 11 Aug 2009 09:23:30 -0400 Received: by ewy7 with SMTP id 7so4281750ewy.42 for ; Tue, 11 Aug 2009 06:23:28 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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 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>_______________________________________________ >>> 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