[O] [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
Please see the attached patch, I'd love for this to be applied. Cheers, From 04358f2eecf99e43f79956f0d3bc66aa0ab4b95d Mon Sep 17 00:00:00 2001 From: Eric Schulte schulte.e...@gmail.com Date: Sun, 14 Apr 2013 11:43:30 -0600 Subject: [PATCH 3/3] customizable verbatim export for LaTeX (fancyvrb) This patch allows custom export of verbatim environments to LaTeX. Allowing the usage of packages such as fancyvrb. * lisp/ox-latex.el (org-latex-verbatim-env): New defcustom allowing customization of verbatim export for latex. (org-latex-example-block): Use new defcustom verbatim environment. (org-latex-fixed-width): Use new defcustom verbatim environment. (org-latex-quote-section): Use new defcustom verbatim environment. (org-latex-src-block): Use new defcustom verbatim environment. (org-latex-table): Use new defcustom verbatim environment. --- lisp/ox-latex.el | 40 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 5975ce2..91747c3 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -957,6 +957,14 @@ log of a latex-run. (string :tag Regexp) (string :tag Message +(defcustom org-latex-verbatim-env + verbatim + Environment to use for verbatim markup in latex export. +To use the fancyvrb package set this variable to \Verbatim\. + :group 'org-export-latex + :version 24.4 + :package-version '(Org . 8.0) + :type 'string) ;;; Internal Functions @@ -1320,8 +1328,10 @@ information. (when (org-string-nw-p (org-element-property :value example-block)) (org-latex--wrap-label example-block - (format \\begin{verbatim}\n%s\\end{verbatim} - (org-export-format-code-default example-block info) + (format \\begin{%s}\n%s\\end{%s} + org-latex-verbatim-env + (org-export-format-code-default example-block info) + org-latex-verbatim-env Export Block @@ -1349,9 +1359,11 @@ CONTENTS is nil. INFO is a plist holding contextual information. CONTENTS is nil. INFO is a plist holding contextual information. (org-latex--wrap-label fixed-width - (format \\begin{verbatim}\n%s\\end{verbatim} + (format \\begin{%s}\n%s\\end{%s} + org-latex-verbatim-env (org-remove-indentation - (org-element-property :value fixed-width) + (org-element-property :value fixed-width)) + org-latex-verbatim-env))) Footnote Reference @@ -2098,8 +2110,8 @@ holding contextual information. CONTENTS is nil. INFO is a plist holding contextual information. (let ((value (org-remove-indentation (org-element-property :value quote-section -(when value (format \\begin{verbatim}\n%s\\end{verbatim} value - +(when value (format \\begin{%s}\n%s\\end{%s} + org-latex-verbatim-env value org-latex-verbatim-env Radio Target @@ -2171,8 +2183,10 @@ contextual information. caption-str (format (or float-env %s) - (concat (format \\begin{verbatim}\n%s\\end{verbatim} - (org-export-format-code-default src-block info)) + (concat (format \\begin{%s}\n%s\\end{%s} + org-latex-verbatim-env + (org-export-format-code-default src-block info) + org-latex-verbatim-env) ;; Case 2. Custom environment. (custom-env (format \\begin{%s}\n%s\\end{%s}\n custom-env @@ -2377,10 +2391,12 @@ contextual information. (cond ;; Case 1: Verbatim table. ((string= type verbatim) - (format \\begin{verbatim}\n%s\n\\end{verbatim} + (format \\begin{%s}\n%s\n\\end{%s} + org-latex-verbatim-env ;; Re-create table, without affiliated keywords. (org-trim (org-element-interpret-data - `(table nil ,@(org-element-contents table)) + `(table nil ,@(org-element-contents table + org-latex-verbatim-env)) ;; Case 2: Matrix. ((or (string= type math) (string= type inline-math)) (org-latex--math-table table info)) @@ -2741,8 +2757,8 @@ holding contextual information. Transcode a VERBATIM object from Org to LaTeX. CONTENTS is nil. INFO is a plist used as a communication channel. - (org-latex--text-markup (org-element-property :value verbatim) 'verbatim)) - + (org-latex--text-markup (org-element-property :value verbatim) + org-latex-verbatim-env)) Verse Block -- 1.8.2.1 -- Eric Schulte http://cs.unm.edu/~eschulte
Re: [O] [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
Eric Schulte schulte.e...@gmail.com writes: Please see the attached patch, I'd love for this to be applied. You can use a filter function that will replace default verbatim with whatever you want: #+begin_src emacs-lisp (defun my-latex-custom-verbatim (element backend info) (when (org-export-derived-backend-p backend 'latex) (replace-regexp-in-string \\`begin{\\(verbatim\\)} Verbatim (replace-regexp-in-string end{\\(verbatim\\)}\n*\\' Verbatim element nil nil 1) nil nil 1))) (add-to-list 'org-export-filter-example-block-functions 'my-latex-custom-verbatim) (add-to-list 'org-export-filter-fixed-width-functions 'my-latex-custom-verbatim) (add-to-list 'org-export-filter-quote-section-functions 'my-latex-custom-verbatim) (add-to-list 'org-export-filter-src-block-functions 'my-latex-custom-verbatim) (add-to-list 'org-export-filter-table-functions 'my-latex-custom-verbatim) #+end_src I'm not sure a new variable is needed here. After all, that's what filters are for. Regards, -- Nicolas Goaziou
Re: [O] [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
Eric Schulte schulte.e...@gmail.com writes: -(concat (format \\begin{verbatim}\n%s\\end{verbatim} -(org-export-format-code-default src-block info)) +(concat (format \\begin{%s}\n%s\\end{%s} +org-latex-verbatim-env +(org-export-format-code-default src-block info) +org-latex-verbatim-env) IIUC you don't need concat+format here. -- Daimrod/Greg pgp1eukSKehML.pgp Description: PGP signature
Re: [O] [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
Nicolas Goaziou n.goaz...@gmail.com writes: I'm not sure a new variable is needed here. After all, that's what filters are for. Filters are for advanced Emacs users, not normal Emacs users. A normal Emacs users is someone who knows how to set an option but who doesn't know how to write a function. This is always a trade-off: if something is badly needed by users, let's have an option. If something is needed only for a few users, let's encourage someone to share her/his filter(s)*. I don't really have an opinion here: my impression is that the filter is correct in this case. * Btw, maybe we should consider gathering filters in some unique place, so that users can search and find them easily? Either a new directory in Worg or a new repository on the server? This is powerful enough to deserve a separate place IMO. -- Bastien
Re: [O] [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
Bastien b...@gnu.org writes: Nicolas Goaziou n.goaz...@gmail.com writes: I'm not sure a new variable is needed here. After all, that's what filters are for. Filters are for advanced Emacs users, not normal Emacs users. A normal Emacs users is someone who knows how to set an option but who doesn't know how to write a function. This is always a trade-off: if something is badly needed by users, let's have an option. If something is needed only for a few users, let's encourage someone to share her/his filter(s)*. I don't really have an opinion here: my impression is that the filter is correct in this case. * Btw, maybe we should consider gathering filters in some unique place, so that users can search and find them easily? Either a new directory in Worg or a new repository on the server? This is powerful enough to deserve a separate place IMO. Perhaps the Library of Babel would be a good place? All the best, Tom -- Thomas S. Dye http://www.tsdye.com
Re: [O] [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
Bastien b...@gnu.org writes: Nicolas Goaziou n.goaz...@gmail.com writes: I'm not sure a new variable is needed here. After all, that's what filters are for. Filters are for advanced Emacs users, not normal Emacs users. A normal Emacs users is someone who knows how to set an option but who doesn't know how to write a function. This is always a trade-off: if something is badly needed by users, let's have an option. If something is needed only for a few users, let's encourage someone to share her/his filter(s)*. I don't really have an opinion here: my impression is that the filter is correct in this case. Yea, a filter seems appropriate here to me as well. I hadn't thought of this option when proposing the patch. * Btw, maybe we should consider gathering filters in some unique place, so that users can search and find them easily? Either a new directory in Worg or a new repository on the server? This is powerful enough to deserve a separate place IMO. Here's my fancyvrb filter for when such a place is created. (defun org-latex-filter-fancyvrb (text backend info) Convert begin/end{verbatim} to begin/end{Verbatim}. Allows use of the fancyvrb latex package. (when (or (org-export-derived-backend-p backend 'beamer) (org-export-derived-backend-p backend 'latex)) (replace-regexp-in-string \\(begin\\|end\\){verbatim} \\1{Verbatim} text))) (add-to-list 'org-export-filter-final-output-functions 'org-latex-filter-fancyvrb) Cheers, -- Eric Schulte http://cs.unm.edu/~eschulte
Re: [O] [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
Hello, Eric Schulte schulte.e...@gmail.com writes: Here's my fancyvrb filter for when such a place is created. (defun org-latex-filter-fancyvrb (text backend info) Convert begin/end{verbatim} to begin/end{Verbatim}. Allows use of the fancyvrb latex package. (when (or (org-export-derived-backend-p backend 'beamer) (org-export-derived-backend-p backend 'latex)) `beamer' is derived from `latex' so a back-end derived from `beamer' will ultimately be derived from `latex'. Hence: (org-export-derived-backend-p backend 'beamer) can be removed. Regards, -- Nicolas Goaziou