emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alan Schmitt <alan.schmitt@polytechnique.org>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode@gnu.org
Subject: Re: interaction between org-latex-custom-lang-environments and name when exporting to latex
Date: Wed, 25 Nov 2015 08:59:59 +0100	[thread overview]
Message-ID: <m2a8q2wlts.fsf@polytechnique.org> (raw)
In-Reply-To: <87vb8rbkum.fsf@gmx.us> (rasmus@gmx.us's message of "Tue, 24 Nov 2015 14:14:25 +0100")


[-- Attachment #1.1: Type: text/plain, Size: 93 bytes --]

Hello,

Here is a patch that allows the use of a format string in
custom-lang-environments.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-ox-latex-Extend-custom-lang-environments.patch --]
[-- Type: text/x-patch, Size: 3383 bytes --]

From e4731375eaf622df0187d47d949fb9f4e53330be Mon Sep 17 00:00:00 2001
From: Alan Schmitt <alan.schmitt@polytechnique.org>
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 syntax:
   "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 \"\\\\begin{listing}\\n\\\\begin{minted}{ocaml}%c\\\\end{minted}\\n\\\\caption{%C}\\n\\\\label{%l}\")))
 
 would have the effect that if org encounters begin_src python
 during latex export it will output
 
   \\begin{pythoncode}
   <src block body>
-  \\end{pythoncode}")
+  \\end{pythoncode}
+
+and if org encounters begin_src ocaml during latex export it will
+output
+
+  \\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.
        (custom-env
-	(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))
-- 
2.6.3


[-- Attachment #1.3: Type: text/plain, Size: 135 bytes --]


Best,

Alan

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

  reply	other threads:[~2015-11-25  8:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 12:59 interaction between org-latex-custom-lang-environments and name when exporting to latex Alan Schmitt
2015-11-20  7:55 ` Alan Schmitt
2015-11-20 10:41   ` Rasmus
2015-11-20 11:06     ` Alan Schmitt
2015-11-23 11:13     ` Alan Schmitt
2015-11-23 17:54       ` Rasmus
2015-11-24  8:07         ` Alan Schmitt
2015-11-24 13:14           ` Rasmus
2015-11-25  7:59             ` Alan Schmitt [this message]
2015-11-25  9:57               ` Rasmus
2015-11-27 16:27                 ` Alan Schmitt
2015-11-27 21:05                   ` Rasmus
2015-11-30 12:12                     ` Alan Schmitt
2015-11-30 13:11                       ` Rasmus
2015-12-01  8:14                         ` Alan Schmitt

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=m2a8q2wlts.fsf@polytechnique.org \
    --to=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=rasmus@gmx.us \
    /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).