emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
@ 2013-04-14 17:48 Eric Schulte
  2013-04-14 19:26 ` Nicolas Goaziou
  2013-04-14 20:02 ` Daimrod
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Schulte @ 2013-04-14 17:48 UTC (permalink / raw)
  To: Org Mode Mailing List

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

Please see the attached patch, I'd love for this to be applied.

Cheers,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-customizable-verbatim-export-for-LaTeX-fancyvrb.patch --]
[-- Type: text/x-patch, Size: 4345 bytes --]

From 04358f2eecf99e43f79956f0d3bc66aa0ab4b95d Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@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)
 
 \f
 ;;; 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


[-- Attachment #3: Type: text/plain, Size: 46 bytes --]


-- 
Eric Schulte
http://cs.unm.edu/~eschulte

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

* Re: [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
  2013-04-14 17:48 [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb) Eric Schulte
@ 2013-04-14 19:26 ` Nicolas Goaziou
  2013-04-14 23:25   ` Bastien
  2013-04-14 20:02 ` Daimrod
  1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2013-04-14 19:26 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode Mailing List

Eric Schulte <schulte.eric@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

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

* Re: [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
  2013-04-14 17:48 [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb) Eric Schulte
  2013-04-14 19:26 ` Nicolas Goaziou
@ 2013-04-14 20:02 ` Daimrod
  1 sibling, 0 replies; 7+ messages in thread
From: Daimrod @ 2013-04-14 20:02 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode Mailing List

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

Eric Schulte <schulte.eric@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

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

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

* Re: [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
  2013-04-14 19:26 ` Nicolas Goaziou
@ 2013-04-14 23:25   ` Bastien
  2013-04-15  0:07     ` Thomas S. Dye
  2013-04-15  0:25     ` Eric Schulte
  0 siblings, 2 replies; 7+ messages in thread
From: Bastien @ 2013-04-14 23:25 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode Mailing List, Eric Schulte

Nicolas Goaziou <n.goaziou@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

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

* Re: [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
  2013-04-14 23:25   ` Bastien
@ 2013-04-15  0:07     ` Thomas S. Dye
  2013-04-15  0:25     ` Eric Schulte
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas S. Dye @ 2013-04-15  0:07 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode Mailing List, Nicolas Goaziou, Eric Schulte

Bastien <bzg@gnu.org> writes:

> Nicolas Goaziou <n.goaziou@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

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

* Re: [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
  2013-04-14 23:25   ` Bastien
  2013-04-15  0:07     ` Thomas S. Dye
@ 2013-04-15  0:25     ` Eric Schulte
  2013-04-15  5:40       ` Nicolas Goaziou
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Schulte @ 2013-04-15  0:25 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode Mailing List, Nicolas Goaziou

Bastien <bzg@gnu.org> writes:

> Nicolas Goaziou <n.goaziou@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

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

* Re: [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb)
  2013-04-15  0:25     ` Eric Schulte
@ 2013-04-15  5:40       ` Nicolas Goaziou
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2013-04-15  5:40 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Bastien, Org Mode Mailing List

Hello,

Eric Schulte <schulte.eric@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

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

end of thread, other threads:[~2013-04-15  5:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-14 17:48 [patch] ox-latex.el to allow customization of verbatim environments (e.g., to use fancyvrb) Eric Schulte
2013-04-14 19:26 ` Nicolas Goaziou
2013-04-14 23:25   ` Bastien
2013-04-15  0:07     ` Thomas S. Dye
2013-04-15  0:25     ` Eric Schulte
2013-04-15  5:40       ` Nicolas Goaziou
2013-04-14 20:02 ` Daimrod

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).