summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Schmitt <alan.schmitt@polytechnique.org>2015-11-25 08:48:58 +0100
committerAlan Schmitt <alan.schmitt@polytechnique.org>2015-11-30 12:59:12 +0100
commit2aa80849daecaf3c88815ac08d70269b9effb0ca (patch)
treeb7127df24d8492fb4f8314fb45504c48b7b115bc
parent4dd06b2cdfc411e5390f2f6f9d799244a34a34e0 (diff)
downloadorg-mode-2aa80849daecaf3c88815ac08d70269b9effb0ca.tar.gz
ox-latex: Extend custom-lang-environments
* ox-latex.el (org-latex-custom-lang-environments): Extend the documentation string. * ox-latex.el (org-latex-src-block): Allow a custom language environment to be a format string to be directly inserted.
-rw-r--r--lisp/ox-latex.el58
1 files changed, 46 insertions, 12 deletions
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index bbf7f41..eaad29f 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1025,17 +1025,44 @@ 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 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:
+
+ %s 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}
+\\\\begin{minted}{ocaml}
+%s\\\\end{minted}
+\\\\caption{%c}
+\\\\label{%l}\")))
-would have the effect that if org encounters begin_src python
-during latex export it will output
+would have the effect that if Org encounters a Python source block
+during LaTeX export it will produce
\\begin{pythoncode}
<src block body>
- \\end{pythoncode}")
+ \\end{pythoncode}
+
+and if Org encounters an Ocaml source block during LaTeX export it
+will produce
+
+ \\begin{listing}
+ \\begin{minted}{ocaml}
+ <src block body>
+ \\end{minted}
+ \\caption{<caption>}
+ \\label{<label>}
+ \\end{listing}")
;;;; Compilation
@@ -2756,13 +2783,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 (org-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
+ `((?s . ,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))