[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] interaction between org-latex-custom-lang-environments and name

From: Alan Schmitt
Subject: Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex
Date: Wed, 25 Nov 2015 08:59:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin)


Here is a patch that allows the use of a format string in

From e4731375eaf622df0187d47d949fb9f4e53330be Mon Sep 17 00:00:00 2001
From: Alan Schmitt <address@hidden>
Date: Wed, 25 Nov 2015 08:48:58 +0100
Subject: [PATCH] ox-latex: Extend custom-lang-environments

* lisp/ox-latex.el (org-latex-custom-lang-environments): extend the
  documentation string.
* lisp/ox-latex.el (org-latex-src-block): allow a custom language
  environment to be a format string to be directly inserted.
 lisp/ox-latex.el | 50 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index bbf7f41..1b0bff5 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1025,17 +1025,40 @@ block-specific options, you may use the following 
   "Alist mapping languages to language-specific LaTeX environments.
 It is used during export of src blocks by the listings and minted
-latex packages.  For example,
+latex packages.  The environment may either be a simple string,
+composed of only letters and numbers.  In this case, the string is
+directly the name of the latex environment to use.  The environment
+may also be a format string.  In this case the format string will be
+directly exported.  This format string may contain these elements:
+  %c for the formatted source
+  %C for the caption
+  %f for the float attribute
+  %l for an appropriate label 
+For example,
   (setq org-latex-custom-lang-environments
-     '((python \"pythoncode\")))
+     '((python \"pythoncode\")
+       (ocaml 
 would have the effect that if org encounters begin_src python
 during latex export it will output
   <src block body>
-  \\end{pythoncode}")
+  \\end{pythoncode}
+and if org encounters begin_src ocaml during latex export it will
+  \\begin{listing}
+  \\begin{minted}{ocaml}
+  <src block body>
+  \\end{minted}
+  \\caption{<caption>}
+  \\label{<label>}
+  \\end{listing}")
 ;;;; Compilation
@@ -2756,13 +2779,20 @@ contextual information."
                           (org-export-format-code-default src-block info))))))
        ;; Case 2.  Custom environment.
-       (let ((caption-str (org-latex--caption/label-string src-block info)))
-         (format "\\begin{%s}\n%s\\end{%s}\n"
-                 custom-env
-                 (concat (and caption-above-p caption-str)
-                         (org-export-format-code-default src-block info)
-                         (and (not caption-above-p) caption-str))
-                 custom-env)))
+       (let ((caption-str (org-latex--caption/label-string src-block info))
+              (formatted-src (org-export-format-code-default src-block info)))
+          (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
+             (format "\\begin{%s}\n%s\\end{%s}\n"
+                     custom-env
+                     (concat (and caption-above-p caption-str)
+                             formatted-src
+                             (and (not caption-above-p) caption-str))
+                     custom-env)
+           (format-spec custom-env
+                        `((?c . ,formatted-src)
+                          (?C . ,caption)
+                          (?f . ,float)
+                          (?l . ,(org-latex--label src-block info)))))))
        ;; Case 3.  Use minted package.
        ((eq listings 'minted)
        (let* ((caption-str (org-latex--caption/label-string src-block info))



OpenPGP Key ID : 040D0A3B4ED2E5C7
Athmospheric CO₂ (Updated November 22, 2015, Mauna Loa Obs.): 400.35 ppm

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]